Colin Cross | 8e0c511 | 2015-01-23 14:15:10 -0800 | [diff] [blame] | 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 | |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 15 | package main |
| 16 | |
| 17 | import ( |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 18 | "flag" |
Dan Willemsen | cd4e0ce | 2017-07-19 22:43:30 -0700 | [diff] [blame] | 19 | "path/filepath" |
| 20 | |
Jamie Gennis | 6cafc2c | 2015-03-20 22:39:29 -0400 | [diff] [blame] | 21 | "github.com/google/blueprint" |
| 22 | "github.com/google/blueprint/bootstrap" |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 23 | ) |
| 24 | |
| 25 | var runAsPrimaryBuilder bool |
Dan Willemsen | efd2de7 | 2015-07-22 17:06:06 -0700 | [diff] [blame] | 26 | var buildPrimaryBuilder bool |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 27 | |
| 28 | func init() { |
| 29 | flag.BoolVar(&runAsPrimaryBuilder, "p", false, "run as a primary builder") |
| 30 | } |
| 31 | |
Dan Willemsen | efd2de7 | 2015-07-22 17:06:06 -0700 | [diff] [blame] | 32 | type Config struct { |
Dan Willemsen | efd2de7 | 2015-07-22 17:06:06 -0700 | [diff] [blame] | 33 | generatingPrimaryBuilder bool |
| 34 | } |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 35 | |
Dan Willemsen | efd2de7 | 2015-07-22 17:06:06 -0700 | [diff] [blame] | 36 | func (c Config) GeneratingPrimaryBuilder() bool { |
| 37 | return c.generatingPrimaryBuilder |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Dan Willemsen | ab223a5 | 2018-07-05 21:56:59 -0700 | [diff] [blame] | 40 | func (c Config) RemoveAbandonedFilesUnder() (under, exempt []string) { |
| 41 | if c.generatingPrimaryBuilder { |
| 42 | under = []string{filepath.Join(bootstrap.BuildDir, ".bootstrap")} |
| 43 | exempt = []string{filepath.Join(bootstrap.BuildDir, ".bootstrap", "build.ninja")} |
| 44 | } |
| 45 | return |
Dan Willemsen | cd4e0ce | 2017-07-19 22:43:30 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 48 | func main() { |
| 49 | flag.Parse() |
| 50 | |
| 51 | ctx := blueprint.NewContext() |
| 52 | if !runAsPrimaryBuilder { |
| 53 | ctx.SetIgnoreUnknownModuleTypes(true) |
| 54 | } |
| 55 | |
Dan Willemsen | efd2de7 | 2015-07-22 17:06:06 -0700 | [diff] [blame] | 56 | config := Config{ |
Dan Willemsen | 1e72321 | 2017-07-18 19:37:37 -0700 | [diff] [blame] | 57 | generatingPrimaryBuilder: !runAsPrimaryBuilder, |
Dan Willemsen | efd2de7 | 2015-07-22 17:06:06 -0700 | [diff] [blame] | 58 | } |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 59 | |
| 60 | bootstrap.Main(ctx, config) |
| 61 | } |