Merge "Remove exportable modules when generating snapshots targeting older platform" into main
diff --git a/android/buildinfo_prop.go b/android/buildinfo_prop.go
index 8288fc5..083f3ef 100644
--- a/android/buildinfo_prop.go
+++ b/android/buildinfo_prop.go
@@ -23,7 +23,7 @@
func init() {
ctx := InitRegistrationContext
- ctx.RegisterParallelSingletonModuleType("buildinfo_prop", buildinfoPropFactory)
+ ctx.RegisterModuleType("buildinfo_prop", buildinfoPropFactory)
}
type buildinfoPropProperties struct {
@@ -32,7 +32,7 @@
}
type buildinfoPropModule struct {
- SingletonModuleBase
+ ModuleBase
properties buildinfoPropProperties
@@ -88,6 +88,10 @@
}
func (p *buildinfoPropModule) GenerateAndroidBuildActions(ctx ModuleContext) {
+ if ctx.ModuleName() != "buildinfo.prop" || ctx.ModuleDir() != "build/soong" {
+ ctx.ModuleErrorf("There can only be one buildinfo_prop module in build/soong")
+ return
+ }
p.outputFilePath = PathForModuleOut(ctx, p.Name()).OutputPath
if !ctx.Config().KatiEnabled() {
WriteFileRule(ctx, p.outputFilePath, "# no buildinfo.prop if kati is disabled")
@@ -111,10 +115,11 @@
cmd.FlagWithArg("--build-id=", config.BuildId())
cmd.FlagWithArg("--build-keys=", config.BuildKeys())
- // shouldn't depend on BuildNumberFile and BuildThumbprintFile to prevent from rebuilding
- // on every incremental build.
- cmd.FlagWithArg("--build-number-file=", config.BuildNumberFile(ctx).String())
+ // Note: depending on BuildNumberFile will cause the build.prop file to be rebuilt
+ // every build, but that's intentional.
+ cmd.FlagWithInput("--build-number-file=", config.BuildNumberFile(ctx))
if shouldAddBuildThumbprint(config) {
+ // In the previous make implementation, a dependency was not added on the thumbprint file
cmd.FlagWithArg("--build-thumbprint-file=", config.BuildThumbprintFile(ctx).String())
}
@@ -123,8 +128,10 @@
cmd.FlagWithArg("--build-variant=", buildVariant)
cmd.FlagForEachArg("--cpu-abis=", config.DeviceAbi())
- // shouldn't depend on BUILD_DATETIME_FILE to prevent from rebuilding on every incremental
- // build.
+ // Technically we should also have a dependency on BUILD_DATETIME_FILE,
+ // but it can be either an absolute or relative path, which is hard to turn into
+ // a Path object. So just rely on the BuildNumberFile always changing to cause
+ // us to rebuild.
cmd.FlagWithArg("--date-file=", ctx.Config().Getenv("BUILD_DATETIME_FILE"))
if len(config.ProductLocales()) > 0 {
@@ -163,12 +170,8 @@
ctx.InstallFile(p.installPath, p.Name(), p.outputFilePath)
}
-func (f *buildinfoPropModule) GenerateSingletonBuildActions(ctx SingletonContext) {
- // does nothing; buildinfo_prop is a singeton because two buildinfo modules don't make sense.
-}
-
func (p *buildinfoPropModule) AndroidMkEntries() []AndroidMkEntries {
- return []AndroidMkEntries{AndroidMkEntries{
+ return []AndroidMkEntries{{
Class: "ETC",
OutputFile: OptionalPathForPath(p.outputFilePath),
ExtraEntries: []AndroidMkExtraEntriesFunc{
@@ -184,7 +187,7 @@
// buildinfo_prop module generates a build.prop file, which contains a set of common
// system/build.prop properties, such as ro.build.version.*. Not all properties are implemented;
// currently this module is only for microdroid.
-func buildinfoPropFactory() SingletonModule {
+func buildinfoPropFactory() Module {
module := &buildinfoPropModule{}
module.AddProperties(&module.properties)
InitAndroidModule(module)
diff --git a/android/config.go b/android/config.go
index 5a6d40f..a18cb8b 100644
--- a/android/config.go
+++ b/android/config.go
@@ -370,6 +370,7 @@
} else {
// Make a decoder for it
jsonDecoder := json.NewDecoder(configFileReader)
+ jsonDecoder.DisallowUnknownFields()
err = jsonDecoder.Decode(configurable)
if err != nil {
return fmt.Errorf("config file: %s did not parse correctly: %s", filename, err.Error())
@@ -1333,10 +1334,6 @@
return c.productVariables.SourceRootDirs
}
-func (c *config) IncludeTags() []string {
- return c.productVariables.IncludeTags
-}
-
func (c *config) HostStaticBinaries() bool {
return Bool(c.productVariables.HostStaticBinaries)
}
@@ -1912,10 +1909,10 @@
}
func (c *deviceConfig) ShippingApiLevel() ApiLevel {
- if c.config.productVariables.ShippingApiLevel == nil {
+ if c.config.productVariables.Shipping_api_level == nil {
return NoneApiLevel
}
- apiLevel, _ := strconv.Atoi(*c.config.productVariables.ShippingApiLevel)
+ apiLevel, _ := strconv.Atoi(*c.config.productVariables.Shipping_api_level)
return uncheckedFinalApiLevel(apiLevel)
}
diff --git a/android/gen_notice.go b/android/gen_notice.go
index 6815f64..9adde9e 100644
--- a/android/gen_notice.go
+++ b/android/gen_notice.go
@@ -176,6 +176,7 @@
}
out := m.getStem() + m.getSuffix()
m.output = PathForModuleOut(ctx, out).OutputPath
+ ctx.SetOutputFiles(Paths{m.output}, "")
}
func GenNoticeFactory() Module {
@@ -193,16 +194,6 @@
return module
}
-var _ OutputFileProducer = (*genNoticeModule)(nil)
-
-// Implements OutputFileProducer
-func (m *genNoticeModule) OutputFiles(tag string) (Paths, error) {
- if tag == "" {
- return Paths{m.output}, nil
- }
- return nil, fmt.Errorf("unrecognized tag %q", tag)
-}
-
var _ AndroidMkEntriesProvider = (*genNoticeModule)(nil)
// Implements AndroidMkEntriesProvider
diff --git a/android/module.go b/android/module.go
index fed1d0e..dc585d2 100644
--- a/android/module.go
+++ b/android/module.go
@@ -915,6 +915,10 @@
// moduleInfoJSON can be filled out by GenerateAndroidBuildActions to write a JSON file that will
// be included in the final module-info.json produced by Make.
moduleInfoJSON *ModuleInfoJSON
+
+ // outputFiles stores the output of a module by tag and is used to set
+ // the OutputFilesProvider in GenerateBuildActions
+ outputFiles OutputFilesInfo
}
func (m *ModuleBase) AddJSONData(d *map[string]interface{}) {
@@ -1996,6 +2000,10 @@
m.buildParams = ctx.buildParams
m.ruleParams = ctx.ruleParams
m.variables = ctx.variables
+
+ if m.outputFiles.DefaultOutputFiles != nil || m.outputFiles.TaggedOutputFiles != nil {
+ SetProvider(ctx, OutputFilesProvider, m.outputFiles)
+ }
}
func SetJarJarPrefixHandler(handler func(ModuleContext)) {
@@ -2445,11 +2453,15 @@
}
func outputFilesForModule(ctx PathContext, module blueprint.Module, tag string) (Paths, error) {
+ outputFilesFromProvider, err := outputFilesForModuleFromProvider(ctx, module, tag)
+ if outputFilesFromProvider != nil || err != nil {
+ return outputFilesFromProvider, err
+ }
if outputFileProducer, ok := module.(OutputFileProducer); ok {
paths, err := outputFileProducer.OutputFiles(tag)
if err != nil {
- return nil, fmt.Errorf("failed to get output file from module %q: %s",
- pathContextName(ctx, module), err.Error())
+ return nil, fmt.Errorf("failed to get output file from module %q at tag %q: %s",
+ pathContextName(ctx, module), tag, err.Error())
}
return paths, nil
} else if sourceFileProducer, ok := module.(SourceFileProducer); ok {
@@ -2459,10 +2471,54 @@
paths := sourceFileProducer.Srcs()
return paths, nil
} else {
- return nil, fmt.Errorf("module %q is not an OutputFileProducer", pathContextName(ctx, module))
+ return nil, fmt.Errorf("module %q is not an OutputFileProducer or SourceFileProducer", pathContextName(ctx, module))
}
}
+// This method uses OutputFilesProvider for output files
+// *inter-module-communication*.
+// If mctx module is the same as the param module the output files are obtained
+// from outputFiles property of module base, to avoid both setting and
+// reading OutputFilesProvider before GenerateBuildActions is finished. Also
+// only empty-string-tag is supported in this case.
+// If a module doesn't have the OutputFilesProvider, nil is returned.
+func outputFilesForModuleFromProvider(ctx PathContext, module blueprint.Module, tag string) (Paths, error) {
+ // TODO: support OutputFilesProvider for singletons
+ mctx, ok := ctx.(ModuleContext)
+ if !ok {
+ return nil, nil
+ }
+ if mctx.Module() != module {
+ if outputFilesProvider, ok := OtherModuleProvider(mctx, module, OutputFilesProvider); ok {
+ if tag == "" {
+ return outputFilesProvider.DefaultOutputFiles, nil
+ } else if taggedOutputFiles, hasTag := outputFilesProvider.TaggedOutputFiles[tag]; hasTag {
+ return taggedOutputFiles, nil
+ } else {
+ return nil, fmt.Errorf("unsupported module reference tag %q", tag)
+ }
+ }
+ } else {
+ if tag == "" {
+ return mctx.Module().base().outputFiles.DefaultOutputFiles, nil
+ } else {
+ return nil, fmt.Errorf("unsupported tag %q for module getting its own output files", tag)
+ }
+ }
+ // TODO: Add a check for param module not having OutputFilesProvider set
+ return nil, nil
+}
+
+type OutputFilesInfo struct {
+ // default output files when tag is an empty string ""
+ DefaultOutputFiles Paths
+
+ // the corresponding output files for given tags
+ TaggedOutputFiles map[string]Paths
+}
+
+var OutputFilesProvider = blueprint.NewProvider[OutputFilesInfo]()
+
// Modules can implement HostToolProvider and return a valid OptionalPath from HostToolPath() to
// specify that they can be used as a tool by a genrule module.
type HostToolProvider interface {
diff --git a/android/module_context.go b/android/module_context.go
index 18adb30..591e270 100644
--- a/android/module_context.go
+++ b/android/module_context.go
@@ -212,6 +212,10 @@
// GenerateAndroidBuildActions. If it is called then the struct will be written out and included in
// the module-info.json generated by Make, and Make will not generate its own data for this module.
ModuleInfoJSON() *ModuleInfoJSON
+
+ // SetOutputFiles stores the outputFiles to outputFiles property, which is used
+ // to set the OutputFilesProvider later.
+ SetOutputFiles(outputFiles Paths, tag string)
}
type moduleContext struct {
@@ -707,6 +711,24 @@
return moduleInfoJSON
}
+func (m *moduleContext) SetOutputFiles(outputFiles Paths, tag string) {
+ if tag == "" {
+ if len(m.module.base().outputFiles.DefaultOutputFiles) > 0 {
+ m.ModuleErrorf("Module %s default OutputFiles cannot be overwritten", m.ModuleName())
+ }
+ m.module.base().outputFiles.DefaultOutputFiles = outputFiles
+ } else {
+ if m.module.base().outputFiles.TaggedOutputFiles == nil {
+ m.module.base().outputFiles.TaggedOutputFiles = make(map[string]Paths)
+ }
+ if _, exists := m.module.base().outputFiles.TaggedOutputFiles[tag]; exists {
+ m.ModuleErrorf("Module %s OutputFiles at tag %s cannot be overwritten", m.ModuleName(), tag)
+ } else {
+ m.module.base().outputFiles.TaggedOutputFiles[tag] = outputFiles
+ }
+ }
+}
+
// Returns a list of paths expanded from globs and modules referenced using ":module" syntax. The property must
// be tagged with `android:"path" to support automatic source module dependency resolution.
//
diff --git a/android/paths.go b/android/paths.go
index 8d92aa4..edc0700 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -565,21 +565,15 @@
if aModule, ok := module.(Module); ok && !aModule.Enabled(ctx) {
return nil, missingDependencyError{[]string{moduleName}}
}
- if outProducer, ok := module.(OutputFileProducer); ok {
- outputFiles, err := outProducer.OutputFiles(tag)
- if err != nil {
- return nil, fmt.Errorf("path dependency %q: %s", path, err)
- }
- return outputFiles, nil
- } else if tag != "" {
- return nil, fmt.Errorf("path dependency %q is not an output file producing module", path)
- } else if goBinary, ok := module.(bootstrap.GoBinaryTool); ok {
+ if goBinary, ok := module.(bootstrap.GoBinaryTool); ok && tag == "" {
goBinaryPath := PathForGoBinary(ctx, goBinary)
return Paths{goBinaryPath}, nil
- } else if srcProducer, ok := module.(SourceFileProducer); ok {
- return srcProducer.Srcs(), nil
+ }
+ outputFiles, err := outputFilesForModule(ctx, module, tag)
+ if outputFiles != nil && err == nil {
+ return outputFiles, nil
} else {
- return nil, fmt.Errorf("path dependency %q is not a source file producing module", path)
+ return nil, err
}
}
diff --git a/android/register.go b/android/register.go
index aeb3b4c..eb6a35e 100644
--- a/android/register.go
+++ b/android/register.go
@@ -156,7 +156,6 @@
func NewContext(config Config) *Context {
ctx := &Context{blueprint.NewContext(), config}
ctx.SetSrcDir(absSrcDir)
- ctx.AddIncludeTags(config.IncludeTags()...)
ctx.AddSourceRootDirs(config.SourceRootDirs()...)
return ctx
}
diff --git a/android/test_config.go b/android/test_config.go
index a15343a..f251038 100644
--- a/android/test_config.go
+++ b/android/test_config.go
@@ -50,7 +50,7 @@
AAPTCharacteristics: stringPtr("nosdcard"),
AAPTPrebuiltDPI: []string{"xhdpi", "xxhdpi"},
UncompressPrivAppDex: boolPtr(true),
- ShippingApiLevel: stringPtr("30"),
+ Shipping_api_level: stringPtr("30"),
},
outDir: buildDir,
diff --git a/android/variable.go b/android/variable.go
index 9a95563..1633816 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -55,6 +55,10 @@
Base_dir *string
}
+ Shipping_api_level struct {
+ Cflags []string
+ }
+
// unbundled_build is a catch-all property to annotate modules that don't build in one or
// more unbundled branches, usually due to dependencies missing from the manifest.
Unbundled_build struct {
@@ -440,7 +444,7 @@
PrebuiltHiddenApiDir *string `json:",omitempty"`
- ShippingApiLevel *string `json:",omitempty"`
+ Shipping_api_level *string `json:",omitempty"`
BuildBrokenPluginValidation []string `json:",omitempty"`
BuildBrokenClangAsFlags bool `json:",omitempty"`
@@ -472,7 +476,6 @@
IgnorePrefer32OnDevice bool `json:",omitempty"`
- IncludeTags []string `json:",omitempty"`
SourceRootDirs []string `json:",omitempty"`
AfdoProfiles []string `json:",omitempty"`
diff --git a/apex/apex.go b/apex/apex.go
index 1dec61b..e79afad 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -2112,7 +2112,7 @@
}
case bpfTag:
if bpfProgram, ok := child.(bpf.BpfModule); ok {
- filesToCopy, _ := bpfProgram.OutputFiles("")
+ filesToCopy := android.OutputFilesForModule(ctx, bpfProgram, "")
apex_sub_dir := bpfProgram.SubDir()
for _, bpfFile := range filesToCopy {
vctx.filesInfo = append(vctx.filesInfo, apexFileForBpfProgram(ctx, bpfFile, apex_sub_dir, bpfProgram))
diff --git a/apex/bootclasspath_fragment_test.go b/apex/bootclasspath_fragment_test.go
index 778c20a..af9123e 100644
--- a/apex/bootclasspath_fragment_test.go
+++ b/apex/bootclasspath_fragment_test.go
@@ -197,6 +197,12 @@
updatable: false,
}
+ override_apex {
+ name: "com.mycompany.android.art",
+ base: "com.android.art",
+ min_sdk_version: "33", // mycompany overrides the min_sdk_version
+ }
+
apex_key {
name: "com.android.art.key",
public_key: "testkey.avbpubkey",
@@ -325,6 +331,26 @@
checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo")
})
+ t.Run("boot image files from source of override apex", func(t *testing.T) {
+ result := android.GroupFixturePreparers(
+ commonPreparer,
+
+ // Configure some libraries in the art bootclasspath_fragment that match the source
+ // bootclasspath_fragment's contents property.
+ java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
+ dexpreopt.FixtureSetTestOnlyArtBootImageJars("com.android.art:foo", "com.android.art:bar"),
+ addSource("foo", "bar"),
+ java.FixtureSetBootImageInstallDirOnDevice("art", "apex/com.android.art/javalib"),
+ ).RunTest(t)
+
+ ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.mycompany.android.art_com.mycompany.android.art", []string{
+ "etc/boot-image.prof",
+ "etc/classpaths/bootclasspath.pb",
+ "javalib/bar.jar",
+ "javalib/foo.jar",
+ })
+ })
+
t.Run("generate boot image profile even if dexpreopt is disabled", func(t *testing.T) {
result := android.GroupFixturePreparers(
commonPreparer,
diff --git a/bin/Android.bp b/bin/Android.bp
new file mode 100644
index 0000000..4d6d911
--- /dev/null
+++ b/bin/Android.bp
@@ -0,0 +1,26 @@
+// Copyright 2024 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+ default_team: "trendy_team_build",
+}
+
+filegroup {
+ name: "run_tool_with_logging_script",
+ visibility: [
+ "//build/soong/tests:__subpackages__",
+ ],
+ srcs: ["run_tool_with_logging"],
+}
diff --git a/bin/dirmods b/bin/dirmods
index d43506a..52d935a 100755
--- a/bin/dirmods
+++ b/bin/dirmods
@@ -14,25 +14,27 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+'''
+Lists all modules in the given directory or its decendant directories, as cached
+in module-info.json. If any build change is made, and it should be reflected in
+the output, you should run 'refreshmod' first.
+'''
+
import sys
sys.dont_write_bytecode = True
-import modinfo
-
+import argparse
import os
-# Get the path of a specific module in the android tree, as cached in module-info.json.
-# If any build change is made, and it should be reflected in the output, you should run
-# 'refreshmod' first. Note: This is the inverse of pathmod.
+import modinfo
-def main(argv):
- if len(argv) != 2:
- sys.stderr.write("usage: usage: dirmods <path>\n")
- sys.exit(1)
- d = argv[1]
- while d.endswith('/'):
- d = d[:-1]
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument('path')
+ args = parser.parse_args()
+
+ d = os.path.normpath(args.path)
prefix = d + '/'
module_info = modinfo.ReadModuleInfo()
@@ -49,4 +51,4 @@
print(name)
if __name__ == "__main__":
- main(sys.argv)
+ main()
diff --git a/bin/outmod b/bin/outmod
index 681b405..022ff36 100755
--- a/bin/outmod
+++ b/bin/outmod
@@ -14,26 +14,29 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# Get the path of a specific module in the android tree, as cached in module-info.json.
-# If any build change is made, and it should be reflected in the output, you should run
-# 'refreshmod' first. Note: This is the inverse of dirmods.
+'''
+Lists the output files of a specific module in the android tree, as cached in
+module-info.json. If any build change is made, and it should be reflected in the
+output, you should run 'refreshmod' first.
+'''
import sys
sys.dont_write_bytecode = True
-import modinfo
-
+import argparse
import os
+import modinfo
-def main(argv):
- if len(argv) != 2:
- sys.stderr.write("usage: outmod <module>\n")
- sys.exit(1)
- for output in modinfo.GetModule(modinfo.ReadModuleInfo(), argv[1])['installed']:
- print(os.path.join(os.getenv("ANDROID_BUILD_TOP"), output))
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument('module')
+ args = parser.parse_args()
+
+ for output in modinfo.GetModule(modinfo.ReadModuleInfo(), args.module)['installed']:
+ print(os.path.join(os.getenv("ANDROID_BUILD_TOP", ""), output))
if __name__ == "__main__":
- main(sys.argv)
+ main()
diff --git a/bin/pathmod b/bin/pathmod
index 90d84b5..70cf958 100755
--- a/bin/pathmod
+++ b/bin/pathmod
@@ -14,24 +14,28 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# Get the path of a specific module in the android tree, as cached in module-info.json.
-# If any build change is made, and it should be reflected in the output, you should run
-# 'refreshmod' first. Note: This is the inverse of dirmods.
+'''
+Get the path of a specific module in the android tree, as cached in module-info.json.
+If any build change is made, and it should be reflected in the output, you should run
+'refreshmod' first. Note: This is the inverse of dirmods.
+'''
import sys
sys.dont_write_bytecode = True
-import modinfo
-
+import argparse
import os
+import modinfo
-def main(argv):
- if len(argv) != 2:
- sys.stderr.write("usage: pathmod <module>\n")
- sys.exit(1)
- print(modinfo.GetModule(modinfo.ReadModuleInfo(), argv[1])['path'][0])
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument('module')
+ args = parser.parse_args()
+
+ path = modinfo.GetModule(modinfo.ReadModuleInfo(), args.module)['path'][0]
+ print(os.path.join(os.getenv("ANDROID_BUILD_TOP", ""), path))
if __name__ == "__main__":
- main(sys.argv)
+ main()
diff --git a/bin/run_tool_with_logging b/bin/run_tool_with_logging
new file mode 100755
index 0000000..2b2c8d8
--- /dev/null
+++ b/bin/run_tool_with_logging
@@ -0,0 +1,55 @@
+#!/bin/bash
+
+# Copyright (C) 2024 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Run commands in a subshell for us to handle forced terminations with a trap
+# handler.
+(
+tool_tag="$1"
+shift
+tool_binary="$1"
+shift
+
+# If the logger is not configured, run the original command and return.
+if [[ -z "${ANDROID_TOOL_LOGGER}" ]]; then
+ "${tool_binary}" "${@}"
+ exit $?
+fi
+
+# Otherwise, run the original command and call the logger when done.
+start_time=$(date +%s.%N)
+logger=${ANDROID_TOOL_LOGGER}
+
+# Install a trap to call the logger even when the process terminates abnormally.
+# The logger is run in the background and its output suppressed to avoid
+# interference with the user flow.
+trap '
+exit_code=$?;
+# Remove the trap to prevent duplicate log.
+trap - EXIT;
+"${logger}" \
+ --tool_tag="${tool_tag}" \
+ --start_timestamp="${start_time}" \
+ --end_timestamp="$(date +%s.%N)" \
+ --tool_args="$*" \
+ --exit_code="${exit_code}" \
+ ${ANDROID_TOOL_LOGGER_EXTRA_ARGS} \
+ > /dev/null 2>&1 &
+exit ${exit_code}
+' SIGINT SIGTERM SIGQUIT EXIT
+
+# Run the original command.
+"${tool_binary}" "${@}"
+)
diff --git a/bpf/bpf.go b/bpf/bpf.go
index 38fbd88..2eb869e 100644
--- a/bpf/bpf.go
+++ b/bpf/bpf.go
@@ -65,8 +65,6 @@
type BpfModule interface {
android.Module
- OutputFiles(tag string) (android.Paths, error)
-
// Returns the sub install directory if the bpf module is included by apex.
SubDir() string
}
@@ -213,6 +211,8 @@
}
android.SetProvider(ctx, blueprint.SrcsFileProviderKey, blueprint.SrcsFileProviderData{SrcPaths: srcs.Strings()})
+
+ ctx.SetOutputFiles(bpf.objs, "")
}
func (bpf *bpf) AndroidMk() android.AndroidMkData {
@@ -255,23 +255,10 @@
}
}
-// Implements OutputFileFileProducer interface so that the obj output can be used in the data property
-// of other modules.
-func (bpf *bpf) OutputFiles(tag string) (android.Paths, error) {
- switch tag {
- case "":
- return bpf.objs, nil
- default:
- return nil, fmt.Errorf("unsupported module reference tag %q", tag)
- }
-}
-
func (bpf *bpf) SubDir() string {
return bpf.properties.Sub_dir
}
-var _ android.OutputFileProducer = (*bpf)(nil)
-
func BpfFactory() android.Module {
module := &bpf{}
diff --git a/cc/androidmk.go b/cc/androidmk.go
index e1bc336..62ba4de 100644
--- a/cc/androidmk.go
+++ b/cc/androidmk.go
@@ -486,14 +486,14 @@
ctx.subAndroidMk(entries, p.libraryDecorator)
if p.shared() {
ctx.subAndroidMk(entries, &p.prebuiltLinker)
- androidMkWriteAllowUndefinedSymbols(p.baseLinker, entries)
+ androidMkWritePrebuiltOptions(p.baseLinker, entries)
}
}
func (p *prebuiltBinaryLinker) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
ctx.subAndroidMk(entries, p.binaryDecorator)
ctx.subAndroidMk(entries, &p.prebuiltLinker)
- androidMkWriteAllowUndefinedSymbols(p.baseLinker, entries)
+ androidMkWritePrebuiltOptions(p.baseLinker, entries)
}
func (a *apiLibraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
@@ -524,11 +524,17 @@
})
}
-func androidMkWriteAllowUndefinedSymbols(linker *baseLinker, entries *android.AndroidMkEntries) {
+func androidMkWritePrebuiltOptions(linker *baseLinker, entries *android.AndroidMkEntries) {
allow := linker.Properties.Allow_undefined_symbols
if allow != nil {
entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
entries.SetBool("LOCAL_ALLOW_UNDEFINED_SYMBOLS", *allow)
})
}
+ ignore := linker.Properties.Ignore_max_page_size
+ if ignore != nil {
+ entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
+ entries.SetBool("LOCAL_IGNORE_MAX_PAGE_SIZE", *ignore)
+ })
+ }
}
diff --git a/cc/compiler.go b/cc/compiler.go
index 34d98c0..75a144d 100644
--- a/cc/compiler.go
+++ b/cc/compiler.go
@@ -101,7 +101,7 @@
Generated_headers []string `android:"arch_variant,variant_prepend"`
// pass -frtti instead of -fno-rtti
- Rtti *bool
+ Rtti *bool `android:"arch_variant"`
// C standard version to use. Can be a specific version (such as "gnu11"),
// "experimental" (which will use draft versions like C1x when available),
diff --git a/cc/linker.go b/cc/linker.go
index 1b5a33a..1675df6 100644
--- a/cc/linker.go
+++ b/cc/linker.go
@@ -65,6 +65,10 @@
// This flag should only be necessary for compiling low-level libraries like libc.
Allow_undefined_symbols *bool `android:"arch_variant"`
+ // ignore max page size. By default, max page size must be the
+ // max page size set for the target.
+ Ignore_max_page_size *bool `android:"arch_variant"`
+
// don't link in libclang_rt.builtins-*.a
No_libcrt *bool `android:"arch_variant"`
diff --git a/cmd/release_config/build_flag/main.go b/cmd/release_config/build_flag/main.go
index cc2b57a..f74784b 100644
--- a/cmd/release_config/build_flag/main.go
+++ b/cmd/release_config/build_flag/main.go
@@ -48,6 +48,11 @@
// Panic on errors.
debug bool
+
+ // Allow missing release config.
+ // If true, and we cannot find the named release config, values for
+ // `trunk_staging` will be used.
+ allowMissing bool
}
type CommandFunc func(*rc_lib.ReleaseConfigs, Flags, string, []string) error
@@ -284,7 +289,7 @@
}
// Reload the release configs.
- configs, err = rc_lib.ReadReleaseConfigMaps(commonFlags.maps, commonFlags.targetReleases[0], commonFlags.useGetBuildVar)
+ configs, err = rc_lib.ReadReleaseConfigMaps(commonFlags.maps, commonFlags.targetReleases[0], commonFlags.useGetBuildVar, commonFlags.allowMissing)
if err != nil {
return err
}
@@ -307,6 +312,7 @@
flag.Var(&commonFlags.maps, "map", "path to a release_config_map.textproto. may be repeated")
flag.StringVar(&commonFlags.outDir, "out-dir", rc_lib.GetDefaultOutDir(), "basepath for the output. Multiple formats are created")
flag.Var(&commonFlags.targetReleases, "release", "TARGET_RELEASE for this build")
+ flag.BoolVar(&commonFlags.allowMissing, "allow-missing", false, "Use trunk_staging values if release not found")
flag.BoolVar(&commonFlags.allReleases, "all-releases", false, "operate on all releases. (Ignored for set command)")
flag.BoolVar(&commonFlags.useGetBuildVar, "use-get-build-var", true, "use get_build_var PRODUCT_RELEASE_CONFIG_MAPS to get needed maps")
flag.BoolVar(&commonFlags.debug, "debug", false, "turn on debugging output for errors")
@@ -342,7 +348,7 @@
if relName == "--all" || relName == "-all" {
commonFlags.allReleases = true
}
- configs, err = rc_lib.ReadReleaseConfigMaps(commonFlags.maps, relName, commonFlags.useGetBuildVar)
+ configs, err = rc_lib.ReadReleaseConfigMaps(commonFlags.maps, relName, commonFlags.useGetBuildVar, commonFlags.allowMissing)
if err != nil {
errorExit(err)
}
diff --git a/cmd/release_config/release_config/main.go b/cmd/release_config/release_config/main.go
index 24deacc..bd4ab49 100644
--- a/cmd/release_config/release_config/main.go
+++ b/cmd/release_config/release_config/main.go
@@ -34,7 +34,7 @@
var json, pb, textproto, inheritance bool
var product string
var allMake bool
- var useBuildVar bool
+ var useBuildVar, allowMissing bool
var guard bool
defaultRelease := os.Getenv("TARGET_RELEASE")
@@ -47,6 +47,7 @@
flag.BoolVar(&quiet, "quiet", false, "disable warning messages")
flag.Var(&releaseConfigMapPaths, "map", "path to a release_config_map.textproto. may be repeated")
flag.StringVar(&targetRelease, "release", defaultRelease, "TARGET_RELEASE for this build")
+ flag.BoolVar(&allowMissing, "allow-missing", false, "Use trunk_staging values if release not found")
flag.StringVar(&outputDir, "out_dir", rc_lib.GetDefaultOutDir(), "basepath for the output. Multiple formats are created")
flag.BoolVar(&textproto, "textproto", true, "write artifacts as text protobuf")
flag.BoolVar(&json, "json", true, "write artifacts as json")
@@ -65,7 +66,7 @@
if err = os.Chdir(top); err != nil {
panic(err)
}
- configs, err = rc_lib.ReadReleaseConfigMaps(releaseConfigMapPaths, targetRelease, useBuildVar)
+ configs, err = rc_lib.ReadReleaseConfigMaps(releaseConfigMapPaths, targetRelease, useBuildVar, allowMissing)
if err != nil {
panic(err)
}
diff --git a/cmd/release_config/release_config_lib/release_configs.go b/cmd/release_config/release_config_lib/release_configs.go
index 4b4e355..052cde8 100644
--- a/cmd/release_config/release_config_lib/release_configs.go
+++ b/cmd/release_config/release_config_lib/release_configs.go
@@ -76,22 +76,26 @@
// A map from the config directory to its order in the list of config
// directories.
configDirIndexes ReleaseConfigDirMap
+
+ // True if we should allow a missing primary release config. In this
+ // case, we will substitute `trunk_staging` values, but the release
+ // config will not be in ALL_RELEASE_CONFIGS_FOR_PRODUCT.
+ allowMissing bool
}
func (configs *ReleaseConfigs) WriteInheritanceGraph(outFile string) error {
data := []string{}
usedAliases := make(map[string]bool)
priorStages := make(map[string][]string)
- rankedStageNames := make(map[string]bool)
for _, config := range configs.ReleaseConfigs {
+ if config.Name == "root" {
+ continue
+ }
var fillColor string
inherits := []string{}
for _, inherit := range config.InheritNames {
if inherit == "root" {
- // Only show "root" if we have no other inheritance.
- if len(config.InheritNames) > 1 {
- continue
- }
+ continue
}
data = append(data, fmt.Sprintf(`"%s" -> "%s"`, config.Name, inherit))
inherits = append(inherits, inherit)
@@ -108,14 +112,9 @@
}
// Add links for all of the advancement progressions.
for priorStage := range config.PriorStagesMap {
- stageName := config.Name
- if len(config.OtherNames) > 0 {
- stageName = config.OtherNames[0]
- }
data = append(data, fmt.Sprintf(`"%s" -> "%s" [ style=dashed color="#81c995" ]`,
- priorStage, stageName))
- priorStages[stageName] = append(priorStages[stageName], priorStage)
- rankedStageNames[stageName] = true
+ priorStage, config.Name))
+ priorStages[config.Name] = append(priorStages[config.Name], priorStage)
}
label := config.Name
if len(inherits) > 0 {
@@ -124,16 +123,24 @@
if len(config.OtherNames) > 0 {
label += "\\nother names: " + strings.Join(config.OtherNames, " ")
}
- // The active release config has a light blue fill.
- if config.Name == *configs.Artifact.ReleaseConfig.Name {
+ switch config.Name {
+ case *configs.Artifact.ReleaseConfig.Name:
+ // The active release config has a light blue fill.
fillColor = `fillcolor="#d2e3fc" `
+ case "trunk", "trunk_staging":
+ // Certain workflow stages have a light green fill.
+ fillColor = `fillcolor="#ceead6" `
+ default:
+ // Look for "next" and "*_next", make them light green as well.
+ for _, n := range config.OtherNames {
+ if n == "next" || strings.HasSuffix(n, "_next") {
+ fillColor = `fillcolor="#ceead6" `
+ }
+ }
}
data = append(data,
fmt.Sprintf(`"%s" [ label="%s" %s]`, config.Name, label, fillColor))
}
- if len(rankedStageNames) > 0 {
- data = append(data, fmt.Sprintf("subgraph {rank=same %s}", strings.Join(SortedMapKeys(rankedStageNames), " ")))
- }
slices.Sort(data)
data = append([]string{
"digraph {",
@@ -374,6 +381,11 @@
if config, ok := configs.ReleaseConfigs[name]; ok {
return config, nil
}
+ if configs.allowMissing {
+ if config, ok := configs.ReleaseConfigs["trunk_staging"]; ok {
+ return config, nil
+ }
+ }
return nil, fmt.Errorf("Missing config %s. Trace=%v", name, trace)
}
@@ -521,7 +533,7 @@
return nil
}
-func ReadReleaseConfigMaps(releaseConfigMapPaths StringList, targetRelease string, useBuildVar bool) (*ReleaseConfigs, error) {
+func ReadReleaseConfigMaps(releaseConfigMapPaths StringList, targetRelease string, useBuildVar, allowMissing bool) (*ReleaseConfigs, error) {
var err error
if len(releaseConfigMapPaths) == 0 {
@@ -538,6 +550,7 @@
}
configs := ReleaseConfigsFactory()
+ configs.allowMissing = allowMissing
mapsRead := make(map[string]bool)
var idx int
for _, releaseConfigMapPath := range releaseConfigMapPaths {
diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go
index 4490dd2..3dac8bd 100644
--- a/cmd/soong_build/main.go
+++ b/cmd/soong_build/main.go
@@ -98,7 +98,6 @@
ctx := android.NewContext(configuration)
ctx.SetNameInterface(newNameResolver(configuration))
ctx.SetAllowMissingDependencies(configuration.AllowMissingDependencies())
- ctx.AddIncludeTags(configuration.IncludeTags()...)
ctx.AddSourceRootDirs(configuration.SourceRootDirs()...)
return ctx
}
diff --git a/cmd/soong_ui/main.go b/cmd/soong_ui/main.go
index fe3f8f7..2d3156a 100644
--- a/cmd/soong_ui/main.go
+++ b/cmd/soong_ui/main.go
@@ -155,7 +155,6 @@
// Create a new trace file writer, making it log events to the log instance.
trace := tracer.New(log)
- defer trace.Close()
// Create a new Status instance, which manages action counts and event output channels.
stat := &status.Status{}
@@ -194,14 +193,29 @@
soongMetricsFile := filepath.Join(logsDir, c.logsPrefix+"soong_metrics")
rbeMetricsFile := filepath.Join(logsDir, c.logsPrefix+"rbe_metrics.pb")
soongBuildMetricsFile := filepath.Join(logsDir, c.logsPrefix+"soong_build_metrics.pb")
+ buildTraceFile := filepath.Join(logsDir, c.logsPrefix+"build.trace.gz")
metricsFiles := []string{
buildErrorFile, // build error strings
rbeMetricsFile, // high level metrics related to remote build execution.
soongMetricsFile, // high level metrics related to this build system.
soongBuildMetricsFile, // high level metrics related to soong build
+ buildTraceFile,
}
+ defer func() {
+ stat.Finish()
+ criticalPath.WriteToMetrics(met)
+ met.Dump(soongMetricsFile)
+ if !config.SkipMetricsUpload() {
+ build.UploadMetrics(buildCtx, config, c.simpleOutput, buildStarted, metricsFiles...)
+ }
+ }()
+
+ // This has to come after the metrics uploading function, so that
+ // build.trace.gz is closed and ready for upload.
+ defer trace.Close()
+
os.MkdirAll(logsDir, 0777)
log.SetOutput(filepath.Join(logsDir, c.logsPrefix+"soong.log"))
@@ -222,16 +236,7 @@
config = freshConfig()
}
- defer func() {
- stat.Finish()
- criticalPath.WriteToMetrics(met)
- met.Dump(soongMetricsFile)
- if !config.SkipMetricsUpload() {
- build.UploadMetrics(buildCtx, config, c.simpleOutput, buildStarted, metricsFiles...)
- }
- }()
c.run(buildCtx, config, args)
-
}
// This function must not modify config, since product config may cause us to recreate the config,
diff --git a/filesystem/avb_gen_vbmeta_image.go b/filesystem/avb_gen_vbmeta_image.go
index 985f0ea..a7fd782 100644
--- a/filesystem/avb_gen_vbmeta_image.go
+++ b/filesystem/avb_gen_vbmeta_image.go
@@ -81,6 +81,8 @@
a.output = android.PathForModuleOut(ctx, a.installFileName()).OutputPath
cmd.FlagWithOutput("--output_vbmeta_image ", a.output)
builder.Build("avbGenVbmetaImage", fmt.Sprintf("avbGenVbmetaImage %s", ctx.ModuleName()))
+
+ ctx.SetOutputFiles([]android.Path{a.output}, "")
}
var _ android.AndroidMkEntriesProvider = (*avbGenVbmetaImage)(nil)
@@ -99,16 +101,6 @@
}}
}
-var _ android.OutputFileProducer = (*avbGenVbmetaImage)(nil)
-
-// Implements android.OutputFileProducer
-func (a *avbGenVbmetaImage) OutputFiles(tag string) (android.Paths, error) {
- if tag == "" {
- return []android.Path{a.output}, nil
- }
- return nil, fmt.Errorf("unsupported module reference tag %q", tag)
-}
-
type avbGenVbmetaImageDefaults struct {
android.ModuleBase
android.DefaultsModuleBase
diff --git a/filesystem/bootimg.go b/filesystem/bootimg.go
index 352b451..e796ab9 100644
--- a/filesystem/bootimg.go
+++ b/filesystem/bootimg.go
@@ -123,6 +123,8 @@
b.installDir = android.PathForModuleInstall(ctx, "etc")
ctx.InstallFile(b.installDir, b.installFileName(), b.output)
+
+ ctx.SetOutputFiles([]android.Path{b.output}, "")
}
func (b *bootimg) buildBootImage(ctx android.ModuleContext, vendor bool) android.OutputPath {
@@ -292,13 +294,3 @@
}
return nil
}
-
-var _ android.OutputFileProducer = (*bootimg)(nil)
-
-// Implements android.OutputFileProducer
-func (b *bootimg) OutputFiles(tag string) (android.Paths, error) {
- if tag == "" {
- return []android.Path{b.output}, nil
- }
- return nil, fmt.Errorf("unsupported module reference tag %q", tag)
-}
diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go
index d2572c2..c889dd6 100644
--- a/filesystem/filesystem.go
+++ b/filesystem/filesystem.go
@@ -221,6 +221,8 @@
f.installDir = android.PathForModuleInstall(ctx, "etc")
ctx.InstallFile(f.installDir, f.installFileName(), f.output)
+
+ ctx.SetOutputFiles([]android.Path{f.output}, "")
}
func validatePartitionType(ctx android.ModuleContext, p partition) {
@@ -561,16 +563,6 @@
}}
}
-var _ android.OutputFileProducer = (*filesystem)(nil)
-
-// Implements android.OutputFileProducer
-func (f *filesystem) OutputFiles(tag string) (android.Paths, error) {
- if tag == "" {
- return []android.Path{f.output}, nil
- }
- return nil, fmt.Errorf("unsupported module reference tag %q", tag)
-}
-
// Filesystem is the public interface for the filesystem struct. Currently, it's only for the apex
// package to have access to the output file.
type Filesystem interface {
diff --git a/filesystem/logical_partition.go b/filesystem/logical_partition.go
index e2f7d7b..e483fe4 100644
--- a/filesystem/logical_partition.go
+++ b/filesystem/logical_partition.go
@@ -185,6 +185,8 @@
l.installDir = android.PathForModuleInstall(ctx, "etc")
ctx.InstallFile(l.installDir, l.installFileName(), l.output)
+
+ ctx.SetOutputFiles([]android.Path{l.output}, "")
}
// Add a rule that converts the filesystem for the given partition to the given rule builder. The
@@ -231,13 +233,3 @@
func (l *logicalPartition) SignedOutputPath() android.Path {
return nil // logical partition is not signed by itself
}
-
-var _ android.OutputFileProducer = (*logicalPartition)(nil)
-
-// Implements android.OutputFileProducer
-func (l *logicalPartition) OutputFiles(tag string) (android.Paths, error) {
- if tag == "" {
- return []android.Path{l.output}, nil
- }
- return nil, fmt.Errorf("unsupported module reference tag %q", tag)
-}
diff --git a/filesystem/raw_binary.go b/filesystem/raw_binary.go
index 1544ea7..ad36c29 100644
--- a/filesystem/raw_binary.go
+++ b/filesystem/raw_binary.go
@@ -15,8 +15,6 @@
package filesystem
import (
- "fmt"
-
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
@@ -88,6 +86,8 @@
r.output = outputFile
r.installDir = android.PathForModuleInstall(ctx, "etc")
ctx.InstallFile(r.installDir, r.installFileName(), r.output)
+
+ ctx.SetOutputFiles([]android.Path{r.output}, "")
}
var _ android.AndroidMkEntriesProvider = (*rawBinary)(nil)
@@ -109,13 +109,3 @@
func (r *rawBinary) SignedOutputPath() android.Path {
return nil
}
-
-var _ android.OutputFileProducer = (*rawBinary)(nil)
-
-// Implements android.OutputFileProducer
-func (r *rawBinary) OutputFiles(tag string) (android.Paths, error) {
- if tag == "" {
- return []android.Path{r.output}, nil
- }
- return nil, fmt.Errorf("unsupported module reference tag %q", tag)
-}
diff --git a/filesystem/vbmeta.go b/filesystem/vbmeta.go
index 43a2f37..0c6e7f4 100644
--- a/filesystem/vbmeta.go
+++ b/filesystem/vbmeta.go
@@ -211,6 +211,8 @@
v.installDir = android.PathForModuleInstall(ctx, "etc")
ctx.InstallFile(v.installDir, v.installFileName(), v.output)
+
+ ctx.SetOutputFiles([]android.Path{v.output}, "")
}
// Returns the embedded shell command that prints the rollback index
@@ -288,13 +290,3 @@
func (v *vbmeta) SignedOutputPath() android.Path {
return v.OutputPath() // vbmeta is always signed
}
-
-var _ android.OutputFileProducer = (*vbmeta)(nil)
-
-// Implements android.OutputFileProducer
-func (v *vbmeta) OutputFiles(tag string) (android.Paths, error) {
- if tag == "" {
- return []android.Path{v.output}, nil
- }
- return nil, fmt.Errorf("unsupported module reference tag %q", tag)
-}
diff --git a/genrule/genrule.go b/genrule/genrule.go
index dd980cb..26dad01 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -126,7 +126,7 @@
// $(out): a single output file.
// $(genDir): the sandbox directory for this tool; contains $(out).
// $$: a literal $
- Cmd *string
+ Cmd proptools.Configurable[string] `android:"replace_instead_of_append"`
// name of the modules (if any) that produces the host executable. Leave empty for
// prebuilts or scripts that do not need a module to build them.
@@ -403,7 +403,7 @@
var outputFiles android.WritablePaths
var zipArgs strings.Builder
- cmd := String(g.properties.Cmd)
+ cmd := g.properties.Cmd.GetOrDefault(ctx, "")
if g.CmdModifier != nil {
cmd = g.CmdModifier(ctx, cmd)
}
diff --git a/java/app.go b/java/app.go
index d2f2d0b..a24099c 100644
--- a/java/app.go
+++ b/java/app.go
@@ -1380,6 +1380,8 @@
HostRequiredModuleNames: a.HostRequiredModuleNames(),
TestSuites: a.testProperties.Test_suites,
IsHost: false,
+ LocalCertificate: a.certificate.AndroidMkString(),
+ IsUnitTest: Bool(a.testProperties.Test_options.Unit_test),
})
android.SetProvider(ctx, android.TestOnlyProviderKey, android.TestModuleInformation{
TestOnly: true,
diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go
index 4d3d794..16209b7 100644
--- a/java/bootclasspath_fragment.go
+++ b/java/bootclasspath_fragment.go
@@ -524,10 +524,16 @@
}
// Bootclasspath fragment modules that are for the platform do not produce boot related files.
- apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider)
- for _, apex := range apexInfo.InApexVariants {
- if isProfileProviderApex(ctx, apex) {
- return apex
+ apexInfos, _ := android.ModuleProvider(ctx, android.AllApexInfoProvider)
+ if apexInfos == nil {
+ return ""
+ }
+
+ for _, apexInfo := range apexInfos.ApexInfos {
+ for _, apex := range apexInfo.InApexVariants {
+ if isProfileProviderApex(ctx, apex) {
+ return apex
+ }
}
}
diff --git a/java/droidstubs.go b/java/droidstubs.go
index 5ca6c25..b32b754 100644
--- a/java/droidstubs.go
+++ b/java/droidstubs.go
@@ -1054,8 +1054,7 @@
}
if !treatDocumentationIssuesAsErrors {
- // Treat documentation issues as warnings, but error when new.
- cmd.Flag("--error-when-new-category").Flag("Documentation")
+ treatDocumentationIssuesAsWarningErrorWhenNew(cmd)
}
// Add "check released" options. (Detect incompatible API changes from the last public release)
@@ -1083,6 +1082,22 @@
}
}
+// HIDDEN_DOCUMENTATION_ISSUES is the set of documentation related issues that should always be
+// hidden as they are very noisy and provide little value.
+var HIDDEN_DOCUMENTATION_ISSUES = []string{
+ "Deprecated",
+ "IntDef",
+ "Nullable",
+}
+
+func treatDocumentationIssuesAsWarningErrorWhenNew(cmd *android.RuleBuilderCommand) {
+ // Treat documentation issues as warnings, but error when new.
+ cmd.Flag("--error-when-new-category").Flag("Documentation")
+
+ // Hide some documentation issues that generated a lot of noise for little benefit.
+ cmd.FlagForEachArg("--hide ", HIDDEN_DOCUMENTATION_ISSUES)
+}
+
// Sandbox rule for generating exportable stubs and other artifacts
func (d *Droidstubs) exportableStubCmd(ctx android.ModuleContext, params stubsCommandConfigParams) {
optionalCmdParams := stubsCommandParams{
@@ -1154,7 +1169,7 @@
}
// Treat documentation issues as warnings, but error when new.
- cmd.Flag("--error-when-new-category").Flag("Documentation")
+ treatDocumentationIssuesAsWarningErrorWhenNew(cmd)
if params.stubConfig.generateStubs {
rule.Command().
diff --git a/java/java.go b/java/java.go
index b851e74..08fb678 100644
--- a/java/java.go
+++ b/java/java.go
@@ -1504,6 +1504,8 @@
RequiredModuleNames: j.RequiredModuleNames(),
TestSuites: j.testProperties.Test_suites,
IsHost: true,
+ LocalSdkVersion: j.sdkVersion.String(),
+ IsUnitTest: Bool(j.testProperties.Test_options.Unit_test),
})
}
diff --git a/java/sdk_library_test.go b/java/sdk_library_test.go
index d240e70..39f8c76 100644
--- a/java/sdk_library_test.go
+++ b/java/sdk_library_test.go
@@ -492,7 +492,7 @@
PrepareForTestWithJavaSdkLibraryFiles,
FixtureWithLastReleaseApis("foo"),
).
- ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`module "bar" variant "android_common": path dependency ":foo{.public.annotations.zip}": annotations.zip not available for api scope public`)).
+ ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`module "bar" variant "android_common": failed to get output file from module "foo" at tag ".public.annotations.zip": annotations.zip not available for api scope public`)).
RunTestWithBp(t, `
java_sdk_library {
name: "foo",
diff --git a/tests/Android.bp b/tests/Android.bp
new file mode 100644
index 0000000..458cf4b
--- /dev/null
+++ b/tests/Android.bp
@@ -0,0 +1,34 @@
+// Copyright 2024 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+ default_team: "trendy_team_build",
+}
+
+python_test_host {
+ name: "run_tool_with_logging_test",
+ main: "run_tool_with_logging_test.py",
+ pkg_path: "testdata",
+ srcs: [
+ "run_tool_with_logging_test.py",
+ ],
+ test_options: {
+ unit_test: true,
+ },
+ data: [
+ ":run_tool_with_logging_script",
+ ":tool_event_logger",
+ ],
+}
diff --git a/tests/run_tool_with_logging_test.py b/tests/run_tool_with_logging_test.py
new file mode 100644
index 0000000..57a6d62
--- /dev/null
+++ b/tests/run_tool_with_logging_test.py
@@ -0,0 +1,337 @@
+# Copyright 2024 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import dataclasses
+import glob
+from importlib import resources
+import logging
+import os
+from pathlib import Path
+import re
+import shutil
+import signal
+import stat
+import subprocess
+import sys
+import tempfile
+import textwrap
+import time
+import unittest
+
+EXII_RETURN_CODE = 0
+INTERRUPTED_RETURN_CODE = 130
+
+
+class RunToolWithLoggingTest(unittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ super().setUpClass()
+ # Configure to print logging to stdout.
+ logging.basicConfig(filename=None, level=logging.DEBUG)
+ console = logging.StreamHandler(sys.stdout)
+ logging.getLogger("").addHandler(console)
+
+ def setUp(self):
+ super().setUp()
+ self.working_dir = tempfile.TemporaryDirectory()
+ # Run all the tests from working_dir which is our temp Android build top.
+ os.chdir(self.working_dir.name)
+
+ self.logging_script_path = self._import_executable("run_tool_with_logging")
+
+ def tearDown(self):
+ self.working_dir.cleanup()
+ super().tearDown()
+
+ def test_does_not_log_when_logger_var_empty(self):
+ test_tool = TestScript.create(self.working_dir)
+
+ self._run_script_and_wait(f"""
+ export ANDROID_TOOL_LOGGER=""
+ {self.logging_script_path} "FAKE_TOOL" {test_tool.executable} arg1 arg2
+ """)
+
+ test_tool.assert_called_once_with_args("arg1 arg2")
+
+ def test_does_not_log_with_logger_unset(self):
+ test_tool = TestScript.create(self.working_dir)
+
+ self._run_script_and_wait(f"""
+ unset ANDROID_TOOL_LOGGER
+ {self.logging_script_path} "FAKE_TOOL" {test_tool.executable} arg1 arg2
+ """)
+
+ test_tool.assert_called_once_with_args("arg1 arg2")
+
+ def test_log_success_with_logger_enabled(self):
+ test_tool = TestScript.create(self.working_dir)
+ test_logger = TestScript.create(self.working_dir)
+
+ self._run_script_and_wait(f"""
+ export ANDROID_TOOL_LOGGER="{test_logger.executable}"
+ {self.logging_script_path} "FAKE_TOOL" {test_tool.executable} arg1 arg2
+ """)
+
+ test_tool.assert_called_once_with_args("arg1 arg2")
+ expected_logger_args = (
+ "--tool_tag=FAKE_TOOL --start_timestamp=\d+\.\d+ --end_timestamp="
+ "\d+\.\d+ --tool_args=arg1 arg2 --exit_code=0"
+ )
+ test_logger.assert_called_once_with_args(expected_logger_args)
+
+ def test_run_tool_output_is_same_with_and_without_logging(self):
+ test_tool = TestScript.create(self.working_dir, "echo 'tool called'")
+ test_logger = TestScript.create(self.working_dir)
+
+ run_tool_with_logging_stdout, run_tool_with_logging_stderr = (
+ self._run_script_and_wait(f"""
+ export ANDROID_TOOL_LOGGER="{test_logger.executable}"
+ {self.logging_script_path} "FAKE_TOOL" {test_tool.executable} arg1 arg2
+ """)
+ )
+
+ run_tool_without_logging_stdout, run_tool_without_logging_stderr = (
+ self._run_script_and_wait(f"""
+ export ANDROID_TOOL_LOGGER="{test_logger.executable}"
+ {test_tool.executable} arg1 arg2
+ """)
+ )
+
+ self.assertEqual(
+ run_tool_with_logging_stdout, run_tool_without_logging_stdout
+ )
+ self.assertEqual(
+ run_tool_with_logging_stderr, run_tool_without_logging_stderr
+ )
+
+ def test_logger_output_is_suppressed(self):
+ test_tool = TestScript.create(self.working_dir)
+ test_logger = TestScript.create(self.working_dir, "echo 'logger called'")
+
+ run_tool_with_logging_output, _ = self._run_script_and_wait(f"""
+ export ANDROID_TOOL_LOGGER="{test_logger.executable}"
+ {self.logging_script_path} "FAKE_TOOL" {test_tool.executable} arg1 arg2
+ """)
+
+ self.assertNotIn("logger called", run_tool_with_logging_output)
+
+ def test_logger_error_is_suppressed(self):
+ test_tool = TestScript.create(self.working_dir)
+ test_logger = TestScript.create(
+ self.working_dir, "echo 'logger failed' > /dev/stderr; exit 1"
+ )
+
+ _, err = self._run_script_and_wait(f"""
+ export ANDROID_TOOL_LOGGER="{test_logger.executable}"
+ {self.logging_script_path} "FAKE_TOOL" {test_tool.executable} arg1 arg2
+ """)
+
+ self.assertNotIn("logger failed", err)
+
+ def test_log_success_when_tool_interrupted(self):
+ test_tool = TestScript.create(self.working_dir, script_body="sleep 100")
+ test_logger = TestScript.create(self.working_dir)
+
+ process = self._run_script(f"""
+ export ANDROID_TOOL_LOGGER="{test_logger.executable}"
+ {self.logging_script_path} "FAKE_TOOL" {test_tool.executable} arg1 arg2
+ """)
+
+ pgid = os.getpgid(process.pid)
+ # Give sometime for the subprocess to start.
+ time.sleep(1)
+ # Kill the subprocess and any processes created in the same group.
+ os.killpg(pgid, signal.SIGINT)
+
+ returncode, _, _ = self._wait_for_process(process)
+ self.assertEqual(returncode, INTERRUPTED_RETURN_CODE)
+
+ expected_logger_args = (
+ "--tool_tag=FAKE_TOOL --start_timestamp=\d+\.\d+ --end_timestamp="
+ "\d+\.\d+ --tool_args=arg1 arg2 --exit_code=130"
+ )
+ test_logger.assert_called_once_with_args(expected_logger_args)
+
+ def test_logger_can_be_toggled_on(self):
+ test_tool = TestScript.create(self.working_dir)
+ test_logger = TestScript.create(self.working_dir)
+
+ self._run_script_and_wait(f"""
+ export ANDROID_TOOL_LOGGER=""
+ export ANDROID_TOOL_LOGGER="{test_logger.executable}"
+ {self.logging_script_path} "FAKE_TOOL" {test_tool.executable} arg1 arg2
+ """)
+
+ test_logger.assert_called_with_times(1)
+
+ def test_logger_can_be_toggled_off(self):
+ test_tool = TestScript.create(self.working_dir)
+ test_logger = TestScript.create(self.working_dir)
+
+ self._run_script_and_wait(f"""
+ export ANDROID_TOOL_LOGGER="{test_logger.executable}"
+ export ANDROID_TOOL_LOGGER=""
+ {self.logging_script_path} "FAKE_TOOL" {test_tool.executable} arg1 arg2
+ """)
+
+ test_logger.assert_not_called()
+
+ def test_integration_tool_event_logger_dry_run(self):
+ test_tool = TestScript.create(self.working_dir)
+ logger_path = self._import_executable("tool_event_logger")
+
+ self._run_script_and_wait(f"""
+ TMPDIR="{self.working_dir.name}"
+ export ANDROID_TOOL_LOGGER="{logger_path}"
+ export ANDROID_TOOL_LOGGER_EXTRA_ARGS="--dry_run"
+ {self.logging_script_path} "FAKE_TOOL" {test_tool.executable} arg1 arg2
+ """)
+
+ self._assert_logger_dry_run()
+
+ def test_tool_args_do_not_fail_logger(self):
+ test_tool = TestScript.create(self.working_dir)
+ logger_path = self._import_executable("tool_event_logger")
+
+ self._run_script_and_wait(f"""
+ TMPDIR="{self.working_dir.name}"
+ export ANDROID_TOOL_LOGGER="{logger_path}"
+ export ANDROID_TOOL_LOGGER_EXTRA_ARGS="--dry_run"
+ {self.logging_script_path} "FAKE_TOOL" {test_tool.executable} --tool-arg1
+ """)
+
+ self._assert_logger_dry_run()
+
+ def _import_executable(self, executable_name: str) -> Path:
+ # logger = "tool_event_logger"
+ executable_path = Path(self.working_dir.name).joinpath(executable_name)
+ with resources.as_file(
+ resources.files("testdata").joinpath(executable_name)
+ ) as p:
+ shutil.copy(p, executable_path)
+ Path.chmod(executable_path, 0o755)
+ return executable_path
+
+ def _assert_logger_dry_run(self):
+ log_files = glob.glob(self.working_dir.name + "/tool_event_logger_*/*.log")
+ self.assertEqual(len(log_files), 1)
+
+ with open(log_files[0], "r") as f:
+ lines = f.readlines()
+ self.assertEqual(len(lines), 1)
+ self.assertIn("dry run", lines[0])
+
+ def _run_script_and_wait(self, test_script: str) -> tuple[str, str]:
+ process = self._run_script(test_script)
+ returncode, out, err = self._wait_for_process(process)
+ logging.debug("script stdout: %s", out)
+ logging.debug("script stderr: %s", err)
+ self.assertEqual(returncode, EXII_RETURN_CODE)
+ return out, err
+
+ def _run_script(self, test_script: str) -> subprocess.Popen:
+ return subprocess.Popen(
+ test_script,
+ shell=True,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ text=True,
+ start_new_session=True,
+ executable="/bin/bash",
+ )
+
+ def _wait_for_process(
+ self, process: subprocess.Popen
+ ) -> tuple[int, str, str]:
+ pgid = os.getpgid(process.pid)
+ out, err = process.communicate()
+ # Wait for all process in the same group to complete since the logger runs
+ # as a separate detached process.
+ self._wait_for_process_group(pgid)
+ return (process.returncode, out, err)
+
+ def _wait_for_process_group(self, pgid: int, timeout: int = 5):
+ """Waits for all subprocesses within the process group to complete."""
+ start_time = time.time()
+ while True:
+ if time.time() - start_time > timeout:
+ raise TimeoutError(
+ f"Process group did not complete after {timeout} seconds"
+ )
+ for pid in os.listdir("/proc"):
+ if pid.isdigit():
+ try:
+ if os.getpgid(int(pid)) == pgid:
+ time.sleep(0.1)
+ break
+ except (FileNotFoundError, PermissionError, ProcessLookupError):
+ pass
+ else:
+ # All processes have completed.
+ break
+
+
+@dataclasses.dataclass
+class TestScript:
+ executable: Path
+ output_file: Path
+
+ def create(temp_dir: Path, script_body: str = ""):
+ with tempfile.NamedTemporaryFile(dir=temp_dir.name, delete=False) as f:
+ output_file = f.name
+
+ with tempfile.NamedTemporaryFile(dir=temp_dir.name, delete=False) as f:
+ executable = f.name
+ executable_contents = textwrap.dedent(f"""
+ #!/bin/bash
+
+ echo "${{@}}" >> {output_file}
+ {script_body}
+ """)
+ f.write(executable_contents.encode("utf-8"))
+
+ Path.chmod(f.name, os.stat(f.name).st_mode | stat.S_IEXEC)
+
+ return TestScript(executable, output_file)
+
+ def assert_called_with_times(self, expected_call_times: int):
+ lines = self._read_contents_from_output_file()
+ assert len(lines) == expected_call_times, (
+ f"Expect to call {expected_call_times} times, but actually called"
+ f" {len(lines)} times."
+ )
+
+ def assert_called_with_args(self, expected_args: str):
+ lines = self._read_contents_from_output_file()
+ assert len(lines) > 0
+ assert re.search(expected_args, lines[0]), (
+ f"Expect to call with args {expected_args}, but actually called with"
+ f" args {lines[0]}."
+ )
+
+ def assert_not_called(self):
+ self.assert_called_with_times(0)
+
+ def assert_called_once_with_args(self, expected_args: str):
+ self.assert_called_with_times(1)
+ self.assert_called_with_args(expected_args)
+
+ def _read_contents_from_output_file(self) -> list[str]:
+ with open(self.output_file, "r") as f:
+ return f.readlines()
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tradefed/providers.go b/tradefed/providers.go
index 66cb625..0abac12 100644
--- a/tradefed/providers.go
+++ b/tradefed/providers.go
@@ -6,7 +6,8 @@
"github.com/google/blueprint"
)
-// Output files we need from a base test that we derive from.
+// Data that test_module_config[_host] modules types will need from
+// their dependencies to write out build rules and AndroidMkEntries.
type BaseTestProviderData struct {
// data files and apps for android_test
InstalledFiles android.Paths
@@ -19,8 +20,14 @@
RequiredModuleNames []string
// List of test suites base uses.
TestSuites []string
- // Used for bases that are Host
+ // True indicates the base modules is built for Host.
IsHost bool
+ // Base's sdk version for AndroidMkEntries, generally only used for Host modules.
+ LocalSdkVersion string
+ // Base's certificate for AndroidMkEntries, generally only used for device modules.
+ LocalCertificate string
+ // Indicates if the base module was a unit test.
+ IsUnitTest bool
}
var BaseTestProviderKey = blueprint.NewProvider[BaseTestProviderData]()
diff --git a/tradefed_modules/test_module_config.go b/tradefed_modules/test_module_config.go
index b2d5631..f9622d3 100644
--- a/tradefed_modules/test_module_config.go
+++ b/tradefed_modules/test_module_config.go
@@ -5,6 +5,8 @@
"android/soong/tradefed"
"encoding/json"
"fmt"
+ "io"
+ "strings"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
@@ -23,14 +25,17 @@
type testModuleConfigModule struct {
android.ModuleBase
android.DefaultableModuleBase
- base android.Module
tradefedProperties
// Our updated testConfig.
testConfig android.OutputPath
- manifest android.InstallPath
+ manifest android.OutputPath
provider tradefed.BaseTestProviderData
+
+ supportFiles android.InstallPaths
+
+ isHost bool
}
// Host is mostly the same as non-host, just some diffs for AddDependency and
@@ -94,7 +99,6 @@
// Takes base's Tradefed Config xml file and generates a new one with the test properties
// appeneded from this module.
-// Rewrite the name of the apk in "test-file-name" to be our module's name, rather than the original one.
func (m *testModuleConfigModule) fixTestConfig(ctx android.ModuleContext, baseTestConfig android.Path) android.OutputPath {
// Test safe to do when no test_runner_options, but check for that earlier?
fixedConfig := android.PathForModuleOut(ctx, "test_config_fixer", ctx.ModuleName()+".config")
@@ -106,9 +110,8 @@
}
xmlTestModuleConfigSnippet, _ := json.Marshal(options)
escaped := proptools.NinjaAndShellEscape(string(xmlTestModuleConfigSnippet))
- command.FlagWithArg("--test-file-name=", ctx.ModuleName()+".apk").
- FlagWithArg("--orig-test-file-name=", *m.tradefedProperties.Base+".apk").
- FlagWithArg("--test-runner-options=", escaped)
+ command.FlagWithArg("--test-runner-options=", escaped)
+
rule.Build("fix_test_config", "fix test config")
return fixedConfig.OutputPath
}
@@ -190,6 +193,7 @@
module.AddProperties(&module.tradefedProperties)
android.InitAndroidMultiTargetsArchModule(module, android.HostSupported, android.MultilibCommon)
android.InitDefaultableModule(module)
+ module.isHost = true
return module
}
@@ -198,39 +202,66 @@
var _ android.AndroidMkEntriesProvider = (*testModuleConfigModule)(nil)
func (m *testModuleConfigModule) AndroidMkEntries() []android.AndroidMkEntries {
- // We rely on base writing LOCAL_COMPATIBILITY_SUPPORT_FILES for its data files
- entriesList := m.base.(android.AndroidMkEntriesProvider).AndroidMkEntries()
- entries := &entriesList[0]
- entries.OutputFile = android.OptionalPathForPath(m.provider.OutputFile)
- entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
- entries.SetString("LOCAL_MODULE", m.Name()) // out module name, not base's
+ appClass := "APPS"
+ include := "$(BUILD_SYSTEM)/soong_app_prebuilt.mk"
+ if m.isHost {
+ appClass = "JAVA_LIBRARIES"
+ include = "$(BUILD_SYSTEM)/soong_java_prebuilt.mk"
+ }
+ return []android.AndroidMkEntries{{
+ Class: appClass,
+ OutputFile: android.OptionalPathForPath(m.manifest),
+ Include: include,
+ Required: []string{*m.Base},
+ ExtraEntries: []android.AndroidMkExtraEntriesFunc{
+ func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
+ entries.SetPath("LOCAL_FULL_TEST_CONFIG", m.testConfig)
+ entries.SetString("LOCAL_MODULE_TAGS", "tests")
+ entries.SetString("LOCAL_TEST_MODULE_CONFIG_BASE", *m.Base)
+ if m.provider.LocalSdkVersion != "" {
+ entries.SetString("LOCAL_SDK_VERSION", m.provider.LocalSdkVersion)
+ }
+ if m.provider.LocalCertificate != "" {
+ entries.SetString("LOCAL_CERTIFICATE", m.provider.LocalCertificate)
+ }
- // Out update config file with extra options.
- entries.SetPath("LOCAL_FULL_TEST_CONFIG", m.testConfig)
- entries.SetString("LOCAL_MODULE_TAGS", "tests")
+ entries.SetBoolIfTrue("LOCAL_IS_UNIT_TEST", m.provider.IsUnitTest)
+ entries.AddCompatibilityTestSuites(m.tradefedProperties.Test_suites...)
- // Don't append to base's test-suites, only use the ones we define, so clear it before
- // appending to it.
- entries.SetString("LOCAL_COMPATIBILITY_SUITE", "")
- entries.AddCompatibilityTestSuites(m.tradefedProperties.Test_suites...)
+ // The app_prebuilt_internal.mk files try create a copy of the OutputFile as an .apk.
+ // Normally, this copies the "package.apk" from the intermediate directory here.
+ // To prevent the copy of the large apk and to prevent confusion with the real .apk we
+ // link to, we set the STEM here to a bogus name and we set OutputFile to a small file (our manifest).
+ // We do this so we don't have to add more conditionals to base_rules.mk
+ // soong_java_prebult has the same issue for .jars so use this in both module types.
+ entries.SetString("LOCAL_MODULE_STEM", fmt.Sprintf("UNUSED-%s", *m.Base))
- if len(m.provider.HostRequiredModuleNames) > 0 {
- entries.AddStrings("LOCAL_HOST_REQUIRED_MODULES", m.provider.HostRequiredModuleNames...)
- }
- if len(m.provider.RequiredModuleNames) > 0 {
- entries.AddStrings("LOCAL_REQUIRED_MODULES", m.provider.RequiredModuleNames...)
- }
-
- if m.provider.IsHost == false {
- // Not needed for jar_host_test
- //
- // Clear the JNI symbols because they belong to base not us. Either transform the names in the string
- // or clear the variable because we don't need it, we are copying bases libraries not generating
- // new ones.
- entries.SetString("LOCAL_SOONG_JNI_LIBS_SYMBOLS", "")
- }
- })
- return entriesList
+ // In normal java/app modules, the module writes LOCAL_COMPATIBILITY_SUPPORT_FILES
+ // and then base_rules.mk ends up copying each of those dependencies from .intermediates to the install directory.
+ // tasks/general-tests.mk, tasks/devices-tests.mk also use these to figure out
+ // which testcase files to put in a zip for running tests on another machine.
+ //
+ // We need our files to end up in the zip, but we don't want \.mk files to
+ // `install` files for us.
+ // So we create a new make variable to indicate these should be in the zip
+ // but not installed.
+ entries.AddStrings("LOCAL_SOONG_INSTALLED_COMPATIBILITY_SUPPORT_FILES", m.supportFiles.Strings()...)
+ },
+ },
+ // Ensure each of our supportFiles depends on the installed file in base so that our symlinks will always
+ // resolve. The provider gives us the .intermediate path for the support file in base, we change it to
+ // the installed path with a string substitution.
+ ExtraFooters: []android.AndroidMkExtraFootersFunc{
+ func(w io.Writer, name, prefix, moduleDir string) {
+ for _, f := range m.supportFiles.Strings() {
+ // convert out/.../testcases/FrameworksServicesTests_contentprotection/file1.apk
+ // to out/.../testcases/FrameworksServicesTests/file1.apk
+ basePath := strings.Replace(f, "/"+m.Name()+"/", "/"+*m.Base+"/", 1)
+ fmt.Fprintf(w, "%s: %s\n", f, basePath)
+ }
+ },
+ },
+ }}
}
func (m *testModuleConfigHostModule) DepsMutator(ctx android.BottomUpMutatorContext) {
@@ -248,7 +279,7 @@
// - written via soong_java_prebuilt.mk
//
// 4) out/host/linux-x86/testcases/derived-module/* # data dependencies from base.
-// - written via soong_java_prebuilt.mk
+// - written via our InstallSymlink
func (m *testModuleConfigHostModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
m.validateBase(ctx, &testModuleConfigHostTag, "java_test_host", true)
m.generateManifestAndConfig(ctx)
@@ -260,7 +291,6 @@
ctx.VisitDirectDepsWithTag(*depTag, func(dep android.Module) {
if provider, ok := android.OtherModuleProvider(ctx, dep, tradefed.BaseTestProviderKey); ok {
if baseShouldBeHost == provider.IsHost {
- m.base = dep
m.provider = provider
} else {
if baseShouldBeHost {
@@ -277,7 +307,9 @@
// Actions to write:
// 1. manifest file to testcases dir
-// 2. New Module.config / AndroidTest.xml file with our options.
+// 2. Symlink to base.apk under base's arch dir
+// 3. Symlink to all data dependencies
+// 4. New Module.config / AndroidTest.xml file with our options.
func (m *testModuleConfigModule) generateManifestAndConfig(ctx android.ModuleContext) {
// Keep before early returns.
android.SetProvider(ctx, android.TestOnlyProviderKey, android.TestModuleInformation{
@@ -292,7 +324,6 @@
if m.provider.TestConfig == nil {
return
}
-
// 1) A manifest file listing the base, write text to a tiny file.
installDir := android.PathForModuleInstall(ctx, ctx.ModuleName())
manifest := android.PathForModuleOut(ctx, "test_module_config.manifest")
@@ -301,9 +332,53 @@
// Assume the primary install file is last
// so we need to Install our file last.
ctx.InstallFile(installDir, manifest.Base(), manifest)
+ m.manifest = manifest.OutputPath
- // 2) Module.config / AndroidTest.xml
+ // 2) Symlink to base.apk
+ baseApk := m.provider.OutputFile
+
+ // Typically looks like this for baseApk
+ // FrameworksServicesTests
+ // └── x86_64
+ // └── FrameworksServicesTests.apk
+ symlinkName := fmt.Sprintf("%s/%s", ctx.DeviceConfig().DeviceArch(), baseApk.Base())
+ // Only android_test, not java_host_test puts the output in the DeviceArch dir.
+ if m.provider.IsHost || ctx.DeviceConfig().DeviceArch() == "" {
+ // testcases/CtsDevicePolicyManagerTestCases
+ // ├── CtsDevicePolicyManagerTestCases.jar
+ symlinkName = baseApk.Base()
+ }
+ target := installedBaseRelativeToHere(symlinkName, *m.tradefedProperties.Base)
+ installedApk := ctx.InstallAbsoluteSymlink(installDir, symlinkName, target)
+ m.supportFiles = append(m.supportFiles, installedApk)
+
+ // 3) Symlink for all data deps
+ // And like this for data files and required modules
+ // FrameworksServicesTests
+ // ├── data
+ // │ └── broken_shortcut.xml
+ // ├── JobTestApp.apk
+ for _, f := range m.provider.InstalledFiles {
+ symlinkName := f.Rel()
+ target := installedBaseRelativeToHere(symlinkName, *m.tradefedProperties.Base)
+ installedPath := ctx.InstallAbsoluteSymlink(installDir, symlinkName, target)
+ m.supportFiles = append(m.supportFiles, installedPath)
+ }
+
+ // 4) Module.config / AndroidTest.xml
m.testConfig = m.fixTestConfig(ctx, m.provider.TestConfig)
}
var _ android.AndroidMkEntriesProvider = (*testModuleConfigHostModule)(nil)
+
+// Given a relative path to a file in the current directory or a subdirectory,
+// return a relative path under our sibling directory named `base`.
+// There should be one "../" for each subdir we descend plus one to backup to "base".
+//
+// ThisDir/file1
+// ThisDir/subdir/file2
+// would return "../base/file1" or "../../subdir/file2"
+func installedBaseRelativeToHere(targetFileName string, base string) string {
+ backup := strings.Repeat("../", strings.Count(targetFileName, "/")+1)
+ return fmt.Sprintf("%s%s/%s", backup, base, targetFileName)
+}
diff --git a/tradefed_modules/test_module_config_test.go b/tradefed_modules/test_module_config_test.go
index b2049b1..97179f5 100644
--- a/tradefed_modules/test_module_config_test.go
+++ b/tradefed_modules/test_module_config_test.go
@@ -16,6 +16,7 @@
import (
"android/soong/android"
"android/soong/java"
+ "fmt"
"strconv"
"strings"
"testing"
@@ -69,15 +70,36 @@
entries := android.AndroidMkEntriesForTest(t, ctx.TestContext, derived.Module())[0]
// Ensure some entries from base are there, specifically support files for data and helper apps.
- assertEntryPairValues(t, entries.EntryMap["LOCAL_COMPATIBILITY_SUPPORT_FILES"], []string{"HelperApp.apk", "data/testfile"})
+ // Do not use LOCAL_COMPATIBILITY_SUPPORT_FILES, but instead use LOCAL_SOONG_INSTALLED_COMPATIBILITY_SUPPORT_FILES
+ android.AssertStringPathsRelativeToTopEquals(t, "support-files", ctx.Config,
+ []string{"out/soong/target/product/test_device/testcases/derived_test/arm64/base.apk",
+ "out/soong/target/product/test_device/testcases/derived_test/HelperApp.apk",
+ "out/soong/target/product/test_device/testcases/derived_test/data/testfile"},
+ entries.EntryMap["LOCAL_SOONG_INSTALLED_COMPATIBILITY_SUPPORT_FILES"])
+ android.AssertArrayString(t, "", entries.EntryMap["LOCAL_COMPATIBILITY_SUPPORT_FILES"], []string{})
+
+ android.AssertArrayString(t, "", entries.EntryMap["LOCAL_REQUIRED_MODULES"], []string{"base"})
+ android.AssertArrayString(t, "", entries.EntryMap["LOCAL_CERTIFICATE"], []string{"build/make/target/product/security/testkey.x509.pem"})
+ android.AssertStringEquals(t, "", entries.Class, "APPS")
// And some new derived entries are there.
android.AssertArrayString(t, "", entries.EntryMap["LOCAL_MODULE_TAGS"], []string{"tests"})
- // And ones we override
- android.AssertArrayString(t, "", entries.EntryMap["LOCAL_SOONG_JNI_LIBS_SYMBOLS"], []string{""})
-
android.AssertStringMatches(t, "", entries.EntryMap["LOCAL_FULL_TEST_CONFIG"][0], "derived_test/android_common/test_config_fixer/derived_test.config")
+
+ // Check the footer lines. Our support files should depend on base's support files.
+ convertedActual := make([]string, 5)
+ for i, e := range entries.FooterLinesForTests() {
+ // AssertStringPathsRelativeToTop doesn't replace both instances
+ convertedActual[i] = strings.Replace(e, ctx.Config.SoongOutDir(), "", 2)
+ }
+ android.AssertArrayString(t, fmt.Sprintf("%s", ctx.Config.SoongOutDir()), convertedActual, []string{
+ "include $(BUILD_SYSTEM)/soong_app_prebuilt.mk",
+ "/target/product/test_device/testcases/derived_test/arm64/base.apk: /target/product/test_device/testcases/base/arm64/base.apk",
+ "/target/product/test_device/testcases/derived_test/HelperApp.apk: /target/product/test_device/testcases/base/HelperApp.apk",
+ "/target/product/test_device/testcases/derived_test/data/testfile: /target/product/test_device/testcases/base/data/testfile",
+ "",
+ })
}
// Make sure we call test-config-fixer with the right args.
@@ -92,7 +114,7 @@
derived := ctx.ModuleForTests("derived_test", "android_common")
rule_cmd := derived.Rule("fix_test_config").RuleParams.Command
android.AssertStringDoesContain(t, "Bad FixConfig rule inputs", rule_cmd,
- `--test-file-name=derived_test.apk --orig-test-file-name=base.apk --test-runner-options='[{"Name":"exclude-filter","Key":"","Value":"android.test.example.devcodelab.DevCodelabTest#testHelloFail"},{"Name":"include-annotation","Key":"","Value":"android.platform.test.annotations.LargeTest"}]'`)
+ `--test-runner-options='[{"Name":"exclude-filter","Key":"","Value":"android.test.example.devcodelab.DevCodelabTest#testHelloFail"},{"Name":"include-annotation","Key":"","Value":"android.platform.test.annotations.LargeTest"}]'`)
}
// Ensure we error for a base we don't support.
@@ -195,8 +217,14 @@
name: "base",
sdk_version: "current",
srcs: ["a.java"],
+ data: [":HelperApp", "data/testfile"],
}
+ android_test_helper_app {
+ name: "HelperApp",
+ srcs: ["helper.java"],
+ }
+
test_module_config {
name: "derived_test",
base: "base",
@@ -220,8 +248,12 @@
derived := ctx.ModuleForTests("derived_test", "android_common")
entries := android.AndroidMkEntriesForTest(t, ctx.TestContext, derived.Module())[0]
// All these should be the same in both derived tests
- assertEntryPairValues(t, entries.EntryMap["LOCAL_COMPATIBILITY_SUPPORT_FILES"], []string{"HelperApp.apk", "data/testfile"})
- android.AssertArrayString(t, "", entries.EntryMap["LOCAL_SOONG_JNI_LIBS_SYMBOLS"], []string{""})
+ android.AssertStringPathsRelativeToTopEquals(t, "support-files", ctx.Config,
+ []string{"out/soong/target/product/test_device/testcases/derived_test/arm64/base.apk",
+ "out/soong/target/product/test_device/testcases/derived_test/HelperApp.apk",
+ "out/soong/target/product/test_device/testcases/derived_test/data/testfile"},
+ entries.EntryMap["LOCAL_SOONG_INSTALLED_COMPATIBILITY_SUPPORT_FILES"])
+
// Except this one, which points to the updated tradefed xml file.
android.AssertStringMatches(t, "", entries.EntryMap["LOCAL_FULL_TEST_CONFIG"][0], "derived_test/android_common/test_config_fixer/derived_test.config")
// And this one, the module name.
@@ -232,8 +264,11 @@
derived := ctx.ModuleForTests("another_derived_test", "android_common")
entries := android.AndroidMkEntriesForTest(t, ctx.TestContext, derived.Module())[0]
// All these should be the same in both derived tests
- assertEntryPairValues(t, entries.EntryMap["LOCAL_COMPATIBILITY_SUPPORT_FILES"], []string{"HelperApp.apk", "data/testfile"})
- android.AssertArrayString(t, "", entries.EntryMap["LOCAL_SOONG_JNI_LIBS_SYMBOLS"], []string{""})
+ android.AssertStringPathsRelativeToTopEquals(t, "support-files", ctx.Config,
+ []string{"out/soong/target/product/test_device/testcases/another_derived_test/arm64/base.apk",
+ "out/soong/target/product/test_device/testcases/another_derived_test/HelperApp.apk",
+ "out/soong/target/product/test_device/testcases/another_derived_test/data/testfile"},
+ entries.EntryMap["LOCAL_SOONG_INSTALLED_COMPATIBILITY_SUPPORT_FILES"])
// Except this one, which points to the updated tradefed xml file.
android.AssertStringMatches(t, "", entries.EntryMap["LOCAL_FULL_TEST_CONFIG"][0], "another_derived_test/android_common/test_config_fixer/another_derived_test.config")
// And this one, the module name.
@@ -269,6 +304,8 @@
allEntries := android.AndroidMkEntriesForTest(t, ctx.TestContext, mod)
entries := allEntries[0]
android.AssertArrayString(t, "", entries.EntryMap["LOCAL_MODULE"], []string{"derived_test"})
+ android.AssertArrayString(t, "", entries.EntryMap["LOCAL_SDK_VERSION"], []string{"private_current"})
+ android.AssertStringEquals(t, "", entries.Class, "JAVA_LIBRARIES")
if !mod.Host() {
t.Errorf("host bit is not set for a java_test_host module.")
@@ -385,16 +422,3 @@
t.Errorf("test-only: Expected but not found: %v, Found but not expected: %v", left, right)
}
}
-
-// Use for situations where the entries map contains pairs: [srcPath:installedPath1, srcPath2:installedPath2]
-// and we want to compare the RHS of the pairs, i.e. installedPath1, installedPath2
-func assertEntryPairValues(t *testing.T, actual []string, expected []string) {
- for i, e := range actual {
- parts := strings.Split(e, ":")
- if len(parts) != 2 {
- t.Errorf("Expected entry to have a value delimited by :, received: %s", e)
- return
- }
- android.AssertStringEquals(t, "", parts[1], expected[i])
- }
-}
diff --git a/ui/build/config.go b/ui/build/config.go
index 7426a78..feded1c 100644
--- a/ui/build/config.go
+++ b/ui/build/config.go
@@ -1164,14 +1164,6 @@
c.sourceRootDirs = i
}
-func (c *configImpl) GetIncludeTags() []string {
- return c.includeTags
-}
-
-func (c *configImpl) SetIncludeTags(i []string) {
- c.includeTags = i
-}
-
func (c *configImpl) GetLogsPrefix() string {
return c.logsPrefix
}
diff --git a/ui/build/dumpvars.go b/ui/build/dumpvars.go
index e17bd54..eba86a0 100644
--- a/ui/build/dumpvars.go
+++ b/ui/build/dumpvars.go
@@ -147,7 +147,6 @@
var BannerVars = []string{
"PLATFORM_VERSION_CODENAME",
"PLATFORM_VERSION",
- "PRODUCT_INCLUDE_TAGS",
"PRODUCT_SOURCE_ROOT_DIRS",
"TARGET_PRODUCT",
"TARGET_BUILD_VARIANT",
@@ -301,6 +300,5 @@
config.SetBuildBrokenDupRules(makeVars["BUILD_BROKEN_DUP_RULES"] == "true")
config.SetBuildBrokenUsesNetwork(makeVars["BUILD_BROKEN_USES_NETWORK"] == "true")
config.SetBuildBrokenNinjaUsesEnvVars(strings.Fields(makeVars["BUILD_BROKEN_NINJA_USES_ENV_VARS"]))
- config.SetIncludeTags(strings.Fields(makeVars["PRODUCT_INCLUDE_TAGS"]))
config.SetSourceRootDirs(strings.Fields(makeVars["PRODUCT_SOURCE_ROOT_DIRS"]))
}
diff --git a/ui/build/soong.go b/ui/build/soong.go
index 9955b1f..2f3150d 100644
--- a/ui/build/soong.go
+++ b/ui/build/soong.go
@@ -401,7 +401,6 @@
}
blueprintCtx := blueprint.NewContext()
- blueprintCtx.AddIncludeTags(config.GetIncludeTags()...)
blueprintCtx.AddSourceRootDirs(config.GetSourceRootDirs()...)
blueprintCtx.SetIgnoreUnknownModuleTypes(true)
blueprintConfig := BlueprintConfig{
diff --git a/ui/build/test_build.go b/ui/build/test_build.go
index 3095139..24ad082 100644
--- a/ui/build/test_build.go
+++ b/ui/build/test_build.go
@@ -79,6 +79,10 @@
// bpglob is built explicitly using Microfactory
bpglob := filepath.Join(config.SoongOutDir(), "bpglob")
+ // release-config files are generated from the initial lunch or Kati phase
+ // before running soong and ninja.
+ releaseConfigDir := filepath.Join(outDir, "soong", "release-config")
+
danglingRules := make(map[string]bool)
scanner := bufio.NewScanner(stdout)
@@ -93,7 +97,8 @@
line == variablesFilePath ||
line == dexpreoptConfigFilePath ||
line == buildDatetimeFilePath ||
- line == bpglob {
+ line == bpglob ||
+ strings.HasPrefix(line, releaseConfigDir) {
// Leaf node is in one of Soong's bootstrap directories, which do not have
// full build rules in the primary build.ninja file.
continue