Only write .bazelrc file if it is not empty

This commit is contained in:
Adam Liddell 2021-02-21 20:49:22 +00:00
parent 158caeb0c7
commit 6a0205c72b
57 changed files with 12 additions and 2 deletions

View File

@ -205,6 +205,7 @@ func mustWriteLanguageExampleBazelrcFile(dir string, lang *Language, rule *Rule)
out.w("#")
}
out.w("%s --%s=%s", f.Category, f.Name, f.Value)
out.ln()
}
for _, f := range rule.Flags {
if f.Description != "" {
@ -213,9 +214,18 @@ func mustWriteLanguageExampleBazelrcFile(dir string, lang *Language, rule *Rule)
out.w("#")
}
out.w("%s --%s=%s", f.Category, f.Name, f.Value)
out.ln()
}
// Only write a .bazelrc if it's not empty
if len(out.lines) > 0 {
out.MustWrite(filepath.Join(dir, ".bazelrc"))
} else {
e := os.Remove(filepath.Join(dir, ".bazelrc"))
if e != nil {
log.Fatal(e)
}
}
out.ln()
out.MustWrite(filepath.Join(dir, ".bazelrc"))
}
func mustWriteLanguageDefs(dir string, lang *Language) {