blob: ab3d9b4af14cc9ac8ada734bd8bd6963c0eeaf6a [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 (
Nan Zhangd9ec5e72017-12-01 20:00:31 +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
36 path android.OutputPath
37}
38
Nan Zhangd9ec5e72017-12-01 20:00:31 +000039func NewPythonInstaller(dir, dir64 string) *pythonInstaller {
Nan Zhang5323f8e2017-05-10 13:37:54 -070040 return &pythonInstaller{
Nan Zhangd9ec5e72017-12-01 20:00:31 +000041 dir: dir,
42 dir64: dir64,
Nan Zhang5323f8e2017-05-10 13:37:54 -070043 }
44}
45
46var _ installer = (*pythonInstaller)(nil)
47
Nan Zhangd9ec5e72017-12-01 20:00:31 +000048func (installer *pythonInstaller) installDir(ctx android.ModuleContext) android.OutputPath {
49 dir := installer.dir
50 if ctx.Arch().ArchType.Multilib == "lib64" && installer.dir64 != "" {
51 dir = installer.dir64
52 }
53 if !ctx.Host() && !ctx.Arch().Native {
54 dir = filepath.Join(dir, ctx.Arch().ArchType.String())
55 }
56 return android.PathForModuleInstall(ctx, dir, installer.relative)
57}
58
Nan Zhang5323f8e2017-05-10 13:37:54 -070059func (installer *pythonInstaller) install(ctx android.ModuleContext, file android.Path) {
Nan Zhangd9ec5e72017-12-01 20:00:31 +000060 installer.path = ctx.InstallFile(installer.installDir(ctx), file.Base(), file)
Nan Zhang5323f8e2017-05-10 13:37:54 -070061}