aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--java/aar.go4
-rw-r--r--java/device_host_converter.go11
-rw-r--r--java/java.go46
-rw-r--r--java/java_resources.go8
-rw-r--r--java/java_test.go69
5 files changed, 111 insertions, 27 deletions
diff --git a/java/aar.go b/java/aar.go
index 5e1f88e7..7332e76b 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -647,6 +647,10 @@ func (a *AARImport) ExportedSdkLibs() []string {
647 return nil 647 return nil
648} 648}
649 649
650func (a *AARImport) SrcJarArgs() ([]string, android.Paths) {
651 return nil, nil
652}
653
650var _ android.PrebuiltInterface = (*Import)(nil) 654var _ android.PrebuiltInterface = (*Import)(nil)
651 655
652// android_library_import imports an `.aar` file into the build graph as if it was built with android_library. 656// android_library_import imports an `.aar` file into the build graph as if it was built with android_library.
diff --git a/java/device_host_converter.go b/java/device_host_converter.go
index 9c883e50..b92f4d73 100644
--- a/java/device_host_converter.go
+++ b/java/device_host_converter.go
@@ -34,6 +34,9 @@ type DeviceHostConverter struct {
34 implementationAndResourceJars android.Paths 34 implementationAndResourceJars android.Paths
35 resourceJars android.Paths 35 resourceJars android.Paths
36 36
37 srcJarArgs []string
38 srcJarDeps android.Paths
39
37 combinedHeaderJar android.Path 40 combinedHeaderJar android.Path
38 combinedImplementationJar android.Path 41 combinedImplementationJar android.Path
39} 42}
@@ -100,6 +103,10 @@ func (d *DeviceHostConverter) GenerateAndroidBuildActions(ctx android.ModuleCont
100 d.implementationJars = append(d.implementationJars, dep.ImplementationJars()...) 103 d.implementationJars = append(d.implementationJars, dep.ImplementationJars()...)
101 d.implementationAndResourceJars = append(d.implementationAndResourceJars, dep.ImplementationAndResourcesJars()...) 104 d.implementationAndResourceJars = append(d.implementationAndResourceJars, dep.ImplementationAndResourcesJars()...)
102 d.resourceJars = append(d.resourceJars, dep.ResourceJars()...) 105 d.resourceJars = append(d.resourceJars, dep.ResourceJars()...)
106
107 srcJarArgs, srcJarDeps := dep.SrcJarArgs()
108 d.srcJarArgs = append(d.srcJarArgs, srcJarArgs...)
109 d.srcJarDeps = append(d.srcJarDeps, srcJarDeps...)
103 } else { 110 } else {
104 ctx.PropertyErrorf("libs", "module %q cannot be used as a dependency", ctx.OtherModuleName(m)) 111 ctx.PropertyErrorf("libs", "module %q cannot be used as a dependency", ctx.OtherModuleName(m))
105 } 112 }
@@ -157,6 +164,10 @@ func (d *DeviceHostConverter) ExportedSdkLibs() []string {
157 return nil 164 return nil
158} 165}
159 166
167func (d *DeviceHostConverter) SrcJarArgs() ([]string, android.Paths) {
168 return d.srcJarArgs, d.srcJarDeps
169}
170
160func (d *DeviceHostConverter) AndroidMk() android.AndroidMkData { 171func (d *DeviceHostConverter) AndroidMk() android.AndroidMkData {
161 return android.AndroidMkData{ 172 return android.AndroidMkData{
162 Class: "JAVA_LIBRARIES", 173 Class: "JAVA_LIBRARIES",
diff --git a/java/java.go b/java/java.go
index b9c06a8e..e764ec30 100644
--- a/java/java.go
+++ b/java/java.go
@@ -290,6 +290,10 @@ type Module struct {
290 // jar file containing only resources including from static library dependencies 290 // jar file containing only resources including from static library dependencies
291 resourceJar android.Path 291 resourceJar android.Path
292 292
293 // args and dependencies to package source files into a srcjar
294 srcJarArgs []string
295 srcJarDeps android.Paths
296
293 // jar file containing implementation classes and resources including static library 297 // jar file containing implementation classes and resources including static library
294 // dependencies 298 // dependencies
295 implementationAndResourcesJar android.Path 299 implementationAndResourcesJar android.Path
@@ -365,6 +369,7 @@ type Dependency interface {
365 DexJar() android.Path 369 DexJar() android.Path
366 AidlIncludeDirs() android.Paths 370 AidlIncludeDirs() android.Paths
367 ExportedSdkLibs() []string 371 ExportedSdkLibs() []string
372 SrcJarArgs() ([]string, android.Paths)
368} 373}
369 374
370type SdkLibraryDependency interface { 375type SdkLibraryDependency interface {
@@ -1113,6 +1118,14 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
1113 } 1118 }
1114 } 1119 }
1115 1120
1121 j.srcJarArgs, j.srcJarDeps = resourcePathsToJarArgs(srcFiles), srcFiles
1122
1123 var includeSrcJar android.WritablePath
1124 if Bool(j.properties.Include_srcs) {
1125 includeSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+".srcjar")
1126 TransformResourcesToJar(ctx, includeSrcJar, j.srcJarArgs, j.srcJarDeps)
1127 }
1128
1116 dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs, 1129 dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs,
1117 j.properties.Exclude_java_resource_dirs, j.properties.Exclude_java_resources) 1130 j.properties.Exclude_java_resource_dirs, j.properties.Exclude_java_resources)
1118 fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources) 1131 fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
@@ -1130,12 +1143,6 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
1130 resArgs = append(resArgs, extraArgs...) 1143 resArgs = append(resArgs, extraArgs...)
1131 resDeps = append(resDeps, extraDeps...) 1144 resDeps = append(resDeps, extraDeps...)
1132 1145
1133 if Bool(j.properties.Include_srcs) {
1134 srcArgs, srcDeps := SourceFilesToJarArgs(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
1135 resArgs = append(resArgs, srcArgs...)
1136 resDeps = append(resDeps, srcDeps...)
1137 }
1138
1139 if len(resArgs) > 0 { 1146 if len(resArgs) > 0 {
1140 resourceJar := android.PathForModuleOut(ctx, "res", jarName) 1147 resourceJar := android.PathForModuleOut(ctx, "res", jarName)
1141 TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps) 1148 TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
@@ -1145,17 +1152,22 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
1145 } 1152 }
1146 } 1153 }
1147 1154
1148 if len(deps.staticResourceJars) > 0 { 1155 var resourceJars android.Paths
1149 var jars android.Paths 1156 if j.resourceJar != nil {
1150 if j.resourceJar != nil { 1157 resourceJars = append(resourceJars, j.resourceJar)
1151 jars = append(jars, j.resourceJar) 1158 }
1152 } 1159 if Bool(j.properties.Include_srcs) {
1153 jars = append(jars, deps.staticResourceJars...) 1160 resourceJars = append(resourceJars, includeSrcJar)
1161 }
1162 resourceJars = append(resourceJars, deps.staticResourceJars...)
1154 1163
1164 if len(resourceJars) > 1 {
1155 combinedJar := android.PathForModuleOut(ctx, "res-combined", jarName) 1165 combinedJar := android.PathForModuleOut(ctx, "res-combined", jarName)
1156 TransformJarsToJar(ctx, combinedJar, "for resources", jars, android.OptionalPath{}, 1166 TransformJarsToJar(ctx, combinedJar, "for resources", resourceJars, android.OptionalPath{},
1157 false, nil, nil) 1167 false, nil, nil)
1158 j.resourceJar = combinedJar 1168 j.resourceJar = combinedJar
1169 } else if len(resourceJars) == 1 {
1170 j.resourceJar = resourceJars[0]
1159 } 1171 }
1160 1172
1161 jars = append(jars, deps.staticJars...) 1173 jars = append(jars, deps.staticJars...)
@@ -1443,6 +1455,10 @@ func (j *Module) ExportedSdkLibs() []string {
1443 return j.exportedSdkLibs 1455 return j.exportedSdkLibs
1444} 1456}
1445 1457
1458func (j *Module) SrcJarArgs() ([]string, android.Paths) {
1459 return j.srcJarArgs, j.srcJarDeps
1460}
1461
1446var _ logtagsProducer = (*Module)(nil) 1462var _ logtagsProducer = (*Module)(nil)
1447 1463
1448func (j *Module) logtags() android.Paths { 1464func (j *Module) logtags() android.Paths {
@@ -1920,6 +1936,10 @@ func (j *Import) ExportedSdkLibs() []string {
1920 return j.exportedSdkLibs 1936 return j.exportedSdkLibs
1921} 1937}
1922 1938
1939func (j *Import) SrcJarArgs() ([]string, android.Paths) {
1940 return nil, nil
1941}
1942
1923// Add compile time check for interface implementation 1943// Add compile time check for interface implementation
1924var _ android.IDEInfo = (*Import)(nil) 1944var _ android.IDEInfo = (*Import)(nil)
1925var _ android.IDECustomizedModuleName = (*Import)(nil) 1945var _ android.IDECustomizedModuleName = (*Import)(nil)
diff --git a/java/java_resources.go b/java/java_resources.go
index 1bbeb9a6..787d74a0 100644
--- a/java/java_resources.go
+++ b/java/java_resources.go
@@ -85,14 +85,6 @@ func ResourceFilesToJarArgs(ctx android.ModuleContext,
85 return resourceFilesToJarArgs(ctx, res, exclude) 85 return resourceFilesToJarArgs(ctx, res, exclude)
86} 86}
87 87
88// Convert java_resources properties to arguments to soong_zip -jar, keeping files that should
89// normally not used as resources like *.java
90func SourceFilesToJarArgs(ctx android.ModuleContext,
91 res, exclude []string) (args []string, deps android.Paths) {
92
93 return resourceFilesToJarArgs(ctx, res, exclude)
94}
95
96func resourceFilesToJarArgs(ctx android.ModuleContext, 88func resourceFilesToJarArgs(ctx android.ModuleContext,
97 res, exclude []string) (args []string, deps android.Paths) { 89 res, exclude []string) (args []string, deps android.Paths) {
98 90
diff --git a/java/java_test.go b/java/java_test.go
index 5335d789..53df6f48 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -482,12 +482,6 @@ func TestResources(t *testing.T) {
482 args: "-C java-res -f java-res/a/a -f java-res/b/b", 482 args: "-C java-res -f java-res/a/a -f java-res/b/b",
483 }, 483 },
484 { 484 {
485 // Test that a module with "include_srcs: true" includes its source files in the resources jar
486 name: "include sources",
487 prop: `include_srcs: true`,
488 args: "-C . -f a.java -f b.java -f c.java",
489 },
490 {
491 // Test that a module with wildcards in java_resource_dirs has the correct path prefixes 485 // Test that a module with wildcards in java_resource_dirs has the correct path prefixes
492 name: "wildcard dirs", 486 name: "wildcard dirs",
493 prop: `java_resource_dirs: ["java-res/*"]`, 487 prop: `java_resource_dirs: ["java-res/*"]`,
@@ -555,6 +549,69 @@ func TestResources(t *testing.T) {
555 } 549 }
556} 550}
557 551
552func TestIncludeSrcs(t *testing.T) {
553 ctx := testJava(t, `
554 java_library {
555 name: "foo",
556 srcs: [
557 "a.java",
558 "b.java",
559 "c.java",
560 ],
561 include_srcs: true,
562 }
563
564 java_library {
565 name: "bar",
566 srcs: [
567 "a.java",
568 "b.java",
569 "c.java",
570 ],
571 java_resource_dirs: ["java-res"],
572 include_srcs: true,
573 }
574 `)
575
576 // Test a library with include_srcs: true
577 foo := ctx.ModuleForTests("foo", "android_common").Output("withres/foo.jar")
578 fooSrcJar := ctx.ModuleForTests("foo", "android_common").Output("foo.srcjar")
579
580 if g, w := fooSrcJar.Output.String(), foo.Inputs.Strings(); !inList(g, w) {
581 t.Errorf("foo combined jars %v does not contain %q", w, g)
582 }
583
584 if g, w := fooSrcJar.Args["jarArgs"], "-C . -f a.java -f b.java -f c.java"; g != w {
585 t.Errorf("foo source jar args %q is not %q", w, g)
586 }
587
588 // Test a library with include_srcs: true and resources
589 bar := ctx.ModuleForTests("bar", "android_common").Output("withres/bar.jar")
590 barResCombined := ctx.ModuleForTests("bar", "android_common").Output("res-combined/bar.jar")
591 barRes := ctx.ModuleForTests("bar", "android_common").Output("res/bar.jar")
592 barSrcJar := ctx.ModuleForTests("bar", "android_common").Output("bar.srcjar")
593
594 if g, w := barSrcJar.Output.String(), barResCombined.Inputs.Strings(); !inList(g, w) {
595 t.Errorf("bar combined resource jars %v does not contain %q", w, g)
596 }
597
598 if g, w := barRes.Output.String(), barResCombined.Inputs.Strings(); !inList(g, w) {
599 t.Errorf("bar combined resource jars %v does not contain %q", w, g)
600 }
601
602 if g, w := barResCombined.Output.String(), bar.Inputs.Strings(); !inList(g, w) {
603 t.Errorf("bar combined jars %v does not contain %q", w, g)
604 }
605
606 if g, w := barSrcJar.Args["jarArgs"], "-C . -f a.java -f b.java -f c.java"; g != w {
607 t.Errorf("bar source jar args %q is not %q", w, g)
608 }
609
610 if g, w := barRes.Args["jarArgs"], "-C java-res -f java-res/a/a -f java-res/b/b"; g != w {
611 t.Errorf("bar resource jar args %q is not %q", w, g)
612 }
613}
614
558func TestGeneratedSources(t *testing.T) { 615func TestGeneratedSources(t *testing.T) {
559 ctx := testJava(t, ` 616 ctx := testJava(t, `
560 java_library { 617 java_library {