blob: a133bf20876cc04b9c0b79ea5c6bcf6e3ae75c28 [file] [log] [blame]
Colin Cross4d9c2d12016-07-29 12:48:20 -07001// 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
28
29 // install symlinks to the module
30 Symlinks []string `android:"arch_variant"`
31}
32
Colin Crossb916a382016-07-29 17:28:03 -070033type installLocation int
34
35const (
36 InstallInSystem installLocation = 0
37 InstallInData = iota
38)
39
40func NewBaseInstaller(dir, dir64 string, location installLocation) *baseInstaller {
41 return &baseInstaller{
42 dir: dir,
43 dir64: dir64,
44 location: location,
45 }
46}
47
Colin Cross4d9c2d12016-07-29 12:48:20 -070048type baseInstaller struct {
49 Properties InstallerProperties
50
Colin Crossb916a382016-07-29 17:28:03 -070051 dir string
52 dir64 string
53 location installLocation
Colin Cross4d9c2d12016-07-29 12:48:20 -070054
55 path android.OutputPath
56}
57
58var _ installer = (*baseInstaller)(nil)
59
Colin Cross42742b82016-08-01 13:20:05 -070060func (installer *baseInstaller) installerProps() []interface{} {
Colin Cross4d9c2d12016-07-29 12:48:20 -070061 return []interface{}{&installer.Properties}
62}
63
64func (installer *baseInstaller) install(ctx ModuleContext, file android.Path) {
65 subDir := installer.dir
66 if ctx.toolchain().Is64Bit() && installer.dir64 != "" {
67 subDir = installer.dir64
68 }
69 if !ctx.Host() && !ctx.Arch().Native {
70 subDir = filepath.Join(subDir, ctx.Arch().ArchType.String())
71 }
72 dir := android.PathForModuleInstall(ctx, subDir, installer.Properties.Relative_install_path)
73 installer.path = ctx.InstallFile(dir, file)
74 for _, symlink := range installer.Properties.Symlinks {
75 ctx.InstallSymlink(dir, symlink, installer.path)
76 }
77}
78
79func (installer *baseInstaller) inData() bool {
Colin Crossb916a382016-07-29 17:28:03 -070080 return installer.location == InstallInData
Colin Cross4d9c2d12016-07-29 12:48:20 -070081}