Add clang_verify property for cc.

This property is to support cflags "-Xclang -verify" build pass in Soong. The behaviors of clang_verify:
- append cflags "-Xclang -verify"
- append "&& touch $out" to the clang command line

Bug: 311284462
Test: go test -run TestClangVerify

Change-Id: Ic5825e2d649da4c3c5ed6da916e9804d7e3c03da
This commit is contained in:
kellyhung 2024-05-19 21:16:07 +08:00
parent 46469d6a03
commit d62ea30647
5 changed files with 53 additions and 6 deletions

View file

@ -46,18 +46,18 @@ var (
blueprint.RuleParams{
Depfile: "${out}.d",
Deps: blueprint.DepsGCC,
Command: "$relPwd ${config.CcWrapper}$ccCmd -c $cFlags -MD -MF ${out}.d -o $out $in",
Command: "$relPwd ${config.CcWrapper}$ccCmd -c $cFlags -MD -MF ${out}.d -o $out $in$postCmd",
CommandDeps: []string{"$ccCmd"},
},
"ccCmd", "cFlags")
"ccCmd", "cFlags", "postCmd")
// Rule to invoke gcc with given command and flags, but no dependencies.
ccNoDeps = pctx.AndroidStaticRule("ccNoDeps",
blueprint.RuleParams{
Command: "$relPwd $ccCmd -c $cFlags -o $out $in",
Command: "$relPwd $ccCmd -c $cFlags -o $out $in$postCmd",
CommandDeps: []string{"$ccCmd"},
},
"ccCmd", "cFlags")
"ccCmd", "cFlags", "postCmd")
// Rules to invoke ld to link binaries. Uses a .rsp file to list dependencies, as there may
// be many.
@ -400,6 +400,7 @@ type builderFlags struct {
gcovCoverage bool
sAbiDump bool
emitXrefs bool
clangVerify bool
assemblerWithCpp bool // True if .s files should be processed with the c preprocessor.
@ -591,6 +592,7 @@ func transformSourceToObj(ctx ModuleContext, subdir string, srcFiles, noTidySrcs
var moduleToolingFlags string
var ccCmd string
var postCmd string
tidy := flags.tidy
coverage := flags.gcovCoverage
dump := flags.sAbiDump
@ -635,6 +637,10 @@ func transformSourceToObj(ctx ModuleContext, subdir string, srcFiles, noTidySrcs
ccCmd = "${config.ClangBin}/" + ccCmd
if flags.clangVerify {
postCmd = " && touch $$out"
}
var implicitOutputs android.WritablePaths
if coverage {
gcnoFile := android.ObjPathWithExt(ctx, subdir, srcFile, "gcno")
@ -651,8 +657,9 @@ func transformSourceToObj(ctx ModuleContext, subdir string, srcFiles, noTidySrcs
Implicits: cFlagsDeps,
OrderOnly: pathDeps,
Args: map[string]string{
"cFlags": shareFlags("cFlags", moduleFlags),
"ccCmd": ccCmd, // short and not shared
"cFlags": shareFlags("cFlags", moduleFlags),
"ccCmd": ccCmd, // short and not shared
"postCmd": postCmd,
},
})

View file

@ -260,6 +260,7 @@ type Flags struct {
GcovCoverage bool // True if coverage files should be generated.
SAbiDump bool // True if header abi dumps should be generated.
EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
ClangVerify bool // If true, append cflags "-Xclang -verify" and append "&& touch $out" to the clang command line.
// The instruction set required for clang ("arm" or "thumb").
RequiredInstructionSet string

View file

@ -3218,3 +3218,32 @@ func TestVendorSdkVersion(t *testing.T) {
testSdkVersionFlag("libfoo", "30")
testSdkVersionFlag("libbar", "29")
}
func TestClangVerify(t *testing.T) {
t.Parallel()
ctx := testCc(t, `
cc_library {
name: "lib_no_clang_verify",
srcs: ["libnocv.cc"],
}
cc_library {
name: "lib_clang_verify",
srcs: ["libcv.cc"],
clang_verify: true,
}
`)
module := ctx.ModuleForTests("lib_no_clang_verify", "android_arm64_armv8-a_shared")
cFlags_no_cv := module.Rule("cc").Args["cFlags"]
if strings.Contains(cFlags_no_cv, "-Xclang") || strings.Contains(cFlags_no_cv, "-verify") {
t.Errorf("expected %q not in cflags, got %q", "-Xclang -verify", cFlags_no_cv)
}
cFlags_cv := ctx.ModuleForTests("lib_clang_verify", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"]
if strings.Contains(cFlags_cv, "-Xclang") && strings.Contains(cFlags_cv, "-verify") {
t.Errorf("expected %q in cflags, got %q", "-Xclang -verify", cFlags_cv)
}
}

View file

@ -120,6 +120,10 @@ type BaseCompilerProperties struct {
// ban targeting bpf in cc rules instead use bpf_rules. (b/323415017)
Bpf_target *bool
// Add "-Xclang -verify" to the cflags and appends "touch $out" to
// the clang command line.
Clang_verify bool
Yacc *YaccProperties
Lex *LexProperties
@ -390,6 +394,11 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
flags.Yacc = compiler.Properties.Yacc
flags.Lex = compiler.Properties.Lex
flags.ClangVerify = compiler.Properties.Clang_verify
if compiler.Properties.Clang_verify {
flags.Local.CFlags = append(flags.Local.CFlags, "-Xclang", "-verify")
}
// Include dir cflags
localIncludeDirs := android.PathsForModuleSrc(ctx, compiler.Properties.Local_include_dirs)
if len(localIncludeDirs) > 0 {

View file

@ -68,6 +68,7 @@ func flagsToBuilderFlags(in Flags) builderFlags {
needTidyFiles: in.NeedTidyFiles,
sAbiDump: in.SAbiDump,
emitXrefs: in.EmitXrefs,
clangVerify: in.ClangVerify,
systemIncludeFlags: strings.Join(in.SystemIncludeFlags, " "),