Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 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 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
| 18 | "path/filepath" |
| 19 | |
| 20 | "android/soong/android" |
| 21 | ) |
| 22 | |
| 23 | // This file handles installing files into their final location |
| 24 | |
| 25 | type InstallerProperties struct { |
| 26 | // install to a subdirectory of the default install path for the module |
Colin Cross | 600c9df | 2016-09-13 12:26:16 -0700 | [diff] [blame^] | 27 | Relative_install_path string `android:"arch_variant"` |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 28 | |
| 29 | // install symlinks to the module |
| 30 | Symlinks []string `android:"arch_variant"` |
| 31 | } |
| 32 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 33 | type installLocation int |
| 34 | |
| 35 | const ( |
| 36 | InstallInSystem installLocation = 0 |
| 37 | InstallInData = iota |
| 38 | ) |
| 39 | |
| 40 | func NewBaseInstaller(dir, dir64 string, location installLocation) *baseInstaller { |
| 41 | return &baseInstaller{ |
| 42 | dir: dir, |
| 43 | dir64: dir64, |
| 44 | location: location, |
| 45 | } |
| 46 | } |
| 47 | |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 48 | type baseInstaller struct { |
| 49 | Properties InstallerProperties |
| 50 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 51 | dir string |
| 52 | dir64 string |
Colin Cross | 600c9df | 2016-09-13 12:26:16 -0700 | [diff] [blame^] | 53 | relative string |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 54 | location installLocation |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 55 | |
| 56 | path android.OutputPath |
| 57 | } |
| 58 | |
| 59 | var _ installer = (*baseInstaller)(nil) |
| 60 | |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 61 | func (installer *baseInstaller) installerProps() []interface{} { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 62 | return []interface{}{&installer.Properties} |
| 63 | } |
| 64 | |
| 65 | func (installer *baseInstaller) install(ctx ModuleContext, file android.Path) { |
| 66 | subDir := installer.dir |
| 67 | if ctx.toolchain().Is64Bit() && installer.dir64 != "" { |
| 68 | subDir = installer.dir64 |
| 69 | } |
| 70 | if !ctx.Host() && !ctx.Arch().Native { |
| 71 | subDir = filepath.Join(subDir, ctx.Arch().ArchType.String()) |
| 72 | } |
Colin Cross | 600c9df | 2016-09-13 12:26:16 -0700 | [diff] [blame^] | 73 | dir := android.PathForModuleInstall(ctx, subDir, installer.Properties.Relative_install_path, installer.relative) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 74 | installer.path = ctx.InstallFile(dir, file) |
| 75 | for _, symlink := range installer.Properties.Symlinks { |
| 76 | ctx.InstallSymlink(dir, symlink, installer.path) |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | func (installer *baseInstaller) inData() bool { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 81 | return installer.location == InstallInData |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 82 | } |