diff options
author | Andy Quan <andyq@google.com> | 2023-02-16 14:09:50 -0800 |
---|---|---|
committer | Andy Quan <andyq@google.com> | 2023-02-16 14:09:50 -0800 |
commit | 99a750fbb46bd6acc2c1417515dfbd753830ad6f (patch) | |
tree | 238c70509eae1a52beca6df0b701869b1367c88b | |
parent | 0dbbfd37d8f5f06f4283dcab1870671ba7c482df (diff) | |
parent | cb3243f07ff880cb1e16e0c41e40cebadccd8af0 (diff) |
DO NOT MERGE - Merge tm-qpr2-release into tm-platform-merge
Bug: 269346300
Change-Id: I58d38a1f0fe2191102e70d43be3e90d6f690d301
-rw-r--r-- | android/neverallow.go | 2 | ||||
-rw-r--r-- | cmd/pom2bp/pom2bp.go | 35 | ||||
-rw-r--r-- | filesystem/filesystem.go | 12 | ||||
-rw-r--r-- | java/base.go | 9 | ||||
-rw-r--r-- | java/java.go | 14 | ||||
-rw-r--r-- | java/kotlin.go | 5 | ||||
-rw-r--r-- | java/kotlin_test.go | 15 | ||||
-rw-r--r-- | java/robolectric.go | 12 | ||||
-rw-r--r-- | third_party/zip/writer.go | 12 |
9 files changed, 102 insertions, 14 deletions
diff --git a/android/neverallow.go b/android/neverallow.go index aa47bcaeb..38d97224b 100644 --- a/android/neverallow.go +++ b/android/neverallow.go @@ -153,7 +153,9 @@ func createJavaDeviceForHostRules() []Rule { javaDeviceForHostProjectsAllowedList := []string{ "development/build", "external/guava", + "external/kotlinx.coroutines", "external/robolectric-shadows", + "external/robolectric", "frameworks/layoutlib", } diff --git a/cmd/pom2bp/pom2bp.go b/cmd/pom2bp/pom2bp.go index e0638b8ed..ba0648d19 100644 --- a/cmd/pom2bp/pom2bp.go +++ b/cmd/pom2bp/pom2bp.go @@ -207,6 +207,10 @@ func (p Pom) IsJar() bool { return p.Packaging == "jar" } +func (p Pom) IsApk() bool { + return p.Packaging == "apk" +} + func (p Pom) IsHostModule() bool { return hostModuleNames.IsHostModule(p.GroupId, p.ArtifactId) } @@ -244,6 +248,8 @@ func (p Pom) BazelTargetType() string { func (p Pom) ImportModuleType() string { if p.IsAar() { return "android_library_import" + } else if p.IsApk() { + return "android_app_import" } else if p.IsHostOnly() { return "java_import_host" } else { @@ -254,6 +260,8 @@ func (p Pom) ImportModuleType() string { func (p Pom) BazelImportTargetType() string { if p.IsAar() { return "aar_import" + } else if p.IsApk() { + return "apk_import" } else { return "java_import" } @@ -262,6 +270,8 @@ func (p Pom) BazelImportTargetType() string { func (p Pom) ImportProperty() string { if p.IsAar() { return "aars" + } else if p.IsApk() { + return "apk" } else { return "jars" } @@ -270,6 +280,8 @@ func (p Pom) ImportProperty() string { func (p Pom) BazelImportProperty() string { if p.IsAar() { return "aar" + } else if p.IsApk() { + return "apk" } else { return "jars" } @@ -493,8 +505,12 @@ func (p *Pom) ExtractMinSdkVersion() error { var bpTemplate = template.Must(template.New("bp").Parse(` {{.ImportModuleType}} { name: "{{.BpName}}", + {{- if .IsApk}} + {{.ImportProperty}}: "{{.ArtifactFile}}", + {{- else}} {{.ImportProperty}}: ["{{.ArtifactFile}}"], sdk_version: "{{.SdkVersion}}", + {{- end}} {{- if .Jetifier}} jetifier: true, {{- end}} @@ -535,8 +551,14 @@ var bpTemplate = template.Must(template.New("bp").Parse(` ], {{- end}} {{- else if not .IsHostOnly}} + {{- if not .IsApk}} min_sdk_version: "{{.DefaultMinSdkVersion}}", {{- end}} + {{- end}} + {{- if .IsApk}} + presigned: true + {{- end}} + } `)) @@ -828,6 +850,7 @@ Usage: %s [--rewrite <regex>=<replace>] [--exclude <module>] [--extra-static-lib var regen string var pom2build bool + var prepend string flag.Var(&excludes, "exclude", "Exclude module") flag.Var(&extraStaticLibs, "extra-static-libs", "Extra static dependencies needed when depending on a module") @@ -844,6 +867,7 @@ Usage: %s [--rewrite <regex>=<replace>] [--exclude <module>] [--extra-static-lib flag.BoolVar(&jetifier, "jetifier", false, "Sets jetifier: true on all modules") flag.StringVar(®en, "regen", "", "Rewrite specified file") flag.BoolVar(&pom2build, "pom2build", false, "If true, will generate a Bazel BUILD file *instead* of a .bp file") + flag.StringVar(&prepend, "prepend", "", "Path to a file containing text to insert at the beginning of the generated build file") flag.Parse() if regen != "" { @@ -975,6 +999,15 @@ Usage: %s [--rewrite <regex>=<replace>] [--exclude <module>] [--extra-static-lib fmt.Fprintln(buf, commentString, "pom2bp", strings.Join(proptools.ShellEscapeList(os.Args[1:]), " ")) } + if prepend != "" { + contents, err := ioutil.ReadFile(prepend) + if err != nil { + fmt.Fprintln(os.Stderr, "Error reading", prepend, err) + os.Exit(1) + } + fmt.Fprintln(buf, string(contents)) + } + depsTemplate := bpDepsTemplate template := bpTemplate if pom2build { @@ -984,7 +1017,7 @@ Usage: %s [--rewrite <regex>=<replace>] [--exclude <module>] [--extra-static-lib for _, pom := range poms { var err error - if staticDeps { + if staticDeps && !pom.IsApk() { err = depsTemplate.Execute(buf, pom) } else { err = template.Execute(buf, pom) diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go index ccf9e9d3b..665faaaed 100644 --- a/filesystem/filesystem.go +++ b/filesystem/filesystem.go @@ -66,9 +66,13 @@ type filesystemProperties struct { // TODO(jiyong): allow apex_key to be specified here Avb_private_key *string `android:"path"` - // Hash and signing algorithm for avbtool. Default is SHA256_RSA4096. + // Signing algorithm for avbtool. Default is SHA256_RSA4096. Avb_algorithm *string + // Hash algorithm used for avbtool (for descriptors). This is passed as hash_algorithm to + // avbtool. Default used by avbtool is sha1. + Avb_hash_algorithm *string + // Name of the partition stored in vbmeta desc. Defaults to the name of this module. Partition_name *string @@ -318,7 +322,11 @@ func (f *filesystem) buildPropFile(ctx android.ModuleContext) (propFile android. addStr("avb_algorithm", algorithm) key := android.PathForModuleSrc(ctx, proptools.String(f.properties.Avb_private_key)) addPath("avb_key_path", key) - addStr("avb_add_hashtree_footer_args", "--do_not_generate_fec") + avb_add_hashtree_footer_args := "--do_not_generate_fec" + if hashAlgorithm := proptools.String(f.properties.Avb_hash_algorithm); hashAlgorithm != "" { + avb_add_hashtree_footer_args += " --hash_algorithm " + hashAlgorithm + } + addStr("avb_add_hashtree_footer_args", avb_add_hashtree_footer_args) partitionName := proptools.StringDefault(f.properties.Partition_name, f.Name()) addStr("partition_name", partitionName) } diff --git a/java/base.go b/java/base.go index 7aa281495..f4a91f56c 100644 --- a/java/base.go +++ b/java/base.go @@ -749,9 +749,7 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) { // Kotlin files ctx.AddVariationDependencies(nil, kotlinStdlibTag, "kotlin-stdlib", "kotlin-stdlib-jdk7", "kotlin-stdlib-jdk8") - if len(j.properties.Plugins) > 0 { - ctx.AddVariationDependencies(nil, kotlinAnnotationsTag, "kotlin-annotations") - } + ctx.AddVariationDependencies(nil, kotlinAnnotationsTag, "kotlin-annotations") } // Framework libraries need special handling in static coverage builds: they should not have @@ -1107,8 +1105,6 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { flags.classpath = append(flags.classpath, deps.kotlinStdlib...) flags.classpath = append(flags.classpath, deps.kotlinAnnotations...) - flags.dexClasspath = append(flags.dexClasspath, deps.kotlinAnnotations...) - flags.kotlincClasspath = append(flags.kotlincClasspath, flags.bootClasspath...) flags.kotlincClasspath = append(flags.kotlincClasspath, flags.classpath...) @@ -1140,9 +1136,12 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { // Jar kotlin classes into the final jar after javac if BoolDefault(j.properties.Static_kotlin_stdlib, true) { kotlinJars = append(kotlinJars, deps.kotlinStdlib...) + kotlinJars = append(kotlinJars, deps.kotlinAnnotations...) kotlinHeaderJars = append(kotlinHeaderJars, deps.kotlinStdlib...) + kotlinHeaderJars = append(kotlinHeaderJars, deps.kotlinAnnotations...) } else { flags.dexClasspath = append(flags.dexClasspath, deps.kotlinStdlib...) + flags.dexClasspath = append(flags.dexClasspath, deps.kotlinAnnotations...) } } diff --git a/java/java.go b/java/java.go index 1e99aa32f..9830d08dd 100644 --- a/java/java.go +++ b/java/java.go @@ -526,6 +526,20 @@ func (v javaVersion) String() string { } } +func (v javaVersion) StringForKotlinc() string { + // $ ./external/kotlinc/bin/kotlinc -jvm-target foo + // error: unknown JVM target version: foo + // Supported versions: 1.6, 1.8, 9, 10, 11, 12, 13, 14, 15, 16, 17 + switch v { + case JAVA_VERSION_7: + return "1.6" + case JAVA_VERSION_9: + return "9" + default: + return v.String() + } +} + // Returns true if javac targeting this version uses system modules instead of a bootclasspath. func (v javaVersion) usesJavaModules() bool { return v >= 9 diff --git a/java/kotlin.go b/java/kotlin.go index 903c6249b..9bff5ea01 100644 --- a/java/kotlin.go +++ b/java/kotlin.go @@ -119,9 +119,8 @@ func kotlinCompile(ctx android.ModuleContext, outputFile, headerOutputFile andro "srcJarDir": android.PathForModuleOut(ctx, "kotlinc", "srcJars").String(), "kotlinBuildFile": android.PathForModuleOut(ctx, "kotlinc-build.xml").String(), "emptyDir": android.PathForModuleOut(ctx, "kotlinc", "empty").String(), - // http://b/69160377 kotlinc only supports -jvm-target 1.6 and 1.8 - "kotlinJvmTarget": "1.8", - "name": kotlinName, + "kotlinJvmTarget": flags.javaVersion.StringForKotlinc(), + "name": kotlinName, }, }) } diff --git a/java/kotlin_test.go b/java/kotlin_test.go index 435d78294..491ce2939 100644 --- a/java/kotlin_test.go +++ b/java/kotlin_test.go @@ -42,6 +42,11 @@ func TestKotlin(t *testing.T) { } `) + kotlinStdlib := ctx.ModuleForTests("kotlin-stdlib", "android_common"). + Output("turbine-combined/kotlin-stdlib.jar").Output + kotlinAnnotations := ctx.ModuleForTests("kotlin-annotations", "android_common"). + Output("turbine-combined/kotlin-annotations.jar").Output + fooKotlinc := ctx.ModuleForTests("foo", "android_common").Rule("kotlinc") fooJavac := ctx.ModuleForTests("foo", "android_common").Rule("javac") fooJar := ctx.ModuleForTests("foo", "android_common").Output("combined/foo.jar") @@ -69,6 +74,16 @@ func TestKotlin(t *testing.T) { fooJar.Inputs.Strings(), fooKotlincClasses.String()) } + if !inList(kotlinStdlib.String(), fooJar.Inputs.Strings()) { + t.Errorf("foo jar inputs %v does not contain %v", + fooJar.Inputs.Strings(), kotlinStdlib.String()) + } + + if !inList(kotlinAnnotations.String(), fooJar.Inputs.Strings()) { + t.Errorf("foo jar inputs %v does not contain %v", + fooJar.Inputs.Strings(), kotlinAnnotations.String()) + } + if !inList(fooKotlincHeaderClasses.String(), fooHeaderJar.Inputs.Strings()) { t.Errorf("foo header jar inputs %v does not contain %q", fooHeaderJar.Inputs.Strings(), fooKotlincHeaderClasses.String()) diff --git a/java/robolectric.go b/java/robolectric.go index f71952172..80be04612 100644 --- a/java/robolectric.go +++ b/java/robolectric.go @@ -23,6 +23,8 @@ import ( "android/soong/android" "android/soong/java/config" "android/soong/tradefed" + + "github.com/google/blueprint/proptools" ) func init() { @@ -63,6 +65,10 @@ type robolectricProperties struct { // The version number of a robolectric prebuilt to use from prebuilts/misc/common/robolectric // instead of the one built from source in external/robolectric-shadows. Robolectric_prebuilt_version *string + + // Use /external/robolectric rather than /external/robolectric-shadows as the version of robolectri + // to use. /external/robolectric closely tracks github's master, and will fully replace /external/robolectric-shadows + Upstream *bool } type robolectricTest struct { @@ -106,7 +112,11 @@ func (r *robolectricTest) DepsMutator(ctx android.BottomUpMutatorContext) { if v := String(r.robolectricProperties.Robolectric_prebuilt_version); v != "" { ctx.AddVariationDependencies(nil, libTag, fmt.Sprintf(robolectricPrebuiltLibPattern, v)) } else { - ctx.AddVariationDependencies(nil, libTag, robolectricCurrentLib) + if proptools.Bool(r.robolectricProperties.Upstream) { + ctx.AddVariationDependencies(nil, libTag, robolectricCurrentLib+"_upstream") + } else { + ctx.AddVariationDependencies(nil, libTag, robolectricCurrentLib) + } } ctx.AddVariationDependencies(nil, libTag, robolectricDefaultLibs...) diff --git a/third_party/zip/writer.go b/third_party/zip/writer.go index f5268385d..8a957e163 100644 --- a/third_party/zip/writer.go +++ b/third_party/zip/writer.go @@ -162,9 +162,17 @@ func (w *Writer) Close() error { if records > uint16max { records = uint16max } + // Only store uint32max for the size and the offset if they don't fit. + // Robolectric currently doesn't support zip64 and fails to find the + // offset to the central directory when the number of files in the zip + // is larger than 2^16. + if size > uint32max { + size = uint32max + } + if offset > uint32max { + offset = uint32max + } // END ANDROID CHANGE - size = uint32max - offset = uint32max } // write end record |