Forbit extra quotes in tidy flag lists
* Start with clang-tidy flags; maybe other flags should be checked too. Bug: 180862582 Test: make Change-Id: I82f86a911733693a14fe56a35e28590b065e3ae7
This commit is contained in:
parent
a777d960ab
commit
217e09a784
23
cc/tidy.go
23
cc/tidy.go
|
@ -42,6 +42,21 @@ type tidyFeature struct {
|
||||||
Properties TidyProperties
|
Properties TidyProperties
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var quotedFlagRegexp, _ = regexp.Compile(`^-?-[^=]+=('|").*('|")$`)
|
||||||
|
|
||||||
|
// When passing flag -name=value, if user add quotes around 'value',
|
||||||
|
// the quotation marks will be preserved by NinjaAndShellEscapeList
|
||||||
|
// and the 'value' string with quotes won't work like the intended value.
|
||||||
|
// So here we report an error if -*='*' is found.
|
||||||
|
func checkNinjaAndShellEscapeList(ctx ModuleContext, prop string, slice []string) []string {
|
||||||
|
for _, s := range slice {
|
||||||
|
if quotedFlagRegexp.MatchString(s) {
|
||||||
|
ctx.PropertyErrorf(prop, "Extra quotes in: %s", s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return proptools.NinjaAndShellEscapeList(slice)
|
||||||
|
}
|
||||||
|
|
||||||
func (tidy *tidyFeature) props() []interface{} {
|
func (tidy *tidyFeature) props() []interface{} {
|
||||||
return []interface{}{&tidy.Properties}
|
return []interface{}{&tidy.Properties}
|
||||||
}
|
}
|
||||||
|
@ -74,8 +89,8 @@ func (tidy *tidyFeature) flags(ctx ModuleContext, flags Flags) Flags {
|
||||||
if len(withTidyFlags) > 0 {
|
if len(withTidyFlags) > 0 {
|
||||||
flags.TidyFlags = append(flags.TidyFlags, withTidyFlags)
|
flags.TidyFlags = append(flags.TidyFlags, withTidyFlags)
|
||||||
}
|
}
|
||||||
esc := proptools.NinjaAndShellEscapeList
|
esc := checkNinjaAndShellEscapeList
|
||||||
flags.TidyFlags = append(flags.TidyFlags, esc(tidy.Properties.Tidy_flags)...)
|
flags.TidyFlags = append(flags.TidyFlags, esc(ctx, "tidy_flags", tidy.Properties.Tidy_flags)...)
|
||||||
// If TidyFlags does not contain -header-filter, add default header filter.
|
// If TidyFlags does not contain -header-filter, add default header filter.
|
||||||
// Find the substring because the flag could also appear as --header-filter=...
|
// Find the substring because the flag could also appear as --header-filter=...
|
||||||
// and with or without single or double quotes.
|
// and with or without single or double quotes.
|
||||||
|
@ -119,7 +134,7 @@ func (tidy *tidyFeature) flags(ctx ModuleContext, flags Flags) Flags {
|
||||||
tidyChecks += config.TidyChecksForDir(ctx.ModuleDir())
|
tidyChecks += config.TidyChecksForDir(ctx.ModuleDir())
|
||||||
}
|
}
|
||||||
if len(tidy.Properties.Tidy_checks) > 0 {
|
if len(tidy.Properties.Tidy_checks) > 0 {
|
||||||
tidyChecks = tidyChecks + "," + strings.Join(esc(
|
tidyChecks = tidyChecks + "," + strings.Join(esc(ctx, "tidy_checks",
|
||||||
config.ClangRewriteTidyChecks(tidy.Properties.Tidy_checks)), ",")
|
config.ClangRewriteTidyChecks(tidy.Properties.Tidy_checks)), ",")
|
||||||
}
|
}
|
||||||
if ctx.Windows() {
|
if ctx.Windows() {
|
||||||
|
@ -165,7 +180,7 @@ func (tidy *tidyFeature) flags(ctx ModuleContext, flags Flags) Flags {
|
||||||
flags.TidyFlags = append(flags.TidyFlags, "-warnings-as-errors=-*")
|
flags.TidyFlags = append(flags.TidyFlags, "-warnings-as-errors=-*")
|
||||||
}
|
}
|
||||||
} else if len(tidy.Properties.Tidy_checks_as_errors) > 0 {
|
} else if len(tidy.Properties.Tidy_checks_as_errors) > 0 {
|
||||||
tidyChecksAsErrors := "-warnings-as-errors=" + strings.Join(esc(tidy.Properties.Tidy_checks_as_errors), ",")
|
tidyChecksAsErrors := "-warnings-as-errors=" + strings.Join(esc(ctx, "tidy_checks_as_errors", tidy.Properties.Tidy_checks_as_errors), ",")
|
||||||
flags.TidyFlags = append(flags.TidyFlags, tidyChecksAsErrors)
|
flags.TidyFlags = append(flags.TidyFlags, tidyChecksAsErrors)
|
||||||
}
|
}
|
||||||
return flags
|
return flags
|
||||||
|
|
Loading…
Reference in New Issue