• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.OutputPath
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.OutputPath {
65	dir := installer.dir
66	if ctx.toolchain().Is64Bit() && installer.dir64 != "" {
67		dir = installer.dir64
68	}
69	if !ctx.Host() && !ctx.Arch().Native {
70		dir = filepath.Join(dir, ctx.Arch().ArchType.String())
71	}
72	if installer.location == InstallInData && ctx.useVndk() {
73		dir = filepath.Join(dir, "vendor")
74	}
75	return android.PathForModuleInstall(ctx, dir, installer.subDir,
76		installer.relativeInstallPath(), installer.relative)
77}
78
79func (installer *baseInstaller) install(ctx ModuleContext, file android.Path) {
80	installer.path = ctx.InstallFile(installer.installDir(ctx), file.Base(), file)
81}
82
83func (installer *baseInstaller) inData() bool {
84	return installer.location == InstallInData
85}
86
87func (installer *baseInstaller) inSanitizerDir() bool {
88	return installer.location == InstallInSanitizerDir
89}
90
91func (installer *baseInstaller) hostToolPath() android.OptionalPath {
92	return android.OptionalPath{}
93}
94
95func (installer *baseInstaller) relativeInstallPath() string {
96	return String(installer.Properties.Relative_install_path)
97}
98