| 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"` | 
| Inseob Kim | 800d114 | 2021-06-14 12:03:51 +0900 | [diff] [blame] | 28 |  | 
|  | 29 | // Install output directly in {partition}/, not in any subdir.  This is only intended for use by | 
|  | 30 | // init_first_stage. | 
|  | 31 | Install_in_root *bool `android:"arch_variant"` | 
| Trevor Radcliffe | 0dbe615 | 2021-10-18 21:56:21 +0000 | [diff] [blame] | 32 |  | 
|  | 33 | // Install output directly in {partition}/xbin | 
| David Brazdil | 3eb5a74 | 2022-04-26 14:06:30 +0100 | [diff] [blame] | 34 | Install_in_xbin *bool `android:"arch_variant"` | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 35 | } | 
|  | 36 |  | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 37 | type installLocation int | 
|  | 38 |  | 
|  | 39 | const ( | 
| Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 40 | InstallInSystem       installLocation = 0 | 
|  | 41 | InstallInData                         = iota | 
|  | 42 | InstallInSanitizerDir                 = iota | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 43 | ) | 
|  | 44 |  | 
|  | 45 | func NewBaseInstaller(dir, dir64 string, location installLocation) *baseInstaller { | 
|  | 46 | return &baseInstaller{ | 
|  | 47 | dir:      dir, | 
|  | 48 | dir64:    dir64, | 
|  | 49 | location: location, | 
|  | 50 | } | 
|  | 51 | } | 
|  | 52 |  | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 53 | type baseInstaller struct { | 
|  | 54 | Properties InstallerProperties | 
|  | 55 |  | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 56 | dir      string | 
|  | 57 | dir64    string | 
| Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 58 | subDir   string | 
| Colin Cross | 600c9df | 2016-09-13 12:26:16 -0700 | [diff] [blame] | 59 | relative string | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 60 | location installLocation | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 61 |  | 
| Colin Cross | 5c1d5fb | 2023-11-15 12:39:40 -0800 | [diff] [blame] | 62 | installDeps android.InstallPaths | 
|  | 63 |  | 
| Colin Cross | 70dda7e | 2019-10-01 22:05:35 -0700 | [diff] [blame] | 64 | path android.InstallPath | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 65 | } | 
|  | 66 |  | 
|  | 67 | var _ installer = (*baseInstaller)(nil) | 
|  | 68 |  | 
| Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 69 | func (installer *baseInstaller) installerProps() []interface{} { | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 70 | return []interface{}{&installer.Properties} | 
|  | 71 | } | 
|  | 72 |  | 
| Colin Cross | 70dda7e | 2019-10-01 22:05:35 -0700 | [diff] [blame] | 73 | func (installer *baseInstaller) installDir(ctx ModuleContext) android.InstallPath { | 
| Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 74 | dir := installer.dir | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 75 | if ctx.toolchain().Is64Bit() && installer.dir64 != "" { | 
| Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 76 | dir = installer.dir64 | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 77 | } | 
| Inseob Kim | 800d114 | 2021-06-14 12:03:51 +0900 | [diff] [blame] | 78 |  | 
|  | 79 | if installer.installInRoot() { | 
|  | 80 | dir = "" | 
| Trevor Radcliffe | 0dbe615 | 2021-10-18 21:56:21 +0000 | [diff] [blame] | 81 | } else if installer.installInXbin() { | 
|  | 82 | dir = "xbin" | 
| Inseob Kim | 800d114 | 2021-06-14 12:03:51 +0900 | [diff] [blame] | 83 | } | 
|  | 84 |  | 
| dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 85 | if ctx.Target().NativeBridge == android.NativeBridgeEnabled { | 
|  | 86 | dir = filepath.Join(dir, ctx.Target().NativeBridgeRelativePath) | 
| Colin Cross | 3b19f5d | 2019-09-17 14:45:31 -0700 | [diff] [blame] | 87 | } else if !ctx.Host() && ctx.Config().HasMultilibConflict(ctx.Arch().ArchType) { | 
|  | 88 | dir = filepath.Join(dir, ctx.Arch().ArchType.String()) | 
| dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 89 | } | 
| Kiyoung Kim | aa39480 | 2024-01-08 12:55:45 +0900 | [diff] [blame] | 90 | if installer.location == InstallInData && ctx.InVendorOrProduct() { | 
| Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 91 | if ctx.inProduct() { | 
|  | 92 | dir = filepath.Join(dir, "product") | 
|  | 93 | } else { | 
|  | 94 | dir = filepath.Join(dir, "vendor") | 
|  | 95 | } | 
| Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 96 | } | 
| Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 97 | return android.PathForModuleInstall(ctx, dir, installer.subDir, | 
| Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 98 | installer.relativeInstallPath(), installer.relative) | 
| Colin Cross | 9b09f24 | 2016-12-07 13:37:42 -0800 | [diff] [blame] | 99 | } | 
|  | 100 |  | 
|  | 101 | func (installer *baseInstaller) install(ctx ModuleContext, file android.Path) { | 
| Colin Cross | 5c1d5fb | 2023-11-15 12:39:40 -0800 | [diff] [blame] | 102 | installer.path = ctx.InstallFile(installer.installDir(ctx), file.Base(), file, installer.installDeps...) | 
|  | 103 | } | 
|  | 104 |  | 
|  | 105 | func (installer *baseInstaller) installTestData(ctx ModuleContext, data []android.DataPath) { | 
|  | 106 | installedData := ctx.InstallTestData(installer.installDir(ctx), data) | 
|  | 107 | installer.installDeps = append(installer.installDeps, installedData...) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 108 | } | 
|  | 109 |  | 
| Paul Duffin | 0cb37b9 | 2020-03-04 14:52:46 +0000 | [diff] [blame] | 110 | func (installer *baseInstaller) everInstallable() bool { | 
|  | 111 | // Most cc modules are installable. | 
|  | 112 | return true | 
|  | 113 | } | 
|  | 114 |  | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 115 | func (installer *baseInstaller) inData() bool { | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 116 | return installer.location == InstallInData | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 117 | } | 
| Dan Willemsen | 4aa75ca | 2016-09-28 16:18:03 -0700 | [diff] [blame] | 118 |  | 
| Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 119 | func (installer *baseInstaller) inSanitizerDir() bool { | 
|  | 120 | return installer.location == InstallInSanitizerDir | 
|  | 121 | } | 
|  | 122 |  | 
| Dan Willemsen | 4aa75ca | 2016-09-28 16:18:03 -0700 | [diff] [blame] | 123 | func (installer *baseInstaller) hostToolPath() android.OptionalPath { | 
|  | 124 | return android.OptionalPath{} | 
|  | 125 | } | 
| Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 126 |  | 
|  | 127 | func (installer *baseInstaller) relativeInstallPath() string { | 
|  | 128 | return String(installer.Properties.Relative_install_path) | 
|  | 129 | } | 
| Martin Stjernholm | bf37d16 | 2020-03-31 16:05:34 +0100 | [diff] [blame] | 130 |  | 
| Iván Budnik | 295da16 | 2023-03-10 16:11:26 +0000 | [diff] [blame] | 131 | func (installer *baseInstaller) makeUninstallable(mod *Module) { | 
|  | 132 | mod.ModuleBase.MakeUninstallable() | 
|  | 133 | } | 
|  | 134 |  | 
| Inseob Kim | 800d114 | 2021-06-14 12:03:51 +0900 | [diff] [blame] | 135 | func (installer *baseInstaller) installInRoot() bool { | 
|  | 136 | return Bool(installer.Properties.Install_in_root) | 
|  | 137 | } | 
| Trevor Radcliffe | 0dbe615 | 2021-10-18 21:56:21 +0000 | [diff] [blame] | 138 |  | 
|  | 139 | func (installer *baseInstaller) installInXbin() bool { | 
|  | 140 | return Bool(installer.Properties.Install_in_xbin) | 
|  | 141 | } |