github.com/westcoastroms/westcoastroms-build@v0.0.0-20190928114312-2350e5a73030/build/soong/cc/relocation_packer.go (about)

     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  
    15  package cc
    16  
    17  import (
    18  	"runtime"
    19  
    20  	"github.com/google/blueprint"
    21  
    22  	"android/soong/android"
    23  )
    24  
    25  func init() {
    26  	pctx.SourcePathVariable("relocationPackerCmd", "prebuilts/misc/${config.HostPrebuiltTag}/relocation_packer/relocation_packer")
    27  }
    28  
    29  var relocationPackerRule = pctx.AndroidStaticRule("packRelocations",
    30  	blueprint.RuleParams{
    31  		Command:     "rm -f $out && cp $in $out && $relocationPackerCmd $out",
    32  		CommandDeps: []string{"$relocationPackerCmd"},
    33  	})
    34  
    35  type 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  
    43  type relocationPacker struct {
    44  	Properties RelocationPackerProperties
    45  }
    46  
    47  func (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.Config().Getenv("DISABLE_RELOCATION_PACKER") == "true" {
    57  		enabled = false
    58  	}
    59  	if ctx.useSdk() {
    60  		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  
    70  func (p *relocationPacker) needsPacking(ctx ModuleContext) bool {
    71  	if ctx.Config().EmbeddedInMake() {
    72  		return false
    73  	}
    74  	return p.Properties.PackingRelocations
    75  }
    76  
    77  func (p *relocationPacker) pack(ctx ModuleContext, in, out android.ModuleOutPath, flags builderFlags) {
    78  	ctx.Build(pctx, android.BuildParams{
    79  		Rule:        relocationPackerRule,
    80  		Description: "pack relocations",
    81  		Output:      out,
    82  		Input:       in,
    83  	})
    84  }