summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <treehugger-gerrit@google.com> 2021-06-28 19:31:59 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2021-06-28 19:31:59 +0000
commit26999937e22dc0beb6b7162c6a2fc426b08901b9 (patch)
tree0f917bfa124c287ea7f80b268a027ebfa3dbe65b
parent6eb16f8f879afe4e85bb2ea1713a614d3192659a (diff)
parentf05ca9c0eac6369632e433b6ddda0f74a32a66f7 (diff)
Merge changes I5823fdb5,I3e44c137
* changes: Tag android_app_import's apk as `android:"path"` genrule supports OutputFileProducer
-rw-r--r--genrule/genrule.go16
-rw-r--r--genrule/genrule_test.go57
-rw-r--r--java/app_import.go2
3 files changed, 73 insertions, 2 deletions
diff --git a/genrule/genrule.go b/genrule/genrule.go
index 77dae755a..8372a6450 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -211,6 +211,22 @@ func (g *Module) GeneratedDeps() android.Paths {
return g.outputDeps
}
+func (g *Module) OutputFiles(tag string) (android.Paths, error) {
+ if tag == "" {
+ return append(android.Paths{}, g.outputFiles...), nil
+ }
+ // otherwise, tag should match one of outputs
+ for _, outputFile := range g.outputFiles {
+ if outputFile.Rel() == tag {
+ return android.Paths{outputFile}, nil
+ }
+ }
+ return nil, fmt.Errorf("unsupported module reference tag %q", tag)
+}
+
+var _ android.SourceFileProducer = (*Module)(nil)
+var _ android.OutputFileProducer = (*Module)(nil)
+
func toolDepsMutator(ctx android.BottomUpMutatorContext) {
if g, ok := ctx.Module().(*Module); ok {
for _, tool := range g.properties.Tools {
diff --git a/genrule/genrule_test.go b/genrule/genrule_test.go
index 3ce4f85f9..714d2f8a9 100644
--- a/genrule/genrule_test.go
+++ b/genrule/genrule_test.go
@@ -31,12 +31,12 @@ func TestMain(m *testing.M) {
var prepareForGenRuleTest = android.GroupFixturePreparers(
android.PrepareForTestWithArchMutator,
android.PrepareForTestWithDefaults,
-
android.PrepareForTestWithFilegroup,
PrepareForTestWithGenRuleBuildComponents,
android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
ctx.RegisterModuleType("tool", toolFactory)
ctx.RegisterModuleType("output", outputProducerFactory)
+ ctx.RegisterModuleType("use_source", useSourceFactory)
}),
android.FixtureMergeMockFs(android.MockFS{
"tool": nil,
@@ -684,6 +684,42 @@ func TestGenruleAllowMissingDependencies(t *testing.T) {
}
}
+func TestGenruleOutputFiles(t *testing.T) {
+ bp := `
+ genrule {
+ name: "gen",
+ out: ["foo", "sub/bar"],
+ cmd: "echo foo > $(location foo) && echo bar > $(location sub/bar)",
+ }
+ use_source {
+ name: "gen_foo",
+ srcs: [":gen{foo}"],
+ }
+ use_source {
+ name: "gen_bar",
+ srcs: [":gen{sub/bar}"],
+ }
+ use_source {
+ name: "gen_all",
+ srcs: [":gen"],
+ }
+ `
+
+ result := prepareForGenRuleTest.RunTestWithBp(t, testGenruleBp()+bp)
+ android.AssertPathsRelativeToTopEquals(t,
+ "genrule.tag with output",
+ []string{"out/soong/.intermediates/gen/gen/foo"},
+ result.ModuleForTests("gen_foo", "").Module().(*useSource).srcs)
+ android.AssertPathsRelativeToTopEquals(t,
+ "genrule.tag with output in subdir",
+ []string{"out/soong/.intermediates/gen/gen/sub/bar"},
+ result.ModuleForTests("gen_bar", "").Module().(*useSource).srcs)
+ android.AssertPathsRelativeToTopEquals(t,
+ "genrule.tag with all",
+ []string{"out/soong/.intermediates/gen/gen/foo", "out/soong/.intermediates/gen/gen/sub/bar"},
+ result.ModuleForTests("gen_all", "").Module().(*useSource).srcs)
+}
+
func TestGenruleWithBazel(t *testing.T) {
bp := `
genrule {
@@ -750,3 +786,22 @@ func (t *testOutputProducer) OutputFiles(tag string) (android.Paths, error) {
}
var _ android.OutputFileProducer = (*testOutputProducer)(nil)
+
+type useSource struct {
+ android.ModuleBase
+ props struct {
+ Srcs []string `android:"path"`
+ }
+ srcs android.Paths
+}
+
+func (s *useSource) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ s.srcs = android.PathsForModuleSrc(ctx, s.props.Srcs)
+}
+
+func useSourceFactory() android.Module {
+ module := &useSource{}
+ module.AddProperties(&module.props)
+ android.InitAndroidModule(module)
+ return module
+}
diff --git a/java/app_import.go b/java/app_import.go
index 6fe620407..5a87b074b 100644
--- a/java/app_import.go
+++ b/java/app_import.go
@@ -61,7 +61,7 @@ type AndroidAppImport struct {
type AndroidAppImportProperties struct {
// A prebuilt apk to import
- Apk *string
+ Apk *string `android:"path"`
// The name of a certificate in the default certificate directory or an android_app_certificate
// module name in the form ":module". Should be empty if presigned or default_dev_cert is set.