diff options
-rw-r--r-- | android/config.go | 20 | ||||
-rw-r--r-- | android/variable.go | 6 | ||||
-rw-r--r-- | androidmk/androidmk/androidmk.go | 38 | ||||
-rw-r--r-- | androidmk/androidmk/androidmk_test.go | 22 | ||||
-rw-r--r-- | androidmk/androidmk/values.go | 54 | ||||
-rw-r--r-- | apex/apex.go | 11 | ||||
-rw-r--r-- | apex/apex_test.go | 55 | ||||
-rw-r--r-- | apex/builder.go | 4 | ||||
-rw-r--r-- | apex/vndk_test.go | 1 | ||||
-rw-r--r-- | cc/coverage.go | 4 | ||||
-rwxr-xr-x | java/app.go | 4 | ||||
-rw-r--r-- | java/lint.go | 21 | ||||
-rw-r--r-- | python/python.go | 12 | ||||
-rw-r--r-- | rust/coverage.go | 2 | ||||
-rw-r--r-- | rust/rust_test.go | 1 | ||||
-rwxr-xr-x | scripts/lint-project-xml.py | 4 | ||||
-rw-r--r-- | sh/sh_binary.go | 16 | ||||
-rw-r--r-- | sh/sh_binary_test.go | 37 |
18 files changed, 252 insertions, 60 deletions
diff --git a/android/config.go b/android/config.go index b90610822..16f3d7321 100644 --- a/android/config.go +++ b/android/config.go @@ -406,6 +406,14 @@ func NewConfig(srcDir, buildDir string) (Config, error) { return Config{}, err } + if Bool(config.productVariables.GcovCoverage) && Bool(config.productVariables.ClangCoverage) { + return Config{}, fmt.Errorf("GcovCoverage and ClangCoverage cannot both be set") + } + + config.productVariables.Native_coverage = proptools.BoolPtr( + Bool(config.productVariables.GcovCoverage) || + Bool(config.productVariables.ClangCoverage)) + return Config{config}, nil } @@ -1057,18 +1065,20 @@ func (c *deviceConfig) JavaCoverageEnabledForPath(path string) bool { return coverage } -func (c *config) NativeLineCoverage() bool { - return Bool(c.productVariables.NativeLineCoverage) -} - +// Returns true if gcov or clang coverage is enabled. func (c *deviceConfig) NativeCoverageEnabled() bool { - return Bool(c.config.productVariables.Native_coverage) || Bool(c.config.productVariables.NativeLineCoverage) + return Bool(c.config.productVariables.GcovCoverage) || + Bool(c.config.productVariables.ClangCoverage) } func (c *deviceConfig) ClangCoverageEnabled() bool { return Bool(c.config.productVariables.ClangCoverage) } +func (c *deviceConfig) GcovCoverageEnabled() bool { + return Bool(c.config.productVariables.GcovCoverage) +} + // NativeCoverageEnabledForPath returns whether (GCOV- or Clang-based) native // code coverage is enabled for path. By default, coverage is not enabled for a // given path unless it is part of the NativeCoveragePaths product variable (and diff --git a/android/variable.go b/android/variable.go index b2149c3ff..2c8bd0720 100644 --- a/android/variable.go +++ b/android/variable.go @@ -270,12 +270,14 @@ type productVariables struct { JavaCoveragePaths []string `json:",omitempty"` JavaCoverageExcludePaths []string `json:",omitempty"` - NativeLineCoverage *bool `json:",omitempty"` - Native_coverage *bool `json:",omitempty"` + GcovCoverage *bool `json:",omitempty"` ClangCoverage *bool `json:",omitempty"` NativeCoveragePaths []string `json:",omitempty"` NativeCoverageExcludePaths []string `json:",omitempty"` + // Set by NewConfig + Native_coverage *bool + SanitizeHost []string `json:",omitempty"` SanitizeDevice []string `json:",omitempty"` SanitizeDeviceDiag []string `json:",omitempty"` diff --git a/androidmk/androidmk/androidmk.go b/androidmk/androidmk/androidmk.go index 4aadbe862..dcd67d871 100644 --- a/androidmk/androidmk/androidmk.go +++ b/androidmk/androidmk/androidmk.go @@ -34,6 +34,7 @@ type bpFile struct { defs []bpparser.Definition localAssignments map[string]*bpparser.Property globalAssignments map[string]*bpparser.Expression + variableRenames map[string]string scope mkparser.Scope module *bpparser.Module @@ -43,6 +44,10 @@ type bpFile struct { inModule bool } +var invalidVariableStringToReplacement = map[string]string{ + "-": "_dash_", +} + func (f *bpFile) insertComment(s string) { f.comments = append(f.comments, &bpparser.CommentGroup{ Comments: []*bpparser.Comment{ @@ -120,6 +125,7 @@ func ConvertFile(filename string, buffer *bytes.Buffer) (string, []error) { scope: androidScope(), localAssignments: make(map[string]*bpparser.Property), globalAssignments: make(map[string]*bpparser.Expression), + variableRenames: make(map[string]string), } var conds []*conditional @@ -224,6 +230,25 @@ func ConvertFile(filename string, buffer *bytes.Buffer) (string, []error) { return string(out), errs } +func renameVariableWithInvalidCharacters(name string) string { + renamed := "" + for invalid, replacement := range invalidVariableStringToReplacement { + if strings.Contains(name, invalid) { + renamed = strings.ReplaceAll(name, invalid, replacement) + } + } + + return renamed +} + +func invalidVariableStrings() string { + invalidStrings := make([]string, 0, len(invalidVariableStringToReplacement)) + for s := range invalidVariableStringToReplacement { + invalidStrings = append(invalidStrings, "\""+s+"\"") + } + return strings.Join(invalidStrings, ", ") +} + func handleAssignment(file *bpFile, assignment *mkparser.Assignment, c *conditional) { if !assignment.Name.Const() { file.errorf(assignment, "unsupported non-const variable name") @@ -238,6 +263,12 @@ func handleAssignment(file *bpFile, assignment *mkparser.Assignment, c *conditio name := assignment.Name.Value(nil) prefix := "" + if newName := renameVariableWithInvalidCharacters(name); newName != "" { + file.warnf("Variable names cannot contain: %s. Renamed \"%s\" to \"%s\"", invalidVariableStrings(), name, newName) + file.variableRenames[name] = newName + name = newName + } + if strings.HasPrefix(name, "LOCAL_") { for _, x := range propertyPrefixes { if strings.HasSuffix(name, "_"+x.mk) { @@ -341,11 +372,11 @@ func makeVariableToBlueprint(file *bpFile, val *mkparser.MakeString, var err error switch typ { case bpparser.ListType: - exp, err = makeToListExpression(val, file.scope) + exp, err = makeToListExpression(val, file) case bpparser.StringType: - exp, err = makeToStringExpression(val, file.scope) + exp, err = makeToStringExpression(val, file) case bpparser.BoolType: - exp, err = makeToBoolExpression(val) + exp, err = makeToBoolExpression(val, file) default: panic("unknown type") } @@ -358,7 +389,6 @@ func makeVariableToBlueprint(file *bpFile, val *mkparser.MakeString, } func setVariable(file *bpFile, plusequals bool, prefix, name string, value bpparser.Expression, local bool) error { - if prefix != "" { name = prefix + "." + name } diff --git a/androidmk/androidmk/androidmk_test.go b/androidmk/androidmk/androidmk_test.go index 54bd586f9..4f307c4fb 100644 --- a/androidmk/androidmk/androidmk_test.go +++ b/androidmk/androidmk/androidmk_test.go @@ -1367,6 +1367,28 @@ android_test_import { `, }, { + desc: "dashed_variable gets renamed", + in: ` + include $(CLEAR_VARS) + + dashed-variable:= a.cpp + + LOCAL_MODULE:= test + LOCAL_SRC_FILES:= $(dashed-variable) + include $(BUILD_EXECUTABLE) + `, + expected: ` + +// ANDROIDMK TRANSLATION WARNING: Variable names cannot contain: "-". Renamed "dashed-variable" to "dashed_dash_variable" +dashed_dash_variable = ["a.cpp"] +cc_binary { + + name: "test", + srcs: dashed_dash_variable, +} +`, + }, + { desc: "undefined_boolean_var", in: ` include $(CLEAR_VARS) diff --git a/androidmk/androidmk/values.go b/androidmk/androidmk/values.go index 6b18a651e..9618142fa 100644 --- a/androidmk/androidmk/values.go +++ b/androidmk/androidmk/values.go @@ -60,8 +60,7 @@ func addValues(val1, val2 bpparser.Expression) (bpparser.Expression, error) { }, nil } -func makeToStringExpression(ms *mkparser.MakeString, scope mkparser.Scope) (bpparser.Expression, error) { - +func makeToStringExpression(ms *mkparser.MakeString, file *bpFile) (bpparser.Expression, error) { var val bpparser.Expression var err error @@ -70,18 +69,18 @@ func makeToStringExpression(ms *mkparser.MakeString, scope mkparser.Scope) (bppa } for i, s := range ms.Strings[1:] { - if ret, ok := ms.Variables[i].EvalFunction(scope); ok { + if ret, ok := ms.Variables[i].EvalFunction(file.scope); ok { if len(ret) > 1 { return nil, fmt.Errorf("Unexpected list value %s", ms.Dump()) } val, err = addValues(val, stringToStringValue(ret[0])) } else { - name := ms.Variables[i].Name - if !name.Const() { - return nil, fmt.Errorf("Unsupported non-const variable name %s", name.Dump()) + name, err := extractVariableName(ms.Variables[i].Name, file) + if err != nil { + return nil, err } tmp := &bpparser.Variable{ - Name: name.Value(nil), + Name: name, Value: &bpparser.String{}, } @@ -125,8 +124,7 @@ func stringToListValue(s string) bpparser.Expression { } -func makeToListExpression(ms *mkparser.MakeString, scope mkparser.Scope) (bpparser.Expression, error) { - +func makeToListExpression(ms *mkparser.MakeString, file *bpFile) (bpparser.Expression, error) { fields := ms.Split(" \t") var listOfListValues []bpparser.Expression @@ -135,14 +133,14 @@ func makeToListExpression(ms *mkparser.MakeString, scope mkparser.Scope) (bppars for _, f := range fields { if len(f.Variables) == 1 && f.Strings[0] == "" && f.Strings[1] == "" { - if ret, ok := f.Variables[0].EvalFunction(scope); ok { + if ret, ok := f.Variables[0].EvalFunction(file.scope); ok { listValue.Values = append(listValue.Values, stringListToStringValueList(ret)...) } else { - // Variable by itself, variable is probably a list - if !f.Variables[0].Name.Const() { - return nil, fmt.Errorf("unsupported non-const variable name") + name, err := extractVariableName(f.Variables[0].Name, file) + if err != nil { + return nil, err } - if f.Variables[0].Name.Value(nil) == "TOP" { + if name == "TOP" { listValue.Values = append(listValue.Values, &bpparser.String{ Value: ".", }) @@ -151,14 +149,14 @@ func makeToListExpression(ms *mkparser.MakeString, scope mkparser.Scope) (bppars listOfListValues = append(listOfListValues, listValue) } listOfListValues = append(listOfListValues, &bpparser.Variable{ - Name: f.Variables[0].Name.Value(nil), + Name: name, Value: &bpparser.List{}, }) listValue = &bpparser.List{} } } } else { - s, err := makeToStringExpression(f, scope) + s, err := makeToStringExpression(f, file) if err != nil { return nil, err } @@ -208,15 +206,15 @@ func stringToBoolValue(s string) (bpparser.Expression, error) { }, nil } -func makeToBoolExpression(ms *mkparser.MakeString) (bpparser.Expression, error) { +func makeToBoolExpression(ms *mkparser.MakeString, file *bpFile) (bpparser.Expression, error) { if !ms.Const() { if len(ms.Variables) == 1 && ms.Strings[0] == "" && ms.Strings[1] == "" { - name := ms.Variables[0].Name - if !name.Const() { - return nil, fmt.Errorf("unsupported non-const variable name") + name, err := extractVariableName(ms.Variables[0].Name, file) + if err != nil { + return nil, err } return &bpparser.Variable{ - Name: name.Value(nil), + Name: name, Value: &bpparser.Bool{}, }, nil } else { @@ -226,3 +224,17 @@ func makeToBoolExpression(ms *mkparser.MakeString) (bpparser.Expression, error) return stringToBoolValue(ms.Value(nil)) } + +func extractVariableName(name *mkparser.MakeString, file *bpFile) (string, error) { + if !name.Const() { + return "", fmt.Errorf("Unsupported non-const variable name %s", name.Dump()) + } + + variableName := name.Value(nil) + + if newName, ok := file.variableRenames[variableName]; ok { + variableName = newName + } + + return variableName, nil +} diff --git a/apex/apex.go b/apex/apex.go index 8424b8216..58cbb13e9 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -984,9 +984,6 @@ type apexBundleProperties struct { // List of providing APEXes' names so that this APEX can depend on provided shared libraries. Uses []string - // A txt file containing list of files that are allowed to be included in this APEX. - Allowed_files *string - // package format of this apex variant; could be non-flattened, flattened, or zip. // imageApex, zipApex or flattened ApexType apexPackaging `blueprint:"mutated"` @@ -1062,6 +1059,9 @@ type overridableProperties struct { // Apex Container Package Name. // Override value for attribute package:name in AndroidManifest.xml Package_name string + + // A txt file containing list of files that are allowed to be included in this APEX. + Allowed_files *string `android:"path"` } type apexPackaging int @@ -1453,6 +1453,9 @@ func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) { } func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) { + if a.overridableProperties.Allowed_files != nil { + android.ExtractSourceDeps(ctx, a.overridableProperties.Allowed_files) + } ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(), androidAppTag, a.overridableProperties.Apps...) ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(), @@ -1552,7 +1555,7 @@ func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext var _ cc.Coverage = (*apexBundle)(nil) func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool { - return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled()) + return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled() } func (a *apexBundle) PreventInstall() { diff --git a/apex/apex_test.go b/apex/apex_test.go index a7a776561..3d5886ea9 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -5396,6 +5396,61 @@ func TestApexKeysTxt(t *testing.T) { ensureNotContains(t, content, "myapex.apex") } +func TestAllowedFiles(t *testing.T) { + ctx, _ := testApex(t, ` + apex { + name: "myapex", + key: "myapex.key", + apps: ["app"], + allowed_files: "allowed.txt", + } + + apex_key { + name: "myapex.key", + public_key: "testkey.avbpubkey", + private_key: "testkey.pem", + } + + android_app { + name: "app", + srcs: ["foo/bar/MyClass.java"], + package_name: "foo", + sdk_version: "none", + system_modules: "none", + apex_available: [ "myapex" ], + } + `, withFiles(map[string][]byte{ + "sub/Android.bp": []byte(` + override_apex { + name: "override_myapex", + base: "myapex", + apps: ["override_app"], + allowed_files: ":allowed", + } + // Overridable "path" property should be referenced indirectly + filegroup { + name: "allowed", + srcs: ["allowed.txt"], + } + override_android_app { + name: "override_app", + base: "app", + package_name: "bar", + } + `), + })) + + rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("diffApexContentRule") + if expected, actual := "allowed.txt", rule.Args["allowed_files_file"]; expected != actual { + t.Errorf("allowed_files_file: expected %q but got %q", expected, actual) + } + + rule2 := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Rule("diffApexContentRule") + if expected, actual := "sub/allowed.txt", rule2.Args["allowed_files_file"]; expected != actual { + t.Errorf("allowed_files_file: expected %q but got %q", expected, actual) + } +} + func TestMain(m *testing.M) { run := func() int { setUp() diff --git a/apex/builder.go b/apex/builder.go index 53c119391..af43417aa 100644 --- a/apex/builder.go +++ b/apex/builder.go @@ -391,7 +391,7 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { emitCommands = append(emitCommands, "sort -o "+imageContentFile.String()+" "+imageContentFile.String()) implicitInputs = append(implicitInputs, a.manifestPbOut) - if a.properties.Allowed_files != nil { + if a.overridableProperties.Allowed_files != nil { ctx.Build(pctx, android.BuildParams{ Rule: emitApexContentRule, Implicits: implicitInputs, @@ -402,7 +402,7 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { }, }) implicitInputs = append(implicitInputs, imageContentFile) - allowedFilesFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.Allowed_files)) + allowedFilesFile := android.PathForModuleSrc(ctx, proptools.String(a.overridableProperties.Allowed_files)) phonyOutput := android.PathForModuleOut(ctx, a.Name()+"-diff-phony-output") ctx.Build(pctx, android.BuildParams{ diff --git a/apex/vndk_test.go b/apex/vndk_test.go index 05cdfcd92..60b6ed5cd 100644 --- a/apex/vndk_test.go +++ b/apex/vndk_test.go @@ -118,6 +118,7 @@ func TestVndkApexUsesVendorVariant(t *testing.T) { t.Run("VNDK APEX supports coverage variants", func(t *testing.T) { ctx, _ := testApex(t, bp, func(fs map[string][]byte, config android.Config) { + config.TestProductVariables.GcovCoverage = proptools.BoolPtr(true) config.TestProductVariables.Native_coverage = proptools.BoolPtr(true) }) diff --git a/cc/coverage.go b/cc/coverage.go index 1a559a9a5..c8233247f 100644 --- a/cc/coverage.go +++ b/cc/coverage.go @@ -74,8 +74,8 @@ func (cov *coverage) deps(ctx DepsContext, deps Deps) Deps { } func (cov *coverage) flags(ctx ModuleContext, flags Flags, deps PathDeps) (Flags, PathDeps) { - gcovCoverage := ctx.DeviceConfig().NativeCoverageEnabled() clangCoverage := ctx.DeviceConfig().ClangCoverageEnabled() + gcovCoverage := ctx.DeviceConfig().GcovCoverageEnabled() if !gcovCoverage && !clangCoverage { return flags, deps @@ -161,7 +161,7 @@ func (cov *coverage) begin(ctx BaseModuleContext) { func SetCoverageProperties(ctx android.BaseModuleContext, properties CoverageProperties, moduleTypeHasCoverage bool, useSdk bool, sdkVersion string) CoverageProperties { // Coverage is disabled globally - if !ctx.DeviceConfig().NativeCoverageEnabled() && !ctx.DeviceConfig().ClangCoverageEnabled() { + if !ctx.DeviceConfig().NativeCoverageEnabled() { return properties } diff --git a/java/app.go b/java/app.go index 4bb292ddf..c568516eb 100755 --- a/java/app.go +++ b/java/app.go @@ -151,7 +151,7 @@ func (as *AndroidAppSet) GenerateAndroidBuildActions(ctx android.ModuleContext) "allow-prereleased": strconv.FormatBool(proptools.Bool(as.properties.Prerelease)), "screen-densities": screenDensities, "sdk-version": ctx.Config().PlatformSdkVersion(), - "stem": ctx.ModuleName(), + "stem": as.BaseModuleName(), }, }) } @@ -938,7 +938,7 @@ func (a *AndroidApp) Privileged() bool { } func (a *AndroidApp) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool { - return ctx.Device() && (ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled()) + return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled() } func (a *AndroidApp) PreventInstall() { diff --git a/java/lint.go b/java/lint.go index fac9a1983..b73d6a51a 100644 --- a/java/lint.go +++ b/java/lint.go @@ -88,7 +88,7 @@ func (l *linter) deps(ctx android.BottomUpMutatorContext) { } func (l *linter) writeLintProjectXML(ctx android.ModuleContext, - rule *android.RuleBuilder) (projectXMLPath, configXMLPath, cacheDir android.WritablePath, deps android.Paths) { + rule *android.RuleBuilder) (projectXMLPath, configXMLPath, cacheDir, homeDir android.WritablePath, deps android.Paths) { var resourcesList android.WritablePath if len(l.resources) > 0 { @@ -106,6 +106,7 @@ func (l *linter) writeLintProjectXML(ctx android.ModuleContext, // Lint looks for a lint.xml file next to the project.xml file, give it one. configXMLPath = android.PathForModuleOut(ctx, "lint", "lint.xml") cacheDir = android.PathForModuleOut(ctx, "lint", "cache") + homeDir = android.PathForModuleOut(ctx, "lint", "home") srcJarDir := android.PathForModuleOut(ctx, "lint-srcjars") srcJarList := zipSyncCmd(ctx, rule, srcJarDir, l.srcJars) @@ -154,8 +155,11 @@ func (l *linter) writeLintProjectXML(ctx android.ModuleContext, cmd.FlagForEachArg("--extra_checks_jar ", l.extraLintCheckJars.Strings()) deps = append(deps, l.extraLintCheckJars...) - // The cache tag in project.xml is relative to the project.xml file. - cmd.FlagWithArg("--cache_dir ", "cache") + cmd.FlagWithArg("--root_dir ", "$PWD") + + // The cache tag in project.xml is relative to the root dir, or the project.xml file if + // the root dir is not set. + cmd.FlagWithArg("--cache_dir ", cacheDir.String()) cmd.FlagWithInput("@", android.PathForSource(ctx, "build/soong/java/lint_defaults.txt")) @@ -165,7 +169,7 @@ func (l *linter) writeLintProjectXML(ctx android.ModuleContext, cmd.FlagForEachArg("--error_check ", l.properties.Lint.Error_checks) cmd.FlagForEachArg("--fatal_check ", l.properties.Lint.Fatal_checks) - return projectXMLPath, configXMLPath, cacheDir, deps + return projectXMLPath, configXMLPath, cacheDir, homeDir, deps } // generateManifest adds a command to the rule to write a dummy manifest cat contains the @@ -207,18 +211,19 @@ func (l *linter) lint(ctx android.ModuleContext) { l.manifest = manifest } - projectXML, lintXML, cacheDir, deps := l.writeLintProjectXML(ctx, rule) + projectXML, lintXML, cacheDir, homeDir, deps := l.writeLintProjectXML(ctx, rule) l.outputs.html = android.PathForModuleOut(ctx, "lint-report.html") l.outputs.text = android.PathForModuleOut(ctx, "lint-report.txt") l.outputs.xml = android.PathForModuleOut(ctx, "lint-report.xml") - rule.Command().Text("rm -rf").Flag(cacheDir.String()) - rule.Command().Text("mkdir -p").Flag(cacheDir.String()) + rule.Command().Text("rm -rf").Flag(cacheDir.String()).Flag(homeDir.String()) + rule.Command().Text("mkdir -p").Flag(cacheDir.String()).Flag(homeDir.String()) rule.Command(). Text("("). Flag("JAVA_OPTS=-Xmx2048m"). + FlagWithArg("ANDROID_SDK_HOME=", homeDir.String()). FlagWithInput("SDK_ANNOTATIONS=", annotationsZipPath(ctx)). FlagWithInput("LINT_OPTS=-DLINT_API_DATABASE=", apiVersionsXmlPath(ctx)). Tool(android.PathForSource(ctx, "prebuilts/cmdline-tools/tools/bin/lint")). @@ -239,7 +244,7 @@ func (l *linter) lint(ctx android.ModuleContext) { Text("|| (").Text("cat").Input(l.outputs.text).Text("; exit 7)"). Text(")") - rule.Command().Text("rm -rf").Flag(cacheDir.String()) + rule.Command().Text("rm -rf").Flag(cacheDir.String()).Flag(homeDir.String()) rule.Build(pctx, ctx, "lint", "lint") } diff --git a/python/python.go b/python/python.go index 8b912be17..a6c9e2a07 100644 --- a/python/python.go +++ b/python/python.go @@ -251,6 +251,18 @@ func (p *Module) HostToolPath() android.OptionalPath { return android.OptionalPathForPath(p.installer.(*binaryDecorator).path) } +func (p *Module) OutputFiles(tag string) (android.Paths, error) { + switch tag { + case "": + if outputFile := p.installSource; outputFile.Valid() { + return android.Paths{outputFile.Path()}, nil + } + return android.Paths{}, nil + default: + return nil, fmt.Errorf("unsupported module reference tag %q", tag) + } +} + func (p *Module) isEmbeddedLauncherEnabled(actual_version string) bool { switch actual_version { case pyVersion2: diff --git a/rust/coverage.go b/rust/coverage.go index 9be57dccf..4e3977be3 100644 --- a/rust/coverage.go +++ b/rust/coverage.go @@ -45,7 +45,7 @@ func (cov *coverage) deps(ctx DepsContext, deps Deps) Deps { func (cov *coverage) flags(ctx ModuleContext, flags Flags, deps PathDeps) (Flags, PathDeps) { - if !ctx.DeviceConfig().NativeCoverageEnabled() && !ctx.DeviceConfig().ClangCoverageEnabled() { + if !ctx.DeviceConfig().NativeCoverageEnabled() { return flags, deps } diff --git a/rust/rust_test.go b/rust/rust_test.go index fe21e3a39..703aaed29 100644 --- a/rust/rust_test.go +++ b/rust/rust_test.go @@ -88,6 +88,7 @@ func testRustContext(t *testing.T, bp string, coverage bool) *android.TestContex config := testConfig(bp) if coverage { + config.TestProductVariables.GcovCoverage = proptools.BoolPtr(true) config.TestProductVariables.Native_coverage = proptools.BoolPtr(true) config.TestProductVariables.NativeCoveragePaths = []string{"*"} } diff --git a/scripts/lint-project-xml.py b/scripts/lint-project-xml.py index 7ab4f0150..38c57cadf 100755 --- a/scripts/lint-project-xml.py +++ b/scripts/lint-project-xml.py @@ -77,6 +77,8 @@ def parse_args(): help='mark the module as a test.') parser.add_argument('--cache_dir', dest='cache_dir', help='directory to use for cached file.') + parser.add_argument('--root_dir', dest='root_dir', + help='directory to use for root dir.') group = parser.add_argument_group('check arguments', 'later arguments override earlier ones.') group.add_argument('--fatal_check', dest='checks', action=check_action('fatal'), default=[], help='treat a lint issue as a fatal error.') @@ -162,6 +164,8 @@ def write_project_xml(f, args): f.write("<?xml version='1.0' encoding='utf-8'?>\n") f.write("<project>\n") + if args.root_dir: + f.write(" <root dir='%s' />\n" % args.root_dir) f.write(" <module name='%s' android='true' %sdesugar='full' >\n" % (args.name, "library='true' " if args.library else "")) if args.manifest: f.write(" <manifest file='%s' %s/>\n" % (args.manifest, test_attr)) diff --git a/sh/sh_binary.go b/sh/sh_binary.go index 7bb267da2..f28b2b685 100644 --- a/sh/sh_binary.go +++ b/sh/sh_binary.go @@ -107,6 +107,8 @@ type ShTest struct { testProperties TestProperties + installDir android.InstallPath + data android.Paths testConfig android.Path } @@ -176,13 +178,13 @@ func (s *ShBinary) AndroidMkEntries() []android.AndroidMkEntries { ExtraEntries: []android.AndroidMkExtraEntriesFunc{ func(entries *android.AndroidMkEntries) { s.customAndroidMkEntries(entries) + entries.SetString("LOCAL_MODULE_RELATIVE_PATH", proptools.String(s.properties.Sub_dir)) }, }, }} } func (s *ShBinary) customAndroidMkEntries(entries *android.AndroidMkEntries) { - entries.SetString("LOCAL_MODULE_RELATIVE_PATH", proptools.String(s.properties.Sub_dir)) entries.SetString("LOCAL_MODULE_SUFFIX", "") entries.SetString("LOCAL_MODULE_STEM", s.outputFilePath.Rel()) if len(s.properties.Symlinks) > 0 { @@ -201,8 +203,14 @@ func (s *ShTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { } else if !ctx.Host() && ctx.Config().HasMultilibConflict(ctx.Arch().ArchType) { testDir = filepath.Join(testDir, ctx.Arch().ArchType.String()) } - installDir := android.PathForModuleInstall(ctx, testDir, proptools.String(s.properties.Sub_dir)) - s.installedFile = ctx.InstallExecutable(installDir, s.outputFilePath.Base(), s.outputFilePath) + if s.SubDir() != "" { + // Don't add the module name to the installation path if sub_dir is specified for backward + // compatibility. + s.installDir = android.PathForModuleInstall(ctx, testDir, s.SubDir()) + } else { + s.installDir = android.PathForModuleInstall(ctx, testDir, s.Name()) + } + s.installedFile = ctx.InstallExecutable(s.installDir, s.outputFilePath.Base(), s.outputFilePath) s.data = android.PathsForModuleSrc(ctx, s.testProperties.Data) @@ -229,7 +237,7 @@ func (s *ShTest) AndroidMkEntries() []android.AndroidMkEntries { ExtraEntries: []android.AndroidMkExtraEntriesFunc{ func(entries *android.AndroidMkEntries) { s.customAndroidMkEntries(entries) - + entries.SetPath("LOCAL_MODULE_PATH", s.installDir.ToMakePath()) entries.AddStrings("LOCAL_COMPATIBILITY_SUITE", s.testProperties.Test_suites...) if s.testConfig != nil { entries.SetPath("LOCAL_FULL_TEST_CONFIG", s.testConfig) diff --git a/sh/sh_binary_test.go b/sh/sh_binary_test.go index 6c0d96abe..3bfe6110a 100644 --- a/sh/sh_binary_test.go +++ b/sh/sh_binary_test.go @@ -55,7 +55,27 @@ func testShBinary(t *testing.T, bp string) (*android.TestContext, android.Config return ctx, config } -func TestShTestTestData(t *testing.T) { +func TestShTestSubDir(t *testing.T) { + ctx, config := testShBinary(t, ` + sh_test { + name: "foo", + src: "test.sh", + sub_dir: "foo_test" + } + `) + + mod := ctx.ModuleForTests("foo", "android_arm64_armv8-a").Module().(*ShTest) + + entries := android.AndroidMkEntriesForTest(t, config, "", mod)[0] + + expectedPath := "/tmp/target/product/test_device/data/nativetest64/foo_test" + actualPath := entries.EntryMap["LOCAL_MODULE_PATH"][0] + if expectedPath != actualPath { + t.Errorf("Unexpected LOCAL_MODULE_PATH expected: %q, actual: %q", expectedPath, actualPath) + } +} + +func TestShTest(t *testing.T) { ctx, config := testShBinary(t, ` sh_test { name: "foo", @@ -71,10 +91,17 @@ func TestShTestTestData(t *testing.T) { mod := ctx.ModuleForTests("foo", "android_arm64_armv8-a").Module().(*ShTest) entries := android.AndroidMkEntriesForTest(t, config, "", mod)[0] - expected := []string{":testdata/data1", ":testdata/sub/data2"} - actual := entries.EntryMap["LOCAL_TEST_DATA"] - if !reflect.DeepEqual(expected, actual) { - t.Errorf("Unexpected test data expected: %q, actual: %q", expected, actual) + + expectedPath := "/tmp/target/product/test_device/data/nativetest64/foo" + actualPath := entries.EntryMap["LOCAL_MODULE_PATH"][0] + if expectedPath != actualPath { + t.Errorf("Unexpected LOCAL_MODULE_PATH expected: %q, actual: %q", expectedPath, actualPath) + } + + expectedData := []string{":testdata/data1", ":testdata/sub/data2"} + actualData := entries.EntryMap["LOCAL_TEST_DATA"] + if !reflect.DeepEqual(expectedData, actualData) { + t.Errorf("Unexpected test data expected: %q, actual: %q", expectedData, actualData) } } |