aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2019-03-29 15:33:06 -0700
committerColin Cross <ccross@android.com>2019-03-29 16:35:06 -0700
commit1d2cf0494af3027f57d8d0d7495dc1a46d20886e (patch)
tree9e8176b3413a444b4e1cf28580d21dadf19c0dea /cmd
parent92b7d584c80f2efa8fe38338d7372f2d14db4b48 (diff)
downloadbuild_soong-1d2cf0494af3027f57d8d0d7495dc1a46d20886e.tar.gz
build_soong-1d2cf0494af3027f57d8d0d7495dc1a46d20886e.tar.bz2
build_soong-1d2cf0494af3027f57d8d0d7495dc1a46d20886e.zip
Add depfile support to RuleBuilder
Allow rules built with RuleBuilder to use depfiles. Ninja only supports a single depfile with single output. If there are multiple outputs in a rule, move all but the first to implicit outputs. If multiple depfiles are specified, use new support in dep_fixer to combine additional depfiles into the first depfile. Test: rule_builder_test.go Change-Id: I7dd4ba7fdf9feaf89b3dd2b7abb0e79006e06018
Diffstat (limited to 'cmd')
-rw-r--r--cmd/dep_fixer/main.go36
1 files changed, 24 insertions, 12 deletions
diff --git a/cmd/dep_fixer/main.go b/cmd/dep_fixer/main.go
index 0647fb29..f94cf2fd 100644
--- a/cmd/dep_fixer/main.go
+++ b/cmd/dep_fixer/main.go
@@ -29,30 +29,42 @@ import (
func main() {
flag.Usage = func() {
- fmt.Fprintf(os.Stderr, "Usage: %s <depfile.d>", os.Args[0])
+ fmt.Fprintf(os.Stderr, "Usage: %s [-o <output>] <depfile.d> [<depfile.d>...]", os.Args[0])
flag.PrintDefaults()
}
output := flag.String("o", "", "Optional output file (defaults to rewriting source if necessary)")
flag.Parse()
- if flag.NArg() != 1 {
- log.Fatal("Expected a single file as an argument")
+ if flag.NArg() < 1 {
+ log.Fatal("Expected at least one input file as an argument")
}
- old, err := ioutil.ReadFile(flag.Arg(0))
- if err != nil {
- log.Fatalf("Error opening %q: %v", flag.Arg(0), err)
- }
+ var mergedDeps *Deps
+ var firstInput []byte
+
+ for i, arg := range flag.Args() {
+ input, err := ioutil.ReadFile(arg)
+ if err != nil {
+ log.Fatalf("Error opening %q: %v", arg, err)
+ }
- deps, err := Parse(flag.Arg(0), bytes.NewBuffer(append([]byte(nil), old...)))
- if err != nil {
- log.Fatalf("Failed to parse: %v", err)
+ deps, err := Parse(arg, bytes.NewBuffer(append([]byte(nil), input...)))
+ if err != nil {
+ log.Fatalf("Failed to parse: %v", err)
+ }
+
+ if i == 0 {
+ mergedDeps = deps
+ firstInput = input
+ } else {
+ mergedDeps.Inputs = append(mergedDeps.Inputs, deps.Inputs...)
+ }
}
- new := deps.Print()
+ new := mergedDeps.Print()
if *output == "" || *output == flag.Arg(0) {
- if !bytes.Equal(old, new) {
+ if !bytes.Equal(firstInput, new) {
err := ioutil.WriteFile(flag.Arg(0), new, 0666)
if err != nil {
log.Fatalf("Failed to write: %v", err)