blob: d9b367c705751e71ddac770caac6bce23d74559a [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"},
Dan Willemsen394e9dc2016-09-14 15:04:48 -070033 })
34
35type RelocationPackerProperties struct {
36 Pack_relocations *bool `android:"arch_variant"`
37
38 // This will be true even if we're embedded in Make, in which case
39 // we'll defer to make to actually do the packing.
40 PackingRelocations bool `blueprint:"mutated"`
41}
42
43type relocationPacker struct {
44 Properties RelocationPackerProperties
45}
46
47func (p *relocationPacker) packingInit(ctx BaseModuleContext) {
48 enabled := true
49 // Relocation packer isn't available on Darwin yet
50 if runtime.GOOS == "darwin" {
51 enabled = false
52 }
53 if ctx.Target().Os != android.Android {
54 enabled = false
55 }
56 if ctx.AConfig().Getenv("DISABLE_RELOCATION_PACKER") == "true" {
57 enabled = false
58 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -070059 if ctx.useSdk() {
Dan Willemsen394e9dc2016-09-14 15:04:48 -070060 enabled = false
61 }
62 if p.Properties.Pack_relocations != nil &&
63 *p.Properties.Pack_relocations == false {
64 enabled = false
65 }
66
67 p.Properties.PackingRelocations = enabled
68}
69
70func (p *relocationPacker) needsPacking(ctx ModuleContext) bool {
71 if ctx.AConfig().EmbeddedInMake() {
72 return false
73 }
74 return p.Properties.PackingRelocations
75}
76
77func (p *relocationPacker) pack(ctx ModuleContext, in, out android.ModuleOutPath, flags builderFlags) {
78 ctx.ModuleBuild(pctx, android.ModuleBuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -070079 Rule: relocationPackerRule,
80 Description: "pack relocations",
81 Output: out,
82 Input: in,
Dan Willemsen394e9dc2016-09-14 15:04:48 -070083 })
84}