blob: 33f29f277011946ddf397d1fe6578873eb404c19 [file] [log] [blame]
Colin Cross4d9c2d12016-07-29 12:48:20 -07001// Copyright 2016 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 cc
16
17import (
18 "path/filepath"
19
20 "android/soong/android"
21)
22
23// This file handles installing files into their final location
24
25type InstallerProperties struct {
26 // install to a subdirectory of the default install path for the module
Nan Zhang0007d812017-11-07 10:57:05 -080027 Relative_install_path *string `android:"arch_variant"`
Colin Cross4d9c2d12016-07-29 12:48:20 -070028}
29
Colin Crossb916a382016-07-29 17:28:03 -070030type installLocation int
31
32const (
Vishwath Mohan1dd88392017-03-29 22:00:18 -070033 InstallInSystem installLocation = 0
34 InstallInData = iota
35 InstallInSanitizerDir = iota
Colin Crossb916a382016-07-29 17:28:03 -070036)
37
38func NewBaseInstaller(dir, dir64 string, location installLocation) *baseInstaller {
39 return &baseInstaller{
40 dir: dir,
41 dir64: dir64,
42 location: location,
43 }
44}
45
Colin Cross4d9c2d12016-07-29 12:48:20 -070046type baseInstaller struct {
47 Properties InstallerProperties
48
Colin Crossb916a382016-07-29 17:28:03 -070049 dir string
50 dir64 string
Justin Yun8effde42017-06-23 19:24:43 +090051 subDir string
Colin Cross600c9df2016-09-13 12:26:16 -070052 relative string
Colin Crossb916a382016-07-29 17:28:03 -070053 location installLocation
Colin Cross4d9c2d12016-07-29 12:48:20 -070054
55 path android.OutputPath
56}
57
58var _ installer = (*baseInstaller)(nil)
59
Colin Cross42742b82016-08-01 13:20:05 -070060func (installer *baseInstaller) installerProps() []interface{} {
Colin Cross4d9c2d12016-07-29 12:48:20 -070061 return []interface{}{&installer.Properties}
62}
63
Colin Cross9b09f242016-12-07 13:37:42 -080064func (installer *baseInstaller) installDir(ctx ModuleContext) android.OutputPath {
Justin Yun8effde42017-06-23 19:24:43 +090065 dir := installer.dir
Colin Cross4d9c2d12016-07-29 12:48:20 -070066 if ctx.toolchain().Is64Bit() && installer.dir64 != "" {
Justin Yun8effde42017-06-23 19:24:43 +090067 dir = installer.dir64
Colin Cross4d9c2d12016-07-29 12:48:20 -070068 }
69 if !ctx.Host() && !ctx.Arch().Native {
Justin Yun8effde42017-06-23 19:24:43 +090070 dir = filepath.Join(dir, ctx.Arch().ArchType.String())
Colin Cross4d9c2d12016-07-29 12:48:20 -070071 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -070072 if installer.location == InstallInData && ctx.useVndk() {
Justin Yun8effde42017-06-23 19:24:43 +090073 dir = filepath.Join(dir, "vendor")
Dan Willemsen4416e5d2017-04-06 12:43:22 -070074 }
Nan Zhang0007d812017-11-07 10:57:05 -080075 return android.PathForModuleInstall(ctx, dir, installer.subDir,
76 String(installer.Properties.Relative_install_path), installer.relative)
Colin Cross9b09f242016-12-07 13:37:42 -080077}
78
79func (installer *baseInstaller) install(ctx ModuleContext, file android.Path) {
Colin Cross5c517922017-08-31 12:29:17 -070080 installer.path = ctx.InstallFile(installer.installDir(ctx), file.Base(), file)
Colin Cross4d9c2d12016-07-29 12:48:20 -070081}
82
83func (installer *baseInstaller) inData() bool {
Colin Crossb916a382016-07-29 17:28:03 -070084 return installer.location == InstallInData
Colin Cross4d9c2d12016-07-29 12:48:20 -070085}
Dan Willemsen4aa75ca2016-09-28 16:18:03 -070086
Vishwath Mohan1dd88392017-03-29 22:00:18 -070087func (installer *baseInstaller) inSanitizerDir() bool {
88 return installer.location == InstallInSanitizerDir
89}
90
Dan Willemsen4aa75ca2016-09-28 16:18:03 -070091func (installer *baseInstaller) hostToolPath() android.OptionalPath {
92 return android.OptionalPath{}
93}