Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
| 18 | "path/filepath" |
| 19 | |
| 20 | "android/soong/android" |
| 21 | ) |
| 22 | |
| 23 | // This file handles installing files into their final location |
| 24 | |
| 25 | type InstallerProperties struct { |
| 26 | // install to a subdirectory of the default install path for the module |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 27 | Relative_install_path *string `android:"arch_variant"` |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 28 | } |
| 29 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 30 | type installLocation int |
| 31 | |
| 32 | const ( |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 33 | InstallInSystem installLocation = 0 |
| 34 | InstallInData = iota |
| 35 | InstallInSanitizerDir = iota |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 36 | ) |
| 37 | |
| 38 | func NewBaseInstaller(dir, dir64 string, location installLocation) *baseInstaller { |
| 39 | return &baseInstaller{ |
| 40 | dir: dir, |
| 41 | dir64: dir64, |
| 42 | location: location, |
| 43 | } |
| 44 | } |
| 45 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 46 | type baseInstaller struct { |
| 47 | Properties InstallerProperties |
| 48 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 49 | dir string |
| 50 | dir64 string |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 51 | subDir string |
Colin Cross | 600c9df | 2016-09-13 12:26:16 -0700 | [diff] [blame] | 52 | relative string |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 53 | location installLocation |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 54 | |
| 55 | path android.OutputPath |
| 56 | } |
| 57 | |
| 58 | var _ installer = (*baseInstaller)(nil) |
| 59 | |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 60 | func (installer *baseInstaller) installerProps() []interface{} { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 61 | return []interface{}{&installer.Properties} |
| 62 | } |
| 63 | |
Colin Cross | 9b09f24 | 2016-12-07 13:37:42 -0800 | [diff] [blame] | 64 | func (installer *baseInstaller) installDir(ctx ModuleContext) android.OutputPath { |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 65 | dir := installer.dir |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 66 | if ctx.toolchain().Is64Bit() && installer.dir64 != "" { |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 67 | dir = installer.dir64 |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 68 | } |
| 69 | if !ctx.Host() && !ctx.Arch().Native { |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 70 | dir = filepath.Join(dir, ctx.Arch().ArchType.String()) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 71 | } |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 72 | if installer.location == InstallInData && ctx.useVndk() { |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 73 | dir = filepath.Join(dir, "vendor") |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 74 | } |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 75 | return android.PathForModuleInstall(ctx, dir, installer.subDir, |
| 76 | String(installer.Properties.Relative_install_path), installer.relative) |
Colin Cross | 9b09f24 | 2016-12-07 13:37:42 -0800 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | func (installer *baseInstaller) install(ctx ModuleContext, file android.Path) { |
Colin Cross | 5c51792 | 2017-08-31 12:29:17 -0700 | [diff] [blame] | 80 | installer.path = ctx.InstallFile(installer.installDir(ctx), file.Base(), file) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | func (installer *baseInstaller) inData() bool { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 84 | return installer.location == InstallInData |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 85 | } |
Dan Willemsen | 4aa75ca | 2016-09-28 16:18:03 -0700 | [diff] [blame] | 86 | |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 87 | func (installer *baseInstaller) inSanitizerDir() bool { |
| 88 | return installer.location == InstallInSanitizerDir |
| 89 | } |
| 90 | |
Dan Willemsen | 4aa75ca | 2016-09-28 16:18:03 -0700 | [diff] [blame] | 91 | func (installer *baseInstaller) hostToolPath() android.OptionalPath { |
| 92 | return android.OptionalPath{} |
| 93 | } |