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 |
| 26 | |
| 27 | func init() { |
| 28 | flag.BoolVar(&runAsPrimaryBuilder, "p", false, "run as a primary builder") |
| 29 | } |
| 30 | |
Dan Willemsen | efd2de7 | 2015-07-22 17:06:06 -0700 | [diff] [blame] | 31 | type Config struct { |
Lukacs T. Berki | 5353744 | 2021-03-12 08:31:19 +0100 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | func (c Config) SrcDir() string { |
Lukacs T. Berki | 98e0efb | 2021-04-14 13:47:52 +0200 | [diff] [blame] | 35 | return bootstrap.CmdlineArgs.BuildDir |
Lukacs T. Berki | 5353744 | 2021-03-12 08:31:19 +0100 | [diff] [blame] | 36 | } |
| 37 | |
Lukacs T. Berki | 7ea1c16 | 2021-03-16 08:54:33 +0100 | [diff] [blame] | 38 | func (c Config) RemoveAbandonedFilesUnder(buildDir string) (under, exempt []string) { |
Lukacs T. Berki | b3b9cb6 | 2021-03-16 09:11:10 +0100 | [diff] [blame] | 39 | if !runAsPrimaryBuilder { |
Lukacs T. Berki | 7ea1c16 | 2021-03-16 08:54:33 +0100 | [diff] [blame] | 40 | under = []string{filepath.Join(buildDir, ".bootstrap")} |
| 41 | exempt = []string{filepath.Join(buildDir, ".bootstrap", "build.ninja")} |
| 42 | } |
Dan Willemsen | ab223a5 | 2018-07-05 21:56:59 -0700 | [diff] [blame] | 43 | return |
Dan Willemsen | cd4e0ce | 2017-07-19 22:43:30 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 46 | func main() { |
| 47 | flag.Parse() |
| 48 | |
| 49 | ctx := blueprint.NewContext() |
| 50 | if !runAsPrimaryBuilder { |
| 51 | ctx.SetIgnoreUnknownModuleTypes(true) |
| 52 | } |
| 53 | |
Lukacs T. Berki | b3b9cb6 | 2021-03-16 09:11:10 +0100 | [diff] [blame] | 54 | config := Config{} |
| 55 | bootstrap.Main(ctx, config, !runAsPrimaryBuilder) |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 56 | } |