blob: 71802efa6a311f0aa781c15ccdf697930ac997ee [file] [log] [blame]
Sasha Smundak26c705f2021-09-30 18:13:54 -07001package main
2
3/*
4 Canoninja reads a Ninja file and changes the rule names to be the digest of the rule contents.
5 Feed it to a filter that extracts only build statements, sort them, and you will have a crude
6 but effective tool to find small differences between two Ninja files.
7*/
8
9import (
10 "canoninja"
11 "flag"
12 "fmt"
13 "os"
14)
15
16func main() {
17 flag.Parse()
18 files := flag.Args()
19 if len(files) == 0 {
20 files = []string{"/dev/stdin"}
21 }
22 rc := 0
23 for _, f := range files {
24 if buffer, err := os.ReadFile(f); err == nil {
25 err = canoninja.Generate(f, buffer, os.Stdout)
26 if err != nil {
27 fmt.Fprintln(os.Stderr, err)
28 rc = 1
29 }
30 } else {
31 fmt.Fprintf(os.Stderr, "%s: %s\n", f, err)
32 rc = 1
33 }
34 }
35 os.Exit(rc)
36}