blob: 9499aebc935e6fe4df4952271c79fcdb87b65f27 [file] [log] [blame]
Colin Cross8e0c5112015-01-23 14:15:10 -08001// 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
Jamie Gennis1bc967e2014-05-27 16:34:41 -070015package bootstrap
16
Dan Willemsen7d0dddd2016-08-13 12:42:11 -070017import (
Dan Willemsena1e6eee2018-03-02 14:54:17 -080018 "os"
19 "path/filepath"
Dan Willemsen7d0dddd2016-08-13 12:42:11 -070020 "runtime"
Dan Willemsena1e6eee2018-03-02 14:54:17 -080021 "strings"
Dan Willemsen7d0dddd2016-08-13 12:42:11 -070022
23 "github.com/google/blueprint"
24)
25
Dan Willemsen1e723212017-07-18 19:37:37 -070026func bootstrapVariable(name string, value func() string) blueprint.Variable {
Dan Willemsen7d0dddd2016-08-13 12:42:11 -070027 return pctx.VariableFunc(name, func(config interface{}) (string, error) {
Dan Willemsen7d0dddd2016-08-13 12:42:11 -070028 return value(), nil
29 })
30}
31
Jamie Gennis1bc967e2014-05-27 16:34:41 -070032var (
Colin Crossc5fa50e2019-12-17 13:12:35 -080033 // These variables are the only configuration needed by the bootstrap
Dan Willemsen1e723212017-07-18 19:37:37 -070034 // modules.
35 srcDir = bootstrapVariable("srcDir", func() string {
Dan Willemsen7d0dddd2016-08-13 12:42:11 -070036 return SrcDir
37 })
Dan Willemsen1e723212017-07-18 19:37:37 -070038 buildDir = bootstrapVariable("buildDir", func() string {
Dan Willemsen7d0dddd2016-08-13 12:42:11 -070039 return BuildDir
40 })
Dan Willemsencd4e0ce2017-07-19 22:43:30 -070041 ninjaBuildDir = bootstrapVariable("ninjaBuildDir", func() string {
42 return NinjaBuildDir
43 })
Dan Willemsen1e723212017-07-18 19:37:37 -070044 goRoot = bootstrapVariable("goRoot", func() string {
Dan Willemsena1e6eee2018-03-02 14:54:17 -080045 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
Dan Willemsen7d0dddd2016-08-13 12:42:11 -070055 })
Dan Willemsen1e723212017-07-18 19:37:37 -070056 compileCmd = bootstrapVariable("compileCmd", func() string {
Dan Willemsen7d0dddd2016-08-13 12:42:11 -070057 return "$goRoot/pkg/tool/" + runtime.GOOS + "_" + runtime.GOARCH + "/compile"
58 })
Dan Willemsen1e723212017-07-18 19:37:37 -070059 linkCmd = bootstrapVariable("linkCmd", func() string {
Dan Willemsen7d0dddd2016-08-13 12:42:11 -070060 return "$goRoot/pkg/tool/" + runtime.GOOS + "_" + runtime.GOARCH + "/link"
61 })
Jamie Gennis1bc967e2014-05-27 16:34:41 -070062)
63
Dan Willemsen30a80c32015-06-24 19:21:21 -070064type ConfigInterface interface {
Dan Willemsenefd2de72015-07-22 17:06:06 -070065 // GeneratingPrimaryBuilder should return true if this build invocation is
Dan Willemsen7d0dddd2016-08-13 12:42:11 -070066 // creating a .bootstrap/build.ninja file to be used to build the
67 // primary builder
Dan Willemsenefd2de72015-07-22 17:06:06 -070068 GeneratingPrimaryBuilder() bool
Jamie Gennis1bc967e2014-05-27 16:34:41 -070069}
Dan Willemsen30a80c32015-06-24 19:21:21 -070070
Dan Willemsencd4e0ce2017-07-19 22:43:30 -070071type ConfigRemoveAbandonedFilesUnder interface {
Dan Willemsenab223a52018-07-05 21:56:59 -070072 // RemoveAbandonedFilesUnder should return two slices:
73 // - a slice of path prefixes that will be cleaned of files that are no
74 // longer active targets, but are listed in the .ninja_log.
75 // - a slice of paths that are exempt from cleaning
76 RemoveAbandonedFilesUnder() (under, except []string)
Colin Cross6d529f02015-11-17 16:16:58 -080077}
78
Dan Willemsenbe275232016-05-26 10:07:59 -070079type ConfigBlueprintToolLocation interface {
80 // BlueprintToolLocation can return a path name to install blueprint tools
81 // designed for end users (bpfmt, bpmodify, and anything else using
82 // blueprint_go_binary).
83 BlueprintToolLocation() string
84}
85
Colin Cross28b28432017-12-11 15:03:11 -080086type StopBefore int
87
88const (
89 StopBeforePrepareBuildActions StopBefore = 1
90)
91
92type ConfigStopBefore interface {
93 StopBefore() StopBefore
94}
95
Dan Willemsen91a657e2015-07-22 17:05:59 -070096type Stage int
97
98const (
Dan Willemsen1e723212017-07-18 19:37:37 -070099 StagePrimary Stage = iota
Dan Willemsen91a657e2015-07-22 17:05:59 -0700100 StageMain
101)
102
Dan Willemsen30a80c32015-06-24 19:21:21 -0700103type Config struct {
Dan Willemsen91a657e2015-07-22 17:05:59 -0700104 stage Stage
Dan Willemsen30a80c32015-06-24 19:21:21 -0700105
106 topLevelBlueprintsFile string
Dan Willemsen87ba2942015-06-23 17:21:00 -0700107
Dan Willemsendac90d32018-10-25 22:02:10 -0700108 emptyNinjaFile bool
Jeff Gastonc3e28442017-08-09 15:13:12 -0700109 runGoTests bool
110 moduleListFile string
Dan Willemsen30a80c32015-06-24 19:21:21 -0700111}