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 |
| 27 | Relative_install_path string |
| 28 | |
| 29 | // install symlinks to the module |
| 30 | Symlinks []string `android:"arch_variant"` |
| 31 | } |
| 32 | |
| 33 | type baseInstaller struct { |
| 34 | Properties InstallerProperties |
| 35 | |
| 36 | dir string |
| 37 | dir64 string |
| 38 | data bool |
| 39 | |
| 40 | path android.OutputPath |
| 41 | } |
| 42 | |
| 43 | var _ installer = (*baseInstaller)(nil) |
| 44 | |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame^] | 45 | func (installer *baseInstaller) installerProps() []interface{} { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 46 | return []interface{}{&installer.Properties} |
| 47 | } |
| 48 | |
| 49 | func (installer *baseInstaller) install(ctx ModuleContext, file android.Path) { |
| 50 | subDir := installer.dir |
| 51 | if ctx.toolchain().Is64Bit() && installer.dir64 != "" { |
| 52 | subDir = installer.dir64 |
| 53 | } |
| 54 | if !ctx.Host() && !ctx.Arch().Native { |
| 55 | subDir = filepath.Join(subDir, ctx.Arch().ArchType.String()) |
| 56 | } |
| 57 | dir := android.PathForModuleInstall(ctx, subDir, installer.Properties.Relative_install_path) |
| 58 | installer.path = ctx.InstallFile(dir, file) |
| 59 | for _, symlink := range installer.Properties.Symlinks { |
| 60 | ctx.InstallSymlink(dir, symlink, installer.path) |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | func (installer *baseInstaller) inData() bool { |
| 65 | return installer.data |
| 66 | } |