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