Merge "Add LOCAL_GENERATED_SOURCES to androidmk"
diff --git a/README.md b/README.md
index 127c52c..18c6604 100644
--- a/README.md
+++ b/README.md
@@ -188,7 +188,7 @@
#### Namespaces
-A presense of the `soong_namespace {..}` in an Android.bp file defines a
+The presence of the `soong_namespace {..}` in an Android.bp file defines a
**namespace**. For instance, having
```
diff --git a/android/license_metadata.go b/android/license_metadata.go
index 3bc53d6..6a5b0da 100644
--- a/android/license_metadata.go
+++ b/android/license_metadata.go
@@ -34,7 +34,7 @@
}, "args")
)
-func buildLicenseMetadata(ctx ModuleContext) {
+func buildLicenseMetadata(ctx ModuleContext, licenseMetadataFile WritablePath) {
base := ctx.Module().base()
if !base.Enabled() {
@@ -45,9 +45,18 @@
return
}
+ var outputFiles Paths
+ if outputFileProducer, ok := ctx.Module().(OutputFileProducer); ok {
+ outputFiles, _ = outputFileProducer.OutputFiles("")
+ outputFiles = PathsIfNonNil(outputFiles...)
+ }
+
+ isContainer := isContainerFromFileExtensions(base.installFiles, outputFiles)
+
var allDepMetadataFiles Paths
var allDepMetadataArgs []string
var allDepOutputFiles Paths
+ var allDepMetadataDepSets []*PathsDepSet
ctx.VisitDirectDepsBlueprint(func(bpdep blueprint.Module) {
dep, _ := bpdep.(Module)
@@ -61,6 +70,9 @@
if ctx.OtherModuleHasProvider(dep, LicenseMetadataProvider) {
info := ctx.OtherModuleProvider(dep, LicenseMetadataProvider).(*LicenseMetadataInfo)
allDepMetadataFiles = append(allDepMetadataFiles, info.LicenseMetadataPath)
+ if isContainer || IsInstallDepNeeded(ctx.OtherModuleDependencyTag(dep)) {
+ allDepMetadataDepSets = append(allDepMetadataDepSets, info.LicenseMetadataDepSet)
+ }
depAnnotations := licenseAnnotationsFromTag(ctx.OtherModuleDependencyTag(dep))
@@ -105,9 +117,16 @@
args = append(args,
JoinWithPrefix(proptools.NinjaAndShellEscapeListIncludingSpaces(base.commonProperties.Effective_license_text.Strings()), "-n "))
- args = append(args,
- JoinWithPrefix(proptools.NinjaAndShellEscapeListIncludingSpaces(allDepMetadataArgs), "-d "))
- orderOnlyDeps = append(orderOnlyDeps, allDepMetadataFiles...)
+ if isContainer {
+ transitiveDeps := newPathsDepSet(nil, allDepMetadataDepSets).ToList()
+ args = append(args,
+ JoinWithPrefix(proptools.NinjaAndShellEscapeListIncludingSpaces(transitiveDeps.Strings()), "-d "))
+ orderOnlyDeps = append(orderOnlyDeps, transitiveDeps...)
+ } else {
+ args = append(args,
+ JoinWithPrefix(proptools.NinjaAndShellEscapeListIncludingSpaces(allDepMetadataArgs), "-d "))
+ orderOnlyDeps = append(orderOnlyDeps, allDepMetadataFiles...)
+ }
args = append(args,
JoinWithPrefix(proptools.NinjaAndShellEscapeListIncludingSpaces(allDepOutputFiles.Strings()), "-s "))
@@ -117,12 +136,6 @@
JoinWithPrefix(proptools.NinjaAndShellEscapeListIncludingSpaces(base.licenseInstallMap), "-m "))
// Built files
- var outputFiles Paths
- if outputFileProducer, ok := ctx.Module().(OutputFileProducer); ok {
- outputFiles, _ = outputFileProducer.OutputFiles("")
- outputFiles = PathsIfNonNil(outputFiles...)
- }
-
if len(outputFiles) > 0 {
args = append(args,
JoinWithPrefix(proptools.NinjaAndShellEscapeListIncludingSpaces(outputFiles.Strings()), "-t "))
@@ -134,13 +147,10 @@
args = append(args,
JoinWithPrefix(proptools.NinjaAndShellEscapeListIncludingSpaces(base.installFiles.Strings()), "-i "))
- isContainer := isContainerFromFileExtensions(base.installFiles, outputFiles)
if isContainer {
args = append(args, "--is_container")
}
- licenseMetadataFile := PathForModuleOut(ctx, "meta_lic")
-
ctx.Build(pctx, BuildParams{
Rule: licenseMetadataRule,
Output: licenseMetadataFile,
@@ -152,7 +162,8 @@
})
ctx.SetProvider(LicenseMetadataProvider, &LicenseMetadataInfo{
- LicenseMetadataPath: licenseMetadataFile,
+ LicenseMetadataPath: licenseMetadataFile,
+ LicenseMetadataDepSet: newPathsDepSet(Paths{licenseMetadataFile}, allDepMetadataDepSets),
})
}
@@ -179,7 +190,8 @@
// LicenseMetadataInfo stores the license metadata path for a module.
type LicenseMetadataInfo struct {
- LicenseMetadataPath Path
+ LicenseMetadataPath Path
+ LicenseMetadataDepSet *PathsDepSet
}
// licenseAnnotationsFromTag returns the LicenseAnnotations for a tag (if any) converted into
@@ -212,6 +224,9 @@
// LicenseAnnotationSharedDependency should be returned by LicenseAnnotations implementations
// of dependency tags when the usage of the dependency is dynamic, for example a shared library
// linkage for native modules or as a classpath library for java modules.
+ //
+ // Dependency tags that need to always return LicenseAnnotationSharedDependency
+ // can embed LicenseAnnotationSharedDependencyTag to implement LicenseAnnotations.
LicenseAnnotationSharedDependency LicenseAnnotation = "dynamic"
// LicenseAnnotationToolchain should be returned by LicenseAnnotations implementations of
@@ -222,6 +237,14 @@
LicenseAnnotationToolchain LicenseAnnotation = "toolchain"
)
+// LicenseAnnotationSharedDependencyTag can be embedded in a dependency tag to implement
+// LicenseAnnotations that always returns LicenseAnnotationSharedDependency.
+type LicenseAnnotationSharedDependencyTag struct{}
+
+func (LicenseAnnotationSharedDependencyTag) LicenseAnnotations() []LicenseAnnotation {
+ return []LicenseAnnotation{LicenseAnnotationSharedDependency}
+}
+
// LicenseAnnotationToolchainDependencyTag can be embedded in a dependency tag to implement
// LicenseAnnotations that always returns LicenseAnnotationToolchain.
type LicenseAnnotationToolchainDependencyTag struct{}
diff --git a/android/module.go b/android/module.go
index 666732f..00aed95 100644
--- a/android/module.go
+++ b/android/module.go
@@ -1321,6 +1321,9 @@
// set of dependency module:location mappings used to populate the license metadata for
// apex containers.
licenseInstallMap []string
+
+ // The path to the generated license metadata file for the module.
+ licenseMetadataFile WritablePath
}
// A struct containing all relevant information about a Bazel target converted via bp2build.
@@ -2076,6 +2079,8 @@
variables: make(map[string]string),
}
+ m.licenseMetadataFile = PathForModuleOut(ctx, "meta_lic")
+
dependencyInstallFiles, dependencyPackagingSpecs := m.computeInstallDeps(ctx)
// set m.installFilesDepSet to only the transitive dependencies to be used as the dependencies
// of installed files of this module. It will be replaced by a depset including the installed
@@ -2207,7 +2212,7 @@
m.installFilesDepSet = newInstallPathsDepSet(m.installFiles, dependencyInstallFiles)
m.packagingSpecsDepSet = newPackagingSpecsDepSet(m.packagingSpecs, dependencyPackagingSpecs)
- buildLicenseMetadata(ctx)
+ buildLicenseMetadata(ctx, m.licenseMetadataFile)
m.buildParams = ctx.buildParams
m.ruleParams = ctx.ruleParams
diff --git a/android/mutator.go b/android/mutator.go
index fa6f2be8..739e4ee 100644
--- a/android/mutator.go
+++ b/android/mutator.go
@@ -323,13 +323,13 @@
// AddVariationDependencies adds deps as dependencies of the current module, but uses the variations
// argument to select which variant of the dependency to use. It returns a slice of modules for
// each dependency (some entries may be nil). A variant of the dependency must exist that matches
- // the all of the non-local variations of the current module, plus the variations argument.
+ // all the non-local variations of the current module, plus the variations argument.
//
// If the mutator is parallel (see MutatorHandle.Parallel), this method will pause until the
// new dependencies have had the current mutator called on them. If the mutator is not
// parallel this method does not affect the ordering of the current mutator pass, but will
// be ordered correctly for all future mutator passes.
- AddVariationDependencies([]blueprint.Variation, blueprint.DependencyTag, ...string) []blueprint.Module
+ AddVariationDependencies(variations []blueprint.Variation, tag blueprint.DependencyTag, names ...string) []blueprint.Module
// AddFarVariationDependencies adds deps as dependencies of the current module, but uses the
// variations argument to select which variant of the dependency to use. It returns a slice of
diff --git a/android/namespace.go b/android/namespace.go
index 4f727e1..fc7bc29 100644
--- a/android/namespace.go
+++ b/android/namespace.go
@@ -74,7 +74,7 @@
// A NameResolver implements blueprint.NameInterface, and implements the logic to
// find a module from namespaces based on a query string.
-// A query string can be a module name or can be be "//namespace_path:module_path"
+// A query string can be a module name or can be "//namespace_path:module_path"
type NameResolver struct {
rootNamespace *Namespace
diff --git a/android/notices.go b/android/notices.go
index d8cfaf2..194a734 100644
--- a/android/notices.go
+++ b/android/notices.go
@@ -16,6 +16,7 @@
import (
"path/filepath"
+ "strings"
"github.com/google/blueprint"
)
@@ -101,55 +102,15 @@
}
}
-// BuildNotices merges the supplied NOTICE files into a single file that lists notices
-// for every key in noticeMap (which would normally be installed files).
-func BuildNotices(ctx ModuleContext, noticeMap map[string]Paths) NoticeOutputs {
- // TODO(jungjw): We should just produce a well-formatted NOTICE.html file in a single pass.
- //
- // generate-notice-files.py, which processes the merged NOTICE file, has somewhat strict rules
- // about input NOTICE file paths.
- // 1. Their relative paths to the src root become their NOTICE index titles. We want to use
- // on-device paths as titles, and so output the merged NOTICE file the corresponding location.
- // 2. They must end with .txt extension. Otherwise, they're ignored.
-
- mergeTool := PathForSource(ctx, "build/soong/scripts/mergenotice.py")
- generateNoticeTool := PathForSource(ctx, "build/soong/scripts/generate-notice-files.py")
-
- outputDir := PathForModuleOut(ctx, "notices")
- builder := NewRuleBuilder(pctx, ctx).
- Sbox(outputDir, PathForModuleOut(ctx, "notices.sbox.textproto"))
- for _, installPath := range SortedStringKeys(noticeMap) {
- noticePath := outputDir.Join(ctx, installPath+".txt")
- // It would be nice if sbox created directories for temporaries, but until then
- // this is simple enough.
- builder.Command().
- Text("(cd").OutputDir().Text("&&").
- Text("mkdir -p").Text(filepath.Dir(installPath)).Text(")")
- builder.Temporary(noticePath)
- builder.Command().
- Tool(mergeTool).
- Flag("--output").Output(noticePath).
- Inputs(noticeMap[installPath])
- }
-
- // Transform the merged NOTICE file into a gzipped HTML file.
- txtOutput := outputDir.Join(ctx, "NOTICE.txt")
- htmlOutput := outputDir.Join(ctx, "NOTICE.html")
- htmlGzOutput := outputDir.Join(ctx, "NOTICE.html.gz")
- title := "\"Notices for " + ctx.ModuleName() + "\""
- builder.Command().Tool(generateNoticeTool).
- FlagWithOutput("--text-output ", txtOutput).
- FlagWithOutput("--html-output ", htmlOutput).
- FlagWithArg("-t ", title).
- Flag("-s").OutputDir()
- builder.Command().BuiltTool("minigzip").
- FlagWithInput("-c ", htmlOutput).
- FlagWithOutput("> ", htmlGzOutput)
- builder.Build("build_notices", "generate notice output")
-
- return NoticeOutputs{
- TxtOutput: OptionalPathForPath(txtOutput),
- HtmlOutput: OptionalPathForPath(htmlOutput),
- HtmlGzOutput: OptionalPathForPath(htmlGzOutput),
- }
+// BuildNoticeTextOutputFromLicenseMetadata writes out a notice text file based on the module's
+// generated license metadata file.
+func BuildNoticeTextOutputFromLicenseMetadata(ctx ModuleContext, outputFile WritablePath) {
+ depsFile := outputFile.ReplaceExtension(ctx, strings.TrimPrefix(outputFile.Ext()+".d", "."))
+ rule := NewRuleBuilder(pctx, ctx)
+ rule.Command().
+ BuiltTool("textnotice").
+ FlagWithOutput("-o ", outputFile).
+ FlagWithDepFile("-d ", depsFile).
+ Input(ctx.Module().base().licenseMetadataFile)
+ rule.Build("container_notice", "container notice file")
}
diff --git a/android/paths.go b/android/paths.go
index 70e427b..4c69de7 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -2149,3 +2149,23 @@
}
return false
}
+
+// PathsDepSet is a thin type-safe wrapper around the generic depSet. It always uses
+// topological order.
+type PathsDepSet struct {
+ depSet
+}
+
+// newPathsDepSet returns an immutable PathsDepSet with the given direct and
+// transitive contents.
+func newPathsDepSet(direct Paths, transitive []*PathsDepSet) *PathsDepSet {
+ return &PathsDepSet{*newDepSet(TOPOLOGICAL, direct, transitive)}
+}
+
+// ToList returns the PathsDepSet flattened to a list in topological order.
+func (d *PathsDepSet) ToList() Paths {
+ if d == nil {
+ return nil
+ }
+ return d.depSet.ToList().(Paths)
+}
diff --git a/android/register.go b/android/register.go
index 1ac4440..10e14e0 100644
--- a/android/register.go
+++ b/android/register.go
@@ -31,7 +31,7 @@
type sortableComponent interface {
// componentName returns the name of the component.
//
- // Uniquely identifies the components within the set of components used at runtimr and during
+ // Uniquely identifies the components within the set of components used at runtime and during
// tests.
componentName() string
diff --git a/android/variable.go b/android/variable.go
index 40dd2d8..ff77fef 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -129,7 +129,7 @@
Exclude_srcs []string
}
- // eng is true for -eng builds, and can be used to turn on additionaly heavyweight debugging
+ // eng is true for -eng builds, and can be used to turn on additional heavyweight debugging
// features.
Eng struct {
Cflags []string
diff --git a/android_sdk/sdk_repo_host.go b/android_sdk/sdk_repo_host.go
index d64eb7a..f050a2e 100644
--- a/android_sdk/sdk_repo_host.go
+++ b/android_sdk/sdk_repo_host.go
@@ -122,17 +122,10 @@
s.CopySpecsToDir(ctx, builder, packageSpecs, dir)
- // Collect licenses to write into NOTICE.txt
- noticeMap := map[string]android.Paths{}
- for path, pkgSpec := range packageSpecs {
- licenseFiles := pkgSpec.EffectiveLicenseFiles()
- if len(licenseFiles) > 0 {
- noticeMap[path] = pkgSpec.EffectiveLicenseFiles()
- }
- }
- notices := android.BuildNotices(ctx, noticeMap)
+ noticeFile := android.PathForModuleOut(ctx, "NOTICES.txt")
+ android.BuildNoticeTextOutputFromLicenseMetadata(ctx, noticeFile)
builder.Command().Text("cp").
- Input(notices.TxtOutput.Path()).
+ Input(noticeFile).
Text(filepath.Join(dir.String(), "NOTICE.txt"))
// Handle `merge_zips` by extracting their contents into our tmpdir
diff --git a/dexpreopt/config.go b/dexpreopt/config.go
index 1f99a96..153b025 100644
--- a/dexpreopt/config.go
+++ b/dexpreopt/config.go
@@ -408,6 +408,7 @@
type dex2oatDependencyTag struct {
blueprint.BaseDependencyTag
+ android.LicenseAnnotationToolchainDependencyTag
}
func (d dex2oatDependencyTag) ExcludeFromVisibilityEnforcement() {
diff --git a/java/hiddenapi.go b/java/hiddenapi.go
index 7c8be1e..3af5f1c 100644
--- a/java/hiddenapi.go
+++ b/java/hiddenapi.go
@@ -297,6 +297,7 @@
type hiddenApiAnnotationsDependencyTag struct {
blueprint.BaseDependencyTag
+ android.LicenseAnnotationSharedDependencyTag
}
// Tag used to mark dependencies on java_library instances that contains Java source files whose
diff --git a/java/java.go b/java/java.go
index ca4b3cf..fef9912 100644
--- a/java/java.go
+++ b/java/java.go
@@ -274,6 +274,9 @@
// True if the dependency is relinked at runtime.
runtimeLinked bool
+
+ // True if the dependency is a toolchain, for example an annotation processor.
+ toolchain bool
}
// installDependencyTag is a dependency tag that is annotated to cause the installed files of the
@@ -287,6 +290,8 @@
func (d dependencyTag) LicenseAnnotations() []android.LicenseAnnotation {
if d.runtimeLinked {
return []android.LicenseAnnotation{android.LicenseAnnotationSharedDependency}
+ } else if d.toolchain {
+ return []android.LicenseAnnotation{android.LicenseAnnotationToolchain}
}
return nil
}
@@ -329,19 +334,19 @@
staticLibTag = dependencyTag{name: "staticlib"}
libTag = dependencyTag{name: "javalib", runtimeLinked: true}
java9LibTag = dependencyTag{name: "java9lib", runtimeLinked: true}
- pluginTag = dependencyTag{name: "plugin"}
- errorpronePluginTag = dependencyTag{name: "errorprone-plugin"}
- exportedPluginTag = dependencyTag{name: "exported-plugin"}
+ pluginTag = dependencyTag{name: "plugin", toolchain: true}
+ errorpronePluginTag = dependencyTag{name: "errorprone-plugin", toolchain: true}
+ exportedPluginTag = dependencyTag{name: "exported-plugin", toolchain: true}
bootClasspathTag = dependencyTag{name: "bootclasspath", runtimeLinked: true}
systemModulesTag = dependencyTag{name: "system modules", runtimeLinked: true}
frameworkResTag = dependencyTag{name: "framework-res"}
kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib", runtimeLinked: true}
kotlinAnnotationsTag = dependencyTag{name: "kotlin-annotations", runtimeLinked: true}
- kotlinPluginTag = dependencyTag{name: "kotlin-plugin"}
+ kotlinPluginTag = dependencyTag{name: "kotlin-plugin", toolchain: true}
proguardRaiseTag = dependencyTag{name: "proguard-raise"}
certificateTag = dependencyTag{name: "certificate"}
instrumentationForTag = dependencyTag{name: "instrumentation_for"}
- extraLintCheckTag = dependencyTag{name: "extra-lint-check"}
+ extraLintCheckTag = dependencyTag{name: "extra-lint-check", toolchain: true}
jniLibTag = dependencyTag{name: "jnilib", runtimeLinked: true}
syspropPublicStubDepTag = dependencyTag{name: "sysprop public stub"}
jniInstallTag = installDependencyTag{name: "jni install"}
diff --git a/snapshot/host_snapshot.go b/snapshot/host_snapshot.go
index 252cef8..09a382e 100644
--- a/snapshot/host_snapshot.go
+++ b/snapshot/host_snapshot.go
@@ -58,7 +58,7 @@
android.ModuleBase
android.PackagingBase
- zipFile android.OptionalPath
+ outputFile android.OutputPath
installDir android.InstallPath
}
@@ -141,7 +141,7 @@
// Create a zip file for the binaries, and a zip of the meta data, then merge zips
depsZipFile := android.PathForModuleOut(ctx, f.Name()+"_deps.zip").OutputPath
modsZipFile := android.PathForModuleOut(ctx, f.Name()+"_mods.zip").OutputPath
- outputFile := android.PathForModuleOut(ctx, f.installFileName()).OutputPath
+ f.outputFile = android.PathForModuleOut(ctx, f.installFileName()).OutputPath
f.installDir = android.PathForModuleInstall(ctx)
@@ -158,26 +158,21 @@
builder.Command().
BuiltTool("merge_zips").
- Output(outputFile).
+ Output(f.outputFile).
Input(metaZipFile).
Input(modsZipFile)
builder.Build("manifest", fmt.Sprintf("Adding manifest %s", f.installFileName()))
- zip := ctx.InstallFile(f.installDir, f.installFileName(), outputFile)
- f.zipFile = android.OptionalPathForPath(zip)
+ ctx.InstallFile(f.installDir, f.installFileName(), f.outputFile)
}
// Implements android.AndroidMkEntriesProvider
func (f *hostSnapshot) AndroidMkEntries() []android.AndroidMkEntries {
- if !f.zipFile.Valid() {
- return []android.AndroidMkEntries{}
- }
-
return []android.AndroidMkEntries{android.AndroidMkEntries{
Class: "ETC",
- OutputFile: f.zipFile,
- DistFiles: android.MakeDefaultDistFiles(f.zipFile.Path()),
+ OutputFile: android.OptionalPathForPath(f.outputFile),
+ DistFiles: android.MakeDefaultDistFiles(f.outputFile),
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
entries.SetString("LOCAL_MODULE_PATH", f.installDir.String())