blob: 30f9612d36a42a54f87408d8f68d8f8997ea44ff [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"`
Inseob Kim800d1142021-06-14 12:03:51 +090028
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 Radcliffe0dbe6152021-10-18 21:56:21 +000032
33 // Install output directly in {partition}/xbin
David Brazdil3eb5a742022-04-26 14:06:30 +010034 Install_in_xbin *bool `android:"arch_variant"`
Colin Cross4d9c2d12016-07-29 12:48:20 -070035}
36
Colin Crossb916a382016-07-29 17:28:03 -070037type installLocation int
38
39const (
Vishwath Mohan1dd88392017-03-29 22:00:18 -070040 InstallInSystem installLocation = 0
41 InstallInData = iota
42 InstallInSanitizerDir = iota
Colin Crossb916a382016-07-29 17:28:03 -070043)
44
45func NewBaseInstaller(dir, dir64 string, location installLocation) *baseInstaller {
46 return &baseInstaller{
47 dir: dir,
48 dir64: dir64,
49 location: location,
50 }
51}
52
Colin Cross4d9c2d12016-07-29 12:48:20 -070053type baseInstaller struct {
54 Properties InstallerProperties
55
Colin Crossb916a382016-07-29 17:28:03 -070056 dir string
57 dir64 string
Justin Yun8effde42017-06-23 19:24:43 +090058 subDir string
Colin Cross600c9df2016-09-13 12:26:16 -070059 relative string
Colin Crossb916a382016-07-29 17:28:03 -070060 location installLocation
Colin Cross4d9c2d12016-07-29 12:48:20 -070061
Colin Cross5c1d5fb2023-11-15 12:39:40 -080062 installDeps android.InstallPaths
63
Colin Cross70dda7e2019-10-01 22:05:35 -070064 path android.InstallPath
Colin Cross4d9c2d12016-07-29 12:48:20 -070065}
66
67var _ installer = (*baseInstaller)(nil)
68
Colin Cross42742b82016-08-01 13:20:05 -070069func (installer *baseInstaller) installerProps() []interface{} {
Colin Cross4d9c2d12016-07-29 12:48:20 -070070 return []interface{}{&installer.Properties}
71}
72
Colin Cross70dda7e2019-10-01 22:05:35 -070073func (installer *baseInstaller) installDir(ctx ModuleContext) android.InstallPath {
Justin Yun8effde42017-06-23 19:24:43 +090074 dir := installer.dir
Colin Cross4d9c2d12016-07-29 12:48:20 -070075 if ctx.toolchain().Is64Bit() && installer.dir64 != "" {
Justin Yun8effde42017-06-23 19:24:43 +090076 dir = installer.dir64
Colin Cross4d9c2d12016-07-29 12:48:20 -070077 }
Inseob Kim800d1142021-06-14 12:03:51 +090078
79 if installer.installInRoot() {
80 dir = ""
Trevor Radcliffe0dbe6152021-10-18 21:56:21 +000081 } else if installer.installInXbin() {
82 dir = "xbin"
Inseob Kim800d1142021-06-14 12:03:51 +090083 }
84
dimitry8d6dde82019-07-11 10:23:53 +020085 if ctx.Target().NativeBridge == android.NativeBridgeEnabled {
86 dir = filepath.Join(dir, ctx.Target().NativeBridgeRelativePath)
Colin Cross3b19f5d2019-09-17 14:45:31 -070087 } else if !ctx.Host() && ctx.Config().HasMultilibConflict(ctx.Arch().ArchType) {
88 dir = filepath.Join(dir, ctx.Arch().ArchType.String())
dimitry8d6dde82019-07-11 10:23:53 +020089 }
Kiyoung Kimaa394802024-01-08 12:55:45 +090090 if installer.location == InstallInData && ctx.InVendorOrProduct() {
Justin Yun5f7f7e82019-11-18 19:52:14 +090091 if ctx.inProduct() {
92 dir = filepath.Join(dir, "product")
93 } else {
94 dir = filepath.Join(dir, "vendor")
95 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -070096 }
Nan Zhang0007d812017-11-07 10:57:05 -080097 return android.PathForModuleInstall(ctx, dir, installer.subDir,
Jiyong Parkb7c24df2019-02-01 12:03:59 +090098 installer.relativeInstallPath(), installer.relative)
Colin Cross9b09f242016-12-07 13:37:42 -080099}
100
101func (installer *baseInstaller) install(ctx ModuleContext, file android.Path) {
Colin Cross5c1d5fb2023-11-15 12:39:40 -0800102 installer.path = ctx.InstallFile(installer.installDir(ctx), file.Base(), file, installer.installDeps...)
103}
104
105func (installer *baseInstaller) installTestData(ctx ModuleContext, data []android.DataPath) {
106 installedData := ctx.InstallTestData(installer.installDir(ctx), data)
107 installer.installDeps = append(installer.installDeps, installedData...)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700108}
109
Paul Duffin0cb37b92020-03-04 14:52:46 +0000110func (installer *baseInstaller) everInstallable() bool {
111 // Most cc modules are installable.
112 return true
113}
114
Colin Cross4d9c2d12016-07-29 12:48:20 -0700115func (installer *baseInstaller) inData() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700116 return installer.location == InstallInData
Colin Cross4d9c2d12016-07-29 12:48:20 -0700117}
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700118
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700119func (installer *baseInstaller) inSanitizerDir() bool {
120 return installer.location == InstallInSanitizerDir
121}
122
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700123func (installer *baseInstaller) hostToolPath() android.OptionalPath {
124 return android.OptionalPath{}
125}
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900126
127func (installer *baseInstaller) relativeInstallPath() string {
128 return String(installer.Properties.Relative_install_path)
129}
Martin Stjernholmbf37d162020-03-31 16:05:34 +0100130
Iván Budnik295da162023-03-10 16:11:26 +0000131func (installer *baseInstaller) makeUninstallable(mod *Module) {
132 mod.ModuleBase.MakeUninstallable()
133}
134
Inseob Kim800d1142021-06-14 12:03:51 +0900135func (installer *baseInstaller) installInRoot() bool {
136 return Bool(installer.Properties.Install_in_root)
137}
Trevor Radcliffe0dbe6152021-10-18 21:56:21 +0000138
139func (installer *baseInstaller) installInXbin() bool {
140 return Bool(installer.Properties.Install_in_xbin)
141}