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 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 27 Relative_install_path *string `android:"arch_variant"` 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"` 32 33 // Install output directly in {partition}/xbin 34 Install_in_xbin *bool `android:"arch_vvariant"` 35} 36 37type installLocation int 38 39const ( 40 InstallInSystem installLocation = 0 41 InstallInData = iota 42 InstallInSanitizerDir = iota 43) 44 45func NewBaseInstaller(dir, dir64 string, location installLocation) *baseInstaller { 46 return &baseInstaller{ 47 dir: dir, 48 dir64: dir64, 49 location: location, 50 } 51} 52 53type baseInstaller struct { 54 Properties InstallerProperties 55 56 dir string 57 dir64 string 58 subDir string 59 relative string 60 location installLocation 61 62 path android.InstallPath 63} 64 65var _ installer = (*baseInstaller)(nil) 66 67func (installer *baseInstaller) installerProps() []interface{} { 68 return []interface{}{&installer.Properties} 69} 70 71func (installer *baseInstaller) installDir(ctx ModuleContext) android.InstallPath { 72 dir := installer.dir 73 if ctx.toolchain().Is64Bit() && installer.dir64 != "" { 74 dir = installer.dir64 75 } 76 77 if installer.installInRoot() { 78 dir = "" 79 } else if installer.installInXbin() { 80 dir = "xbin" 81 } 82 83 if ctx.Target().NativeBridge == android.NativeBridgeEnabled { 84 dir = filepath.Join(dir, ctx.Target().NativeBridgeRelativePath) 85 } else if !ctx.Host() && ctx.Config().HasMultilibConflict(ctx.Arch().ArchType) { 86 dir = filepath.Join(dir, ctx.Arch().ArchType.String()) 87 } 88 if installer.location == InstallInData && ctx.useVndk() { 89 if ctx.inProduct() { 90 dir = filepath.Join(dir, "product") 91 } else { 92 dir = filepath.Join(dir, "vendor") 93 } 94 } 95 return android.PathForModuleInstall(ctx, dir, installer.subDir, 96 installer.relativeInstallPath(), installer.relative) 97} 98 99func (installer *baseInstaller) install(ctx ModuleContext, file android.Path) { 100 installer.path = ctx.InstallFile(installer.installDir(ctx), file.Base(), file) 101} 102 103func (installer *baseInstaller) everInstallable() bool { 104 // Most cc modules are installable. 105 return true 106} 107 108func (installer *baseInstaller) inData() bool { 109 return installer.location == InstallInData 110} 111 112func (installer *baseInstaller) inSanitizerDir() bool { 113 return installer.location == InstallInSanitizerDir 114} 115 116func (installer *baseInstaller) hostToolPath() android.OptionalPath { 117 return android.OptionalPath{} 118} 119 120func (installer *baseInstaller) relativeInstallPath() string { 121 return String(installer.Properties.Relative_install_path) 122} 123 124func (installer *baseInstaller) makeUninstallable(mod *Module) { 125 mod.ModuleBase.MakeUninstallable() 126} 127 128func (installer *baseInstaller) installInRoot() bool { 129 return Bool(installer.Properties.Install_in_root) 130} 131 132func (installer *baseInstaller) installInXbin() bool { 133 return Bool(installer.Properties.Install_in_xbin) 134} 135