installer.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. package cc
  15. import (
  16. "path/filepath"
  17. "android/soong/android"
  18. )
  19. // This file handles installing files into their final location
  20. type InstallerProperties struct {
  21. // install to a subdirectory of the default install path for the module
  22. Relative_install_path *string `android:"arch_variant"`
  23. // Install output directly in {partition}/, not in any subdir. This is only intended for use by
  24. // init_first_stage.
  25. Install_in_root *bool `android:"arch_variant"`
  26. // Install output directly in {partition}/xbin
  27. Install_in_xbin *bool `android:"arch_variant"`
  28. }
  29. type installLocation int
  30. const (
  31. InstallInSystem installLocation = 0
  32. InstallInData = iota
  33. InstallInSanitizerDir = iota
  34. )
  35. func NewBaseInstaller(dir, dir64 string, location installLocation) *baseInstaller {
  36. return &baseInstaller{
  37. dir: dir,
  38. dir64: dir64,
  39. location: location,
  40. }
  41. }
  42. type baseInstaller struct {
  43. Properties InstallerProperties
  44. dir string
  45. dir64 string
  46. subDir string
  47. relative string
  48. location installLocation
  49. path android.InstallPath
  50. }
  51. var _ installer = (*baseInstaller)(nil)
  52. func (installer *baseInstaller) installerProps() []interface{} {
  53. return []interface{}{&installer.Properties}
  54. }
  55. func (installer *baseInstaller) installDir(ctx ModuleContext) android.InstallPath {
  56. dir := installer.dir
  57. if ctx.toolchain().Is64Bit() && installer.dir64 != "" {
  58. dir = installer.dir64
  59. }
  60. if installer.installInRoot() {
  61. dir = ""
  62. } else if installer.installInXbin() {
  63. dir = "xbin"
  64. }
  65. if ctx.Target().NativeBridge == android.NativeBridgeEnabled {
  66. dir = filepath.Join(dir, ctx.Target().NativeBridgeRelativePath)
  67. } else if !ctx.Host() && ctx.Config().HasMultilibConflict(ctx.Arch().ArchType) {
  68. dir = filepath.Join(dir, ctx.Arch().ArchType.String())
  69. }
  70. if installer.location == InstallInData && ctx.useVndk() {
  71. if ctx.inProduct() {
  72. dir = filepath.Join(dir, "product")
  73. } else {
  74. dir = filepath.Join(dir, "vendor")
  75. }
  76. }
  77. return android.PathForModuleInstall(ctx, dir, installer.subDir,
  78. installer.relativeInstallPath(), installer.relative)
  79. }
  80. func (installer *baseInstaller) install(ctx ModuleContext, file android.Path) {
  81. installer.path = ctx.InstallFile(installer.installDir(ctx), file.Base(), file)
  82. }
  83. func (installer *baseInstaller) everInstallable() bool {
  84. // Most cc modules are installable.
  85. return true
  86. }
  87. func (installer *baseInstaller) inData() bool {
  88. return installer.location == InstallInData
  89. }
  90. func (installer *baseInstaller) inSanitizerDir() bool {
  91. return installer.location == InstallInSanitizerDir
  92. }
  93. func (installer *baseInstaller) hostToolPath() android.OptionalPath {
  94. return android.OptionalPath{}
  95. }
  96. func (installer *baseInstaller) relativeInstallPath() string {
  97. return String(installer.Properties.Relative_install_path)
  98. }
  99. func (installer *baseInstaller) makeUninstallable(mod *Module) {
  100. mod.ModuleBase.MakeUninstallable()
  101. }
  102. func (installer *baseInstaller) installInRoot() bool {
  103. return Bool(installer.Properties.Install_in_root)
  104. }
  105. func (installer *baseInstaller) installInXbin() bool {
  106. return Bool(installer.Properties.Install_in_xbin)
  107. }