diff options
61 files changed, 821 insertions, 470 deletions
diff --git a/android/androidmk.go b/android/androidmk.go index 4f6e24c18..72b6584ab 100644 --- a/android/androidmk.go +++ b/android/androidmk.go @@ -518,7 +518,7 @@ func (a *AndroidMkEntries) fillInEntries(ctx fillInEntriesContext, mod blueprint a.AddStrings("LOCAL_TARGET_REQUIRED_MODULES", a.Target_required...) // If the install rule was generated by Soong tell Make about it. - if amod.InstallBypassMake() && len(base.katiInstalls) > 0 { + if len(base.katiInstalls) > 0 { // Assume the primary install file is last since it probably needs to depend on any other // installed files. If that is not the case we can add a method to specify the primary // installed file. diff --git a/android/bazel.go b/android/bazel.go index 51870c39d..f4f9a7242 100644 --- a/android/bazel.go +++ b/android/bazel.go @@ -245,6 +245,7 @@ var ( "build/soong/cc/libbuildversion": Bp2BuildDefaultTrue, // Skip tests subdir "build/soong/cc/ndkstubgen": Bp2BuildDefaultTrue, "build/soong/cc/symbolfile": Bp2BuildDefaultTrue, + "build/soong/scripts": Bp2BuildDefaultTrueRecursively, "cts/common/device-side/nativetesthelper/jni": Bp2BuildDefaultTrueRecursively, "development/apps/DevelopmentSettings": Bp2BuildDefaultTrue, "development/apps/Fallback": Bp2BuildDefaultTrue, @@ -363,9 +364,6 @@ var ( // Per-module denylist to always opt modules out of both bp2build and mixed builds. bp2buildModuleDoNotConvertList = []string{ - "libnativehelper_compat_libc++", // Broken compile: implicit declaration of function 'strerror_r' is invalid in C99 - "art_libdexfile_dex_instruction_list_header", // breaks libart_mterp.armng, header not found - "libandroid_runtime_lazy", // depends on unconverted modules: libbinder_headers "libcmd", // depends on unconverted modules: libbinder @@ -373,14 +371,13 @@ var ( "libsepol", // TODO(b/207408632): Unsupported case of .l sources in cc library rules - "get_clang_version_test", // depends on unconverted module: get_clang_version + "gen-kotlin-build-file.py", // module has same name as source "libbinder", // TODO(b/188503688): Disabled for some archs, "libactivitymanager_aidl", // TODO(b/207426160): Depends on activity_manager_procstate_aidl, which is an aidl filegroup. - "libnativehelper_lazy_mts_jni", // depends on unconverted modules: libgmock_ndk - "libnativehelper_mts_jni", // depends on unconverted modules: libgmock_ndk - "libnativetesthelper_jni", // depends on unconverted modules: libgtest_ndk_c++ + "libnativehelper_lazy_mts_jni", "libnativehelper_mts_jni", // depends on unconverted modules: libgmock_ndk + "libnativetesthelper_jni", "libgmock_main_ndk", "libgmock_ndk", // depends on unconverted module: libgtest_ndk_c++ "statslog-framework-java-gen", "statslog.cpp", "statslog.h", "statslog.rs", "statslog_header.rs", // depends on unconverted modules: stats-log-api-gen @@ -388,8 +385,6 @@ var ( "libstatslog", // depends on unconverted modules: statslog.cpp, statslog.h, ... - "libgmock_main_ndk", "libgmock_ndk", // depends on unconverted module: libgtest_ndk_c++ - "cmd", // depends on unconverted module packagemanager_aidl-cpp, of unsupported type aidl_interface "servicedispatcher", // depends on unconverted module android.debug_aidl, of unsupported type aidl_interface "libutilscallstack", // depends on unconverted module libbacktrace @@ -400,18 +395,11 @@ var ( "libdebuggerd", // depends on unconverted modules libdexfile_support, libunwindstack, gwp_asan_crash_handler, libtombstone_proto, libprotobuf-cpp-lite "libdexfile_static", // depends on libartpalette, libartbase, libdexfile, which are of unsupported type: art_cc_library. - "crasher", // depends on unconverted modules: libseccomp_policy - "static_crasher", // depends on unconverted modules: libdebuggerd_handler, libseccomp_policy - "host_bionic_linker_asm", // depends on extract_linker, a go binary. "host_bionic_linker_script", // depends on extract_linker, a go binary. + "static_crasher", // depends on unconverted modules: libdebuggerd_handler - "pbtombstone", // depends on libprotobuf-cpp-lite, libtombstone_proto - "crash_dump", // depends on unconverted module libprotobuf-cpp-lite - - "libunwindstack_local", "libunwindstack_utils", // depends on unconverted module libunwindstack - "libunwindstack", // depends on libdexfile_support, of unsupported module type art_cc_library_static - "libc_malloc_debug", // depends on unconverted module libunwindstack + "pbtombstone", "crash_dump", // depends on libdebuggerd, libunwindstack "libbase_ndk", // http://b/186826477, fails to link libctscamera2_jni for device (required for CtsCameraTestCases) @@ -422,10 +410,7 @@ var ( "libprotobuf-java-util-full", // b/210751803, we don't handle path property for filegroups "conscrypt", // b/210751803, we don't handle path property for filegroups - "libseccomp_policy", // b/201094425: depends on func_to_syscall_nrs, which depends on py_binary, which is unsupported in mixed builds. - "libfdtrack", // depends on unconverted module libunwindstack - - "gwp_asan_crash_handler", // cc_library, ld.lld: error: undefined symbol: memset + "conv_linker_config", // depends on linker_config_proto, a python lib with proto sources "brotli-fuzzer-corpus", // b/202015218: outputs are in location incompatible with bazel genrule handling. @@ -434,14 +419,8 @@ var ( "platform_tools_properties", "build_tools_source_properties", - // Tests. Handle later. - "libbionic_tests_headers_posix", // http://b/186024507, cc_library_static, sched.h, time.h not found - "libjemalloc5_integrationtest", - "libjemalloc5_stresstestlib", - "libjemalloc5_unittest", - // APEX support - "com.android.runtime", // http://b/194746715, apex, depends on 'libc_malloc_debug' + "com.android.runtime", // depends on unconverted modules: bionic-linker-config, linkerconfig "libgtest_ndk_c++", // b/201816222: Requires sdk_version support. "libgtest_main_ndk_c++", // b/201816222: Requires sdk_version support. @@ -471,6 +450,8 @@ var ( // Per-module denylist to opt modules out of mixed builds. Such modules will // still be generated via bp2build. mixedBuildsDisabledList = []string{ + "art_libdexfile_dex_instruction_list_header", // breaks libart_mterp.armng, header not found + "libbrotli", // http://b/198585397, ld.lld: error: bionic/libc/arch-arm64/generic/bionic/memmove.S:95:(.text+0x10): relocation R_AARCH64_CONDBR19 out of range: -1404176 is not in [-1048576, 1048575]; references __memcpy "minijail_constants_json", // http://b/200899432, bazel-built cc_genrule does not work in mixed build when it is a dependency of another soong module. diff --git a/android/config.go b/android/config.go index 5d90fd21d..5c0e5aea5 100644 --- a/android/config.go +++ b/android/config.go @@ -569,9 +569,6 @@ func (c *config) HostToolDir() string { func (c *config) HostToolPath(ctx PathContext, tool string) Path { path := pathForInstall(ctx, ctx.Config().BuildOS, ctx.Config().BuildArch, "bin", false, tool) - if ctx.Config().KatiEnabled() { - path = path.ToMakePath() - } return path } @@ -581,17 +578,11 @@ func (c *config) HostJNIToolPath(ctx PathContext, lib string) Path { ext = ".dylib" } path := pathForInstall(ctx, ctx.Config().BuildOS, ctx.Config().BuildArch, "lib64", false, lib+ext) - if ctx.Config().KatiEnabled() { - path = path.ToMakePath() - } return path } func (c *config) HostJavaToolPath(ctx PathContext, tool string) Path { path := pathForInstall(ctx, ctx.Config().BuildOS, ctx.Config().BuildArch, "framework", false, tool) - if ctx.Config().KatiEnabled() { - path = path.ToMakePath() - } return path } @@ -667,6 +658,10 @@ func (c *config) IsEnvFalse(key string) bool { return value == "0" || value == "n" || value == "no" || value == "off" || value == "false" } +func (c *config) TargetsJava11() bool { + return c.IsEnvTrue("EXPERIMENTAL_TARGET_JAVA_VERSION_11") +} + // EnvDeps returns the environment variables this build depends on. The first // call to this function blocks future reads from the environment. func (c *config) EnvDeps() map[string]string { @@ -1485,6 +1480,22 @@ func (c *deviceConfig) BoardReqdMaskPolicy() []string { return c.config.productVariables.BoardReqdMaskPolicy } +func (c *deviceConfig) BoardSystemExtPublicPrebuiltDirs() []string { + return c.config.productVariables.BoardSystemExtPublicPrebuiltDirs +} + +func (c *deviceConfig) BoardSystemExtPrivatePrebuiltDirs() []string { + return c.config.productVariables.BoardSystemExtPrivatePrebuiltDirs +} + +func (c *deviceConfig) BoardProductPublicPrebuiltDirs() []string { + return c.config.productVariables.BoardProductPublicPrebuiltDirs +} + +func (c *deviceConfig) BoardProductPrivatePrebuiltDirs() []string { + return c.config.productVariables.BoardProductPrivatePrebuiltDirs +} + func (c *deviceConfig) DirectedVendorSnapshot() bool { return c.config.productVariables.DirectedVendorSnapshot } @@ -1698,7 +1709,7 @@ func (l *ConfiguredJarList) Append(apex string, jar string) ConfiguredJarList { } // Append a list of (apex, jar) pairs to the list. -func (l *ConfiguredJarList) AppendList(other ConfiguredJarList) ConfiguredJarList { +func (l *ConfiguredJarList) AppendList(other *ConfiguredJarList) ConfiguredJarList { apexes := make([]string, 0, l.Len()+other.Len()) jars := make([]string, 0, l.Len()+other.Len()) diff --git a/android/module.go b/android/module.go index c479b596b..6de416535 100644 --- a/android/module.go +++ b/android/module.go @@ -429,7 +429,6 @@ type ModuleContext interface { InstallInRecovery() bool InstallInRoot() bool InstallInVendor() bool - InstallBypassMake() bool InstallForceOS() (*OsType, *ArchType) RequiredModuleNames() []string @@ -496,7 +495,6 @@ type Module interface { InstallInRecovery() bool InstallInRoot() bool InstallInVendor() bool - InstallBypassMake() bool InstallForceOS() (*OsType, *ArchType) HideFromMake() IsHideFromMake() bool @@ -1704,10 +1702,6 @@ func (m *ModuleBase) InstallInRoot() bool { return false } -func (m *ModuleBase) InstallBypassMake() bool { - return true -} - func (m *ModuleBase) InstallForceOS() (*OsType, *ArchType) { return nil, nil } @@ -2829,10 +2823,6 @@ func (m *moduleContext) InstallInRoot() bool { return m.module.InstallInRoot() } -func (m *moduleContext) InstallBypassMake() bool { - return m.module.InstallBypassMake() -} - func (m *moduleContext) InstallForceOS() (*OsType, *ArchType) { return m.module.InstallForceOS() } @@ -2857,12 +2847,6 @@ func (m *moduleContext) skipInstall() bool { return true } - if m.Device() { - if m.Config().KatiEnabled() && !m.InstallBypassMake() { - return true - } - } - return false } @@ -2921,7 +2905,7 @@ func (m *moduleContext) installFile(installPath InstallPath, name string, srcPat orderOnlyDeps = deps } - if m.Config().KatiEnabled() && m.InstallBypassMake() { + if m.Config().KatiEnabled() { // When creating the install rule in Soong but embedding in Make, write the rule to a // makefile instead of directly to the ninja file so that main.mk can add the // dependencies from the `required` property that are hard to resolve in Soong. @@ -2980,7 +2964,7 @@ func (m *moduleContext) InstallSymlink(installPath InstallPath, name string, src } if !m.skipInstall() { - if m.Config().KatiEnabled() && m.InstallBypassMake() { + if m.Config().KatiEnabled() { // When creating the symlink rule in Soong but embedding in Make, write the rule to a // makefile instead of directly to the ninja file so that main.mk can add the // dependencies from the `required` property that are hard to resolve in Soong. @@ -3026,7 +3010,7 @@ func (m *moduleContext) InstallAbsoluteSymlink(installPath InstallPath, name str m.module.base().hooks.runInstallHooks(m, nil, fullInstallPath, true) if !m.skipInstall() { - if m.Config().KatiEnabled() && m.InstallBypassMake() { + if m.Config().KatiEnabled() { // When creating the symlink rule in Soong but embedding in Make, write the rule to a // makefile instead of directly to the ninja file so that main.mk can add the // dependencies from the `required` property that are hard to resolve in Soong. diff --git a/android/module_test.go b/android/module_test.go index 8607a8d34..d9e2c87a4 100644 --- a/android/module_test.go +++ b/android/module_test.go @@ -204,10 +204,6 @@ type depsModule struct { } } -func (m *depsModule) InstallBypassMake() bool { - return true -} - func (m *depsModule) GenerateAndroidBuildActions(ctx ModuleContext) { outputFile := PathForModuleOut(ctx, ctx.ModuleName()) ctx.Build(pctx, BuildParams{ @@ -450,7 +446,7 @@ func TestInstall(t *testing.T) { assertOrderOnlys(symlinkRule("foo")) } -func TestInstallBypassMake(t *testing.T) { +func TestInstallKatiEnabled(t *testing.T) { if runtime.GOOS != "linux" { t.Skip("requires linux") } diff --git a/android/neverallow.go b/android/neverallow.go index 034861958..4bb3e57b5 100644 --- a/android/neverallow.go +++ b/android/neverallow.go @@ -15,6 +15,7 @@ package android import ( + "fmt" "path/filepath" "reflect" "regexp" @@ -372,6 +373,20 @@ type ruleProperty struct { matcher ValueMatcher } +func (r *ruleProperty) String() string { + return fmt.Sprintf("%q matches: %s", strings.Join(r.fields, "."), r.matcher) +} + +type ruleProperties []ruleProperty + +func (r ruleProperties) String() string { + var s []string + for _, r := range r { + s = append(s, r.String()) + } + return strings.Join(s, " ") +} + // A NeverAllow rule. type Rule interface { In(path ...string) Rule @@ -413,8 +428,8 @@ type rule struct { moduleTypes []string unlessModuleTypes []string - props []ruleProperty - unlessProps []ruleProperty + props ruleProperties + unlessProps ruleProperties onlyBootclasspathJar bool } @@ -424,16 +439,19 @@ func NeverAllow() Rule { return &rule{directDeps: make(map[string]bool)} } +// In adds path(s) where this rule applies. func (r *rule) In(path ...string) Rule { r.paths = append(r.paths, cleanPaths(path)...) return r } +// NotIn adds path(s) to that this rule does not apply to. func (r *rule) NotIn(path ...string) Rule { r.unlessPaths = append(r.unlessPaths, cleanPaths(path)...) return r } +// InDirectDeps adds dep(s) that are not allowed with this rule. func (r *rule) InDirectDeps(deps ...string) Rule { for _, d := range deps { r.directDeps[d] = true @@ -441,25 +459,30 @@ func (r *rule) InDirectDeps(deps ...string) Rule { return r } +// WithOsClass adds osClass(es) that this rule applies to. func (r *rule) WithOsClass(osClasses ...OsClass) Rule { r.osClasses = append(r.osClasses, osClasses...) return r } +// ModuleType adds type(s) that this rule applies to. func (r *rule) ModuleType(types ...string) Rule { r.moduleTypes = append(r.moduleTypes, types...) return r } +// NotModuleType adds type(s) that this rule does not apply to.. func (r *rule) NotModuleType(types ...string) Rule { r.unlessModuleTypes = append(r.unlessModuleTypes, types...) return r } +// With specifies property/value combinations that are restricted for this rule. func (r *rule) With(properties, value string) Rule { return r.WithMatcher(properties, selectMatcher(value)) } +// WithMatcher specifies property/matcher combinations that are restricted for this rule. func (r *rule) WithMatcher(properties string, matcher ValueMatcher) Rule { r.props = append(r.props, ruleProperty{ fields: fieldNamesForProperties(properties), @@ -468,10 +491,12 @@ func (r *rule) WithMatcher(properties string, matcher ValueMatcher) Rule { return r } +// Without specifies property/value combinations that this rule does not apply to. func (r *rule) Without(properties, value string) Rule { return r.WithoutMatcher(properties, selectMatcher(value)) } +// Without specifies property/matcher combinations that this rule does not apply to. func (r *rule) WithoutMatcher(properties string, matcher ValueMatcher) Rule { r.unlessProps = append(r.unlessProps, ruleProperty{ fields: fieldNamesForProperties(properties), @@ -487,49 +512,54 @@ func selectMatcher(expected string) ValueMatcher { return &equalMatcher{expected: expected} } +// Because specifies a reason for this rule. func (r *rule) Because(reason string) Rule { r.reason = reason return r } +// BootclasspathJar whether this rule only applies to Jars in the Bootclasspath func (r *rule) BootclasspathJar() Rule { r.onlyBootclasspathJar = true return r } func (r *rule) String() string { - s := "neverallow" - for _, v := range r.paths { - s += " dir:" + v + "*" + s := []string{"neverallow requirements. Not allowed:"} + if len(r.paths) > 0 { + s = append(s, fmt.Sprintf("in dirs: %q", r.paths)) } - for _, v := range r.unlessPaths { - s += " -dir:" + v + "*" + if len(r.moduleTypes) > 0 { + s = append(s, fmt.Sprintf("module types: %q", r.moduleTypes)) } - for _, v := range r.moduleTypes { - s += " type:" + v + if len(r.props) > 0 { + s = append(s, fmt.Sprintf("properties matching: %s", r.props)) } - for _, v := range r.unlessModuleTypes { - s += " -type:" + v + if len(r.directDeps) > 0 { + s = append(s, fmt.Sprintf("dep(s): %q", SortedStringKeys(r.directDeps))) } - for _, v := range r.props { - s += " " + strings.Join(v.fields, ".") + v.matcher.String() + if len(r.osClasses) > 0 { + s = append(s, fmt.Sprintf("os class(es): %q", r.osClasses)) } - for _, v := range r.unlessProps { - s += " -" + strings.Join(v.fields, ".") + v.matcher.String() + if r.onlyBootclasspathJar { + s = append(s, "in bootclasspath jar") } - for k := range r.directDeps { - s += " deps:" + k + if len(r.unlessPaths) > 0 { + s = append(s, fmt.Sprintf("EXCEPT in dirs: %q", r.unlessPaths)) } - for _, v := range r.osClasses { - s += " os:" + v.String() + if len(r.unlessModuleTypes) > 0 { + s = append(s, fmt.Sprintf("EXCEPT module types: %q", r.unlessModuleTypes)) } - if r.onlyBootclasspathJar { - s += " inBcp" + if len(r.unlessProps) > 0 { + s = append(s, fmt.Sprintf("EXCEPT properties matching: %q", r.unlessProps)) } if len(r.reason) != 0 { - s += " which is restricted because " + r.reason + s = append(s, " which is restricted because "+r.reason) + } + if len(s) == 1 { + s[0] = "neverallow requirements (empty)" } - return s + return strings.Join(s, "\n\t") } func (r *rule) appliesToPath(dir string) bool { diff --git a/android/neverallow_test.go b/android/neverallow_test.go index 18a870501..58a90b307 100644 --- a/android/neverallow_test.go +++ b/android/neverallow_test.go @@ -15,6 +15,7 @@ package android import ( + "regexp" "testing" "github.com/google/blueprint" @@ -55,7 +56,37 @@ var neverallowTests = []struct { }`), }, expectedErrors: []string{ - `module "libother": violates neverallow deps:not_allowed_in_direct_deps`, + regexp.QuoteMeta("module \"libother\": violates neverallow requirements. Not allowed:\n\tdep(s): [\"not_allowed_in_direct_deps\"]"), + }, + }, + { + name: "multiple constraints", + rules: []Rule{ + NeverAllow(). + InDirectDeps("not_allowed_in_direct_deps"). + In("other"). + ModuleType("cc_library"). + NotIn("top"). + NotModuleType("cc_binary"), + }, + fs: map[string][]byte{ + "top/Android.bp": []byte(` + cc_library { + name: "not_allowed_in_direct_deps", + }`), + "other/Android.bp": []byte(` + cc_library { + name: "libother", + static_libs: ["not_allowed_in_direct_deps"], + }`), + }, + expectedErrors: []string{ + regexp.QuoteMeta(`module "libother": violates neverallow requirements. Not allowed: + in dirs: ["other/"] + module types: ["cc_library"] + dep(s): ["not_allowed_in_direct_deps"] + EXCEPT in dirs: ["top/"] + EXCEPT module types: ["cc_binary"]`), }, }, diff --git a/android/paths.go b/android/paths.go index e68106ce9..70e427b2a 100644 --- a/android/paths.go +++ b/android/paths.go @@ -112,7 +112,6 @@ type ModuleInstallPathContext interface { InstallInDebugRamdisk() bool InstallInRecovery() bool InstallInRoot() bool - InstallBypassMake() bool InstallForceOS() (*OsType, *ArchType) } @@ -465,9 +464,6 @@ func (p OutputPaths) Strings() []string { // PathForGoBinary returns the path to the installed location of a bootstrap_go_binary module. func PathForGoBinary(ctx PathContext, goBinary bootstrap.GoBinaryTool) Path { goBinaryInstallDir := pathForInstall(ctx, ctx.Config().BuildOS, ctx.Config().BuildArch, "bin", false) - if ctx.Config().KatiEnabled() { - goBinaryInstallDir = goBinaryInstallDir.ToMakePath() - } rel := Rel(ctx, goBinaryInstallDir.String(), goBinary.InstallPath()) return goBinaryInstallDir.Join(ctx, rel) } @@ -1646,8 +1642,8 @@ func (p InstallPath) withRel(rel string) InstallPath { return p } -// ToMakePath returns a new InstallPath that points to Make's install directory instead of Soong's, -// i.e. out/ instead of out/soong/. +// Deprecated: ToMakePath is a noop, PathForModuleInstall always returns Make paths when building +// embedded in Make. func (p InstallPath) ToMakePath() InstallPath { p.makePath = true return p @@ -1688,9 +1684,6 @@ func osAndArch(ctx ModuleInstallPathContext) (OsType, ArchType) { func makePathForInstall(ctx ModuleInstallPathContext, os OsType, arch ArchType, partition string, debug bool, pathComponents ...string) InstallPath { ret := pathForInstall(ctx, os, arch, partition, debug, pathComponents...) - if ctx.InstallBypassMake() && ctx.Config().KatiEnabled() { - ret = ret.ToMakePath() - } return ret } @@ -1732,7 +1725,10 @@ func pathForInstall(ctx PathContext, os OsType, arch ArchType, partition string, soongOutDir: ctx.Config().soongOutDir, partitionDir: partionPath, partition: partition, - makePath: false, + } + + if ctx.Config().KatiEnabled() { + base.makePath = true } return base.Join(ctx, pathComponents...) @@ -2008,10 +2004,6 @@ func (m testModuleInstallPathContext) InstallInRoot() bool { return m.inRoot } -func (m testModuleInstallPathContext) InstallBypassMake() bool { - return false -} - func (m testModuleInstallPathContext) InstallForceOS() (*OsType, *ArchType) { return m.forceOS, m.forceArch } diff --git a/android/paths_test.go b/android/paths_test.go index 3cad8529d..2f87977a9 100644 --- a/android/paths_test.go +++ b/android/paths_test.go @@ -1486,7 +1486,8 @@ func TestPathRelativeToTop(t *testing.T) { AssertPathRelativeToTopEquals(t, "install path for soong", "out/soong/target/product/test_device/system/install/path", p) }) t.Run("install for make", func(t *testing.T) { - p := PathForModuleInstall(ctx, "install/path").ToMakePath() + p := PathForModuleInstall(ctx, "install/path") + p.makePath = true AssertPathRelativeToTopEquals(t, "install path for make", "out/target/product/test_device/system/install/path", p) }) t.Run("output", func(t *testing.T) { @@ -1500,14 +1501,12 @@ func TestPathRelativeToTop(t *testing.T) { t.Run("mixture", func(t *testing.T) { paths := Paths{ PathForModuleInstall(ctx, "install/path"), - PathForModuleInstall(ctx, "install/path").ToMakePath(), PathForOutput(ctx, "output/path"), PathForSource(ctx, "source/path"), } expected := []string{ "out/soong/target/product/test_device/system/install/path", - "out/target/product/test_device/system/install/path", "out/soong/output/path", "source/path", } diff --git a/android/rule_builder.go b/android/rule_builder.go index f8de5fb96..1c6b1c086 100644 --- a/android/rule_builder.go +++ b/android/rule_builder.go @@ -839,14 +839,6 @@ func sboxPathForToolRel(ctx BuilderContext, path Path) string { // The tool is in the Soong output directory, it will be copied to __SBOX_OUT_DIR__/tools/out return filepath.Join(sboxToolsSubDir, "out", relOutSoong) } - if ctx.Config().KatiEnabled() { - toolDir = toolDir.ToMakePath() - relOut, isRelOut, _ := maybeRelErr(toolDir.String(), path.String()) - if isRelOut { - // The tool is in the Make output directory, it will be copied to __SBOX_OUT_DIR__/tools/out - return filepath.Join(sboxToolsSubDir, "out", relOut) - } - } // The tool is in the source directory, it will be copied to __SBOX_OUT_DIR__/tools/src return filepath.Join(sboxToolsSubDir, "src", path.String()) } diff --git a/android/test_suites.go b/android/test_suites.go index 22f6cf229..55e1da79c 100644 --- a/android/test_suites.go +++ b/android/test_suites.go @@ -60,7 +60,7 @@ func robolectricTestSuite(ctx SingletonContext, files map[string]InstallPaths) W for _, module := range SortedStringKeys(files) { installedPaths = append(installedPaths, files[module]...) } - testCasesDir := pathForInstall(ctx, ctx.Config().BuildOS, X86, "testcases", false).ToMakePath() + testCasesDir := pathForInstall(ctx, ctx.Config().BuildOS, X86, "testcases", false) outputFile := PathForOutput(ctx, "packaging", "robolectric-tests.zip") rule := NewRuleBuilder(pctx, ctx) diff --git a/android/variable.go b/android/variable.go index a70681088..bc93835f2 100644 --- a/android/variable.go +++ b/android/variable.go @@ -344,13 +344,17 @@ type productVariables struct { RecoverySnapshotDirsIncluded []string `json:",omitempty"` HostFakeSnapshotEnabled bool `json:",omitempty"` - BoardVendorSepolicyDirs []string `json:",omitempty"` - BoardOdmSepolicyDirs []string `json:",omitempty"` - BoardReqdMaskPolicy []string `json:",omitempty"` - BoardPlatVendorPolicy []string `json:",omitempty"` - SystemExtPublicSepolicyDirs []string `json:",omitempty"` - SystemExtPrivateSepolicyDirs []string `json:",omitempty"` - BoardSepolicyM4Defs []string `json:",omitempty"` + BoardVendorSepolicyDirs []string `json:",omitempty"` + BoardOdmSepolicyDirs []string `json:",omitempty"` + BoardReqdMaskPolicy []string `json:",omitempty"` + BoardPlatVendorPolicy []string `json:",omitempty"` + BoardSystemExtPublicPrebuiltDirs []string `json:",omitempty"` + BoardSystemExtPrivatePrebuiltDirs []string `json:",omitempty"` + BoardProductPublicPrebuiltDirs []string `json:",omitempty"` + BoardProductPrivatePrebuiltDirs []string `json:",omitempty"` + SystemExtPublicSepolicyDirs []string `json:",omitempty"` + SystemExtPrivateSepolicyDirs []string `json:",omitempty"` + BoardSepolicyM4Defs []string `json:",omitempty"` BoardSepolicyVers *string `json:",omitempty"` PlatformSepolicyVersion *string `json:",omitempty"` diff --git a/androidmk/androidmk/android.go b/androidmk/androidmk/android.go index 1045ca6e4..ae526887a 100644 --- a/androidmk/androidmk/android.go +++ b/androidmk/androidmk/android.go @@ -229,6 +229,8 @@ func init() { "LOCAL_IS_UNIT_TEST": "unit_test", "LOCAL_ENFORCE_USES_LIBRARIES": "enforce_uses_libs", + + "LOCAL_CHECK_ELF_FILES": "check_elf_files", }) } diff --git a/androidmk/androidmk/androidmk_test.go b/androidmk/androidmk/androidmk_test.go index a2d6992e6..ea537056d 100644 --- a/androidmk/androidmk/androidmk_test.go +++ b/androidmk/androidmk/androidmk_test.go @@ -1566,6 +1566,25 @@ android_app { } `, }, + { + desc: "LOCAL_CHECK_ELF_FILES", + in: ` +include $(CLEAR_VARS) +LOCAL_MODULE := foo +LOCAL_SRC_FILES := test.c +LOCAL_MODULE_CLASS := SHARED_LIBRARIES +LOCAL_CHECK_ELF_FILES := false +include $(BUILD_PREBUILT) + `, + expected: ` +cc_prebuilt_library_shared { + name: "foo", + srcs: ["test.c"], + + check_elf_files: false, +} +`, + }, } func TestEndToEnd(t *testing.T) { diff --git a/apex/androidmk.go b/apex/androidmk.go index f001fa265..8cca137a0 100644 --- a/apex/androidmk.go +++ b/apex/androidmk.go @@ -149,7 +149,7 @@ func (a *apexBundle) androidMkForFiles(w io.Writer, apexBundleName, apexName, mo var modulePath string if apexType == flattenedApex { // /system/apex/<name>/{lib|framework|...} - modulePath = filepath.Join(a.installDir.ToMakePath().String(), apexBundleName, fi.installDir) + modulePath = filepath.Join(a.installDir.String(), apexBundleName, fi.installDir) fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", modulePath) if a.primaryApexType && !symbolFilesNotNeeded { fmt.Fprintln(w, "LOCAL_SOONG_SYMBOL_PATH :=", pathWhenActivated) @@ -362,7 +362,7 @@ func (a *apexBundle) androidMkForType() android.AndroidMkData { data.Entries.WriteLicenseVariables(w) fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") // do we need a new class? fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", a.outputFile.String()) - fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", a.installDir.ToMakePath().String()) + fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", a.installDir.String()) stemSuffix := apexType.suffix() if a.isCompressed { stemSuffix = imageCapexSuffix diff --git a/apex/apex.go b/apex/apex.go index b7faa5b98..635ff30a3 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -458,10 +458,6 @@ type apexBundle struct { modulePaths []string } -func (*apexBundle) InstallBypassMake() bool { - return true -} - // apexFileClass represents a type of file that can be included in APEX. type apexFileClass int @@ -2647,7 +2643,7 @@ func makeApexAvailableBaseline() map[string][]string { // // Module separator // - m["com.android.bluetooth.updatable"] = []string{ + m["com.android.bluetooth"] = []string{ "android.hardware.audio.common@5.0", "android.hardware.bluetooth.a2dp@1.0", "android.hardware.bluetooth.audio@2.0", diff --git a/apex/apex_test.go b/apex/apex_test.go index a749ea161..727a1f2ec 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -2657,7 +2657,10 @@ func TestFilesInSubDirWhenNativeBridgeEnabled(t *testing.T) { } func TestVendorApex(t *testing.T) { - ctx := testApex(t, ` + result := android.GroupFixturePreparers( + prepareForApexTest, + android.FixtureModifyConfig(android.SetKatiEnabledForTests), + ).RunTestWithBp(t, ` apex { name: "myapex", key: "myapex.key", @@ -2681,24 +2684,24 @@ func TestVendorApex(t *testing.T) { } `) - ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ + ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{ "bin/mybin", "lib64/libfoo.so", // TODO(b/159195575): Add an option to use VNDK libs from VNDK APEX "lib64/libc++.so", }) - apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) - data := android.AndroidMkDataForTest(t, ctx, apexBundle) + apexBundle := result.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) + data := android.AndroidMkDataForTest(t, result.TestContext, apexBundle) name := apexBundle.BaseModuleName() prefix := "TARGET_" var builder strings.Builder data.Custom(&builder, name, prefix, "", data) - androidMk := android.StringRelativeToTop(ctx.Config(), builder.String()) + androidMk := android.StringRelativeToTop(result.Config, builder.String()) installPath := "out/target/product/test_device/vendor/apex" ensureContains(t, androidMk, "LOCAL_MODULE_PATH := "+installPath) - apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") + apexManifestRule := result.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") requireNativeLibs := names(apexManifestRule.Args["requireNativeLibs"]) ensureListNotContains(t, requireNativeLibs, ":vndk") } @@ -7454,7 +7457,7 @@ func TestApexPermittedPackagesRules(t *testing.T) { }, { name: "Bootclasspath apex jar not satisfying allowed module packages on Q.", - expectedError: `module "bcp_lib2" .* which is restricted because jars that are part of the myapex module may only allow these packages: foo.bar with min_sdk < T. Please jarjar or move code around.`, + expectedError: `(?s)module "bcp_lib2" .* which is restricted because jars that are part of the myapex module may only allow these packages: foo.bar with min_sdk < T. Please jarjar or move code around.`, bp: ` java_library { name: "bcp_lib1", @@ -7491,7 +7494,7 @@ func TestApexPermittedPackagesRules(t *testing.T) { }, { name: "Bootclasspath apex jar not satisfying allowed module packages on R.", - expectedError: `module "bcp_lib2" .* which is restricted because jars that are part of the myapex module may only allow these packages: foo.bar with min_sdk < T. Please jarjar or move code around.`, + expectedError: `(?s)module "bcp_lib2" .* which is restricted because jars that are part of the myapex module may only allow these packages: foo.bar with min_sdk < T. Please jarjar or move code around.`, bp: ` java_library { name: "bcp_lib1", @@ -8500,7 +8503,7 @@ func TestAndroidMk_DexpreoptBuiltInstalledForApex_Prebuilt(t *testing.T) { java_import { name: "foo", jars: ["foo.jar"], - installable: true, + apex_available: ["myapex"], } `, dexpreopt.FixtureSetApexSystemServerJars("myapex:foo"), diff --git a/apex/bootclasspath_fragment_test.go b/apex/bootclasspath_fragment_test.go index 7ecf9b20f..ce828e1af 100644 --- a/apex/bootclasspath_fragment_test.go +++ b/apex/bootclasspath_fragment_test.go @@ -16,6 +16,7 @@ package apex import ( "fmt" + "path" "sort" "strings" "testing" @@ -442,6 +443,24 @@ func TestBootclasspathFragmentInArtApex(t *testing.T) { checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo") }) + t.Run("boot image disable generate profile", 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"), + addSource("foo", "bar"), + dexpreopt.FixtureDisableGenerateProfile(true), + ).RunTest(t) + + files := getFiles(t, result.TestContext, "com.android.art", "android_common_com.android.art_image") + for _, file := range files { + matched, _ := path.Match("etc/boot-image.prof", file.path) + android.AssertBoolEquals(t, "\"etc/boot-image.prof\" should not be in the APEX", matched, false) + } + }) + t.Run("boot image files with preferred prebuilt", func(t *testing.T) { result := android.GroupFixturePreparers( commonPreparer, diff --git a/apex/prebuilt.go b/apex/prebuilt.go index 254c90ec0..02d807516 100644 --- a/apex/prebuilt.go +++ b/apex/prebuilt.go @@ -222,7 +222,7 @@ func (p *prebuiltCommon) AndroidMkEntries() []android.AndroidMkEntries { Host_required: p.hostRequired, ExtraEntries: []android.AndroidMkExtraEntriesFunc{ func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { - entries.SetString("LOCAL_MODULE_PATH", p.installDir.ToMakePath().String()) + entries.SetString("LOCAL_MODULE_PATH", p.installDir.String()) entries.SetString("LOCAL_MODULE_STEM", p.installFilename) entries.SetPath("LOCAL_SOONG_INSTALLED_MODULE", p.installedFile) entries.SetString("LOCAL_SOONG_INSTALL_PAIRS", p.outputApex.String()+":"+p.installedFile.String()) @@ -256,7 +256,7 @@ func (p *prebuiltCommon) createEntriesForApexFile(fi apexFile, apexName string) Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk", ExtraEntries: []android.AndroidMkExtraEntriesFunc{ func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { - entries.SetString("LOCAL_MODULE_PATH", p.installDir.ToMakePath().String()) + entries.SetString("LOCAL_MODULE_PATH", p.installDir.String()) entries.SetString("LOCAL_SOONG_INSTALLED_MODULE", filepath.Join(p.installDir.String(), fi.stem())) entries.SetString("LOCAL_SOONG_INSTALL_PAIRS", fi.builtFile.String()+":"+filepath.Join(p.installDir.String(), fi.stem())) @@ -472,10 +472,6 @@ type Prebuilt struct { inputApex android.Path } -func (p *Prebuilt) InstallBypassMake() bool { - return true -} - type ApexFileProperties struct { // the path to the prebuilt .apex file to import. // diff --git a/bp2build/cc_library_static_conversion_test.go b/bp2build/cc_library_static_conversion_test.go index e2e55ddee..e65a1fa0b 100644 --- a/bp2build/cc_library_static_conversion_test.go +++ b/bp2build/cc_library_static_conversion_test.go @@ -1433,3 +1433,21 @@ func TestCcLibraryStaticUseVersionLib(t *testing.T) { }, }) } + +func TestCcLibraryStaticStdInFlags(t *testing.T) { + runCcLibraryStaticTestCase(t, bp2buildTestCase{ + blueprint: soongCcProtoPreamble + `cc_library_static { + name: "foo", + cflags: ["-std=candcpp"], + conlyflags: ["-std=conly"], + cppflags: ["-std=cpp"], + include_build_directory: false, +}`, + expectedBazelTargets: []string{ + makeBazelTarget("cc_library_static", "foo", attrNameToString{ + "conlyflags": `["-std=conly"]`, + "cppflags": `["-std=cpp"]`, + }), + }, + }) +} diff --git a/cc/androidmk.go b/cc/androidmk.go index 636bab81e..800b58f33 100644 --- a/cc/androidmk.go +++ b/cc/androidmk.go @@ -453,7 +453,7 @@ func (installer *baseInstaller) AndroidMkEntries(ctx AndroidMkContext, entries * } entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { - path, file := filepath.Split(installer.path.ToMakePath().String()) + path, file := filepath.Split(installer.path.String()) stem, suffix, _ := android.SplitFileExt(file) entries.SetString("LOCAL_MODULE_SUFFIX", suffix) entries.SetString("LOCAL_MODULE_PATH", path) @@ -532,7 +532,7 @@ func (c *snapshotLibraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entrie c.libraryDecorator.androidMkWriteExportedFlags(entries) if c.shared() || c.static() { - path, file := filepath.Split(c.path.ToMakePath().String()) + path, file := filepath.Split(c.path.String()) stem, suffix, ext := android.SplitFileExt(file) entries.SetString("LOCAL_BUILT_MODULE_STEM", "$(LOCAL_MODULE)"+ext) entries.SetString("LOCAL_MODULE_SUFFIX", suffix) diff --git a/cc/bp2build.go b/cc/bp2build.go index fad40beea..2119ee43f 100644 --- a/cc/bp2build.go +++ b/cc/bp2build.go @@ -162,7 +162,7 @@ func bp2buildParseStaticOrSharedProps(ctx android.BazelConversionPathContext, mo attrs := staticOrSharedAttributes{} setAttrs := func(axis bazel.ConfigurationAxis, config string, props StaticOrSharedProperties) { - attrs.Copts.SetSelectValue(axis, config, props.Cflags) + attrs.Copts.SetSelectValue(axis, config, parseCommandLineFlags(props.Cflags, filterOutStdFlag)) attrs.Srcs.SetSelectValue(axis, config, android.BazelLabelForModuleSrc(ctx, props.Srcs)) attrs.System_dynamic_deps.SetSelectValue(axis, config, bazelLabelForSharedDeps(ctx, props.System_shared_libs)) @@ -279,9 +279,18 @@ type compilerAttributes struct { protoSrcs bazel.LabelListAttribute } -func parseCommandLineFlags(soongFlags []string) []string { +type filterOutFn func(string) bool + +func filterOutStdFlag(flag string) bool { + return strings.HasPrefix(flag, "-std=") +} + +func parseCommandLineFlags(soongFlags []string, filterOut filterOutFn) []string { var result []string for _, flag := range soongFlags { + if filterOut != nil && filterOut(flag) { + continue + } // Soong's cflags can contain spaces, like `-include header.h`. For // Bazel's copts, split them up to be compatible with the // no_copts_tokenization feature. @@ -308,10 +317,14 @@ func (ca *compilerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversi ca.absoluteIncludes.SetSelectValue(axis, config, props.Include_dirs) ca.localIncludes.SetSelectValue(axis, config, localIncludeDirs) - ca.copts.SetSelectValue(axis, config, parseCommandLineFlags(props.Cflags)) - ca.asFlags.SetSelectValue(axis, config, parseCommandLineFlags(props.Asflags)) - ca.conlyFlags.SetSelectValue(axis, config, parseCommandLineFlags(props.Conlyflags)) - ca.cppFlags.SetSelectValue(axis, config, parseCommandLineFlags(props.Cppflags)) + // In Soong, cflags occur on the command line before -std=<val> flag, resulting in the value being + // overridden. In Bazel we always allow overriding, via flags; however, this can cause + // incompatibilities, so we remove "-std=" flags from Cflag properties while leaving it in other + // cases. + ca.copts.SetSelectValue(axis, config, parseCommandLineFlags(props.Cflags, filterOutStdFlag)) + ca.asFlags.SetSelectValue(axis, config, parseCommandLineFlags(props.Asflags, nil)) + ca.conlyFlags.SetSelectValue(axis, config, parseCommandLineFlags(props.Conlyflags, nil)) + ca.cppFlags.SetSelectValue(axis, config, parseCommandLineFlags(props.Cppflags, nil)) ca.rtti.SetSelectValue(axis, config, props.Rtti) } @@ -1385,8 +1385,6 @@ func (c *Module) InstallInRoot() bool { return c.installer != nil && c.installer.installInRoot() } -func (c *Module) InstallBypassMake() bool { return true } - type baseModuleContext struct { android.BaseModuleContext moduleContextImpl diff --git a/cc/config/global.go b/cc/config/global.go index 2091e186f..7f2c23e4a 100644 --- a/cc/config/global.go +++ b/cc/config/global.go @@ -224,8 +224,6 @@ var ( "-Wno-pessimizing-move", // http://b/154270751 // New warnings to be fixed after clang-r399163 "-Wno-non-c-typedef-for-linkage", // http://b/161304145 - // New warnings to be fixed after clang-r407598 - "-Wno-string-concatenation", // http://b/175068488 // New warnings to be fixed after clang-r428724 "-Wno-align-mismatch", // http://b/193679946 // New warnings to be fixed after clang-r433403 @@ -265,6 +263,9 @@ var ( // http://b/199369603 "-Wno-null-pointer-subtraction", + + // http://b/175068488 + "-Wno-string-concatenation", } IllegalFlags = []string{ diff --git a/dexpreopt/config.go b/dexpreopt/config.go index 6d6b41d4b..1f99a96c1 100644 --- a/dexpreopt/config.go +++ b/dexpreopt/config.go @@ -100,6 +100,48 @@ type GlobalConfig struct { RelaxUsesLibraryCheck bool } +var allPlatformSystemServerJarsKey = android.NewOnceKey("allPlatformSystemServerJars") + +// Returns all jars on the platform that system_server loads, including those on classpath and those +// loaded dynamically. +func (g *GlobalConfig) AllPlatformSystemServerJars(ctx android.PathContext) *android.ConfiguredJarList { + return ctx.Config().Once(allPlatformSystemServerJarsKey, func() interface{} { + res := g.SystemServerJars.AppendList(&g.StandaloneSystemServerJars) + return &res + }).(*android.ConfiguredJarList) +} + +var allApexSystemServerJarsKey = android.NewOnceKey("allApexSystemServerJars") + +// Returns all jars delivered via apex that system_server loads, including those on classpath and +// those loaded dynamically. +func (g *GlobalConfig) AllApexSystemServerJars(ctx android.PathContext) *android.ConfiguredJarList { + return ctx.Config().Once(allApexSystemServerJarsKey, func() interface{} { + res := g.ApexSystemServerJars.AppendList(&g.ApexStandaloneSystemServerJars) + return &res + }).(*android.ConfiguredJarList) +} + +var allSystemServerClasspathJarsKey = android.NewOnceKey("allSystemServerClasspathJars") + +// Returns all system_server classpath jars. +func (g *GlobalConfig) AllSystemServerClasspathJars(ctx android.PathContext) *android.ConfiguredJarList { + return ctx.Config().Once(allSystemServerClasspathJarsKey, func() interface{} { + res := g.SystemServerJars.AppendList(&g.ApexSystemServerJars) + return &res + }).(*android.ConfiguredJarList) +} + +var allSystemServerJarsKey = android.NewOnceKey("allSystemServerJars") + +// Returns all jars that system_server loads. +func (g *GlobalConfig) AllSystemServerJars(ctx android.PathContext) *android.ConfiguredJarList { + return ctx.Config().Once(allSystemServerJarsKey, func() interface{} { + res := g.AllPlatformSystemServerJars(ctx).AppendList(g.AllApexSystemServerJars(ctx)) + return &res + }).(*android.ConfiguredJarList) +} + // GlobalSoongConfig contains the global config that is generated from Soong, // stored in dexpreopt_soong.config. type GlobalSoongConfig struct { diff --git a/dexpreopt/dexpreopt.go b/dexpreopt/dexpreopt.go index 3145315e3..de139c439 100644 --- a/dexpreopt/dexpreopt.go +++ b/dexpreopt/dexpreopt.go @@ -115,7 +115,7 @@ func dexpreoptDisabled(ctx android.PathContext, global *GlobalConfig, module *Mo // /data. If we don't do this they will need to be extracted which is not favorable for RAM usage // or performance. If PreoptExtractedApk is true, we ignore the only preopt boot image options. if global.OnlyPreoptBootImageAndSystemServer && !global.BootJars.ContainsJar(module.Name) && - !AllSystemServerJars(ctx, global).ContainsJar(module.Name) && !module.PreoptExtractedApk { + !global.AllSystemServerJars(ctx).ContainsJar(module.Name) && !module.PreoptExtractedApk { return true } @@ -197,8 +197,8 @@ func bootProfileCommand(ctx android.PathContext, globalSoong *GlobalSoongConfig, } // Returns the dex location of a system server java library. -func GetSystemServerDexLocation(global *GlobalConfig, lib string) string { - if apex := global.ApexSystemServerJars.ApexOfJar(lib); apex != "" { +func GetSystemServerDexLocation(ctx android.PathContext, global *GlobalConfig, lib string) string { + if apex := global.AllApexSystemServerJars(ctx).ApexOfJar(lib); apex != "" { return fmt.Sprintf("/apex/%s/javalib/%s.jar", apex, lib) } return fmt.Sprintf("/system/framework/%s.jar", lib) @@ -240,7 +240,8 @@ func dexpreoptCommand(ctx android.PathContext, globalSoong *GlobalSoongConfig, g invocationPath := odexPath.ReplaceExtension(ctx, "invocation") - systemServerJars := AllSystemServerJars(ctx, global) + systemServerJars := global.AllSystemServerJars(ctx) + systemServerClasspathJars := global.AllSystemServerClasspathJars(ctx) rule.Command().FlagWithArg("mkdir -p ", filepath.Dir(odexPath.String())) rule.Command().FlagWithOutput("rm -f ", odexPath) @@ -251,10 +252,15 @@ func dexpreoptCommand(ctx android.PathContext, globalSoong *GlobalSoongConfig, g var clcHost android.Paths var clcTarget []string - for i := 0; i < jarIndex; i++ { - lib := systemServerJars.Jar(i) + endIndex := systemServerClasspathJars.IndexOfJar(module.Name) + if endIndex < 0 { + // The jar is a standalone one. Use the full classpath as the class loader context. + endIndex = systemServerClasspathJars.Len() + } + for i := 0; i < endIndex; i++ { + lib := systemServerClasspathJars.Jar(i) clcHost = append(clcHost, SystemServerDexJarHostPath(ctx, lib)) - clcTarget = append(clcTarget, GetSystemServerDexLocation(global, lib)) + clcTarget = append(clcTarget, GetSystemServerDexLocation(ctx, global, lib)) } if DexpreoptRunningInSoong { @@ -270,12 +276,22 @@ func dexpreoptCommand(ctx android.PathContext, globalSoong *GlobalSoongConfig, g // cannot see the rule in the generated dexpreopt.sh script). } - checkSystemServerOrder(ctx, jarIndex) + clcHostString := "PCL[" + strings.Join(clcHost.Strings(), ":") + "]" + clcTargetString := "PCL[" + strings.Join(clcTarget, ":") + "]" + + if systemServerClasspathJars.ContainsJar(module.Name) { + checkSystemServerOrder(ctx, jarIndex) + } else { + // Standalone jars are loaded by separate class loaders with SYSTEMSERVERCLASSPATH as the + // parent. + clcHostString = "PCL[];" + clcHostString + clcTargetString = "PCL[];" + clcTargetString + } rule.Command(). - Text("class_loader_context_arg=--class-loader-context=PCL[" + strings.Join(clcHost.Strings(), ":") + "]"). + Text(`class_loader_context_arg=--class-loader-context="` + clcHostString + `"`). Implicits(clcHost). - Text("stored_class_loader_context_arg=--stored-class-loader-context=PCL[" + strings.Join(clcTarget, ":") + "]") + Text(`stored_class_loader_context_arg=--stored-class-loader-context="` + clcTargetString + `"`) } else { // There are three categories of Java modules handled here: @@ -533,17 +549,6 @@ func makefileMatch(pattern, s string) bool { } } -var allSystemServerJarsKey = android.NewOnceKey("allSystemServerJars") - -// TODO: eliminate the superficial global config parameter by moving global config definition -// from java subpackage to dexpreopt. -func AllSystemServerJars(ctx android.PathContext, global *GlobalConfig) *android.ConfiguredJarList { - return ctx.Config().Once(allSystemServerJarsKey, func() interface{} { - allSystemServerJars := global.SystemServerJars.AppendList(global.ApexSystemServerJars) - return &allSystemServerJars - }).(*android.ConfiguredJarList) -} - // A predefined location for the system server dex jars. This is needed in order to generate // class loader context for dex2oat, as the path to the jar in the Soong module may be unknown // at that time (Soong processes the jars in dependency order, which may be different from the @@ -567,7 +572,7 @@ func checkSystemServerOrder(ctx android.PathContext, jarIndex int) { mctx, isModule := ctx.(android.ModuleContext) if isModule { config := GetGlobalConfig(ctx) - jars := AllSystemServerJars(ctx, config) + jars := config.AllSystemServerClasspathJars(ctx) mctx.WalkDeps(func(dep android.Module, parent android.Module) bool { depIndex := jars.IndexOfJar(dep.Name()) if jarIndex < depIndex && !config.BrokenSuboptimalOrderOfSystemServerJars { diff --git a/dexpreopt/dexpreopt_test.go b/dexpreopt/dexpreopt_test.go index 798d77604..07e4fad01 100644 --- a/dexpreopt/dexpreopt_test.go +++ b/dexpreopt/dexpreopt_test.go @@ -50,6 +50,15 @@ func testApexModuleConfig(ctx android.PathContext, name, apexName string) *Modul android.PathForOutput(ctx, fmt.Sprintf("%s/enforce_uses_libraries.status", name))) } +func testPlatformSystemServerModuleConfig(ctx android.PathContext, name string) *ModuleConfig { + return createTestModuleConfig( + name, + fmt.Sprintf("/system/framework/%s.jar", name), + android.PathForOutput(ctx, fmt.Sprintf("%s/dexpreopt/%s.jar", name, name)), + android.PathForOutput(ctx, fmt.Sprintf("%s/aligned/%s.jar", name, name)), + android.PathForOutput(ctx, fmt.Sprintf("%s/enforce_uses_libraries.status", name))) +} + func createTestModuleConfig(name, dexLocation string, buildPath, dexPath, enforceUsesLibrariesStatusFile android.OutputPath) *ModuleConfig { return &ModuleConfig{ Name: name, @@ -181,6 +190,52 @@ func TestDexPreoptApexSystemServerJars(t *testing.T) { android.AssertStringEquals(t, "installs", wantInstalls.String(), rule.Installs().String()) } +func TestDexPreoptStandaloneSystemServerJars(t *testing.T) { + config := android.TestConfig("out", nil, "", nil) + ctx := android.BuilderContextForTesting(config) + globalSoong := globalSoongConfigForTests() + global := GlobalConfigForTests(ctx) + module := testPlatformSystemServerModuleConfig(ctx, "service-A") + + global.StandaloneSystemServerJars = android.CreateTestConfiguredJarList( + []string{"platform:service-A"}) + + rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module) + if err != nil { + t.Fatal(err) + } + + wantInstalls := android.RuleBuilderInstalls{ + {android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.odex"), "/system/framework/oat/arm/service-A.odex"}, + {android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.vdex"), "/system/framework/oat/arm/service-A.vdex"}, + } + + android.AssertStringEquals(t, "installs", wantInstalls.String(), rule.Installs().String()) +} + +func TestDexPreoptApexStandaloneSystemServerJars(t *testing.T) { + config := android.TestConfig("out", nil, "", nil) + ctx := android.BuilderContextForTesting(config) + globalSoong := globalSoongConfigForTests() + global := GlobalConfigForTests(ctx) + module := testApexModuleConfig(ctx, "service-A", "com.android.apex1") + + global.ApexStandaloneSystemServerJars = android.CreateTestConfiguredJarList( + []string{"com.android.apex1:service-A"}) + + rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module) + if err != nil { + t.Fatal(err) + } + + wantInstalls := android.RuleBuilderInstalls{ + {android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.odex"), "/system/framework/oat/arm/apex@com.android.apex1@javalib@service-A.jar@classes.odex"}, + {android.PathForOutput(ctx, "service-A/dexpreopt/oat/arm/javalib.vdex"), "/system/framework/oat/arm/apex@com.android.apex1@javalib@service-A.jar@classes.vdex"}, + } + + android.AssertStringEquals(t, "installs", wantInstalls.String(), rule.Installs().String()) +} + func TestDexPreoptProfile(t *testing.T) { config := android.TestConfig("out", nil, "", nil) ctx := android.BuilderContextForTesting(config) diff --git a/dexpreopt/testing.go b/dexpreopt/testing.go index 5131cd3f4..47ae494e3 100644 --- a/dexpreopt/testing.go +++ b/dexpreopt/testing.go @@ -167,3 +167,10 @@ func FixtureSetBootImageProfiles(profiles ...string) android.FixturePreparer { dexpreoptConfig.BootImageProfiles = android.PathsForSource(ctx, profiles) }) } + +// FixtureDisableGenerateProfile sets the DisableGenerateProfile property in the global config. +func FixtureDisableGenerateProfile(disable bool) android.FixturePreparer { + return FixtureModifyGlobalConfig(func(_ android.PathContext, dexpreoptConfig *GlobalConfig) { + dexpreoptConfig.DisableGenerateProfile = disable + }) +} diff --git a/etc/prebuilt_etc.go b/etc/prebuilt_etc.go index 80ab41be6..c2866abfa 100644 --- a/etc/prebuilt_etc.go +++ b/etc/prebuilt_etc.go @@ -376,7 +376,7 @@ func (p *PrebuiltEtc) AndroidMkEntries() []android.AndroidMkEntries { ExtraEntries: []android.AndroidMkExtraEntriesFunc{ func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { entries.SetString("LOCAL_MODULE_TAGS", "optional") - entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.ToMakePath().String()) + entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.String()) entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base()) if len(p.properties.Symlinks) > 0 { entries.AddStrings("LOCAL_MODULE_SYMLINKS", p.properties.Symlinks...) diff --git a/etc/snapshot_etc.go b/etc/snapshot_etc.go index 9a25d5a72..b54a8a6ec 100644 --- a/etc/snapshot_etc.go +++ b/etc/snapshot_etc.go @@ -128,7 +128,7 @@ func (p *SnapshotEtc) AndroidMkEntries() []android.AndroidMkEntries { ExtraEntries: []android.AndroidMkExtraEntriesFunc{ func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { entries.SetString("LOCAL_MODULE_TAGS", "optional") - entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.ToMakePath().String()) + entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.String()) entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base()) }, }, diff --git a/filesystem/bootimg.go b/filesystem/bootimg.go index 73d807dbf..fc973a4dc 100644 --- a/filesystem/bootimg.go +++ b/filesystem/bootimg.go @@ -267,7 +267,7 @@ func (b *bootimg) AndroidMkEntries() []android.AndroidMkEntries { OutputFile: android.OptionalPathForPath(b.output), ExtraEntries: []android.AndroidMkExtraEntriesFunc{ func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { - entries.SetString("LOCAL_MODULE_PATH", b.installDir.ToMakePath().String()) + entries.SetString("LOCAL_MODULE_PATH", b.installDir.String()) entries.SetString("LOCAL_INSTALLED_MODULE_STEM", b.installFileName()) }, }, diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go index b2caa51d2..079625895 100644 --- a/filesystem/filesystem.go +++ b/filesystem/filesystem.go @@ -394,7 +394,7 @@ func (f *filesystem) AndroidMkEntries() []android.AndroidMkEntries { OutputFile: android.OptionalPathForPath(f.output), ExtraEntries: []android.AndroidMkExtraEntriesFunc{ func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { - entries.SetString("LOCAL_MODULE_PATH", f.installDir.ToMakePath().String()) + entries.SetString("LOCAL_MODULE_PATH", f.installDir.String()) entries.SetString("LOCAL_INSTALLED_MODULE_STEM", f.installFileName()) }, }, diff --git a/filesystem/logical_partition.go b/filesystem/logical_partition.go index 739e609ed..e2f7d7bdf 100644 --- a/filesystem/logical_partition.go +++ b/filesystem/logical_partition.go @@ -215,7 +215,7 @@ func (l *logicalPartition) AndroidMkEntries() []android.AndroidMkEntries { OutputFile: android.OptionalPathForPath(l.output), ExtraEntries: []android.AndroidMkExtraEntriesFunc{ func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { - entries.SetString("LOCAL_MODULE_PATH", l.installDir.ToMakePath().String()) + entries.SetString("LOCAL_MODULE_PATH", l.installDir.String()) entries.SetString("LOCAL_INSTALLED_MODULE_STEM", l.installFileName()) }, }, diff --git a/filesystem/vbmeta.go b/filesystem/vbmeta.go index 3f16c0d71..63e0abaac 100644 --- a/filesystem/vbmeta.go +++ b/filesystem/vbmeta.go @@ -247,7 +247,7 @@ func (v *vbmeta) AndroidMkEntries() []android.AndroidMkEntries { OutputFile: android.OptionalPathForPath(v.output), ExtraEntries: []android.AndroidMkExtraEntriesFunc{ func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { - entries.SetString("LOCAL_MODULE_PATH", v.installDir.ToMakePath().String()) + entries.SetString("LOCAL_MODULE_PATH", v.installDir.String()) entries.SetString("LOCAL_INSTALLED_MODULE_STEM", v.installFileName()) }, }, diff --git a/java/androidmk.go b/java/androidmk.go index 272a4fd36..19fe7e2fb 100644 --- a/java/androidmk.go +++ b/java/androidmk.go @@ -182,7 +182,14 @@ func (j *TestHelperLibrary) AndroidMkEntries() []android.AndroidMkEntries { } func (prebuilt *Import) AndroidMkEntries() []android.AndroidMkEntries { - if prebuilt.hideApexVariantFromMake || !prebuilt.ContainingSdk().Unversioned() { + if prebuilt.hideApexVariantFromMake { + // For a library imported from a prebuilt APEX, we don't need a Make module for itself, as we + // don't need to install it. However, we need to add its dexpreopt outputs as sub-modules, if it + // is preopted. + dexpreoptEntries := prebuilt.dexpreopter.AndroidMkEntriesForApex() + return append(dexpreoptEntries, android.AndroidMkEntries{Disabled: true}) + } + if !prebuilt.ContainingSdk().Unversioned() { return []android.AndroidMkEntries{android.AndroidMkEntries{ Disabled: true, }} @@ -685,7 +692,7 @@ func (r *RuntimeResourceOverlay) AndroidMkEntries() []android.AndroidMkEntries { ExtraEntries: []android.AndroidMkExtraEntriesFunc{ func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { entries.SetString("LOCAL_CERTIFICATE", r.certificate.AndroidMkString()) - entries.SetPath("LOCAL_MODULE_PATH", r.installDir.ToMakePath()) + entries.SetPath("LOCAL_MODULE_PATH", r.installDir) entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", r.properties.Overrides...) }, }, diff --git a/java/app.go b/java/app.go index b753c0cb8..1c69aeb7a 100755 --- a/java/app.go +++ b/java/app.go @@ -485,7 +485,7 @@ func (a *AndroidApp) jniBuildActions(jniLibs []jniLib, ctx android.ModuleContext a.jniLibs = jniLibs if a.shouldEmbedJnis(ctx) { jniJarFile = android.PathForModuleOut(ctx, "jnilibs.zip") - a.installPathForJNISymbols = a.installPath(ctx).ToMakePath() + a.installPathForJNISymbols = a.installPath(ctx) TransformJniLibsToJar(ctx, jniJarFile, jniLibs, a.useEmbeddedNativeLibs(ctx)) for _, jni := range jniLibs { if jni.coverageFile.Valid() { diff --git a/java/app_import.go b/java/app_import.go index 4d1969ebb..3e5f972a4 100644 --- a/java/app_import.go +++ b/java/app_import.go @@ -108,8 +108,6 @@ func (a *AndroidAppImport) IsInstallable() bool { return true } -func (a *AndroidAppImport) InstallBypassMake() bool { return true } - // Updates properties with variant-specific values. func (a *AndroidAppImport) processVariants(ctx android.LoadHookContext) { config := ctx.Config() diff --git a/java/base.go b/java/base.go index c45ef641e..7cd71a270 100644 --- a/java/base.go +++ b/java/base.go @@ -122,6 +122,14 @@ type CommonProperties struct { Javacflags []string } + Openjdk11 struct { + // List of source files that should only be used when passing -source 1.9 or higher + Srcs []string `android:"path"` + + // List of javac flags that should only be used when passing -source 1.9 or higher + Javacflags []string + } + // When compiling language level 9+ .java code in packages that are part of // a system module, patch_module names the module that your sources and // dependencies should be patched into. The Android runtime currently @@ -959,6 +967,10 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { if flags.javaVersion.usesJavaModules() { j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...) } + if ctx.Config().TargetsJava11() { + j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk11.Srcs...) + } + srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs) if hasSrcExt(srcFiles.Strings(), ".proto") { flags = protoFlags(ctx, &j.properties, &j.protoProperties, flags) diff --git a/java/classpath_fragment.go b/java/classpath_fragment.go index e77971b13..ca2752877 100644 --- a/java/classpath_fragment.go +++ b/java/classpath_fragment.go @@ -204,7 +204,7 @@ func (c *ClasspathFragmentBase) androidMkEntries() []android.AndroidMkEntries { OutputFile: android.OptionalPathForPath(c.outputFilepath), ExtraEntries: []android.AndroidMkExtraEntriesFunc{ func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { - entries.SetString("LOCAL_MODULE_PATH", c.installDirPath.ToMakePath().String()) + entries.SetString("LOCAL_MODULE_PATH", c.installDirPath.String()) entries.SetString("LOCAL_INSTALLED_MODULE_STEM", c.outputFilepath.Base()) }, }, diff --git a/java/dexpreopt.go b/java/dexpreopt.go index f3a53eed9..e9bc51878 100644 --- a/java/dexpreopt.go +++ b/java/dexpreopt.go @@ -115,6 +115,11 @@ func isApexVariant(ctx android.BaseModuleContext) bool { return !apexInfo.IsForPlatform() } +func forPrebuiltApex(ctx android.BaseModuleContext) bool { + apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) + return apexInfo.ForPrebuiltApex +} + func moduleName(ctx android.BaseModuleContext) string { // Remove the "prebuilt_" prefix if the module is from a prebuilt because the prefix is not // expected by dexpreopter. @@ -134,7 +139,9 @@ func (d *dexpreopter) dexpreoptDisabled(ctx android.BaseModuleContext) bool { return true } - if !ctx.Module().(DexpreopterInterface).IsInstallable() { + // If the module is from a prebuilt APEX, it shouldn't be installable, but it can still be + // dexpreopted. + if !ctx.Module().(DexpreopterInterface).IsInstallable() && !forPrebuiltApex(ctx) { return true } @@ -152,15 +159,16 @@ func (d *dexpreopter) dexpreoptDisabled(ctx android.BaseModuleContext) bool { return true } + isApexSystemServerJar := global.AllApexSystemServerJars(ctx).ContainsJar(moduleName(ctx)) if isApexVariant(ctx) { // Don't preopt APEX variant module unless the module is an APEX system server jar and we are // building the entire system image. - if !global.ApexSystemServerJars.ContainsJar(moduleName(ctx)) || ctx.Config().UnbundledBuild() { + if !isApexSystemServerJar || ctx.Config().UnbundledBuild() { return true } } else { // Don't preopt the platform variant of an APEX system server jar to avoid conflicts. - if global.ApexSystemServerJars.ContainsJar(moduleName(ctx)) { + if isApexSystemServerJar { return true } } @@ -191,8 +199,8 @@ func (d *dexpreopter) odexOnSystemOther(ctx android.ModuleContext, installPath a func (d *dexpreopter) getInstallPath( ctx android.ModuleContext, defaultInstallPath android.InstallPath) android.InstallPath { global := dexpreopt.GetGlobalConfig(ctx) - if global.ApexSystemServerJars.ContainsJar(moduleName(ctx)) { - dexLocation := dexpreopt.GetSystemServerDexLocation(global, moduleName(ctx)) + if global.AllApexSystemServerJars(ctx).ContainsJar(moduleName(ctx)) { + dexLocation := dexpreopt.GetSystemServerDexLocation(ctx, global, moduleName(ctx)) return android.PathForModuleInPartitionInstall(ctx, "", strings.TrimPrefix(dexLocation, "/")) } if !d.dexpreoptDisabled(ctx) && isApexVariant(ctx) && @@ -229,8 +237,7 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Wr return } - isSystemServerJar := global.SystemServerJars.ContainsJar(moduleName(ctx)) || - global.ApexSystemServerJars.ContainsJar(moduleName(ctx)) + isSystemServerJar := global.AllSystemServerJars(ctx).ContainsJar(moduleName(ctx)) bootImage := defaultBootImageConfig(ctx) if global.UseArtImage { @@ -336,6 +343,8 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Wr dexpreoptRule.Build("dexpreopt", "dexpreopt") + isApexSystemServerJar := global.AllApexSystemServerJars(ctx).ContainsJar(moduleName(ctx)) + for _, install := range dexpreoptRule.Installs() { // Remove the "/" prefix because the path should be relative to $ANDROID_PRODUCT_OUT. installDir := strings.TrimPrefix(filepath.Dir(install.To), "/") @@ -343,7 +352,7 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Wr arch := filepath.Base(installDir) installPath := android.PathForModuleInPartitionInstall(ctx, "", installDir) - if global.ApexSystemServerJars.ContainsJar(moduleName(ctx)) { + if isApexSystemServerJar { // APEX variants of java libraries are hidden from Make, so their dexpreopt // outputs need special handling. Currently, for APEX variants of java // libraries, only those in the system server classpath are handled here. @@ -362,7 +371,7 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Wr } } - if !global.ApexSystemServerJars.ContainsJar(moduleName(ctx)) { + if !isApexSystemServerJar { d.builtInstalled = dexpreoptRule.Installs().String() } } @@ -381,7 +390,7 @@ func (d *dexpreopter) AndroidMkEntriesForApex() []android.AndroidMkEntries { OutputFile: android.OptionalPathForPath(install.outputPathOnHost), ExtraEntries: []android.AndroidMkExtraEntriesFunc{ func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { - entries.SetString("LOCAL_MODULE_PATH", install.installDirOnDevice.ToMakePath().String()) + entries.SetString("LOCAL_MODULE_PATH", install.installDirOnDevice.String()) entries.SetString("LOCAL_INSTALLED_MODULE_STEM", install.installFileOnDevice) entries.SetString("LOCAL_NOT_AVAILABLE_FOR_PLATFORM", "false") }, diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go index 75083e8c2..c599c4da0 100644 --- a/java/dexpreopt_bootjars.go +++ b/java/dexpreopt_bootjars.go @@ -506,8 +506,18 @@ func copyBootJarsToPredefinedLocations(ctx android.ModuleContext, srcBootDexJars dst := dstBootJarsByModule[name] if src == nil { + // A dex boot jar should be provided by the source java module. It needs to be installable or + // have compile_dex=true - cf. assignments to java.Module.dexJarFile. + // + // However, the source java module may be either replaced or overridden (using prefer:true) by + // a prebuilt java module with the same name. In that case the dex boot jar needs to be + // provided by the corresponding prebuilt APEX module. That APEX is the one that refers + // through a exported_(boot|systemserver)classpath_fragments property to a + // prebuilt_(boot|systemserver)classpath_fragment module, which in turn lists the prebuilt + // java module in the contents property. If that chain is broken then this dependency will + // fail. if !ctx.Config().AllowMissingDependencies() { - ctx.ModuleErrorf("module %s does not provide a dex boot jar", name) + ctx.ModuleErrorf("module %s does not provide a dex boot jar (see comment next to this message in Soong for details)", name) } else { ctx.AddMissingDependencies([]string{name}) } diff --git a/java/dexpreopt_check.go b/java/dexpreopt_check.go index 565901d35..149cbb758 100644 --- a/java/dexpreopt_check.go +++ b/java/dexpreopt_check.go @@ -59,7 +59,7 @@ func dexpreoptSystemserverCheckFactory() android.SingletonModule { func getInstallPath(ctx android.ModuleContext, location string) android.InstallPath { return android.PathForModuleInPartitionInstall( - ctx, "", strings.TrimPrefix(location, "/")).ToMakePath() + ctx, "", strings.TrimPrefix(location, "/")) } func (m *dexpreoptSystemserverCheck) GenerateAndroidBuildActions(ctx android.ModuleContext) { @@ -72,9 +72,10 @@ func (m *dexpreoptSystemserverCheck) GenerateAndroidBuildActions(ctx android.Mod return } - systemServerJars := dexpreopt.AllSystemServerJars(ctx, global) + // TODO(b/203198541): Check all system server jars. + systemServerJars := global.AllSystemServerClasspathJars(ctx) for _, jar := range systemServerJars.CopyOfJars() { - dexLocation := dexpreopt.GetSystemServerDexLocation(global, jar) + dexLocation := dexpreopt.GetSystemServerDexLocation(ctx, global, jar) odexLocation := dexpreopt.ToOdexPath(dexLocation, targets[0].Arch.ArchType) odexPath := getInstallPath(ctx, odexLocation) vdexPath := getInstallPath(ctx, pathtools.ReplaceExtension(odexLocation, "vdex")) diff --git a/java/java.go b/java/java.go index f77c694ba..9b4a005f0 100644 --- a/java/java.go +++ b/java/java.go @@ -267,8 +267,6 @@ func (j *Module) XrefJavaFiles() android.Paths { return j.kytheFiles } -func (j *Module) InstallBypassMake() bool { return true } - type dependencyTag struct { blueprint.BaseDependencyTag name string @@ -451,7 +449,7 @@ func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext an return normalizeJavaVersion(ctx, javaVersion) } else if ctx.Device() { return defaultJavaLanguageVersion(ctx, sdkContext.SdkVersion(ctx)) - } else if ctx.Config().IsEnvTrue("EXPERIMENTAL_TARGET_JAVA_VERSION_11") { + } else if ctx.Config().TargetsJava11() { // Temporary experimental flag to be able to try and build with // java version 11 options. The flag, if used, just sets Java // 11 as the default version, leaving any components that diff --git a/java/lint.go b/java/lint.go index fe3218e90..7845c336b 100644 --- a/java/lint.go +++ b/java/lint.go @@ -377,6 +377,7 @@ func (l *linter) lint(ctx android.ModuleContext) { html := android.PathForModuleOut(ctx, "lint", "lint-report.html") text := android.PathForModuleOut(ctx, "lint", "lint-report.txt") xml := android.PathForModuleOut(ctx, "lint", "lint-report.xml") + baseline := android.PathForModuleOut(ctx, "lint", "lint-baseline.xml") depSetsBuilder := NewLintDepSetBuilder().Direct(html, text, xml) @@ -447,6 +448,8 @@ func (l *linter) lint(ctx android.ModuleContext) { cmd.FlagWithInput("--baseline ", lintBaseline.Path()) } + cmd.FlagWithOutput("--write-reference-baseline ", baseline) + cmd.Text("|| (").Text("if [ -e").Input(text).Text("]; then cat").Input(text).Text("; fi; exit 7)") rule.Command().Text("rm -rf").Flag(lintPaths.cacheDir.String()).Flag(lintPaths.homeDir.String()) diff --git a/java/platform_compat_config.go b/java/platform_compat_config.go index 0d8ebac02..f442ddfd4 100644 --- a/java/platform_compat_config.go +++ b/java/platform_compat_config.go @@ -115,7 +115,7 @@ func (p *platformCompatConfig) AndroidMkEntries() []android.AndroidMkEntries { Include: "$(BUILD_PREBUILT)", ExtraEntries: []android.AndroidMkExtraEntriesFunc{ func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { - entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.ToMakePath().String()) + entries.SetString("LOCAL_MODULE_PATH", p.installDirPath.String()) entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.configFile.Base()) }, }, diff --git a/java/robolectric.go b/java/robolectric.go index 16af546ba..f71952172 100644 --- a/java/robolectric.go +++ b/java/robolectric.go @@ -352,7 +352,6 @@ func RobolectricTestFactory() android.Module { return module } -func (r *robolectricTest) InstallBypassMake() bool { return true } func (r *robolectricTest) InstallInTestcases() bool { return true } func (r *robolectricTest) InstallForceOS() (*android.OsType, *android.ArchType) { return &r.forceOSType, &r.forceArchType @@ -430,7 +429,6 @@ func (r *robolectricRuntimes) GenerateAndroidBuildActions(ctx android.ModuleCont } } -func (r *robolectricRuntimes) InstallBypassMake() bool { return true } func (r *robolectricRuntimes) InstallInTestcases() bool { return true } func (r *robolectricRuntimes) InstallForceOS() (*android.OsType, *android.ArchType) { return &r.forceOSType, &r.forceArchType diff --git a/java/rro_test.go b/java/rro_test.go index 27abbe4f3..be0d7ba47 100644 --- a/java/rro_test.go +++ b/java/rro_test.go @@ -62,6 +62,7 @@ func TestRuntimeResourceOverlay(t *testing.T) { result := android.GroupFixturePreparers( PrepareForTestWithJavaDefaultModules, PrepareForTestWithOverlayBuildComponents, + android.FixtureModifyConfig(android.SetKatiEnabledForTests), fs.AddToFixture(), ).RunTestWithBp(t, bp) @@ -127,7 +128,10 @@ func TestRuntimeResourceOverlay(t *testing.T) { } func TestRuntimeResourceOverlay_JavaDefaults(t *testing.T) { - ctx, config := testJava(t, ` + result := android.GroupFixturePreparers( + PrepareForTestWithJavaDefaultModules, + android.FixtureModifyConfig(android.SetKatiEnabledForTests), + ).RunTestWithBp(t, ` java_defaults { name: "rro_defaults", theme: "default_theme", @@ -148,7 +152,7 @@ func TestRuntimeResourceOverlay_JavaDefaults(t *testing.T) { // // RRO module with defaults // - m := ctx.ModuleForTests("foo_with_defaults", "android_common") + m := result.ModuleForTests("foo_with_defaults", "android_common") // Check AAPT2 link flags. aapt2Flags := strings.Split(m.Output("package-res.apk").Args["flags"], " ") @@ -159,14 +163,14 @@ func TestRuntimeResourceOverlay_JavaDefaults(t *testing.T) { } // Check device location. - path := android.AndroidMkEntriesForTest(t, ctx, m.Module())[0].EntryMap["LOCAL_MODULE_PATH"] + path := android.AndroidMkEntriesForTest(t, result.TestContext, m.Module())[0].EntryMap["LOCAL_MODULE_PATH"] expectedPath := []string{shared.JoinPath("out/target/product/test_device/product/overlay/default_theme")} - android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_MODULE_PATH", config, expectedPath, path) + android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_MODULE_PATH", result.Config, expectedPath, path) // // RRO module without defaults // - m = ctx.ModuleForTests("foo_barebones", "android_common") + m = result.ModuleForTests("foo_barebones", "android_common") // Check AAPT2 link flags. aapt2Flags = strings.Split(m.Output("package-res.apk").Args["flags"], " ") @@ -176,9 +180,9 @@ func TestRuntimeResourceOverlay_JavaDefaults(t *testing.T) { } // Check device location. - path = android.AndroidMkEntriesForTest(t, ctx, m.Module())[0].EntryMap["LOCAL_MODULE_PATH"] + path = android.AndroidMkEntriesForTest(t, result.TestContext, m.Module())[0].EntryMap["LOCAL_MODULE_PATH"] expectedPath = []string{shared.JoinPath("out/target/product/test_device/product/overlay")} - android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_MODULE_PATH", config, expectedPath, path) + android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_MODULE_PATH", result.Config, expectedPath, path) } func TestOverrideRuntimeResourceOverlay(t *testing.T) { diff --git a/java/sdk.go b/java/sdk.go index de7070eef..756a24deb 100644 --- a/java/sdk.go +++ b/java/sdk.go @@ -55,7 +55,7 @@ func defaultJavaLanguageVersion(ctx android.EarlyModuleContext, s android.SdkSpe return JAVA_VERSION_7 } else if sdk.FinalOrFutureInt() <= 29 { return JAVA_VERSION_8 - } else if ctx.Config().IsEnvTrue("EXPERIMENTAL_TARGET_JAVA_VERSION_11") { + } else if ctx.Config().TargetsJava11() { // Temporary experimental flag to be able to try and build with // java version 11 options. The flag, if used, just sets Java // 11 as the default version, leaving any components that diff --git a/java/sdk_library.go b/java/sdk_library.go index de0d796cc..0bc8895fe 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -1392,6 +1392,10 @@ func (module *SdkLibrary) createStubsLibrary(mctx android.DefaultableHookContext Srcs []string Javacflags []string } + Openjdk11 struct { + Srcs []string + Javacflags []string + } Dist struct { Targets []string Dest *string @@ -1418,6 +1422,8 @@ func (module *SdkLibrary) createStubsLibrary(mctx android.DefaultableHookContext } props.Openjdk9.Srcs = module.properties.Openjdk9.Srcs props.Openjdk9.Javacflags = module.properties.Openjdk9.Javacflags + props.Openjdk11.Srcs = module.properties.Openjdk11.Srcs + props.Openjdk11.Javacflags = module.properties.Openjdk11.Javacflags // We compile the stubs for 1.8 in line with the main android.jar stubs, and potential // interop with older developer tools that don't support 1.9. props.Java_version = proptools.StringPtr("1.8") @@ -2641,7 +2647,7 @@ func (module *sdkLibraryXml) AndroidMkEntries() []android.AndroidMkEntries { ExtraEntries: []android.AndroidMkExtraEntriesFunc{ func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { entries.SetString("LOCAL_MODULE_TAGS", "optional") - entries.SetString("LOCAL_MODULE_PATH", module.installDirPath.ToMakePath().String()) + entries.SetString("LOCAL_MODULE_PATH", module.installDirPath.String()) entries.SetString("LOCAL_INSTALLED_MODULE_STEM", module.outputFilePath.Base()) }, }, diff --git a/java/systemserver_classpath_fragment.go b/java/systemserver_classpath_fragment.go index 2ec33a422..fa61ea68c 100644 --- a/java/systemserver_classpath_fragment.go +++ b/java/systemserver_classpath_fragment.go @@ -60,7 +60,7 @@ func (p *platformSystemServerClasspathModule) GenerateAndroidBuildActions(ctx an classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, p.classpathType) standaloneConfiguredJars := p.standaloneConfiguredJars(ctx) standaloneClasspathJars := configuredJarListToClasspathJars(ctx, standaloneConfiguredJars, STANDALONE_SYSTEMSERVER_JARS) - configuredJars = configuredJars.AppendList(standaloneConfiguredJars) + configuredJars = configuredJars.AppendList(&standaloneConfiguredJars) classpathJars = append(classpathJars, standaloneClasspathJars...) p.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars) } @@ -122,7 +122,7 @@ func (s *SystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.Mo classpathJars := configuredJarListToClasspathJars(ctx, configuredJars, s.classpathType) standaloneConfiguredJars := s.standaloneConfiguredJars(ctx) standaloneClasspathJars := configuredJarListToClasspathJars(ctx, standaloneConfiguredJars, STANDALONE_SYSTEMSERVER_JARS) - configuredJars = configuredJars.AppendList(standaloneConfiguredJars) + configuredJars = configuredJars.AppendList(&standaloneConfiguredJars) classpathJars = append(classpathJars, standaloneClasspathJars...) s.classpathFragmentBase().generateClasspathProtoBuildActions(ctx, configuredJars, classpathJars) diff --git a/linkerconfig/linkerconfig.go b/linkerconfig/linkerconfig.go index 8d0ad7cf2..dbc112e5a 100644 --- a/linkerconfig/linkerconfig.go +++ b/linkerconfig/linkerconfig.go @@ -155,7 +155,7 @@ func (l *linkerConfig) AndroidMkEntries() []android.AndroidMkEntries { OutputFile: android.OptionalPathForPath(l.outputFilePath), ExtraEntries: []android.AndroidMkExtraEntriesFunc{ func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { - entries.SetString("LOCAL_MODULE_PATH", l.installDirPath.ToMakePath().String()) + entries.SetString("LOCAL_MODULE_PATH", l.installDirPath.String()) entries.SetString("LOCAL_INSTALLED_MODULE_STEM", l.outputFilePath.Base()) entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !installable) entries.SetString("LINKER_CONFIG_PATH_"+l.Name(), l.OutputFile().String()) diff --git a/mk2rbc/expr.go b/mk2rbc/expr.go index 81b31c736..7cd4899ab 100644 --- a/mk2rbc/expr.go +++ b/mk2rbc/expr.go @@ -16,21 +16,22 @@ package mk2rbc import ( "fmt" - "strconv" "strings" ) -// Represents an expression in the Starlark code. An expression has -// a type, and it can be evaluated. +// Represents an expression in the Starlark code. An expression has a type. type starlarkExpr interface { starlarkNode typ() starlarkType - // Try to substitute variable values. Return substitution result - // and whether it is the same as the original expression. - eval(valueMap map[string]starlarkExpr) (res starlarkExpr, same bool) // Emit the code to copy the expression, otherwise we will end up // with source and target pointing to the same list. emitListVarCopy(gctx *generationContext) + // Return the expression, calling the transformer func for + // every expression in the tree. If the transformer func returns non-nil, + // its result is used in place of the expression it was called with in the + // resulting expression. The resulting starlarkExpr will contain as many + // of the same objects from the original expression as possible. + transform(transformer func(expr starlarkExpr) starlarkExpr) starlarkExpr } func maybeString(expr starlarkExpr) (string, bool) { @@ -44,12 +45,6 @@ type stringLiteralExpr struct { literal string } -func (s *stringLiteralExpr) eval(_ map[string]starlarkExpr) (res starlarkExpr, same bool) { - res = s - same = true - return -} - func (s *stringLiteralExpr) emit(gctx *generationContext) { gctx.writef("%q", s.literal) } @@ -62,17 +57,19 @@ func (s *stringLiteralExpr) emitListVarCopy(gctx *generationContext) { s.emit(gctx) } +func (s *stringLiteralExpr) transform(transformer func(expr starlarkExpr) starlarkExpr) starlarkExpr { + if replacement := transformer(s); replacement != nil { + return replacement + } else { + return s + } +} + // Integer literal type intLiteralExpr struct { literal int } -func (s *intLiteralExpr) eval(_ map[string]starlarkExpr) (res starlarkExpr, same bool) { - res = s - same = true - return -} - func (s *intLiteralExpr) emit(gctx *generationContext) { gctx.writef("%d", s.literal) } @@ -85,15 +82,19 @@ func (s *intLiteralExpr) emitListVarCopy(gctx *generationContext) { s.emit(gctx) } +func (s *intLiteralExpr) transform(transformer func(expr starlarkExpr) starlarkExpr) starlarkExpr { + if replacement := transformer(s); replacement != nil { + return replacement + } else { + return s + } +} + // Boolean literal type boolLiteralExpr struct { literal bool } -func (b *boolLiteralExpr) eval(_ map[string]starlarkExpr) (res starlarkExpr, same bool) { - return b, true -} - func (b *boolLiteralExpr) emit(gctx *generationContext) { if b.literal { gctx.write("True") @@ -110,6 +111,14 @@ func (b *boolLiteralExpr) emitListVarCopy(gctx *generationContext) { b.emit(gctx) } +func (b *boolLiteralExpr) transform(transformer func(expr starlarkExpr) starlarkExpr) starlarkExpr { + if replacement := transformer(b); replacement != nil { + return replacement + } else { + return b + } +} + // interpolateExpr represents Starlark's interpolation operator <string> % list // we break <string> into a list of chunks, i.e., "first%second%third" % (X, Y) // will have chunks = ["first", "second", "third"] and args = [X, Y] @@ -118,6 +127,35 @@ type interpolateExpr struct { args []starlarkExpr } +func NewInterpolateExpr(parts []starlarkExpr) starlarkExpr { + result := &interpolateExpr{} + needString := true + for _, part := range parts { + if needString { + if strLit, ok := part.(*stringLiteralExpr); ok { + result.chunks = append(result.chunks, strLit.literal) + } else { + result.chunks = append(result.chunks, "") + } + needString = false + } else { + if strLit, ok := part.(*stringLiteralExpr); ok { + result.chunks[len(result.chunks)-1] += strLit.literal + } else { + result.args = append(result.args, part) + needString = true + } + } + } + if len(result.chunks) == len(result.args) { + result.chunks = append(result.chunks, "") + } + if len(result.args) == 0 { + return &stringLiteralExpr{literal: strings.Join(result.chunks, "")} + } + return result +} + func (xi *interpolateExpr) emit(gctx *generationContext) { if len(xi.chunks) != len(xi.args)+1 { panic(fmt.Errorf("malformed interpolateExpr: #chunks(%d) != #args(%d)+1", @@ -151,37 +189,6 @@ func (xi *interpolateExpr) emit(gctx *generationContext) { } } -func (xi *interpolateExpr) eval(valueMap map[string]starlarkExpr) (res starlarkExpr, same bool) { - same = true - newChunks := []string{xi.chunks[0]} - var newArgs []starlarkExpr - for i, arg := range xi.args { - newArg, sameArg := arg.eval(valueMap) - same = same && sameArg - switch x := newArg.(type) { - case *stringLiteralExpr: - newChunks[len(newChunks)-1] += x.literal + xi.chunks[i+1] - same = false - continue - case *intLiteralExpr: - newChunks[len(newChunks)-1] += strconv.Itoa(x.literal) + xi.chunks[i+1] - same = false - continue - default: - newChunks = append(newChunks, xi.chunks[i+1]) - newArgs = append(newArgs, newArg) - } - } - if same { - res = xi - } else if len(newChunks) == 1 { - res = &stringLiteralExpr{newChunks[0]} - } else { - res = &interpolateExpr{chunks: newChunks, args: newArgs} - } - return -} - func (_ *interpolateExpr) typ() starlarkType { return starlarkTypeString } @@ -190,19 +197,29 @@ func (xi *interpolateExpr) emitListVarCopy(gctx *generationContext) { xi.emit(gctx) } +func (xi *interpolateExpr) transform(transformer func(expr starlarkExpr) starlarkExpr) starlarkExpr { + argsCopy := make([]starlarkExpr, len(xi.args)) + for i, arg := range xi.args { + argsCopy[i] = arg.transform(transformer) + } + xi.args = argsCopy + if replacement := transformer(xi); replacement != nil { + return replacement + } else { + return xi + } +} + type variableRefExpr struct { ref variable isDefined bool } -func (v *variableRefExpr) eval(map[string]starlarkExpr) (res starlarkExpr, same bool) { - predefined, ok := v.ref.(*predefinedVariable) - if same = !ok; same { - res = v - } else { - res = predefined.value +func NewVariableRefExpr(ref variable, isDefined bool) starlarkExpr { + if predefined, ok := ref.(*predefinedVariable); ok { + return predefined.value } - return + return &variableRefExpr{ref, isDefined} } func (v *variableRefExpr) emit(gctx *generationContext) { @@ -220,17 +237,16 @@ func (v *variableRefExpr) emitListVarCopy(gctx *generationContext) { } } -type toStringExpr struct { - expr starlarkExpr -} - -func (s *toStringExpr) eval(valueMap map[string]starlarkExpr) (res starlarkExpr, same bool) { - if x, same := s.expr.eval(valueMap); same { - res = s +func (v *variableRefExpr) transform(transformer func(expr starlarkExpr) starlarkExpr) starlarkExpr { + if replacement := transformer(v); replacement != nil { + return replacement } else { - res = &toStringExpr{expr: x} + return v } - return +} + +type toStringExpr struct { + expr starlarkExpr } func (s *toStringExpr) emit(ctx *generationContext) { @@ -265,17 +281,17 @@ func (s *toStringExpr) emitListVarCopy(gctx *generationContext) { s.emit(gctx) } -type notExpr struct { - expr starlarkExpr -} - -func (n *notExpr) eval(valueMap map[string]starlarkExpr) (res starlarkExpr, same bool) { - if x, same := n.expr.eval(valueMap); same { - res = n +func (s *toStringExpr) transform(transformer func(expr starlarkExpr) starlarkExpr) starlarkExpr { + s.expr = s.expr.transform(transformer) + if replacement := transformer(s); replacement != nil { + return replacement } else { - res = ¬Expr{expr: x} + return s } - return +} + +type notExpr struct { + expr starlarkExpr } func (n *notExpr) emit(ctx *generationContext) { @@ -291,22 +307,20 @@ func (n *notExpr) emitListVarCopy(gctx *generationContext) { n.emit(gctx) } +func (n *notExpr) transform(transformer func(expr starlarkExpr) starlarkExpr) starlarkExpr { + n.expr = n.expr.transform(transformer) + if replacement := transformer(n); replacement != nil { + return replacement + } else { + return n + } +} + type eqExpr struct { left, right starlarkExpr isEq bool // if false, it's != } -func (eq *eqExpr) eval(valueMap map[string]starlarkExpr) (res starlarkExpr, same bool) { - xLeft, sameLeft := eq.left.eval(valueMap) - xRight, sameRight := eq.right.eval(valueMap) - if same = sameLeft && sameRight; same { - res = eq - } else { - res = &eqExpr{left: xLeft, right: xRight, isEq: eq.isEq} - } - return -} - func (eq *eqExpr) emit(gctx *generationContext) { var stringOperand string var otherOperand starlarkExpr @@ -360,18 +374,21 @@ func (eq *eqExpr) emitListVarCopy(gctx *generationContext) { eq.emit(gctx) } +func (eq *eqExpr) transform(transformer func(expr starlarkExpr) starlarkExpr) starlarkExpr { + eq.left = eq.left.transform(transformer) + eq.right = eq.right.transform(transformer) + if replacement := transformer(eq); replacement != nil { + return replacement + } else { + return eq + } +} + // variableDefinedExpr corresponds to Make's ifdef VAR type variableDefinedExpr struct { v variable } -func (v *variableDefinedExpr) eval(_ map[string]starlarkExpr) (res starlarkExpr, same bool) { - res = v - same = true - return - -} - func (v *variableDefinedExpr) emit(gctx *generationContext) { if v.v != nil { v.v.emitDefined(gctx) @@ -388,24 +405,13 @@ func (v *variableDefinedExpr) emitListVarCopy(gctx *generationContext) { v.emit(gctx) } -type listExpr struct { - items []starlarkExpr +func (v *variableDefinedExpr) transform(transformer func(expr starlarkExpr) starlarkExpr) starlarkExpr { + // TODO: VariableDefinedExpr isn't really an expression? + return v } -func (l *listExpr) eval(valueMap map[string]starlarkExpr) (res starlarkExpr, same bool) { - newItems := make([]starlarkExpr, len(l.items)) - same = true - for i, item := range l.items { - var sameItem bool - newItems[i], sameItem = item.eval(valueMap) - same = same && sameItem - } - if same { - res = l - } else { - res = &listExpr{newItems} - } - return +type listExpr struct { + items []starlarkExpr } func (l *listExpr) emit(gctx *generationContext) { @@ -442,6 +448,19 @@ func (l *listExpr) emitListVarCopy(gctx *generationContext) { l.emit(gctx) } +func (l *listExpr) transform(transformer func(expr starlarkExpr) starlarkExpr) starlarkExpr { + itemsCopy := make([]starlarkExpr, len(l.items)) + for i, item := range l.items { + itemsCopy[i] = item.transform(transformer) + } + l.items = itemsCopy + if replacement := transformer(l); replacement != nil { + return replacement + } else { + return l + } +} + func newStringListExpr(items []string) *listExpr { v := listExpr{} for _, item := range items { @@ -481,22 +500,6 @@ func (c *concatExpr) emit(gctx *generationContext) { gctx.indentLevel -= 2 } -func (c *concatExpr) eval(valueMap map[string]starlarkExpr) (res starlarkExpr, same bool) { - same = true - xConcat := &concatExpr{items: make([]starlarkExpr, len(c.items))} - for i, item := range c.items { - var sameItem bool - xConcat.items[i], sameItem = item.eval(valueMap) - same = same && sameItem - } - if same { - res = c - } else { - res = xConcat - } - return -} - func (_ *concatExpr) typ() starlarkType { return starlarkTypeList } @@ -505,6 +508,19 @@ func (c *concatExpr) emitListVarCopy(gctx *generationContext) { c.emit(gctx) } +func (c *concatExpr) transform(transformer func(expr starlarkExpr) starlarkExpr) starlarkExpr { + itemsCopy := make([]starlarkExpr, len(c.items)) + for i, item := range c.items { + itemsCopy[i] = item.transform(transformer) + } + c.items = itemsCopy + if replacement := transformer(c); replacement != nil { + return replacement + } else { + return c + } +} + // inExpr generates <expr> [not] in <list> type inExpr struct { expr starlarkExpr @@ -512,19 +528,6 @@ type inExpr struct { isNot bool } -func (i *inExpr) eval(valueMap map[string]starlarkExpr) (res starlarkExpr, same bool) { - x := &inExpr{isNot: i.isNot} - var sameExpr, sameList bool - x.expr, sameExpr = i.expr.eval(valueMap) - x.list, sameList = i.list.eval(valueMap) - if same = sameExpr && sameList; same { - res = i - } else { - res = x - } - return -} - func (i *inExpr) emit(gctx *generationContext) { i.expr.emit(gctx) if i.isNot { @@ -543,35 +546,44 @@ func (i *inExpr) emitListVarCopy(gctx *generationContext) { i.emit(gctx) } +func (i *inExpr) transform(transformer func(expr starlarkExpr) starlarkExpr) starlarkExpr { + i.expr = i.expr.transform(transformer) + i.list = i.list.transform(transformer) + if replacement := transformer(i); replacement != nil { + return replacement + } else { + return i + } +} + type indexExpr struct { array starlarkExpr index starlarkExpr } -func (ix indexExpr) emit(gctx *generationContext) { +func (ix *indexExpr) emit(gctx *generationContext) { ix.array.emit(gctx) gctx.write("[") ix.index.emit(gctx) gctx.write("]") } -func (ix indexExpr) typ() starlarkType { +func (ix *indexExpr) typ() starlarkType { return starlarkTypeString } -func (ix indexExpr) eval(valueMap map[string]starlarkExpr) (res starlarkExpr, same bool) { - newArray, isSameArray := ix.array.eval(valueMap) - newIndex, isSameIndex := ix.index.eval(valueMap) - if same = isSameArray && isSameIndex; same { - res = ix - } else { - res = &indexExpr{newArray, newIndex} - } - return +func (ix *indexExpr) emitListVarCopy(gctx *generationContext) { + ix.emit(gctx) } -func (ix indexExpr) emitListVarCopy(gctx *generationContext) { - ix.emit(gctx) +func (ix *indexExpr) transform(transformer func(expr starlarkExpr) starlarkExpr) starlarkExpr { + ix.array = ix.array.transform(transformer) + ix.index = ix.index.transform(transformer) + if replacement := transformer(ix); replacement != nil { + return replacement + } else { + return ix + } } type callExpr struct { @@ -581,27 +593,6 @@ type callExpr struct { returnType starlarkType } -func (cx *callExpr) eval(valueMap map[string]starlarkExpr) (res starlarkExpr, same bool) { - newCallExpr := &callExpr{name: cx.name, args: make([]starlarkExpr, len(cx.args)), - returnType: cx.returnType} - if cx.object != nil { - newCallExpr.object, same = cx.object.eval(valueMap) - } else { - same = true - } - for i, args := range cx.args { - var s bool - newCallExpr.args[i], s = args.eval(valueMap) - same = same && s - } - if same { - res = cx - } else { - res = newCallExpr - } - return -} - func (cx *callExpr) emit(gctx *generationContext) { sep := "" if cx.object != nil { @@ -642,28 +633,27 @@ func (cx *callExpr) emitListVarCopy(gctx *generationContext) { cx.emit(gctx) } +func (cx *callExpr) transform(transformer func(expr starlarkExpr) starlarkExpr) starlarkExpr { + if cx.object != nil { + cx.object = cx.object.transform(transformer) + } + argsCopy := make([]starlarkExpr, len(cx.args)) + for i, arg := range cx.args { + argsCopy[i] = arg.transform(transformer) + } + if replacement := transformer(cx); replacement != nil { + return replacement + } else { + return cx + } +} + type ifExpr struct { condition starlarkExpr ifTrue starlarkExpr ifFalse starlarkExpr } -func (i *ifExpr) eval(valueMap map[string]starlarkExpr) (res starlarkExpr, same bool) { - cond, condSame := i.condition.eval(valueMap) - t, tSame := i.ifTrue.eval(valueMap) - f, fSame := i.ifFalse.eval(valueMap) - same = condSame && tSame && fSame - if same { - return i, same - } else { - return &ifExpr{ - condition: cond, - ifTrue: t, - ifFalse: f, - }, same - } -} - func (i *ifExpr) emit(gctx *generationContext) { gctx.write("(") i.ifTrue.emit(gctx) @@ -691,17 +681,78 @@ func (i *ifExpr) emitListVarCopy(gctx *generationContext) { i.emit(gctx) } +func (i *ifExpr) transform(transformer func(expr starlarkExpr) starlarkExpr) starlarkExpr { + i.condition = i.condition.transform(transformer) + i.ifTrue = i.ifTrue.transform(transformer) + i.ifFalse = i.ifFalse.transform(transformer) + if replacement := transformer(i); replacement != nil { + return replacement + } else { + return i + } +} + +type identifierExpr struct { + name string +} + +func (i *identifierExpr) emit(gctx *generationContext) { + gctx.write(i.name) +} + +func (i *identifierExpr) typ() starlarkType { + return starlarkTypeUnknown +} + +func (i *identifierExpr) emitListVarCopy(gctx *generationContext) { + i.emit(gctx) +} + +func (i *identifierExpr) transform(transformer func(expr starlarkExpr) starlarkExpr) starlarkExpr { + if replacement := transformer(i); replacement != nil { + return replacement + } else { + return i + } +} + +type foreachExpr struct { + varName string + list starlarkExpr + action starlarkExpr +} + +func (f *foreachExpr) emit(gctx *generationContext) { + gctx.write("[") + f.action.emit(gctx) + gctx.write(" for " + f.varName + " in ") + f.list.emit(gctx) + gctx.write("]") +} + +func (f *foreachExpr) typ() starlarkType { + return starlarkTypeList +} + +func (f *foreachExpr) emitListVarCopy(gctx *generationContext) { + f.emit(gctx) +} + +func (f *foreachExpr) transform(transformer func(expr starlarkExpr) starlarkExpr) starlarkExpr { + f.list = f.list.transform(transformer) + f.action = f.action.transform(transformer) + if replacement := transformer(f); replacement != nil { + return replacement + } else { + return f + } +} + type badExpr struct { errorLocation ErrorLocation message string } -func (b *badExpr) eval(_ map[string]starlarkExpr) (res starlarkExpr, same bool) { - res = b - same = true - return -} - func (b *badExpr) emit(gctx *generationContext) { gctx.emitConversionError(b.errorLocation, b.message) } @@ -714,6 +765,14 @@ func (_ *badExpr) emitListVarCopy(_ *generationContext) { panic("implement me") } +func (b *badExpr) transform(transformer func(expr starlarkExpr) starlarkExpr) starlarkExpr { + if replacement := transformer(b); replacement != nil { + return replacement + } else { + return b + } +} + func maybeConvertToStringList(expr starlarkExpr) starlarkExpr { if xString, ok := expr.(*stringLiteralExpr); ok { return newStringListExpr(strings.Fields(xString.literal)) diff --git a/mk2rbc/mk2rbc.go b/mk2rbc/mk2rbc.go index 839dea2f4..024311e0e 100644 --- a/mk2rbc/mk2rbc.go +++ b/mk2rbc/mk2rbc.go @@ -111,6 +111,7 @@ var knownFunctions = map[string]struct { "filter": {baseName + ".filter", starlarkTypeList, hiddenArgNone}, "filter-out": {baseName + ".filter_out", starlarkTypeList, hiddenArgNone}, "firstword": {"!firstword", starlarkTypeString, hiddenArgNone}, + "foreach": {"!foreach", starlarkTypeList, hiddenArgNone}, "get-vendor-board-platforms": {"!get-vendor-board-platforms", starlarkTypeList, hiddenArgNone}, // internal macro, used by is-board-platform, etc. "if": {"!if", starlarkTypeUnknown, hiddenArgNone}, "info": {baseName + ".mkinfo", starlarkTypeVoid, hiddenArgNone}, @@ -147,14 +148,10 @@ var knownFunctions = map[string]struct { "warning": {baseName + ".mkwarning", starlarkTypeVoid, hiddenArgNone}, "word": {baseName + "!word", starlarkTypeString, hiddenArgNone}, "wildcard": {baseName + ".expand_wildcard", starlarkTypeList, hiddenArgNone}, + "words": {baseName + ".words", starlarkTypeList, hiddenArgNone}, } -var builtinFuncRex = regexp.MustCompile( - "^(addprefix|addsuffix|abspath|and|basename|call|dir|error|eval" + - "|flavor|foreach|file|filter|filter-out|findstring|firstword|guile" + - "|if|info|join|lastword|notdir|or|origin|patsubst|realpath" + - "|shell|sort|strip|subst|suffix|value|warning|word|wordlist|words" + - "|wildcard)") +var identifierFullMatchRegex = regexp.MustCompile("^[a-zA-Z_][a-zA-Z0-9_]*$") // Conversion request parameters type Request struct { @@ -414,7 +411,6 @@ type parseContext struct { ifNestLevel int moduleNameCount map[string]int // count of imported modules with given basename fatalError error - builtinMakeVars map[string]starlarkExpr outputSuffix string errorLogger ErrorLogger tracedVariables map[string]bool // variables to be traced in the generated script @@ -467,7 +463,6 @@ func newParseContext(ss *StarlarkScript, nodes []mkparser.Node) *parseContext { currentNodeIndex: 0, ifNestLevel: 0, moduleNameCount: make(map[string]int), - builtinMakeVars: map[string]starlarkExpr{}, variables: make(map[string]variable), dependentModules: make(map[string]*moduleInfo), soongNamespaces: make(map[string]map[string]bool), @@ -603,9 +598,6 @@ func (ctx *parseContext) handleAssignment(a *mkparser.Assignment) { } } - // TODO(asmundak): move evaluation to a separate pass - asgn.value, _ = asgn.value.eval(ctx.builtinMakeVars) - asgn.previous = ctx.lastAssignment(name) ctx.setLastAssignment(name, asgn) switch a.Type { @@ -632,7 +624,6 @@ func (ctx *parseContext) handleSoongNsAssignment(name string, asgn *mkparser.Ass ctx.wrapBadExpr(xBad) return } - val, _ = val.eval(ctx.builtinMakeVars) // Unfortunately, Soong namespaces can be set up by directly setting corresponding Make // variables instead of via add_soong_config_namespace + add_soong_config_var_value. @@ -788,7 +779,6 @@ func (ctx *parseContext) newDependentModule(path string, optional bool) *moduleI func (ctx *parseContext) handleSubConfig( v mkparser.Node, pathExpr starlarkExpr, loadAlways bool, processModule func(inheritedModule)) { - pathExpr, _ = pathExpr.eval(ctx.builtinMakeVars) // In a simple case, the name of a module to inherit/include is known statically. if path, ok := maybeString(pathExpr); ok { @@ -1125,7 +1115,7 @@ func (ctx *parseContext) parseCompareSpecialCases(directive *mkparser.Directive, return xBad, true } return &eqExpr{ - left: &variableRefExpr{ctx.addVariable("TARGET_BOARD_PLATFORM"), false}, + left: NewVariableRefExpr(ctx.addVariable("TARGET_BOARD_PLATFORM"), false), right: call.args[0], isEq: isEq, }, true @@ -1134,7 +1124,7 @@ func (ctx *parseContext) parseCompareSpecialCases(directive *mkparser.Directive, return xBad, true } return &inExpr{ - expr: &variableRefExpr{ctx.addVariable("TARGET_BOARD_PLATFORM"), false}, + expr: NewVariableRefExpr(ctx.addVariable("TARGET_BOARD_PLATFORM"), false), list: maybeConvertToStringList(call.args[0]), isNot: !isEq, }, true @@ -1143,7 +1133,7 @@ func (ctx *parseContext) parseCompareSpecialCases(directive *mkparser.Directive, return xBad, true } return &inExpr{ - expr: &variableRefExpr{ctx.addVariable("TARGET_PRODUCT"), true}, + expr: NewVariableRefExpr(ctx.addVariable("TARGET_PRODUCT"), true), list: maybeConvertToStringList(call.args[0]), isNot: !isEq, }, true @@ -1156,8 +1146,8 @@ func (ctx *parseContext) parseCompareSpecialCases(directive *mkparser.Directive, return ctx.newBadExpr(directive, "cannot handle non-constant argument to is-vendor-board-platform"), true } return &inExpr{ - expr: &variableRefExpr{ctx.addVariable("TARGET_BOARD_PLATFORM"), false}, - list: &variableRefExpr{ctx.addVariable(s + "_BOARD_PLATFORMS"), true}, + expr: NewVariableRefExpr(ctx.addVariable("TARGET_BOARD_PLATFORM"), false), + list: NewVariableRefExpr(ctx.addVariable(s+"_BOARD_PLATFORMS"), true), isNot: !isEq, }, true @@ -1186,8 +1176,8 @@ func (ctx *parseContext) parseCompareSpecialCases(directive *mkparser.Directive, // if the expression is ifneq (,$(call is-vendor-board-platform,...)), negate==true, // so we should set inExpr.isNot to false return &inExpr{ - expr: &variableRefExpr{ctx.addVariable("TARGET_BOARD_PLATFORM"), false}, - list: &variableRefExpr{ctx.addVariable("QCOM_BOARD_PLATFORMS"), true}, + expr: NewVariableRefExpr(ctx.addVariable("TARGET_BOARD_PLATFORM"), false), + list: NewVariableRefExpr(ctx.addVariable("QCOM_BOARD_PLATFORMS"), true), isNot: isEq, }, true } @@ -1369,12 +1359,12 @@ func (ctx *parseContext) parseReference(node mkparser.Node, ref *mkparser.MakeSt args: []starlarkExpr{ &stringLiteralExpr{literal: substParts[0]}, &stringLiteralExpr{literal: substParts[1]}, - &variableRefExpr{v, ctx.lastAssignment(v.name()) != nil}, + NewVariableRefExpr(v, ctx.lastAssignment(v.name()) != nil), }, } } if v := ctx.addVariable(refDump); v != nil { - return &variableRefExpr{v, ctx.lastAssignment(v.name()) != nil} + return NewVariableRefExpr(v, ctx.lastAssignment(v.name()) != nil) } return ctx.newBadExpr(node, "unknown variable %s", refDump) } @@ -1412,12 +1402,14 @@ func (ctx *parseContext) parseReference(node mkparser.Node, ref *mkparser.MakeSt switch expr.name { case "if": return ctx.parseIfFunc(node, args) + case "foreach": + return ctx.parseForeachFunc(node, args) case "word": return ctx.parseWordFunc(node, args) case "firstword", "lastword": return ctx.parseFirstOrLastwordFunc(node, expr.name, args) case "my-dir": - return &variableRefExpr{ctx.addVariable("LOCAL_PATH"), true} + return NewVariableRefExpr(ctx.addVariable("LOCAL_PATH"), true) case "subst", "patsubst": return ctx.parseSubstFunc(node, expr.name, args) default: @@ -1496,6 +1488,38 @@ func (ctx *parseContext) parseIfFunc(node mkparser.Node, args *mkparser.MakeStri } } +func (ctx *parseContext) parseForeachFunc(node mkparser.Node, args *mkparser.MakeString) starlarkExpr { + words := args.Split(",") + if len(words) != 3 { + return ctx.newBadExpr(node, "foreach function should have 3 arguments, found "+strconv.Itoa(len(words))) + } + if !words[0].Const() || words[0].Empty() || !identifierFullMatchRegex.MatchString(words[0].Strings[0]) { + return ctx.newBadExpr(node, "first argument to foreach function must be a simple string identifier") + } + loopVarName := words[0].Strings[0] + list := ctx.parseMakeString(node, words[1]) + action := ctx.parseMakeString(node, words[2]).transform(func(expr starlarkExpr) starlarkExpr { + if varRefExpr, ok := expr.(*variableRefExpr); ok && varRefExpr.ref.name() == loopVarName { + return &identifierExpr{loopVarName} + } + return nil + }) + + if list.typ() != starlarkTypeList { + list = &callExpr{ + name: "words", + returnType: knownFunctions["words"].returnType, + args: []starlarkExpr{list}, + } + } + + return &foreachExpr{ + varName: loopVarName, + list: list, + action: action, + } +} + func (ctx *parseContext) parseWordFunc(node mkparser.Node, args *mkparser.MakeString) starlarkExpr { words := args.Split(",") if len(words) != 2 { @@ -1517,7 +1541,7 @@ func (ctx *parseContext) parseWordFunc(node mkparser.Node, args *mkparser.MakeSt if array.typ() != starlarkTypeList { array = &callExpr{object: array, name: "split", returnType: starlarkTypeList} } - return indexExpr{array, &intLiteralExpr{int(index - 1)}} + return &indexExpr{array, &intLiteralExpr{int(index - 1)}} } func (ctx *parseContext) parseFirstOrLastwordFunc(node mkparser.Node, name string, args *mkparser.MakeString) starlarkExpr { @@ -1548,16 +1572,18 @@ func (ctx *parseContext) parseMakeString(node mkparser.Node, mk *mkparser.MakeSt // If we reached here, it's neither string literal nor a simple variable, // we need a full-blown interpolation node that will generate // "a%b%c" % (X, Y) for a$(X)b$(Y)c - xInterp := &interpolateExpr{args: make([]starlarkExpr, len(mk.Variables))} - for i, ref := range mk.Variables { - arg := ctx.parseReference(node, ref.Name) - if x, ok := arg.(*badExpr); ok { - return x + parts := make([]starlarkExpr, len(mk.Variables)+len(mk.Strings)) + for i := 0; i < len(parts); i++ { + if i%2 == 0 { + parts[i] = &stringLiteralExpr{literal: mk.Strings[i/2]} + } else { + parts[i] = ctx.parseReference(node, mk.Variables[i/2].Name) + if x, ok := parts[i].(*badExpr); ok { + return x + } } - xInterp.args[i] = arg } - xInterp.chunks = append(xInterp.chunks, mk.Strings...) - return xInterp + return NewInterpolateExpr(parts) } // Handles the statements whose treatment is the same in all contexts: comment, diff --git a/mk2rbc/mk2rbc_test.go b/mk2rbc/mk2rbc_test.go index a1731a2ec..94c4fe6fa 100644 --- a/mk2rbc/mk2rbc_test.go +++ b/mk2rbc/mk2rbc_test.go @@ -1158,6 +1158,28 @@ def init(g, handle): g["OBJECTS2"] = rblf.mkpatsubst("%.c", "%.o", g["SOURCES"]) `, }, + { + desc: "foreach expressions", + mkname: "product.mk", + in: ` +BOOT_KERNEL_MODULES := foo.ko bar.ko +BOOT_KERNEL_MODULES_FILTER := $(foreach m,$(BOOT_KERNEL_MODULES),%/$(m)) +BOOT_KERNEL_MODULES_LIST := foo.ko +BOOT_KERNEL_MODULES_LIST += bar.ko +BOOT_KERNEL_MODULES_FILTER_2 := $(foreach m,$(BOOT_KERNEL_MODULES_LIST),%/$(m)) + +`, + expected: `load("//build/make/core:product_config.rbc", "rblf") + +def init(g, handle): + cfg = rblf.cfg(handle) + g["BOOT_KERNEL_MODULES"] = "foo.ko bar.ko" + g["BOOT_KERNEL_MODULES_FILTER"] = ["%%/%s" % m for m in rblf.words(g["BOOT_KERNEL_MODULES"])] + g["BOOT_KERNEL_MODULES_LIST"] = ["foo.ko"] + g["BOOT_KERNEL_MODULES_LIST"] += ["bar.ko"] + g["BOOT_KERNEL_MODULES_FILTER_2"] = ["%%/%s" % m for m in g["BOOT_KERNEL_MODULES_LIST"]] +`, + }, } var known_variables = []struct { diff --git a/python/androidmk.go b/python/androidmk.go index ccc85ec6a..233d8679f 100644 --- a/python/androidmk.go +++ b/python/androidmk.go @@ -78,7 +78,7 @@ func (installer *pythonInstaller) AndroidMk(base *Module, entries *android.Andro entries.Required = append(entries.Required, "libc++") entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { - path, file := filepath.Split(installer.path.ToMakePath().String()) + path, file := filepath.Split(installer.path.String()) stem := strings.TrimSuffix(file, filepath.Ext(file)) entries.SetString("LOCAL_MODULE_SUFFIX", filepath.Ext(file)) diff --git a/rust/androidmk.go b/rust/androidmk.go index 1f18b4a12..4e5863215 100644 --- a/rust/androidmk.go +++ b/rust/androidmk.go @@ -193,7 +193,7 @@ func (compiler *baseCompiler) AndroidMk(ctx AndroidMkContext, ret *android.Andro ret.ExtraEntries = append(ret.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { entries.SetPath("LOCAL_SOONG_UNSTRIPPED_BINARY", compiler.unstrippedOutputFile) - path, file := filepath.Split(compiler.path.ToMakePath().String()) + path, file := filepath.Split(compiler.path.String()) stem, suffix, _ := android.SplitFileExt(file) entries.SetString("LOCAL_MODULE_SUFFIX", suffix) entries.SetString("LOCAL_MODULE_PATH", path) diff --git a/rust/library.go b/rust/library.go index 07843fe32..bb2e83fdb 100644 --- a/rust/library.go +++ b/rust/library.go @@ -681,6 +681,12 @@ func LibraryMutator(mctx android.BottomUpMutatorContext) { } variation := v.(*Module).ModuleBase.ImageVariation().Variation + if strings.HasPrefix(variation, cc.VendorVariationPrefix) { + // TODO(b/204303985) + // Disable vendor dylibs until they are supported + v.(*Module).Disable() + } + if strings.HasPrefix(variation, cc.VendorVariationPrefix) && m.HasVendorVariant() && !snapshot.IsVendorProprietaryModule(mctx) && diff --git a/rust/rust.go b/rust/rust.go index 300c0f57a..c2585f2a7 100644 --- a/rust/rust.go +++ b/rust/rust.go @@ -1312,10 +1312,6 @@ func (mod *Module) InstallInRecovery() bool { return mod.InRecovery() } -func (mod *Module) InstallBypassMake() bool { - return true -} - func linkPathFromFilePath(filepath android.Path) string { return strings.Split(filepath.String(), filepath.Base())[0] } diff --git a/sh/sh_binary.go b/sh/sh_binary.go index 2d98e8be0..e1df8ac59 100644 --- a/sh/sh_binary.go +++ b/sh/sh_binary.go @@ -166,10 +166,6 @@ type ShBinary struct { var _ android.HostToolProvider = (*ShBinary)(nil) -func (s *ShBinary) InstallBypassMake() bool { - return true -} - type ShTest struct { ShBinary @@ -435,7 +431,7 @@ func (s *ShTest) AndroidMkEntries() []android.AndroidMkEntries { ExtraEntries: []android.AndroidMkExtraEntriesFunc{ func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { s.customAndroidMkEntries(entries) - entries.SetPath("LOCAL_MODULE_PATH", s.installDir.ToMakePath()) + entries.SetPath("LOCAL_MODULE_PATH", s.installDir) entries.AddCompatibilityTestSuites(s.testProperties.Test_suites...) if s.testConfig != nil { entries.SetPath("LOCAL_FULL_TEST_CONFIG", s.testConfig) diff --git a/sh/sh_binary_test.go b/sh/sh_binary_test.go index 865d5f3d1..28b6fb93a 100644 --- a/sh/sh_binary_test.go +++ b/sh/sh_binary_test.go @@ -42,7 +42,10 @@ func testShBinary(t *testing.T, bp string) (*android.TestContext, android.Config } func TestShTestSubDir(t *testing.T) { - ctx, config := testShBinary(t, ` + result := android.GroupFixturePreparers( + prepareForShTest, + android.FixtureModifyConfig(android.SetKatiEnabledForTests), + ).RunTestWithBp(t, ` sh_test { name: "foo", src: "test.sh", @@ -50,17 +53,20 @@ func TestShTestSubDir(t *testing.T) { } `) - mod := ctx.ModuleForTests("foo", "android_arm64_armv8-a").Module().(*ShTest) + mod := result.ModuleForTests("foo", "android_arm64_armv8-a").Module().(*ShTest) - entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0] + entries := android.AndroidMkEntriesForTest(t, result.TestContext, mod)[0] expectedPath := "out/target/product/test_device/data/nativetest64/foo_test" actualPath := entries.EntryMap["LOCAL_MODULE_PATH"][0] - android.AssertStringPathRelativeToTopEquals(t, "LOCAL_MODULE_PATH[0]", config, expectedPath, actualPath) + android.AssertStringPathRelativeToTopEquals(t, "LOCAL_MODULE_PATH[0]", result.Config, expectedPath, actualPath) } func TestShTest(t *testing.T) { - ctx, config := testShBinary(t, ` + result := android.GroupFixturePreparers( + prepareForShTest, + android.FixtureModifyConfig(android.SetKatiEnabledForTests), + ).RunTestWithBp(t, ` sh_test { name: "foo", src: "test.sh", @@ -72,13 +78,13 @@ func TestShTest(t *testing.T) { } `) - mod := ctx.ModuleForTests("foo", "android_arm64_armv8-a").Module().(*ShTest) + mod := result.ModuleForTests("foo", "android_arm64_armv8-a").Module().(*ShTest) - entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0] + entries := android.AndroidMkEntriesForTest(t, result.TestContext, mod)[0] expectedPath := "out/target/product/test_device/data/nativetest64/foo" actualPath := entries.EntryMap["LOCAL_MODULE_PATH"][0] - android.AssertStringPathRelativeToTopEquals(t, "LOCAL_MODULE_PATH[0]", config, expectedPath, actualPath) + android.AssertStringPathRelativeToTopEquals(t, "LOCAL_MODULE_PATH[0]", result.Config, expectedPath, actualPath) expectedData := []string{":testdata/data1", ":testdata/sub/data2"} actualData := entries.EntryMap["LOCAL_TEST_DATA"] diff --git a/snapshot/host_snapshot.go b/snapshot/host_snapshot.go index 2a25a00e5..252cef816 100644 --- a/snapshot/host_snapshot.go +++ b/snapshot/host_snapshot.go @@ -180,7 +180,7 @@ func (f *hostSnapshot) AndroidMkEntries() []android.AndroidMkEntries { DistFiles: android.MakeDefaultDistFiles(f.zipFile.Path()), ExtraEntries: []android.AndroidMkExtraEntriesFunc{ func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { - entries.SetString("LOCAL_MODULE_PATH", f.installDir.ToMakePath().String()) + entries.SetString("LOCAL_MODULE_PATH", f.installDir.String()) entries.SetString("LOCAL_INSTALLED_MODULE_STEM", f.installFileName()) }, }, |