diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2023-10-09 18:04:21 +0200 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2023-10-10 08:28:19 +0000 |
| commit | 44508f85a0b2f4f42ea89d477d575b1bd5a71b60 (patch) | |
| tree | b95e318638d48a0c070b578a46cddfb8abc30105 /tools | |
| parent | c9be5398c14e7a10cfd807ba0ab9b608624613b1 (diff) | |
tools/syz-fmt: support --dry-run mode
Introduce the --dry-run mode to enable syz-fmt use for description
validation only.
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/syz-fmt/syz-fmt.go | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/tools/syz-fmt/syz-fmt.go b/tools/syz-fmt/syz-fmt.go index 2fe918951..e1966aef3 100644 --- a/tools/syz-fmt/syz-fmt.go +++ b/tools/syz-fmt/syz-fmt.go @@ -6,6 +6,7 @@ package main import ( "bytes" + "flag" "fmt" "os" "path/filepath" @@ -13,15 +14,21 @@ import ( "github.com/google/syzkaller/pkg/ast" "github.com/google/syzkaller/pkg/osutil" + "github.com/google/syzkaller/pkg/tool" "github.com/google/syzkaller/sys/targets" ) +var ( + flagDryRun = flag.Bool("dry-run", false, "do not patch the files, just check if they are well formatted") +) + func main() { - if len(os.Args) < 2 { + defer tool.Init()() + args := flag.Args() + if len(args) < 1 { fmt.Fprintf(os.Stderr, "usage: syz-fmt files... or dirs... or all\n") os.Exit(1) } - args := os.Args[1:] if len(args) == 1 && args[0] == "all" { args = nil for os := range targets.List { @@ -67,6 +74,11 @@ func processFile(file string, mode os.FileMode) { if bytes.Equal(data, formatted) { return } + if *flagDryRun { + fmt.Fprintf(os.Stderr, "%v is not well-formatted, please run syz-fmt against it\n", file) + os.Exit(2) + return + } fmt.Printf("reformatting %v\n", file) if err := osutil.Rename(file, file+"~"); err != nil { fmt.Fprintf(os.Stderr, "%v\n", err) |
