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 "os" 19 "path/filepath" 20 "runtime" 21 "strings" 22 23 "github.com/google/blueprint" 24) 25 26func bootstrapVariable(name string, value func() string) blueprint.Variable { 27 return pctx.VariableFunc(name, func(config interface{}) (string, error) { 28 return value(), nil 29 }) 30} 31 32var ( 33 // These variables are the only configuration needed by the boostrap 34 // modules. 35 srcDir = bootstrapVariable("srcDir", func() string { 36 return SrcDir 37 }) 38 buildDir = bootstrapVariable("buildDir", func() string { 39 return BuildDir 40 }) 41 ninjaBuildDir = bootstrapVariable("ninjaBuildDir", func() string { 42 return NinjaBuildDir 43 }) 44 goRoot = bootstrapVariable("goRoot", func() string { 45 goroot := runtime.GOROOT() 46 // Prefer to omit absolute paths from the ninja file 47 if cwd, err := os.Getwd(); err == nil { 48 if relpath, err := filepath.Rel(cwd, goroot); err == nil { 49 if !strings.HasPrefix(relpath, "../") { 50 goroot = relpath 51 } 52 } 53 } 54 return goroot 55 }) 56 compileCmd = bootstrapVariable("compileCmd", func() string { 57 return "$goRoot/pkg/tool/" + runtime.GOOS + "_" + runtime.GOARCH + "/compile" 58 }) 59 linkCmd = bootstrapVariable("linkCmd", func() string { 60 return "$goRoot/pkg/tool/" + runtime.GOOS + "_" + runtime.GOARCH + "/link" 61 }) 62) 63 64type ConfigInterface interface { 65 // GeneratingPrimaryBuilder should return true if this build invocation is 66 // creating a .bootstrap/build.ninja file to be used to build the 67 // primary builder 68 GeneratingPrimaryBuilder() bool 69} 70 71type ConfigRemoveAbandonedFilesUnder interface { 72 // RemoveAbandonedFilesUnder should return a slice of path prefixes that 73 // will be cleaned of files that are no longer active targets, but are 74 // listed in the .ninja_log. 75 RemoveAbandonedFilesUnder() []string 76} 77 78type ConfigBlueprintToolLocation interface { 79 // BlueprintToolLocation can return a path name to install blueprint tools 80 // designed for end users (bpfmt, bpmodify, and anything else using 81 // blueprint_go_binary). 82 BlueprintToolLocation() string 83} 84 85type StopBefore int 86 87const ( 88 StopBeforePrepareBuildActions StopBefore = 1 89) 90 91type ConfigStopBefore interface { 92 StopBefore() StopBefore 93} 94 95type Stage int 96 97const ( 98 StagePrimary Stage = iota 99 StageMain 100) 101 102type Config struct { 103 stage Stage 104 105 topLevelBlueprintsFile string 106 107 runGoTests bool 108 moduleListFile string 109} 110