blob: 515cc47f2559a377df585d46cf9006185ed518ca [file] [log] [blame]
Nan Zhang5323f8e2017-05-10 13:37:54 -07001// 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
15package python
16
17import (
Colin Cross402be412019-09-18 21:12:18 +000018 "path/filepath"
19
Nan Zhang5323f8e2017-05-10 13:37:54 -070020 "android/soong/android"
21)
22
23// This file handles installing python executables into their final location
24
Nan Zhangd9ec5e72017-12-01 20:00:31 +000025type installLocation int
26
27const (
28 InstallInData installLocation = iota
29)
30
Nan Zhang5323f8e2017-05-10 13:37:54 -070031type pythonInstaller struct {
Nan Zhangd9ec5e72017-12-01 20:00:31 +000032 dir string
33 dir64 string
34 relative string
Nan Zhang5323f8e2017-05-10 13:37:54 -070035
Colin Cross70dda7e2019-10-01 22:05:35 -070036 path android.InstallPath
Logan Chien02880e42018-11-06 17:30:35 +080037
38 androidMkSharedLibs []string
Wei Li664a4fd2021-10-07 06:26:48 +000039 module *Module
Nan Zhang5323f8e2017-05-10 13:37:54 -070040}
41
Wei Li664a4fd2021-10-07 06:26:48 +000042func NewPythonInstaller(dir, dir64 string, module *Module) *pythonInstaller {
Nan Zhang5323f8e2017-05-10 13:37:54 -070043 return &pythonInstaller{
Wei Li664a4fd2021-10-07 06:26:48 +000044 dir: dir,
45 dir64: dir64,
46 module: module,
Nan Zhang5323f8e2017-05-10 13:37:54 -070047 }
48}
49
50var _ installer = (*pythonInstaller)(nil)
51
Colin Cross70dda7e2019-10-01 22:05:35 -070052func (installer *pythonInstaller) installDir(ctx android.ModuleContext) android.InstallPath {
Nan Zhangd9ec5e72017-12-01 20:00:31 +000053 dir := installer.dir
54 if ctx.Arch().ArchType.Multilib == "lib64" && installer.dir64 != "" {
55 dir = installer.dir64
56 }
Colin Cross3b19f5d2019-09-17 14:45:31 -070057 if !ctx.Host() && ctx.Config().HasMultilibConflict(ctx.Arch().ArchType) {
Colin Cross402be412019-09-18 21:12:18 +000058 dir = filepath.Join(dir, ctx.Arch().ArchType.String())
59 }
Nan Zhangd9ec5e72017-12-01 20:00:31 +000060 return android.PathForModuleInstall(ctx, dir, installer.relative)
61}
62
Nan Zhang5323f8e2017-05-10 13:37:54 -070063func (installer *pythonInstaller) install(ctx android.ModuleContext, file android.Path) {
Wei Li664a4fd2021-10-07 06:26:48 +000064 if ctx.ModuleType() == "python_binary_host" && installer.module.MixedBuildsEnabled(ctx) {
65 label := installer.module.BazelModuleBase.GetBazelLabel(ctx, installer.module)
66 binary, _ := ctx.Config().BazelContext.GetPythonBinary(label, android.GetConfigKey(ctx))
67 bazelBinaryOutPath := android.PathForBazelOut(ctx, binary)
68 installer.path = ctx.InstallFile(installer.installDir(ctx), bazelBinaryOutPath.Base(), bazelBinaryOutPath)
69 } else {
70 installer.path = ctx.InstallFile(installer.installDir(ctx), file.Base(), file)
71 }
Nan Zhang5323f8e2017-05-10 13:37:54 -070072}
Logan Chien02880e42018-11-06 17:30:35 +080073
74func (installer *pythonInstaller) setAndroidMkSharedLibs(sharedLibs []string) {
75 installer.androidMkSharedLibs = sharedLibs
76}