1// Copyright 2014 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 bootstrap 16 17import ( 18 "runtime" 19 20 "github.com/google/blueprint" 21) 22 23func bootstrapVariable(name, template string, value func() string) blueprint.Variable { 24 return pctx.VariableFunc(name, func(config interface{}) (string, error) { 25 if c, ok := config.(ConfigInterface); ok && c.GeneratingBootstrapper() { 26 return template, nil 27 } 28 return value(), nil 29 }) 30} 31 32var ( 33 // These variables are the only configuration needed by the boostrap 34 // modules. For the first bootstrap stage, they are set to the 35 // variable name enclosed in "@@" so that their values can be easily 36 // replaced in the generated Ninja file. 37 srcDir = bootstrapVariable("srcDir", "@@SrcDir@@", func() string { 38 return SrcDir 39 }) 40 buildDir = bootstrapVariable("buildDir", "@@BuildDir@@", func() string { 41 return BuildDir 42 }) 43 goRoot = bootstrapVariable("goRoot", "@@GoRoot@@", func() string { 44 return runtime.GOROOT() 45 }) 46 compileCmd = bootstrapVariable("compileCmd", "@@GoCompile@@", func() string { 47 return "$goRoot/pkg/tool/" + runtime.GOOS + "_" + runtime.GOARCH + "/compile" 48 }) 49 linkCmd = bootstrapVariable("linkCmd", "@@GoLink@@", func() string { 50 return "$goRoot/pkg/tool/" + runtime.GOOS + "_" + runtime.GOARCH + "/link" 51 }) 52 bootstrapCmd = bootstrapVariable("bootstrapCmd", "@@Bootstrap@@", func() string { 53 panic("bootstrapCmd is only available for minibootstrap") 54 }) 55) 56 57type ConfigInterface interface { 58 // GeneratingBootstrapper should return true if this build invocation is 59 // creating a .minibootstrap/build.ninja file to be used in a build 60 // bootstrapping sequence. 61 GeneratingBootstrapper() bool 62 // GeneratingPrimaryBuilder should return true if this build invocation is 63 // creating a .bootstrap/build.ninja file to be used to build the 64 // primary builder 65 GeneratingPrimaryBuilder() bool 66} 67 68type ConfigRemoveAbandonedFiles interface { 69 // RemoveAbandonedFiles should return true if files listed in the 70 // .ninja_log but not the output build.ninja file should be deleted. 71 RemoveAbandonedFiles() bool 72} 73 74type ConfigBlueprintToolLocation interface { 75 // BlueprintToolLocation can return a path name to install blueprint tools 76 // designed for end users (bpfmt, bpmodify, and anything else using 77 // blueprint_go_binary). 78 BlueprintToolLocation() string 79} 80 81type Stage int 82 83const ( 84 StageBootstrap Stage = iota 85 StagePrimary 86 StageMain 87) 88 89type Config struct { 90 stage Stage 91 92 topLevelBlueprintsFile string 93 94 runGoTests bool 95} 96