blob: f95b49346357ccfa6953591aef83722cd1604def [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"`
Colin Cross4d9c2d12016-07-29 12:48:20 -070032}
33
Colin Crossb916a382016-07-29 17:28:03 -070034type installLocation int
35
36const (
Vishwath Mohan1dd88392017-03-29 22:00:18 -070037 InstallInSystem installLocation = 0
38 InstallInData = iota
39 InstallInSanitizerDir = iota
Colin Crossb916a382016-07-29 17:28:03 -070040)
41
42func NewBaseInstaller(dir, dir64 string, location installLocation) *baseInstaller {
43 return &baseInstaller{
44 dir: dir,
45 dir64: dir64,
46 location: location,
47 }
48}
49
Colin Cross4d9c2d12016-07-29 12:48:20 -070050type baseInstaller struct {
51 Properties InstallerProperties
52
Colin Crossb916a382016-07-29 17:28:03 -070053 dir string
54 dir64 string
Justin Yun8effde42017-06-23 19:24:43 +090055 subDir string
Colin Cross600c9df2016-09-13 12:26:16 -070056 relative string
Colin Crossb916a382016-07-29 17:28:03 -070057 location installLocation
Colin Cross4d9c2d12016-07-29 12:48:20 -070058
Colin Cross70dda7e2019-10-01 22:05:35 -070059 path android.InstallPath
Colin Cross4d9c2d12016-07-29 12:48:20 -070060}
61
62var _ installer = (*baseInstaller)(nil)
63
Colin Cross42742b82016-08-01 13:20:05 -070064func (installer *baseInstaller) installerProps() []interface{} {
Colin Cross4d9c2d12016-07-29 12:48:20 -070065 return []interface{}{&installer.Properties}
66}
67
Colin Cross70dda7e2019-10-01 22:05:35 -070068func (installer *baseInstaller) installDir(ctx ModuleContext) android.InstallPath {
Justin Yun8effde42017-06-23 19:24:43 +090069 dir := installer.dir
Colin Cross4d9c2d12016-07-29 12:48:20 -070070 if ctx.toolchain().Is64Bit() && installer.dir64 != "" {
Justin Yun8effde42017-06-23 19:24:43 +090071 dir = installer.dir64
Colin Cross4d9c2d12016-07-29 12:48:20 -070072 }
Inseob Kim800d1142021-06-14 12:03:51 +090073
74 if installer.installInRoot() {
75 dir = ""
76 }
77
dimitry8d6dde82019-07-11 10:23:53 +020078 if ctx.Target().NativeBridge == android.NativeBridgeEnabled {
79 dir = filepath.Join(dir, ctx.Target().NativeBridgeRelativePath)
Colin Cross3b19f5d2019-09-17 14:45:31 -070080 } else if !ctx.Host() && ctx.Config().HasMultilibConflict(ctx.Arch().ArchType) {
81 dir = filepath.Join(dir, ctx.Arch().ArchType.String())
dimitry8d6dde82019-07-11 10:23:53 +020082 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -070083 if installer.location == InstallInData && ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +090084 if ctx.inProduct() {
85 dir = filepath.Join(dir, "product")
86 } else {
87 dir = filepath.Join(dir, "vendor")
88 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -070089 }
Nan Zhang0007d812017-11-07 10:57:05 -080090 return android.PathForModuleInstall(ctx, dir, installer.subDir,
Jiyong Parkb7c24df2019-02-01 12:03:59 +090091 installer.relativeInstallPath(), installer.relative)
Colin Cross9b09f242016-12-07 13:37:42 -080092}
93
94func (installer *baseInstaller) install(ctx ModuleContext, file android.Path) {
Colin Cross5c517922017-08-31 12:29:17 -070095 installer.path = ctx.InstallFile(installer.installDir(ctx), file.Base(), file)
Colin Cross4d9c2d12016-07-29 12:48:20 -070096}
97
Paul Duffin0cb37b92020-03-04 14:52:46 +000098func (installer *baseInstaller) everInstallable() bool {
99 // Most cc modules are installable.
100 return true
101}
102
Colin Cross4d9c2d12016-07-29 12:48:20 -0700103func (installer *baseInstaller) inData() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700104 return installer.location == InstallInData
Colin Cross4d9c2d12016-07-29 12:48:20 -0700105}
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700106
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700107func (installer *baseInstaller) inSanitizerDir() bool {
108 return installer.location == InstallInSanitizerDir
109}
110
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700111func (installer *baseInstaller) hostToolPath() android.OptionalPath {
112 return android.OptionalPath{}
113}
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900114
115func (installer *baseInstaller) relativeInstallPath() string {
116 return String(installer.Properties.Relative_install_path)
117}
Martin Stjernholmbf37d162020-03-31 16:05:34 +0100118
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +0100119func (installer *baseInstaller) makeUninstallable(mod *Module) {
120 mod.ModuleBase.MakeUninstallable()
Martin Stjernholmbf37d162020-03-31 16:05:34 +0100121}
Inseob Kim800d1142021-06-14 12:03:51 +0900122
123func (installer *baseInstaller) installInRoot() bool {
124 return Bool(installer.Properties.Install_in_root)
125}