blob: 1dcf1996bd30d56400ead5155d7504a675295eda [file] [log] [blame]
Dan Willemsen751ae872020-07-16 17:49:05 -07001// Copyright 2020 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 android
16
17func init() {
18 RegisterModuleType("prebuilt_build_tool", prebuiltBuildToolFactory)
19}
20
21type prebuiltBuildToolProperties struct {
22 // Source file to be executed for this build tool
23 Src *string `android:"path,arch_variant"`
24
25 // Extra files that should trigger rules using this tool to rebuild
26 Deps []string `android:"path,arch_variant"`
27
28 // Create a make variable with the specified name that contains the path to
29 // this prebuilt built tool, relative to the root of the source tree.
30 Export_to_make_var *string
31}
32
33type prebuiltBuildTool struct {
34 ModuleBase
35 prebuilt Prebuilt
36
37 properties prebuiltBuildToolProperties
38
39 toolPath OptionalPath
40}
41
42func (t *prebuiltBuildTool) Name() string {
43 return t.prebuilt.Name(t.ModuleBase.Name())
44}
45
46func (t *prebuiltBuildTool) Prebuilt() *Prebuilt {
47 return &t.prebuilt
48}
49
50func (t *prebuiltBuildTool) DepsMutator(ctx BottomUpMutatorContext) {
51 if t.properties.Src == nil {
52 ctx.PropertyErrorf("src", "missing prebuilt source file")
53 }
54}
55
56func (t *prebuiltBuildTool) GenerateAndroidBuildActions(ctx ModuleContext) {
57 sourcePath := t.prebuilt.SingleSourcePath(ctx)
58 installedPath := PathForModuleOut(ctx, t.ModuleBase.Name())
59 deps := PathsForModuleSrc(ctx, t.properties.Deps)
60
61 ctx.Build(pctx, BuildParams{
62 Rule: Symlink,
63 Output: installedPath,
64 Input: sourcePath,
65 Implicits: deps,
66 Args: map[string]string{
67 "fromPath": "$$PWD/" + sourcePath.String(),
68 },
69 })
70
71 t.toolPath = OptionalPathForPath(installedPath)
72}
73
74func (t *prebuiltBuildTool) MakeVars(ctx MakeVarsModuleContext) {
75 if makeVar := String(t.properties.Export_to_make_var); makeVar != "" {
76 ctx.StrictRaw(makeVar, t.toolPath.String())
77 }
78}
79
80func (t *prebuiltBuildTool) HostToolPath() OptionalPath {
81 return t.toolPath
82}
83
84var _ HostToolProvider = &prebuiltBuildTool{}
85
86// prebuilt_build_tool is to declare prebuilts to be used during the build, particularly for use
87// in genrules with the "tools" property.
88func prebuiltBuildToolFactory() Module {
89 module := &prebuiltBuildTool{}
90 module.AddProperties(&module.properties)
91 InitSingleSourcePrebuiltModule(module, &module.properties, "Src")
92 InitAndroidArchModule(module, HostSupportedNoCross, MultilibFirst)
93 return module
94}