blob: c509f312cd3106d32f9ba8806b1e37603087512a [file] [log] [blame]
Dan Willemsen394e9dc2016-09-14 15:04:48 -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 "runtime"
19
20 "github.com/google/blueprint"
21
22 "android/soong/android"
23)
24
25func init() {
26 pctx.SourcePathVariable("relocationPackerCmd", "prebuilts/misc/${config.HostPrebuiltTag}/relocation_packer/relocation_packer")
27}
28
29var relocationPackerRule = pctx.AndroidStaticRule("packRelocations",
30 blueprint.RuleParams{
31 Command: "rm -f $out && cp $in $out && $relocationPackerCmd $out",
32 CommandDeps: []string{"$relocationPackerCmd"},
33 Description: "pack relocations $out",
34 })
35
36type RelocationPackerProperties struct {
37 Pack_relocations *bool `android:"arch_variant"`
38
39 // This will be true even if we're embedded in Make, in which case
40 // we'll defer to make to actually do the packing.
41 PackingRelocations bool `blueprint:"mutated"`
42}
43
44type relocationPacker struct {
45 Properties RelocationPackerProperties
46}
47
48func (p *relocationPacker) packingInit(ctx BaseModuleContext) {
49 enabled := true
50 // Relocation packer isn't available on Darwin yet
51 if runtime.GOOS == "darwin" {
52 enabled = false
53 }
54 if ctx.Target().Os != android.Android {
55 enabled = false
56 }
57 if ctx.AConfig().Getenv("DISABLE_RELOCATION_PACKER") == "true" {
58 enabled = false
59 }
60 if ctx.sdk() {
61 enabled = false
62 }
63 if p.Properties.Pack_relocations != nil &&
64 *p.Properties.Pack_relocations == false {
65 enabled = false
66 }
67
68 p.Properties.PackingRelocations = enabled
69}
70
71func (p *relocationPacker) needsPacking(ctx ModuleContext) bool {
72 if ctx.AConfig().EmbeddedInMake() {
73 return false
74 }
75 return p.Properties.PackingRelocations
76}
77
78func (p *relocationPacker) pack(ctx ModuleContext, in, out android.ModuleOutPath, flags builderFlags) {
79 ctx.ModuleBuild(pctx, android.ModuleBuildParams{
80 Rule: relocationPackerRule,
81 Output: out,
82 Input: in,
83 })
84}