From a29ee638ea359b4ca9618cbffb19858b9d29c172 Mon Sep 17 00:00:00 2001 From: Rashid Zaman Date: Fri, 4 Aug 2023 00:39:24 -0700 Subject: [PATCH] bpfmt: Process all blueprint files when a directory is specified Currently when a directory path is specified bpfmt only processes files named "Blueprints" so change this to also process files with a `.bp` suffix. Test: Manual + bpfmt -d frameworks/base/services shows differences Change-Id: I5a6356f387892934ee8e83362db13cda6156ed51 Signed-off-by: Rashid Zaman --- bpfmt/bpfmt.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bpfmt/bpfmt.go b/bpfmt/bpfmt.go index 4e6bd1e..df8b87a 100644 --- a/bpfmt/bpfmt.go +++ b/bpfmt/bpfmt.go @@ -14,6 +14,7 @@ import ( "os" "os/exec" "path/filepath" + "strings" "github.com/google/blueprint/parser" ) @@ -110,9 +111,14 @@ func processReader(filename string, in io.Reader, out io.Writer) error { return err } +func isBlueprintFile(f os.FileInfo) bool { + name := f.Name() + return !f.IsDir() && (name == "Blueprints" || (!strings.HasPrefix(name, ".") && strings.HasSuffix(name, ".bp"))) +} + func walkDir(path string) { visitFile := func(path string, f os.FileInfo, err error) error { - if err == nil && f.Name() == "Blueprints" { + if err == nil && isBlueprintFile(f) { err = processFile(path, os.Stdout) } if err != nil {