blob: de04ab64d866a84c37fef4d7a585d3d9329c71ee [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
Colin Cross600c9df2016-09-13 12:26:16 -070027 Relative_install_path string `android:"arch_variant"`
Colin Cross4d9c2d12016-07-29 12:48:20 -070028}
29
Colin Crossb916a382016-07-29 17:28:03 -070030type installLocation int
31
32const (
33 InstallInSystem installLocation = 0
34 InstallInData = iota
35)
36
37func NewBaseInstaller(dir, dir64 string, location installLocation) *baseInstaller {
38 return &baseInstaller{
39 dir: dir,
40 dir64: dir64,
41 location: location,
42 }
43}
44
Colin Cross4d9c2d12016-07-29 12:48:20 -070045type baseInstaller struct {
46 Properties InstallerProperties
47
Colin Crossb916a382016-07-29 17:28:03 -070048 dir string
49 dir64 string
Jiyong Park4c48f722017-01-20 08:57:02 +090050 subDir string
Colin Cross600c9df2016-09-13 12:26:16 -070051 relative string
Colin Crossb916a382016-07-29 17:28:03 -070052 location installLocation
Colin Cross4d9c2d12016-07-29 12:48:20 -070053
54 path android.OutputPath
55}
56
57var _ installer = (*baseInstaller)(nil)
58
Colin Cross42742b82016-08-01 13:20:05 -070059func (installer *baseInstaller) installerProps() []interface{} {
Colin Cross4d9c2d12016-07-29 12:48:20 -070060 return []interface{}{&installer.Properties}
61}
62
Colin Cross9b09f242016-12-07 13:37:42 -080063func (installer *baseInstaller) installDir(ctx ModuleContext) android.OutputPath {
Jiyong Park4c48f722017-01-20 08:57:02 +090064 dir := installer.dir
Colin Cross4d9c2d12016-07-29 12:48:20 -070065 if ctx.toolchain().Is64Bit() && installer.dir64 != "" {
Jiyong Park4c48f722017-01-20 08:57:02 +090066 dir = installer.dir64
Colin Cross4d9c2d12016-07-29 12:48:20 -070067 }
68 if !ctx.Host() && !ctx.Arch().Native {
Jiyong Park4c48f722017-01-20 08:57:02 +090069 dir = filepath.Join(dir, ctx.Arch().ArchType.String())
Colin Cross4d9c2d12016-07-29 12:48:20 -070070 }
Jiyong Park4c48f722017-01-20 08:57:02 +090071 return android.PathForModuleInstall(ctx, dir, installer.subDir, installer.Properties.Relative_install_path, installer.relative)
Colin Cross9b09f242016-12-07 13:37:42 -080072}
73
74func (installer *baseInstaller) install(ctx ModuleContext, file android.Path) {
75 installer.path = ctx.InstallFile(installer.installDir(ctx), file)
Colin Cross4d9c2d12016-07-29 12:48:20 -070076}
77
78func (installer *baseInstaller) inData() bool {
Colin Crossb916a382016-07-29 17:28:03 -070079 return installer.location == InstallInData
Colin Cross4d9c2d12016-07-29 12:48:20 -070080}
Dan Willemsen4aa75ca2016-09-28 16:18:03 -070081
82func (installer *baseInstaller) hostToolPath() android.OptionalPath {
83 return android.OptionalPath{}
84}