Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 1 | // Copyright 2017 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package python |
| 16 | |
| 17 | import ( |
Colin Cross | 402be41 | 2019-09-18 21:12:18 +0000 | [diff] [blame] | 18 | "path/filepath" |
| 19 | |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 20 | "android/soong/android" |
| 21 | ) |
| 22 | |
| 23 | // This file handles installing python executables into their final location |
| 24 | |
Nan Zhang | d9ec5e7 | 2017-12-01 20:00:31 +0000 | [diff] [blame] | 25 | type installLocation int |
| 26 | |
| 27 | const ( |
| 28 | InstallInData installLocation = iota |
| 29 | ) |
| 30 | |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 31 | type pythonInstaller struct { |
Nan Zhang | d9ec5e7 | 2017-12-01 20:00:31 +0000 | [diff] [blame] | 32 | dir string |
| 33 | dir64 string |
| 34 | relative string |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 35 | |
Colin Cross | 70dda7e | 2019-10-01 22:05:35 -0700 | [diff] [blame] | 36 | path android.InstallPath |
Logan Chien | 02880e4 | 2018-11-06 17:30:35 +0800 | [diff] [blame] | 37 | |
| 38 | androidMkSharedLibs []string |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 39 | } |
| 40 | |
Rupert Shuttleworth | ffc4cc4 | 2021-11-03 09:07:26 +0000 | [diff] [blame] | 41 | func NewPythonInstaller(dir, dir64 string) *pythonInstaller { |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 42 | return &pythonInstaller{ |
Rupert Shuttleworth | ffc4cc4 | 2021-11-03 09:07:26 +0000 | [diff] [blame] | 43 | dir: dir, |
| 44 | dir64: dir64, |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 45 | } |
| 46 | } |
| 47 | |
| 48 | var _ installer = (*pythonInstaller)(nil) |
| 49 | |
Colin Cross | 70dda7e | 2019-10-01 22:05:35 -0700 | [diff] [blame] | 50 | func (installer *pythonInstaller) installDir(ctx android.ModuleContext) android.InstallPath { |
Nan Zhang | d9ec5e7 | 2017-12-01 20:00:31 +0000 | [diff] [blame] | 51 | dir := installer.dir |
| 52 | if ctx.Arch().ArchType.Multilib == "lib64" && installer.dir64 != "" { |
| 53 | dir = installer.dir64 |
| 54 | } |
Colin Cross | 3b19f5d | 2019-09-17 14:45:31 -0700 | [diff] [blame] | 55 | if !ctx.Host() && ctx.Config().HasMultilibConflict(ctx.Arch().ArchType) { |
Colin Cross | 402be41 | 2019-09-18 21:12:18 +0000 | [diff] [blame] | 56 | dir = filepath.Join(dir, ctx.Arch().ArchType.String()) |
| 57 | } |
Nan Zhang | d9ec5e7 | 2017-12-01 20:00:31 +0000 | [diff] [blame] | 58 | return android.PathForModuleInstall(ctx, dir, installer.relative) |
| 59 | } |
| 60 | |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 61 | func (installer *pythonInstaller) install(ctx android.ModuleContext, file android.Path) { |
Rupert Shuttleworth | ffc4cc4 | 2021-11-03 09:07:26 +0000 | [diff] [blame] | 62 | installer.path = ctx.InstallFile(installer.installDir(ctx), file.Base(), file) |
Nan Zhang | 5323f8e | 2017-05-10 13:37:54 -0700 | [diff] [blame] | 63 | } |
Logan Chien | 02880e4 | 2018-11-06 17:30:35 +0800 | [diff] [blame] | 64 | |
| 65 | func (installer *pythonInstaller) setAndroidMkSharedLibs(sharedLibs []string) { |
| 66 | installer.androidMkSharedLibs = sharedLibs |
| 67 | } |