Merge "strip.sh: Fix argument to llvm-strip"
diff --git a/Android.bp b/Android.bp
index 5c76f5a..537b58b 100644
--- a/Android.bp
+++ b/Android.bp
@@ -326,6 +326,50 @@
}
bootstrap_go_package {
+ name: "soong-rust-config",
+ pkgPath: "android/soong/rust/config",
+ deps: [
+ "soong-android",
+ "soong-cc-config",
+ ],
+ srcs: [
+ "rust/config/global.go",
+ "rust/config/toolchain.go",
+ "rust/config/x86_linux_host.go",
+ "rust/config/x86_64_device.go",
+ ],
+}
+
+bootstrap_go_package {
+ name: "soong-rust",
+ pkgPath: "android/soong/rust",
+ deps: [
+ "soong",
+ "soong-android",
+ "soong-cc",
+ "soong-rust-config",
+ ],
+ srcs: [
+ "rust/androidmk.go",
+ "rust/compiler.go",
+ "rust/binary.go",
+ "rust/builder.go",
+ "rust/library.go",
+ "rust/prebuilt.go",
+ "rust/proc_macro.go",
+ "rust/rust.go",
+ "rust/testing.go",
+ ],
+ testSrcs: [
+ "rust/binary_test.go",
+ "rust/compiler_test.go",
+ "rust/library_test.go",
+ "rust/rust_test.go",
+ ],
+ pluginFor: ["soong_build"],
+}
+
+bootstrap_go_package {
name: "soong-python",
pkgPath: "android/soong/python",
deps: [
@@ -558,7 +602,6 @@
"__gnu_unwind_execute",
"__gnu_unwind_frame",
],
- use_gnu_strip: true,
},
},
arm64: {
@@ -606,7 +649,6 @@
"__register_frame_info_table_bases",
"__register_frame_table",
],
- use_gnu_strip: true,
},
}
diff --git a/android/androidmk.go b/android/androidmk.go
index 1f1bd70..124523f 100644
--- a/android/androidmk.go
+++ b/android/androidmk.go
@@ -79,12 +79,14 @@
header bytes.Buffer
footer bytes.Buffer
- AddCustomEntries func(name, prefix, moduleDir string, entries *AndroidMkEntries)
+ ExtraEntries []AndroidMkExtraEntriesFunc
EntryMap map[string][]string
entryOrder []string
}
+type AndroidMkExtraEntriesFunc func(entries *AndroidMkEntries)
+
func (a *AndroidMkEntries) SetString(name, value string) {
if _, ok := a.EntryMap[name]; !ok {
a.entryOrder = append(a.entryOrder, name)
@@ -246,9 +248,8 @@
prefix = "2ND_" + prefix
}
}
- blueprintDir := filepath.Dir(bpPath)
- if a.AddCustomEntries != nil {
- a.AddCustomEntries(name, prefix, blueprintDir, a)
+ for _, extra := range a.ExtraEntries {
+ extra(a)
}
// Write to footer.
diff --git a/android/api_levels.go b/android/api_levels.go
index 961685a..4f6efee 100644
--- a/android/api_levels.go
+++ b/android/api_levels.go
@@ -71,6 +71,7 @@
"O": 26,
"O-MR1": 27,
"P": 28,
+ "Q": 29,
}
for i, codename := range config.PlatformVersionCombinedCodenames() {
apiLevelsMap[codename] = baseApiLevel + i
diff --git a/android/module.go b/android/module.go
index 0ab9be7..dda526f 100644
--- a/android/module.go
+++ b/android/module.go
@@ -1038,6 +1038,13 @@
}
if m.Enabled() {
+ // ensure all direct android.Module deps are enabled
+ ctx.VisitDirectDepsBlueprint(func(bm blueprint.Module) {
+ if _, ok := bm.(Module); ok {
+ ctx.validateAndroidModule(bm, ctx.baseModuleContext.strictVisitDeps)
+ }
+ })
+
notice := proptools.StringDefault(m.commonProperties.Notice, "NOTICE")
if module := SrcIsModule(notice); module != "" {
m.noticeFile = ctx.ExpandOptionalSource(¬ice, "notice")
diff --git a/android/module_test.go b/android/module_test.go
index c790a68..6dca29f 100644
--- a/android/module_test.go
+++ b/android/module_test.go
@@ -14,7 +14,9 @@
package android
-import "testing"
+import (
+ "testing"
+)
func TestSrcIsModule(t *testing.T) {
type args struct {
@@ -139,3 +141,55 @@
})
}
}
+
+type depsModule struct {
+ ModuleBase
+ props struct {
+ Deps []string
+ }
+}
+
+func (m *depsModule) GenerateAndroidBuildActions(ctx ModuleContext) {
+}
+
+func (m *depsModule) DepsMutator(ctx BottomUpMutatorContext) {
+ ctx.AddDependency(ctx.Module(), nil, m.props.Deps...)
+}
+
+func depsModuleFactory() Module {
+ m := &depsModule{}
+ m.AddProperties(&m.props)
+ InitAndroidModule(m)
+ return m
+}
+
+func TestErrorDependsOnDisabledModule(t *testing.T) {
+ ctx := NewTestContext()
+ ctx.RegisterModuleType("deps", ModuleFactoryAdaptor(depsModuleFactory))
+
+ bp := `
+ deps {
+ name: "foo",
+ deps: ["bar"],
+ }
+ deps {
+ name: "bar",
+ enabled: false,
+ }
+ `
+
+ mockFS := map[string][]byte{
+ "Android.bp": []byte(bp),
+ }
+
+ ctx.MockFileSystem(mockFS)
+
+ ctx.Register()
+
+ config := TestConfig(buildDir, nil)
+
+ _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
+ FailIfErrored(t, errs)
+ _, errs = ctx.PrepareBuildActions(config)
+ FailIfNoMatchingErrors(t, `module "foo": depends on disabled module "bar"`, errs)
+}
diff --git a/android/mutator.go b/android/mutator.go
index 8e4343d..e76f847 100644
--- a/android/mutator.go
+++ b/android/mutator.go
@@ -244,8 +244,8 @@
}
func (t *topDownMutatorContext) CreateModule(factory blueprint.ModuleFactory, props ...interface{}) {
- common := []interface{}{&t.Module().base().commonProperties}
- t.bp.CreateModule(factory, append(common, props...)...)
+ inherited := []interface{}{&t.Module().base().commonProperties, &t.Module().base().variableProperties}
+ t.bp.CreateModule(factory, append(inherited, props...)...)
}
func (b *bottomUpMutatorContext) MutatorName() string {
diff --git a/android/neverallow.go b/android/neverallow.go
index 8355bb3..aff706c 100644
--- a/android/neverallow.go
+++ b/android/neverallow.go
@@ -51,6 +51,7 @@
AddNeverAllowRules(createIncludeDirsRules()...)
AddNeverAllowRules(createTrebleRules()...)
AddNeverAllowRules(createLibcoreRules()...)
+ AddNeverAllowRules(createMediaRules()...)
AddNeverAllowRules(createJavaDeviceForHostRules()...)
}
@@ -110,7 +111,7 @@
// TODO(b/67974785): always enforce the manifest
NeverAllow().
- Without("name", "libhidltransport").
+ Without("name", "libhidltransport-impl-internal").
With("product_variables.enforce_vintf_manifest.cflags", "*").
Because("manifest enforcement should be independent of ."),
@@ -151,6 +152,14 @@
return rules
}
+func createMediaRules() []Rule {
+ return []Rule{
+ NeverAllow().
+ With("libs", "updatable-media").
+ Because("updatable-media includes private APIs. Use updatable_media_stubs instead."),
+ }
+}
+
func createJavaDeviceForHostRules() []Rule {
javaDeviceForHostProjectsWhitelist := []string{
"external/guava",
@@ -177,7 +186,7 @@
osClass := ctx.Module().Target().Os.Class
- for _, r := range neverallows {
+ for _, r := range neverallowRules(ctx.Config()) {
n := r.(*rule)
if !n.appliesToPath(dir) {
continue
@@ -551,3 +560,19 @@
panic("Can't handle type: " + value.Kind().String())
}
+
+var neverallowRulesKey = NewOnceKey("neverallowRules")
+
+func neverallowRules(config Config) []Rule {
+ return config.Once(neverallowRulesKey, func() interface{} {
+ // No test rules were set by setTestNeverallowRules, use the global rules
+ return neverallows
+ }).([]Rule)
+}
+
+// Overrides the default neverallow rules for the supplied config.
+//
+// For testing only.
+func setTestNeverallowRules(config Config, testRules []Rule) {
+ config.Once(neverallowRulesKey, func() interface{} { return testRules })
+}
diff --git a/android/neverallow_test.go b/android/neverallow_test.go
index 920b9a5..b75b5b7 100644
--- a/android/neverallow_test.go
+++ b/android/neverallow_test.go
@@ -20,23 +20,29 @@
"github.com/google/blueprint"
)
-func init() {
- // Add extra rules needed for testing.
- AddNeverAllowRules(
- NeverAllow().InDirectDeps("not_allowed_in_direct_deps"),
- )
-}
-
var neverallowTests = []struct {
- name string
- fs map[string][]byte
- expectedError string
+ // The name of the test.
+ name string
+
+ // Optional test specific rules. If specified then they are used instead of the default rules.
+ rules []Rule
+
+ // Additional contents to add to the virtual filesystem used by the tests.
+ fs map[string][]byte
+
+ // The expected error patterns. If empty then no errors are expected, otherwise each error
+ // reported must be matched by at least one of these patterns. A pattern matches if the error
+ // message contains the pattern. A pattern does not have to match the whole error message.
+ expectedErrors []string
}{
// Test General Functionality
// in direct deps tests
{
name: "not_allowed_in_direct_deps",
+ rules: []Rule{
+ NeverAllow().InDirectDeps("not_allowed_in_direct_deps"),
+ },
fs: map[string][]byte{
"top/Blueprints": []byte(`
cc_library {
@@ -48,10 +54,12 @@
static_libs: ["not_allowed_in_direct_deps"],
}`),
},
- expectedError: `module "libother": violates neverallow deps:not_allowed_in_direct_deps`,
+ expectedErrors: []string{
+ `module "libother": violates neverallow deps:not_allowed_in_direct_deps`,
+ },
},
- // Test specific rules
+ // Test android specific rules
// include_dir rule tests
{
@@ -63,7 +71,9 @@
include_dirs: ["art/libdexfile/include"],
}`),
},
- expectedError: "all usages of 'art' have been migrated",
+ expectedErrors: []string{
+ "all usages of 'art' have been migrated",
+ },
},
{
name: "include_dir can reference another location",
@@ -88,7 +98,9 @@
},
}`),
},
- expectedError: "VNDK can never contain a library that is device dependent",
+ expectedErrors: []string{
+ "VNDK can never contain a library that is device dependent",
+ },
},
{
name: "no vndk.enabled under device directory",
@@ -102,7 +114,9 @@
},
}`),
},
- expectedError: "VNDK can never contain a library that is device dependent",
+ expectedErrors: []string{
+ "VNDK can never contain a library that is device dependent",
+ },
},
{
name: "vndk-ext under vendor or device directory",
@@ -124,7 +138,6 @@
},
}`),
},
- expectedError: "",
},
{
@@ -140,22 +153,9 @@
},
}`),
},
- expectedError: "manifest enforcement should be independent",
- },
- {
- name: "libhidltransport enforce_vintf_manifest.cflags",
- fs: map[string][]byte{
- "Blueprints": []byte(`
- cc_library {
- name: "libhidltransport",
- product_variables: {
- enforce_vintf_manifest: {
- cflags: ["-DSHOULD_NOT_EXIST"],
- },
- },
- }`),
+ expectedErrors: []string{
+ "manifest enforcement should be independent",
},
- expectedError: "",
},
{
@@ -171,7 +171,9 @@
},
}`),
},
- expectedError: "nothing should care if linker namespaces are enabled or not",
+ expectedErrors: []string{
+ "nothing should care if linker namespaces are enabled or not",
+ },
},
{
name: "libc_bionic_ndk treble_linker_namespaces.cflags",
@@ -186,7 +188,19 @@
},
}`),
},
- expectedError: "",
+ },
+ {
+ name: "dependency on updatable-media",
+ fs: map[string][]byte{
+ "Blueprints": []byte(`
+ java_library {
+ name: "needs_updatable_media",
+ libs: ["updatable-media"],
+ }`),
+ },
+ expectedErrors: []string{
+ "updatable-media includes private APIs. Use updatable_media_stubs instead.",
+ },
},
{
name: "java_device_for_host",
@@ -197,7 +211,9 @@
libs: ["core-libart"],
}`),
},
- expectedError: "java_device_for_host can only be used in whitelisted projects",
+ expectedErrors: []string{
+ "java_device_for_host can only be used in whitelisted projects",
+ },
},
// Libcore rule tests
{
@@ -219,7 +235,9 @@
sdk_version: "none",
}`),
},
- expectedError: "module \"outside_core_libraries\": violates neverallow",
+ expectedErrors: []string{
+ "module \"outside_core_libraries\": violates neverallow",
+ },
},
{
name: "sdk_version: \"current\"",
@@ -234,22 +252,22 @@
}
func TestNeverallow(t *testing.T) {
- config := TestConfig(buildDir, nil)
-
for _, test := range neverallowTests {
- t.Run(test.name, func(t *testing.T) {
- _, errs := testNeverallow(t, config, test.fs)
+ // Create a test per config to allow for test specific config, e.g. test rules.
+ config := TestConfig(buildDir, nil)
- if test.expectedError == "" {
- FailIfErrored(t, errs)
- } else {
- FailIfNoMatchingErrors(t, test.expectedError, errs)
+ t.Run(test.name, func(t *testing.T) {
+ // If the test has its own rules then use them instead of the default ones.
+ if test.rules != nil {
+ setTestNeverallowRules(config, test.rules)
}
+ _, errs := testNeverallow(config, test.fs)
+ CheckErrorsAgainstExpectations(t, errs, test.expectedErrors)
})
}
}
-func testNeverallow(t *testing.T, config Config, fs map[string][]byte) (*TestContext, []error) {
+func testNeverallow(config Config, fs map[string][]byte) (*TestContext, []error) {
ctx := NewTestContext()
ctx.RegisterModuleType("cc_library", ModuleFactoryAdaptor(newMockCcLibraryModule))
ctx.RegisterModuleType("java_library", ModuleFactoryAdaptor(newMockJavaLibraryModule))
diff --git a/android/prebuilt_etc.go b/android/prebuilt_etc.go
index 9722a25..d29ed16 100644
--- a/android/prebuilt_etc.go
+++ b/android/prebuilt_etc.go
@@ -155,16 +155,18 @@
Class: "ETC",
SubName: nameSuffix,
OutputFile: OptionalPathForPath(p.outputFilePath),
- AddCustomEntries: func(name, prefix, moduleDir string, entries *AndroidMkEntries) {
- entries.SetString("LOCAL_MODULE_TAGS", "optional")
- entries.SetString("LOCAL_MODULE_PATH", "$(OUT_DIR)/"+p.installDirPath.RelPathString())
- entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base())
- entries.SetString("LOCAL_UNINSTALLABLE_MODULE", strconv.FormatBool(!p.Installable()))
- if p.additionalDependencies != nil {
- for _, path := range *p.additionalDependencies {
- entries.SetString("LOCAL_ADDITIONAL_DEPENDENCIES", path.String())
+ ExtraEntries: []AndroidMkExtraEntriesFunc{
+ func(entries *AndroidMkEntries) {
+ entries.SetString("LOCAL_MODULE_TAGS", "optional")
+ entries.SetString("LOCAL_MODULE_PATH", "$(OUT_DIR)/"+p.installDirPath.RelPathString())
+ entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.outputFilePath.Base())
+ entries.SetString("LOCAL_UNINSTALLABLE_MODULE", strconv.FormatBool(!p.Installable()))
+ if p.additionalDependencies != nil {
+ for _, path := range *p.additionalDependencies {
+ entries.SetString("LOCAL_ADDITIONAL_DEPENDENCIES", path.String())
+ }
}
- }
+ },
},
}
}
diff --git a/android/rule_builder.go b/android/rule_builder.go
index 48d070e..6f04672 100644
--- a/android/rule_builder.go
+++ b/android/rule_builder.go
@@ -367,10 +367,6 @@
sboxOutputs[i] = "__SBOX_OUT_DIR__/" + Rel(ctx, r.sboxOutDir.String(), output.String())
}
- if depFile != nil {
- sboxOutputs = append(sboxOutputs, "__SBOX_OUT_DIR__/"+Rel(ctx, r.sboxOutDir.String(), depFile.String()))
- }
-
commandString = proptools.ShellEscape(commandString)
if !strings.HasPrefix(commandString, `'`) {
commandString = `'` + commandString + `'`
@@ -380,8 +376,13 @@
sboxCmd.BuiltTool(ctx, "sbox").
Flag("-c").Text(commandString).
Flag("--sandbox-path").Text(shared.TempDirForOutDir(PathForOutput(ctx).String())).
- Flag("--output-root").Text(r.sboxOutDir.String()).
- Flags(sboxOutputs)
+ Flag("--output-root").Text(r.sboxOutDir.String())
+
+ if depFile != nil {
+ sboxCmd.Flag("--depfile-out").Text(depFile.String())
+ }
+
+ sboxCmd.Flags(sboxOutputs)
commandString = sboxCmd.buf.String()
tools = append(tools, sboxCmd.tools...)
diff --git a/android/rule_builder_test.go b/android/rule_builder_test.go
index 6eba4f1..b484811 100644
--- a/android/rule_builder_test.go
+++ b/android/rule_builder_test.go
@@ -475,6 +475,7 @@
FailIfErrored(t, errs)
check := func(t *testing.T, params TestingBuildParams, wantCommand, wantOutput, wantDepfile string, wantRestat bool, extraCmdDeps []string) {
+ t.Helper()
if params.RuleParams.Command != wantCommand {
t.Errorf("\nwant RuleParams.Command = %q\n got %q", wantCommand, params.RuleParams.Command)
}
@@ -518,13 +519,14 @@
t.Run("sbox", func(t *testing.T) {
outDir := filepath.Join(buildDir, ".intermediates", "foo_sbox")
outFile := filepath.Join(outDir, "foo_sbox")
+ depFile := filepath.Join(outDir, "foo_sbox.d")
sbox := filepath.Join(buildDir, "host", config.PrebuiltOS(), "bin/sbox")
sandboxPath := shared.TempDirForOutDir(buildDir)
- cmd := sbox + ` -c 'cp bar __SBOX_OUT_DIR__/foo_sbox' --sandbox-path ` + sandboxPath + " --output-root " + outDir + " __SBOX_OUT_DIR__/foo_sbox __SBOX_OUT_DIR__/foo_sbox.d"
+ cmd := sbox + ` -c 'cp bar __SBOX_OUT_DIR__/foo_sbox' --sandbox-path ` + sandboxPath + " --output-root " + outDir + " --depfile-out " + depFile + " __SBOX_OUT_DIR__/foo_sbox"
check(t, ctx.ModuleForTests("foo_sbox", "").Rule("rule"),
- cmd, outFile, outFile+".d", false, []string{sbox})
+ cmd, outFile, depFile, false, []string{sbox})
})
t.Run("singleton", func(t *testing.T) {
outFile := filepath.Join(buildDir, "baz")
diff --git a/android/sh_binary.go b/android/sh_binary.go
index 2855aa0..ba0c8be 100644
--- a/android/sh_binary.go
+++ b/android/sh_binary.go
@@ -133,8 +133,10 @@
Class: "EXECUTABLES",
OutputFile: OptionalPathForPath(s.outputFilePath),
Include: "$(BUILD_SYSTEM)/soong_cc_prebuilt.mk",
- AddCustomEntries: func(name, prefix, moduleDir string, entries *AndroidMkEntries) {
- s.customAndroidMkEntries(entries)
+ ExtraEntries: []AndroidMkExtraEntriesFunc{
+ func(entries *AndroidMkEntries) {
+ s.customAndroidMkEntries(entries)
+ },
},
}
}
@@ -156,20 +158,22 @@
Class: "NATIVE_TESTS",
OutputFile: OptionalPathForPath(s.outputFilePath),
Include: "$(BUILD_SYSTEM)/soong_cc_prebuilt.mk",
- AddCustomEntries: func(name, prefix, moduleDir string, entries *AndroidMkEntries) {
- s.customAndroidMkEntries(entries)
+ ExtraEntries: []AndroidMkExtraEntriesFunc{
+ func(entries *AndroidMkEntries) {
+ s.customAndroidMkEntries(entries)
- entries.AddStrings("LOCAL_COMPATIBILITY_SUITE", s.testProperties.Test_suites...)
- entries.SetString("LOCAL_TEST_CONFIG", String(s.testProperties.Test_config))
- for _, d := range s.data {
- rel := d.Rel()
- path := d.String()
- if !strings.HasSuffix(path, rel) {
- panic(fmt.Errorf("path %q does not end with %q", path, rel))
+ entries.AddStrings("LOCAL_COMPATIBILITY_SUITE", s.testProperties.Test_suites...)
+ entries.SetString("LOCAL_TEST_CONFIG", String(s.testProperties.Test_config))
+ for _, d := range s.data {
+ rel := d.Rel()
+ path := d.String()
+ if !strings.HasSuffix(path, rel) {
+ panic(fmt.Errorf("path %q does not end with %q", path, rel))
+ }
+ path = strings.TrimSuffix(path, rel)
+ entries.AddStrings("LOCAL_TEST_DATA", path+":"+rel)
}
- path = strings.TrimSuffix(path, rel)
- entries.AddStrings("LOCAL_TEST_DATA", path+":"+rel)
- }
+ },
},
}
}
diff --git a/android/testing.go b/android/testing.go
index b59f399..447ffd6 100644
--- a/android/testing.go
+++ b/android/testing.go
@@ -372,6 +372,29 @@
}
}
+func CheckErrorsAgainstExpectations(t *testing.T, errs []error, expectedErrorPatterns []string) {
+ t.Helper()
+
+ if expectedErrorPatterns == nil {
+ FailIfErrored(t, errs)
+ } else {
+ for _, expectedError := range expectedErrorPatterns {
+ FailIfNoMatchingErrors(t, expectedError, errs)
+ }
+ if len(errs) > len(expectedErrorPatterns) {
+ t.Errorf("additional errors found, expected %d, found %d",
+ len(expectedErrorPatterns), len(errs))
+ for i, expectedError := range expectedErrorPatterns {
+ t.Errorf("expectedErrors[%d] = %s", i, expectedError)
+ }
+ for i, err := range errs {
+ t.Errorf("errs[%d] = %s", i, err)
+ }
+ }
+ }
+
+}
+
func AndroidMkEntriesForTest(t *testing.T, config Config, bpPath string, mod blueprint.Module) AndroidMkEntries {
var p AndroidMkEntriesProvider
var ok bool
diff --git a/android/variable.go b/android/variable.go
index 0931db8..3f2b9e9 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -115,6 +115,10 @@
Static_libs []string
Srcs []string
}
+
+ Flatten_apex struct {
+ Enabled *bool
+ }
} `android:"arch_variant"`
}
diff --git a/android/visibility_test.go b/android/visibility_test.go
index c44dc9e..d13fadf 100644
--- a/android/visibility_test.go
+++ b/android/visibility_test.go
@@ -860,23 +860,7 @@
t.Run(test.name, func(t *testing.T) {
_, errs := testVisibility(buildDir, test.fs)
- expectedErrors := test.expectedErrors
- if expectedErrors == nil {
- FailIfErrored(t, errs)
- } else {
- for _, expectedError := range expectedErrors {
- FailIfNoMatchingErrors(t, expectedError, errs)
- }
- if len(errs) > len(expectedErrors) {
- t.Errorf("additional errors found, expected %d, found %d", len(expectedErrors), len(errs))
- for i, expectedError := range expectedErrors {
- t.Errorf("expectedErrors[%d] = %s", i, expectedError)
- }
- for i, err := range errs {
- t.Errorf("errs[%d] = %s", i, err)
- }
- }
- }
+ CheckErrorsAgainstExpectations(t, errs, test.expectedErrors)
})
}
}
diff --git a/apex/apex.go b/apex/apex.go
index 9e7f3a0..1e99ff8 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -102,6 +102,24 @@
CommandDeps: []string{"${zip2zip}"},
Description: "app bundle",
}, "abi")
+
+ emitApexContentRule = pctx.StaticRule("emitApexContentRule", blueprint.RuleParams{
+ Command: `rm -f ${out} && touch ${out} && (. ${out}.emit_commands)`,
+ Rspfile: "${out}.emit_commands",
+ RspfileContent: "${emit_commands}",
+ Description: "Emit APEX image content",
+ }, "emit_commands")
+
+ diffApexContentRule = pctx.StaticRule("diffApexContentRule", blueprint.RuleParams{
+ Command: `diff --unchanged-group-format='' \` +
+ `--changed-group-format='%<' \` +
+ `${image_content_file} ${whitelisted_files_file} || (` +
+ `echo -e "New unexpected files were added to ${apex_module_name}." ` +
+ ` "To fix the build run following command:" && ` +
+ `echo "system/apex/tools/update_whitelist.sh ${whitelisted_files_file} ${image_content_file}" && ` +
+ `exit 1)`,
+ Description: "Diff ${image_content_file} and ${whitelisted_files_file}",
+ }, "image_content_file", "whitelisted_files_file", "apex_module_name")
)
var imageApexSuffix = ".apex"
@@ -124,6 +142,7 @@
keyTag = dependencyTag{name: "key"}
certificateTag = dependencyTag{name: "certificate"}
usesTag = dependencyTag{name: "uses"}
+ androidAppTag = dependencyTag{name: "androidApp"}
)
var (
@@ -312,6 +331,12 @@
// List of providing APEXes' names so that this APEX can depend on provided shared libraries.
Uses []string
+
+ // A txt file containing list of files that are whitelisted to be included in this APEX.
+ Whitelisted_files *string
+
+ // List of APKs to package inside APEX
+ Apps []string
}
type apexTargetBundleProperties struct {
@@ -346,6 +371,7 @@
goBinary
javaSharedLib
nativeTest
+ app
)
type apexPackaging int
@@ -410,6 +436,8 @@
return "JAVA_LIBRARIES"
case nativeTest:
return "NATIVE_TESTS"
+ case app:
+ return "APPS"
default:
panic(fmt.Errorf("unknown class %d", class))
}
@@ -435,6 +463,7 @@
bundleModuleFile android.WritablePath
outputFiles map[apexPackaging]android.WritablePath
+ flattenedOutput android.OutputPath
installDir android.OutputPath
prebuiltFileToDelete string
@@ -611,6 +640,10 @@
{Mutator: "arch", Variation: "android_common"},
}, javaLibTag, a.properties.Java_libs...)
+ ctx.AddFarVariationDependencies([]blueprint.Variation{
+ {Mutator: "arch", Variation: "android_common"},
+ }, androidAppTag, a.properties.Apps...)
+
if String(a.properties.Key) == "" {
ctx.ModuleErrorf("key is missing")
return
@@ -639,6 +672,13 @@
} else {
return nil, nil
}
+ case ".flattened":
+ if a.flattened {
+ flattenedApexPath := a.flattenedOutput
+ return android.Paths{flattenedApexPath}, nil
+ } else {
+ return nil, nil
+ }
default:
return nil, fmt.Errorf("unsupported module reference tag %q", tag)
}
@@ -784,6 +824,21 @@
return
}
+func getCopyManifestForAndroidApp(app *java.AndroidApp, pkgName string) (fileToCopy android.Path, dirInApex string) {
+ dirInApex = filepath.Join("app", pkgName)
+ fileToCopy = app.OutputFile()
+ return
+}
+
+// Context "decorator", overriding the InstallBypassMake method to always reply `true`.
+type flattenedApexContext struct {
+ android.ModuleContext
+}
+
+func (c *flattenedApexContext) InstallBypassMake() bool {
+ return true
+}
+
func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
filesInfo := []apexFile{}
@@ -939,6 +994,14 @@
if prebuilt, ok := child.(*Prebuilt); ok && prebuilt.isForceDisabled() {
a.prebuiltFileToDelete = prebuilt.InstallFilename()
}
+ case androidAppTag:
+ if ap, ok := child.(*java.AndroidApp); ok {
+ fileToCopy, dirInApex := getCopyManifestForAndroidApp(ap, ctx.DeviceConfig().OverridePackageNameFor(depName))
+ filesInfo = append(filesInfo, apexFile{fileToCopy, depName, dirInApex, app, ap, nil})
+ return true
+ } else {
+ ctx.PropertyErrorf("apps", "%q is not an android_app module", depName)
+ }
}
} else {
// indirect dependencies
@@ -984,6 +1047,8 @@
}
} else if am.CanHaveApexVariants() && am.IsInstallableToApex() {
ctx.ModuleErrorf("unexpected tag %q for indirect dependency %q", depTag, depName)
+ } else if am.NoApex() && !android.InList(depName, whitelistNoApex[ctx.ModuleName()]) {
+ ctx.ModuleErrorf("tries to include no_apex module %s", depName)
}
}
}
@@ -1049,6 +1114,14 @@
},
})
+ // Temporarily wrap the original `ctx` into a `flattenedApexContext` to have it
+ // reply true to `InstallBypassMake()` (thus making the call
+ // `android.PathForModuleInstall` below use `android.pathForInstallInMakeDir`
+ // instead of `android.PathForOutput`) to return the correct path to the flattened
+ // APEX (as its contents is installed by Make, not Soong).
+ factx := flattenedApexContext{ctx}
+ a.flattenedOutput = android.PathForModuleInstall(&factx, "apex", factx.ModuleName())
+
if a.apexTypes.zip() {
a.buildUnflattenedApex(ctx, zipApex)
}
@@ -1114,8 +1187,12 @@
}
copyCommands := []string{}
+ emitCommands := []string{}
+ imageContentFile := android.PathForModuleOut(ctx, ctx.ModuleName()+"-content.txt")
+ emitCommands = append(emitCommands, "echo ./apex_manifest.json >> "+imageContentFile.String())
for i, src := range filesToCopy {
dest := filepath.Join(a.filesInfo[i].installDir, src.Base())
+ emitCommands = append(emitCommands, "echo './"+dest+"' >> "+imageContentFile.String())
dest_path := filepath.Join(android.PathForModuleOut(ctx, "image"+suffix).String(), dest)
copyCommands = append(copyCommands, "mkdir -p "+filepath.Dir(dest_path))
copyCommands = append(copyCommands, "cp "+src.String()+" "+dest_path)
@@ -1127,6 +1204,35 @@
implicitInputs := append(android.Paths(nil), filesToCopy...)
implicitInputs = append(implicitInputs, a.manifestOut)
+ if a.properties.Whitelisted_files != nil {
+ ctx.Build(pctx, android.BuildParams{
+ Rule: emitApexContentRule,
+ Implicits: implicitInputs,
+ Output: imageContentFile,
+ Description: "emit apex image content",
+ Args: map[string]string{
+ "emit_commands": strings.Join(emitCommands, " && "),
+ },
+ })
+ implicitInputs = append(implicitInputs, imageContentFile)
+ whitelistedFilesFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.Whitelisted_files))
+
+ phonyOutput := android.PathForModuleOut(ctx, ctx.ModuleName()+"-diff-phony-output")
+ ctx.Build(pctx, android.BuildParams{
+ Rule: diffApexContentRule,
+ Implicits: implicitInputs,
+ Output: phonyOutput,
+ Description: "diff apex image content",
+ Args: map[string]string{
+ "whitelisted_files_file": whitelistedFilesFile.String(),
+ "image_content_file": imageContentFile.String(),
+ "apex_module_name": ctx.ModuleName(),
+ },
+ })
+
+ implicitInputs = append(implicitInputs, phonyOutput)
+ }
+
outHostBinDir := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "bin").String()
prebuiltSdkToolsBinDir := filepath.Join("prebuilts", "sdk", "tools", runtime.GOOS, "bin")
@@ -1211,6 +1317,13 @@
optFlags = append(optFlags, "--assets_dir "+filepath.Dir(noticeFile.String()))
}
+ if !ctx.Config().UnbundledBuild() && a.installable() {
+ // Apexes which are supposed to be installed in builtin dirs(/system, etc)
+ // don't need hashtree for activation. Therefore, by removing hashtree from
+ // apex bundle (filesystem image in it, to be specific), we can save storage.
+ optFlags = append(optFlags, "--no_hashtree")
+ }
+
ctx.Build(pctx, android.BuildParams{
Rule: apexRule,
Implicits: implicitInputs,
@@ -1442,6 +1555,8 @@
fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(moduleNames, " "))
}
fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
+ fmt.Fprintln(w, "$(LOCAL_INSTALLED_MODULE): .KATI_IMPLICIT_OUTPUTS :=", a.flattenedOutput.String())
+
} else {
// zip-apex is the less common type so have the name refer to the image-apex
// only and use {name}.zip if you want the zip-apex
@@ -1678,11 +1793,13 @@
Class: "ETC",
OutputFile: android.OptionalPathForPath(p.inputApex),
Include: "$(BUILD_PREBUILT)",
- AddCustomEntries: func(name, prefix, moduleDir string, entries *android.AndroidMkEntries) {
- entries.SetString("LOCAL_MODULE_PATH", filepath.Join("$(OUT_DIR)", p.installDir.RelPathString()))
- entries.SetString("LOCAL_MODULE_STEM", p.installFilename)
- entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable())
- entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", p.properties.Overrides...)
+ ExtraEntries: []android.AndroidMkExtraEntriesFunc{
+ func(entries *android.AndroidMkEntries) {
+ entries.SetString("LOCAL_MODULE_PATH", filepath.Join("$(OUT_DIR)", p.installDir.RelPathString()))
+ entries.SetString("LOCAL_MODULE_STEM", p.installFilename)
+ entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable())
+ entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", p.properties.Overrides...)
+ },
},
}
}
diff --git a/apex/apex_test.go b/apex/apex_test.go
index 387533c..e2d85ae 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -103,6 +103,7 @@
ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory))
ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(java.LibraryFactory))
ctx.RegisterModuleType("java_import", android.ModuleFactoryAdaptor(java.ImportFactory))
+ ctx.RegisterModuleType("android_app", android.ModuleFactoryAdaptor(java.AndroidAppFactory))
ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
ctx.BottomUp("prebuilts", android.PrebuiltMutator).Parallel()
@@ -210,31 +211,33 @@
"system/sepolicy/apex/myapex_keytest-file_contexts": nil,
"system/sepolicy/apex/otherapex-file_contexts": nil,
"system/sepolicy/apex/commonapex-file_contexts": nil,
- "mylib.cpp": nil,
- "mylib_common.cpp": nil,
- "mytest.cpp": nil,
- "mytest1.cpp": nil,
- "mytest2.cpp": nil,
- "mytest3.cpp": nil,
- "myprebuilt": nil,
- "my_include": nil,
- "foo/bar/MyClass.java": nil,
- "prebuilt.jar": nil,
- "vendor/foo/devkeys/test.x509.pem": nil,
- "vendor/foo/devkeys/test.pk8": nil,
- "testkey.x509.pem": nil,
- "testkey.pk8": nil,
- "testkey.override.x509.pem": nil,
- "testkey.override.pk8": nil,
- "vendor/foo/devkeys/testkey.avbpubkey": nil,
- "vendor/foo/devkeys/testkey.pem": nil,
- "NOTICE": nil,
- "custom_notice": nil,
- "testkey2.avbpubkey": nil,
- "testkey2.pem": nil,
- "myapex-arm64.apex": nil,
- "myapex-arm.apex": nil,
- "frameworks/base/api/current.txt": nil,
+ "mylib.cpp": nil,
+ "mylib_common.cpp": nil,
+ "mytest.cpp": nil,
+ "mytest1.cpp": nil,
+ "mytest2.cpp": nil,
+ "mytest3.cpp": nil,
+ "myprebuilt": nil,
+ "my_include": nil,
+ "foo/bar/MyClass.java": nil,
+ "prebuilt.jar": nil,
+ "vendor/foo/devkeys/test.x509.pem": nil,
+ "vendor/foo/devkeys/test.pk8": nil,
+ "testkey.x509.pem": nil,
+ "testkey.pk8": nil,
+ "testkey.override.x509.pem": nil,
+ "testkey.override.pk8": nil,
+ "vendor/foo/devkeys/testkey.avbpubkey": nil,
+ "vendor/foo/devkeys/testkey.pem": nil,
+ "NOTICE": nil,
+ "custom_notice": nil,
+ "testkey2.avbpubkey": nil,
+ "testkey2.pem": nil,
+ "myapex-arm64.apex": nil,
+ "myapex-arm.apex": nil,
+ "frameworks/base/api/current.txt": nil,
+ "build/make/core/proguard.flags": nil,
+ "build/make/core/proguard_basic_keeps.flags": nil,
})
return ctx, config
@@ -1851,6 +1854,36 @@
}
`)
+ testApexError(t, `tries to include no_apex module mylib2`, `
+ apex {
+ name: "commonapex",
+ key: "myapex.key",
+ native_shared_libs: ["mylib"],
+ }
+
+ apex_key {
+ name: "myapex.key",
+ public_key: "testkey.avbpubkey",
+ private_key: "testkey.pem",
+ }
+
+ cc_library {
+ name: "mylib",
+ srcs: ["mylib.cpp"],
+ static_libs: ["mylib2"],
+ system_shared_libs: [],
+ stl: "none",
+ }
+
+ cc_library {
+ name: "mylib2",
+ srcs: ["mylib.cpp"],
+ system_shared_libs: [],
+ stl: "none",
+ no_apex: true,
+ }
+ `)
+
ctx, _ := testApex(t, `
apex {
name: "myapex",
@@ -1902,6 +1935,83 @@
}
+func TestErrorsIfDepsAreNotEnabled(t *testing.T) {
+ testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, `
+ apex {
+ name: "myapex",
+ key: "myapex.key",
+ native_shared_libs: ["libfoo"],
+ }
+
+ apex_key {
+ name: "myapex.key",
+ public_key: "testkey.avbpubkey",
+ private_key: "testkey.pem",
+ }
+
+ cc_library {
+ name: "libfoo",
+ stl: "none",
+ system_shared_libs: [],
+ enabled: false,
+ }
+ `)
+ testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, `
+ apex {
+ name: "myapex",
+ key: "myapex.key",
+ java_libs: ["myjar"],
+ }
+
+ apex_key {
+ name: "myapex.key",
+ public_key: "testkey.avbpubkey",
+ private_key: "testkey.pem",
+ }
+
+ java_library {
+ name: "myjar",
+ srcs: ["foo/bar/MyClass.java"],
+ sdk_version: "none",
+ system_modules: "none",
+ compile_dex: true,
+ enabled: false,
+ }
+ `)
+}
+
+func TestApexWithApps(t *testing.T) {
+ ctx, _ := testApex(t, `
+ apex {
+ name: "myapex",
+ key: "myapex.key",
+ apps: [
+ "AppFoo",
+ ],
+ }
+
+ apex_key {
+ name: "myapex.key",
+ public_key: "testkey.avbpubkey",
+ private_key: "testkey.pem",
+ }
+
+ android_app {
+ name: "AppFoo",
+ srcs: ["foo/bar/MyClass.java"],
+ sdk_version: "none",
+ system_modules: "none",
+ }
+ `)
+
+ module := ctx.ModuleForTests("myapex", "android_common_myapex")
+ apexRule := module.Rule("apexRule")
+ copyCmds := apexRule.Args["copy_commands"]
+
+ ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk")
+
+}
+
func TestMain(m *testing.M) {
run := func() int {
setUp()
diff --git a/cc/androidmk.go b/cc/androidmk.go
index 272d3d4..4b0cb31 100644
--- a/cc/androidmk.go
+++ b/cc/androidmk.go
@@ -68,7 +68,7 @@
OutputFile: c.outputFile,
// TODO(jiyong): add the APEXes providing shared libs to the required modules
// Currently, adding c.Properties.ApexesProvidingSharedLibs is causing multiple
- // runtime APEXes (com.android.runtime.debug|release) to be installed. And this
+ // ART APEXes (com.android.art.debug|release) to be installed. And this
// is breaking some older devices (like marlin) where system.img is small.
Required: c.Properties.AndroidMkRuntimeLibs,
Include: "$(BUILD_SYSTEM)/soong_cc_prebuilt.mk",
diff --git a/cc/binary.go b/cc/binary.go
index fd00060..17e729c 100644
--- a/cc/binary.go
+++ b/cc/binary.go
@@ -50,6 +50,9 @@
// binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
// from PRODUCT_PACKAGES.
Overrides []string
+
+ // Inject boringssl hash into the shared library. This is only intended for use by external/boringssl.
+ Inject_bssl_hash *bool `android:"arch_variant"`
}
func init() {
@@ -342,6 +345,8 @@
flagsToBuilderFlags(flags), afterPrefixSymbols)
}
+ outputFile = maybeInjectBoringSSLHash(ctx, outputFile, binary.Properties.Inject_bssl_hash, fileName)
+
if Bool(binary.baseLinker.Properties.Use_version_lib) {
if ctx.Host() {
versionedOutputFile := outputFile
diff --git a/cc/builder.go b/cc/builder.go
index 00dc742..42d809a 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -271,6 +271,8 @@
sAbiDump bool
emitXrefs bool
+ assemblerWithCpp bool
+
systemIncludeFlags string
groupStaticLibs bool
@@ -428,7 +430,9 @@
switch srcFile.Ext() {
case ".s":
- rule = ccNoDeps
+ if !flags.assemblerWithCpp {
+ rule = ccNoDeps
+ }
fallthrough
case ".S":
ccCmd = "clang"
@@ -547,7 +551,7 @@
flags builderFlags, outputFile android.ModuleOutPath, deps android.Paths) {
arCmd := "${config.ClangBin}/llvm-ar"
- arFlags := "crsD"
+ arFlags := "crsPD"
if !ctx.Darwin() {
arFlags += " -format=gnu"
}
diff --git a/cc/cc.go b/cc/cc.go
index 0245c6a..f97ef5a 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -174,7 +174,8 @@
CFlagsDeps android.Paths // Files depended on by compiler flags
LdFlagsDeps android.Paths // Files depended on by linker flags
- GroupStaticLibs bool
+ AssemblerWithCpp bool
+ GroupStaticLibs bool
proto android.ProtoFlags
protoC bool // Whether to use C instead of C++
@@ -391,6 +392,14 @@
return ok && ccDepTag == testPerSrcDepTag
}
+func SharedDepTag() dependencyTag {
+ return sharedDepTag
+}
+
+func StaticDepTag() dependencyTag {
+ return staticDepTag
+}
+
// Module contains the properties and members used by all C/C++ module types, and implements
// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
// to construct the output file. Behavior can be customized with a Customizer interface
@@ -1053,6 +1062,9 @@
if c.sabi != nil {
flags = c.sabi.flags(ctx, flags)
}
+
+ flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.AsFlags)
+
// Optimization to reduce size of build.ninja
// Replace the long list of flags for each file with a module-local variable
ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
@@ -2311,6 +2323,9 @@
// If the device isn't compiling against the VNDK, we always
// use the core mode.
coreVariantNeeded = true
+ } else if m.Target().NativeBridge == android.NativeBridgeEnabled {
+ // Skip creating vendor variants for natvie bridge modules
+ coreVariantNeeded = true
} else if _, ok := m.linker.(*llndkStubDecorator); ok {
// LL-NDK stubs only exist in the vendor variant, since the
// real libraries will be used in the core variant.
diff --git a/cc/cc_test.go b/cc/cc_test.go
index 52234a8..c9eb421 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -2264,6 +2264,24 @@
}
}
+func TestErrorsIfAModuleDependsOnDisabled(t *testing.T) {
+ testCcError(t, `module "libA" .* depends on disabled module "libB"`, `
+ cc_library {
+ name: "libA",
+ srcs: ["foo.c"],
+ shared_libs: ["libB"],
+ stl: "none",
+ }
+
+ cc_library {
+ name: "libB",
+ srcs: ["foo.c"],
+ enabled: false,
+ stl: "none",
+ }
+ `)
+}
+
// Simple smoke test for the cc_fuzz target that ensures the rule compiles
// correctly.
func TestFuzzTarget(t *testing.T) {
diff --git a/cc/config/clang.go b/cc/config/clang.go
index 47b60e7..3636ae9 100644
--- a/cc/config/clang.go
+++ b/cc/config/clang.go
@@ -101,9 +101,8 @@
// not emit the table by default on Android since NDK still uses GNU binutils.
"-faddrsig",
- // Make implicit fallthrough an error in the future.
+ // -Wimplicit-fallthrough is not enabled by -Wall.
"-Wimplicit-fallthrough",
- "-Wno-error=implicit-fallthrough",
// Help catch common 32/64-bit errors.
"-Werror=int-conversion",
@@ -168,25 +167,17 @@
// new warnings are fixed.
"-Wno-tautological-constant-compare",
"-Wno-tautological-type-limit-compare",
- "-Wno-tautological-unsigned-enum-zero-compare",
- "-Wno-tautological-unsigned-zero-compare",
-
- // http://b/72330874 Disable -Wenum-compare until the instances detected by this new
- // warning are fixed.
- "-Wno-enum-compare",
- "-Wno-enum-compare-switch",
// Disable c++98-specific warning since Android is not concerned with C++98
// compatibility.
"-Wno-c++98-compat-extra-semi",
-
- // Disable this warning because we don't care about behavior with older compilers.
- "-Wno-return-std-move-in-c++11",
}, " "))
- // Extra cflags for projects under external/ directory
+ // Extra cflags for projects under external/ directory to disable warnings that are infeasible
+ // to fix in all the external projects and their upstream repos.
pctx.StaticVariable("ClangExtraExternalCflags", strings.Join([]string{
- // TODO(yikong): Move -Wno flags here
+ "-Wno-enum-compare",
+ "-Wno-enum-compare-switch",
// http://b/72331524 Allow null pointer arithmetic until the instances detected by
// this new warning are fixed.
diff --git a/cc/config/global.go b/cc/config/global.go
index 2150abf..d873494 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -46,6 +46,8 @@
"-g",
"-fno-strict-aliasing",
+
+ "-Werror=date-time",
}
commonGlobalConlyflags = []string{}
@@ -67,7 +69,6 @@
"-Werror=non-virtual-dtor",
"-Werror=address",
"-Werror=sequence-point",
- "-Werror=date-time",
"-Werror=format-security",
}
diff --git a/cc/fuzz.go b/cc/fuzz.go
index c1754b2..d44c02d 100644
--- a/cc/fuzz.go
+++ b/cc/fuzz.go
@@ -17,6 +17,7 @@
import (
"android/soong/android"
"android/soong/cc/config"
+ "github.com/google/blueprint/proptools"
)
func init() {
@@ -120,5 +121,16 @@
ctx.AppendProperties(&disableDarwinAndLinuxBionic)
})
+ // Statically link the STL. This allows fuzz target deployment to not have to
+ // include the STL.
+ android.AddLoadHook(module, func(ctx android.LoadHookContext) {
+ staticStlLinkage := struct {
+ Stl *string
+ }{}
+
+ staticStlLinkage.Stl = proptools.StringPtr("libc++_static")
+ ctx.AppendProperties(&staticStlLinkage)
+ })
+
return module
}
diff --git a/cc/library.go b/cc/library.go
index 2496712..9178a52 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -464,7 +464,7 @@
}
}
}
- if enabled != nil && Bool(enabled) {
+ if Bool(enabled) || ctx.hasStubsVariants() {
return "PLATFORM"
}
return ""
@@ -771,18 +771,7 @@
}
library.unstrippedOutputFile = outputFile
- // TODO(b/137267623): Remove this in favor of a cc_genrule when they support operating on shared libraries.
- if Bool(library.Properties.Inject_bssl_hash) {
- hashedOutputfile := outputFile
- outputFile = android.PathForModuleOut(ctx, "unhashed", fileName)
-
- rule := android.NewRuleBuilder()
- rule.Command().
- BuiltTool(ctx, "bssl_inject_hash").
- FlagWithInput("-in-object ", outputFile).
- FlagWithOutput("-o ", hashedOutputfile)
- rule.Build(pctx, ctx, "injectCryptoHash", "inject crypto hash")
- }
+ outputFile = maybeInjectBoringSSLHash(ctx, outputFile, library.Properties.Inject_bssl_hash, fileName)
if Bool(library.baseLinker.Properties.Use_version_lib) {
if ctx.Host() {
@@ -894,7 +883,7 @@
}
exportedHeaderFlags := strings.Join(SourceAbiFlags, " ")
library.sAbiOutputFile = TransformDumpToLinkedDump(ctx, objs.sAbiDumpFiles, soFile, fileName, exportedHeaderFlags,
- android.OptionalPathForModuleSrc(ctx, library.Properties.Header_abi_checker.Symbol_file),
+ android.OptionalPathForModuleSrc(ctx, library.symbolFileForAbiCheck(ctx)),
library.Properties.Header_abi_checker.Exclude_symbol_versions,
library.Properties.Header_abi_checker.Exclude_symbol_tags)
@@ -952,9 +941,7 @@
isVendor := ctx.useVndk()
isOwnerPlatform := Bool(library.Properties.Sysprop.Platform)
- usePublic := isProduct || (isOwnerPlatform == isVendor)
-
- if usePublic {
+ if !ctx.inRecovery() && (isProduct || (isOwnerPlatform == isVendor)) {
dir = android.PathForModuleGen(ctx, "sysprop/public", "include").String()
}
}
@@ -1097,6 +1084,16 @@
return library.MutatedProperties.BuildStubs
}
+func (library *libraryDecorator) symbolFileForAbiCheck(ctx ModuleContext) *string {
+ if library.Properties.Header_abi_checker.Symbol_file != nil {
+ return library.Properties.Header_abi_checker.Symbol_file
+ }
+ if ctx.hasStubsVariants() && library.Properties.Stubs.Symbol_file != nil {
+ return library.Properties.Stubs.Symbol_file
+ }
+ return nil
+}
+
func (library *libraryDecorator) stubsVersion() string {
return library.MutatedProperties.StubsVersion
}
@@ -1288,3 +1285,38 @@
}
}
}
+
+// maybeInjectBoringSSLHash adds a rule to run bssl_inject_hash on the output file if the module has the
+// inject_bssl_hash or if any static library dependencies have inject_bssl_hash set. It returns the output path
+// that the linked output file should be written to.
+// TODO(b/137267623): Remove this in favor of a cc_genrule when they support operating on shared libraries.
+func maybeInjectBoringSSLHash(ctx android.ModuleContext, outputFile android.ModuleOutPath,
+ inject *bool, fileName string) android.ModuleOutPath {
+ // TODO(b/137267623): Remove this in favor of a cc_genrule when they support operating on shared libraries.
+ injectBoringSSLHash := Bool(inject)
+ ctx.VisitDirectDeps(func(dep android.Module) {
+ tag := ctx.OtherModuleDependencyTag(dep)
+ if tag == staticDepTag || tag == staticExportDepTag || tag == wholeStaticDepTag || tag == lateStaticDepTag {
+ if cc, ok := dep.(*Module); ok {
+ if library, ok := cc.linker.(*libraryDecorator); ok {
+ if Bool(library.Properties.Inject_bssl_hash) {
+ injectBoringSSLHash = true
+ }
+ }
+ }
+ }
+ })
+ if injectBoringSSLHash {
+ hashedOutputfile := outputFile
+ outputFile = android.PathForModuleOut(ctx, "unhashed", fileName)
+
+ rule := android.NewRuleBuilder()
+ rule.Command().
+ BuiltTool(ctx, "bssl_inject_hash").
+ FlagWithInput("-in-object ", outputFile).
+ FlagWithOutput("-o ", hashedOutputfile)
+ rule.Build(pctx, ctx, "injectCryptoHash", "inject crypto hash")
+ }
+
+ return outputFile
+}
diff --git a/cc/sanitize.go b/cc/sanitize.go
index 192b8d9..415518c 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -56,7 +56,8 @@
minimalRuntimeFlags = []string{"-fsanitize-minimal-runtime", "-fno-sanitize-trap=integer,undefined",
"-fno-sanitize-recover=integer,undefined"}
- hwasanGlobalOptions = []string{"heap_history_size=1023,stack_history_size=512"}
+ hwasanGlobalOptions = []string{"heap_history_size=1023", "stack_history_size=512",
+ "export_memory_stats=0", "max_malloc_fill_size=0"}
)
type sanitizerType int
@@ -475,6 +476,12 @@
// TODO(b/133876586): Experimental PM breaks sanitizer coverage.
_, flags.CFlags = removeFromList("-fexperimental-new-pass-manager", flags.CFlags)
flags.CFlags = append(flags.CFlags, "-fno-experimental-new-pass-manager")
+
+ // Disable fortify for fuzzing builds. Generally, we'll be building with
+ // UBSan or ASan here and the fortify checks pollute the stack traces.
+ _, flags.CFlags = removeFromList("-D_FORTIFY_SOURCE=1", flags.CFlags)
+ _, flags.CFlags = removeFromList("-D_FORTIFY_SOURCE=2", flags.CFlags)
+ flags.CFlags = append(flags.CFlags, "-U_FORTIFY_SOURCE")
}
if Bool(sanitize.Properties.Sanitize.Cfi) {
diff --git a/cc/stl.go b/cc/stl.go
index 5578299..458129c 100644
--- a/cc/stl.go
+++ b/cc/stl.go
@@ -207,8 +207,6 @@
func (stl *stl) flags(ctx ModuleContext, flags Flags) Flags {
switch stl.Properties.SelectedStl {
case "libc++", "libc++_static":
- flags.CFlags = append(flags.CFlags, "-D_USING_LIBCXX")
-
if ctx.Darwin() {
// libc++'s headers are annotated with availability macros that
// indicate which version of Mac OS was the first to ship with a
diff --git a/cc/sysprop.go b/cc/sysprop.go
index 656f79f..6cac7fb 100644
--- a/cc/sysprop.go
+++ b/cc/sysprop.go
@@ -21,6 +21,7 @@
)
type syspropLibraryInterface interface {
+ BaseModuleName() string
CcModuleName() string
}
@@ -42,6 +43,6 @@
syspropImplLibrariesLock.Lock()
defer syspropImplLibrariesLock.Unlock()
- syspropImplLibraries[mctx.ModuleName()] = m.CcModuleName()
+ syspropImplLibraries[m.BaseModuleName()] = m.CcModuleName()
}
}
diff --git a/cc/test.go b/cc/test.go
index aff8ba5..1a0d44f 100644
--- a/cc/test.go
+++ b/cc/test.go
@@ -68,6 +68,9 @@
// Add RootTargetPreparer to auto generated test config. This guarantees the test to run
// with root permission.
Require_root *bool
+
+ // Add RunCommandTargetPreparer to stop framework before the test and start it after the test.
+ Disable_framework *bool
}
func init() {
@@ -313,7 +316,13 @@
test.data = android.PathsForModuleSrc(ctx, test.Properties.Data)
var configs []tradefed.Config
if Bool(test.Properties.Require_root) {
- configs = append(configs, tradefed.Preparer{"com.android.tradefed.targetprep.RootTargetPreparer"})
+ configs = append(configs, tradefed.Preparer{"com.android.tradefed.targetprep.RootTargetPreparer", nil})
+ }
+ if Bool(test.Properties.Disable_framework) {
+ var options []tradefed.Option
+ options = append(options, tradefed.Option{"run-command", "stop"})
+ options = append(options, tradefed.Option{"teardown-command", "start"})
+ configs = append(configs, tradefed.Preparer{"com.android.tradefed.targetprep.RunCommandTargetPreparer", options})
}
if Bool(test.testDecorator.Properties.Isolated) {
configs = append(configs, tradefed.Option{"not-shardable", "true"})
@@ -448,7 +457,7 @@
benchmark.data = android.PathsForModuleSrc(ctx, benchmark.Properties.Data)
var configs []tradefed.Config
if Bool(benchmark.Properties.Require_root) {
- configs = append(configs, tradefed.Preparer{"com.android.tradefed.targetprep.RootTargetPreparer"})
+ configs = append(configs, tradefed.Preparer{"com.android.tradefed.targetprep.RootTargetPreparer", nil})
}
benchmark.testConfig = tradefed.AutoGenNativeBenchmarkTestConfig(ctx, benchmark.Properties.Test_config,
benchmark.Properties.Test_config_template, benchmark.Properties.Test_suites, configs)
diff --git a/cc/util.go b/cc/util.go
index fb6338a..7b8ad18 100644
--- a/cc/util.go
+++ b/cc/util.go
@@ -79,7 +79,8 @@
systemIncludeFlags: strings.Join(in.SystemIncludeFlags, " "),
- groupStaticLibs: in.GroupStaticLibs,
+ assemblerWithCpp: in.AssemblerWithCpp,
+ groupStaticLibs: in.GroupStaticLibs,
proto: in.proto,
protoC: in.protoC,
diff --git a/cc/vndk.go b/cc/vndk.go
index 2a86f5b..698fab5 100644
--- a/cc/vndk.go
+++ b/cc/vndk.go
@@ -317,10 +317,13 @@
if !ok {
return
}
-
if !m.Enabled() {
return
}
+ if m.Target().NativeBridge == android.NativeBridgeEnabled {
+ // Skip native_bridge modules
+ return
+ }
if m.isVndk() {
if lib, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
diff --git a/cc/vndk_prebuilt.go b/cc/vndk_prebuilt.go
index c8ff87f..da357ed 100644
--- a/cc/vndk_prebuilt.go
+++ b/cc/vndk_prebuilt.go
@@ -139,6 +139,10 @@
return nil
}
+func (p *vndkPrebuiltLibraryDecorator) nativeCoverage() bool {
+ return false
+}
+
func (p *vndkPrebuiltLibraryDecorator) install(ctx ModuleContext, file android.Path) {
arches := ctx.DeviceConfig().Arches()
if len(arches) == 0 || arches[0].ArchType.String() != p.arch() {
diff --git a/cmd/dep_fixer/Android.bp b/cmd/dep_fixer/Android.bp
index d2d1113..97364d5 100644
--- a/cmd/dep_fixer/Android.bp
+++ b/cmd/dep_fixer/Android.bp
@@ -14,10 +14,6 @@
blueprint_go_binary {
name: "dep_fixer",
- deps: ["androidmk-parser"],
- srcs: [
- "main.go",
- "deps.go",
- ],
- testSrcs: ["deps_test.go"],
+ deps: ["soong-makedeps"],
+ srcs: ["main.go"],
}
diff --git a/cmd/dep_fixer/main.go b/cmd/dep_fixer/main.go
index f94cf2f..d1bd139 100644
--- a/cmd/dep_fixer/main.go
+++ b/cmd/dep_fixer/main.go
@@ -25,6 +25,8 @@
"io/ioutil"
"log"
"os"
+
+ "android/soong/makedeps"
)
func main() {
@@ -39,7 +41,7 @@
log.Fatal("Expected at least one input file as an argument")
}
- var mergedDeps *Deps
+ var mergedDeps *makedeps.Deps
var firstInput []byte
for i, arg := range flag.Args() {
@@ -48,7 +50,7 @@
log.Fatalf("Error opening %q: %v", arg, err)
}
- deps, err := Parse(arg, bytes.NewBuffer(append([]byte(nil), input...)))
+ deps, err := makedeps.Parse(arg, bytes.NewBuffer(append([]byte(nil), input...)))
if err != nil {
log.Fatalf("Failed to parse: %v", err)
}
diff --git a/cmd/sbox/Android.bp b/cmd/sbox/Android.bp
index fe4c7bb..a706810d 100644
--- a/cmd/sbox/Android.bp
+++ b/cmd/sbox/Android.bp
@@ -14,6 +14,7 @@
blueprint_go_binary {
name: "sbox",
+ deps: ["soong-makedeps"],
srcs: [
"sbox.go",
],
diff --git a/cmd/sbox/sbox.go b/cmd/sbox/sbox.go
index 4ac9295..7057b33 100644
--- a/cmd/sbox/sbox.go
+++ b/cmd/sbox/sbox.go
@@ -15,6 +15,7 @@
package main
import (
+ "bytes"
"errors"
"flag"
"fmt"
@@ -25,6 +26,8 @@
"path/filepath"
"strings"
"time"
+
+ "android/soong/makedeps"
)
var (
@@ -152,9 +155,6 @@
return err
}
allOutputs = append(allOutputs, sandboxedDepfile)
- if !strings.Contains(rawCommand, "__SBOX_DEPFILE__") {
- return fmt.Errorf("the --depfile-out argument only makes sense if the command contains the text __SBOX_DEPFILE__")
- }
rawCommand = strings.Replace(rawCommand, "__SBOX_DEPFILE__", filepath.Join(tempDir, sandboxedDepfile), -1)
}
@@ -281,6 +281,26 @@
}
}
+ // Rewrite the depfile so that it doesn't include the (randomized) sandbox directory
+ if depfileOut != "" {
+ in, err := ioutil.ReadFile(depfileOut)
+ if err != nil {
+ return err
+ }
+
+ deps, err := makedeps.Parse(depfileOut, bytes.NewBuffer(in))
+ if err != nil {
+ return err
+ }
+
+ deps.Output = "outputfile"
+
+ err = ioutil.WriteFile(depfileOut, deps.Print(), 0666)
+ if err != nil {
+ return err
+ }
+ }
+
// TODO(jeffrygaston) if a process creates more output files than it declares, should there be a warning?
return nil
}
diff --git a/cmd/soong_ui/main.go b/cmd/soong_ui/main.go
index 39303bf..ec4f90e 100644
--- a/cmd/soong_ui/main.go
+++ b/cmd/soong_ui/main.go
@@ -180,6 +180,11 @@
}
}
+ // Fix up the source tree due to a repo bug where it doesn't remove
+ // linkfiles that have been removed
+ fixBadDanglingLink(buildCtx, "hardware/qcom/sdm710/Android.bp")
+ fixBadDanglingLink(buildCtx, "hardware/qcom/sdm710/Android.mk")
+
f := build.NewSourceFinder(buildCtx, config)
defer f.Shutdown()
build.FindSources(buildCtx, config, f)
@@ -187,6 +192,20 @@
c.run(buildCtx, config, args, logsDir)
}
+func fixBadDanglingLink(ctx build.Context, name string) {
+ _, err := os.Lstat(name)
+ if err != nil {
+ return
+ }
+ _, err = os.Stat(name)
+ if os.IsNotExist(err) {
+ err = os.Remove(name)
+ if err != nil {
+ ctx.Fatalf("Failed to remove dangling link %q: %v", name, err)
+ }
+ }
+}
+
func dumpVar(ctx build.Context, config build.Config, args []string, _ string) {
flags := flag.NewFlagSet("dumpvar", flag.ExitOnError)
flags.Usage = func() {
diff --git a/dexpreopt/config.go b/dexpreopt/config.go
index 51f5519..f39ec4a 100644
--- a/dexpreopt/config.go
+++ b/dexpreopt/config.go
@@ -42,7 +42,7 @@
BootJars []string // modules for jars that form the boot class path
- RuntimeApexJars []string // modules for jars that are in the runtime apex
+ ArtApexJars []string // modules for jars that are in the ART APEX
ProductUpdatableBootModules []string
ProductUpdatableBootLocations []string
@@ -292,7 +292,7 @@
DisableGenerateProfile: false,
ProfileDir: "",
BootJars: nil,
- RuntimeApexJars: nil,
+ ArtApexJars: nil,
ProductUpdatableBootModules: nil,
ProductUpdatableBootLocations: nil,
SystemServerJars: nil,
diff --git a/java/aar.go b/java/aar.go
index a4e6f91..f5d7e97 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -249,7 +249,8 @@
}
packageRes := android.PathForModuleOut(ctx, "package-res.apk")
- srcJar := android.PathForModuleGen(ctx, "R.jar")
+ // the subdir "android" is required to be filtered by package names
+ srcJar := android.PathForModuleGen(ctx, "android", "R.srcjar")
proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options")
rTxt := android.PathForModuleOut(ctx, "R.txt")
// This file isn't used by Soong, but is generated for exporting
@@ -620,7 +621,8 @@
aapt2CompileZip(ctx, flata, aar, "res", compileFlags)
a.exportPackage = android.PathForModuleOut(ctx, "package-res.apk")
- srcJar := android.PathForModuleGen(ctx, "R.jar")
+ // the subdir "android" is required to be filtered by package names
+ srcJar := android.PathForModuleGen(ctx, "android", "R.srcjar")
proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options")
rTxt := android.PathForModuleOut(ctx, "R.txt")
a.extraAaptPackagesFile = android.PathForModuleOut(ctx, "extra_packages")
diff --git a/java/androidmk.go b/java/androidmk.go
index c00e070..0e8e422 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -122,6 +122,15 @@
}
}
+func testSuiteComponentEntries(entries *android.AndroidMkEntries, test_suites []string) {
+ entries.SetString("LOCAL_MODULE_TAGS", "tests")
+ if len(test_suites) > 0 {
+ entries.AddStrings("LOCAL_COMPATIBILITY_SUITE", test_suites...)
+ } else {
+ entries.SetString("LOCAL_COMPATIBILITY_SUITE", "null-suite")
+ }
+}
+
func (j *Test) AndroidMk() android.AndroidMkData {
data := j.Library.AndroidMk()
data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
@@ -614,22 +623,33 @@
Class: "APPS",
OutputFile: android.OptionalPathForPath(a.outputFile),
Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
- AddCustomEntries: func(name, prefix, moduleDir string, entries *android.AndroidMkEntries) {
- entries.SetBoolIfTrue("LOCAL_PRIVILEGED_MODULE", Bool(a.properties.Privileged))
- if a.certificate != nil {
- entries.SetString("LOCAL_CERTIFICATE", a.certificate.Pem.String())
- } else {
- entries.SetString("LOCAL_CERTIFICATE", "PRESIGNED")
- }
- entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", a.properties.Overrides...)
- if len(a.dexpreopter.builtInstalled) > 0 {
- entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", a.dexpreopter.builtInstalled)
- }
- entries.AddStrings("LOCAL_INSTALLED_MODULE_STEM", a.installPath.Rel())
+ ExtraEntries: []android.AndroidMkExtraEntriesFunc{
+ func(entries *android.AndroidMkEntries) {
+ entries.SetBoolIfTrue("LOCAL_PRIVILEGED_MODULE", Bool(a.properties.Privileged))
+ if a.certificate != nil {
+ entries.SetString("LOCAL_CERTIFICATE", a.certificate.Pem.String())
+ } else {
+ entries.SetString("LOCAL_CERTIFICATE", "PRESIGNED")
+ }
+ entries.AddStrings("LOCAL_OVERRIDES_PACKAGES", a.properties.Overrides...)
+ if len(a.dexpreopter.builtInstalled) > 0 {
+ entries.SetString("LOCAL_SOONG_BUILT_INSTALLED", a.dexpreopter.builtInstalled)
+ }
+ entries.AddStrings("LOCAL_INSTALLED_MODULE_STEM", a.installPath.Rel())
+ },
},
}
}
+func (a *AndroidTestImport) AndroidMkEntries() android.AndroidMkEntries {
+ entries := a.AndroidAppImport.AndroidMkEntries()
+ entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
+ testSuiteComponentEntries(entries, a.testProperties.Test_suites)
+ androidMkEntriesWriteTestData(a.data, entries)
+ })
+ return entries
+}
+
func androidMkWriteTestData(data android.Paths, ret *android.AndroidMkData) {
var testFiles []string
for _, d := range data {
@@ -641,3 +661,11 @@
})
}
}
+
+func androidMkEntriesWriteTestData(data android.Paths, entries *android.AndroidMkEntries) {
+ var testFiles []string
+ for _, d := range data {
+ testFiles = append(testFiles, d.String()+":"+d.Rel())
+ }
+ entries.AddStrings("LOCAL_COMPATIBILITY_SUPPORT_FILES", testFiles...)
+}
diff --git a/java/app.go b/java/app.go
index 31f07d3..d00c4c0 100644
--- a/java/app.go
+++ b/java/app.go
@@ -39,6 +39,7 @@
android.RegisterModuleType("android_app_certificate", AndroidAppCertificateFactory)
android.RegisterModuleType("override_android_app", OverrideAndroidAppModuleFactory)
android.RegisterModuleType("android_app_import", AndroidAppImportFactory)
+ android.RegisterModuleType("android_test_import", AndroidTestImportFactory)
initAndroidAppImportVariantGroupTypes()
}
@@ -138,6 +139,10 @@
return nil
}
+func (a *AndroidApp) OutputFile() android.Path {
+ return a.outputFile
+}
+
var _ AndroidLibraryDependency = (*AndroidApp)(nil)
type Certificate struct {
@@ -538,6 +543,15 @@
return String(a.overridableAppProperties.Certificate)
}
+// For OutputFileProducer interface
+func (a *AndroidApp) OutputFiles(tag string) (android.Paths, error) {
+ switch tag {
+ case ".aapt.srcjar":
+ return []android.Path{a.aaptSrcJar}, nil
+ }
+ return a.Library.OutputFiles(tag)
+}
+
// android_app compiles sources and Android resources into an Android application package `.apk` file.
func AndroidAppFactory() android.Module {
module := &AndroidApp{}
@@ -751,14 +765,18 @@
// A prebuilt apk to import
Apk *string
- // The name of a certificate in the default certificate directory, blank to use the default
- // product certificate, or an android_app_certificate module name in the form ":module".
+ // The name of a certificate in the default certificate directory or an android_app_certificate
+ // module name in the form ":module". Should be empty if presigned or default_dev_cert is set.
Certificate *string
// Set this flag to true if the prebuilt apk is already signed. The certificate property must not
// be set for presigned modules.
Presigned *bool
+ // Sign with the default system dev certificate. Must be used judiciously. Most imported apps
+ // need to either specify a specific certificate or be presigned.
+ Default_dev_cert *bool
+
// Specifies that this app should be installed to the priv-app directory,
// where the system will grant it additional privileges not available to
// normal apps.
@@ -862,11 +880,22 @@
}
func (a *AndroidAppImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
- if String(a.properties.Certificate) == "" && !Bool(a.properties.Presigned) {
- ctx.PropertyErrorf("certificate", "No certificate specified for prebuilt")
+ a.generateAndroidBuildActions(ctx)
+}
+
+func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext) {
+ numCertPropsSet := 0
+ if String(a.properties.Certificate) != "" {
+ numCertPropsSet++
}
- if String(a.properties.Certificate) != "" && Bool(a.properties.Presigned) {
- ctx.PropertyErrorf("certificate", "Certificate can't be specified for presigned modules")
+ if Bool(a.properties.Presigned) {
+ numCertPropsSet++
+ }
+ if Bool(a.properties.Default_dev_cert) {
+ numCertPropsSet++
+ }
+ if numCertPropsSet != 1 {
+ ctx.ModuleErrorf("One and only one of certficate, presigned, and default_dev_cert properties must be set")
}
_, certificates := collectAppDeps(ctx)
@@ -907,7 +936,9 @@
// Sign or align the package
// TODO: Handle EXTERNAL
if !Bool(a.properties.Presigned) {
- certificates = processMainCert(a.ModuleBase, *a.properties.Certificate, certificates, ctx)
+ // If the certificate property is empty at this point, default_dev_cert must be set to true.
+ // Which makes processMainCert's behavior for the empty cert string WAI.
+ certificates = processMainCert(a.ModuleBase, String(a.properties.Certificate), certificates, ctx)
if len(certificates) != 1 {
ctx.ModuleErrorf("Unexpected number of certificates were extracted: %q", certificates)
}
@@ -1011,6 +1042,39 @@
return module
}
+type AndroidTestImport struct {
+ AndroidAppImport
+
+ testProperties testProperties
+
+ data android.Paths
+}
+
+func (a *AndroidTestImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ a.generateAndroidBuildActions(ctx)
+
+ a.data = android.PathsForModuleSrc(ctx, a.testProperties.Data)
+}
+
+// android_test_import imports a prebuilt test apk with additional processing specified in the
+// module. DPI or arch variant configurations can be made as with android_app_import.
+func AndroidTestImportFactory() android.Module {
+ module := &AndroidTestImport{}
+ module.AddProperties(&module.properties)
+ module.AddProperties(&module.dexpreoptProperties)
+ module.AddProperties(&module.usesLibrary.usesLibraryProperties)
+ module.AddProperties(&module.testProperties)
+ module.populateAllVariantStructs()
+ android.AddLoadHook(module, func(ctx android.LoadHookContext) {
+ module.processVariants(ctx)
+ })
+
+ InitJavaModule(module, android.DeviceSupported)
+ android.InitSingleSourcePrebuiltModule(module, &module.properties, "Apk")
+
+ return module
+}
+
type UsesLibraryProperties struct {
// A list of shared library modules that will be listed in uses-library tags in the AndroidManifest.xml file.
Uses_libs []string
diff --git a/java/app_builder.go b/java/app_builder.go
index 348c8b4..ec2f6da 100644
--- a/java/app_builder.go
+++ b/java/app_builder.go
@@ -31,31 +31,13 @@
var (
Signapk = pctx.AndroidStaticRule("signapk",
blueprint.RuleParams{
- Command: `${config.JavaCmd} ${config.JavaVmFlags} -Djava.library.path=$$(dirname $signapkJniLibrary) ` +
- `-jar $signapkCmd $flags $certificates $in $out`,
- CommandDeps: []string{"$signapkCmd", "$signapkJniLibrary"},
+ Command: `${config.JavaCmd} ${config.JavaVmFlags} -Djava.library.path=$$(dirname ${config.SignapkJniLibrary}) ` +
+ `-jar ${config.SignapkCmd} $flags $certificates $in $out`,
+ CommandDeps: []string{"${config.SignapkCmd}", "${config.SignapkJniLibrary}"},
},
"flags", "certificates")
-
- androidManifestMerger = pctx.AndroidStaticRule("androidManifestMerger",
- blueprint.RuleParams{
- Command: "java -classpath $androidManifestMergerCmd com.android.manifmerger.Main merge " +
- "--main $in --libs $libsManifests --out $out",
- CommandDeps: []string{"$androidManifestMergerCmd"},
- Description: "merge manifest files",
- },
- "libsManifests")
)
-func init() {
- pctx.SourcePathVariable("androidManifestMergerCmd", "prebuilts/devtools/tools/lib/manifest-merger.jar")
- pctx.HostBinToolVariable("aaptCmd", "aapt")
- pctx.HostJavaToolVariable("signapkCmd", "signapk.jar")
- // TODO(ccross): this should come from the signapk dependencies, but we don't have any way
- // to express host JNI dependencies yet.
- pctx.HostJNIToolVariable("signapkJniLibrary", "libconscrypt_openjdk_jni")
-}
-
var combineApk = pctx.AndroidStaticRule("combineApk",
blueprint.RuleParams{
Command: `${config.MergeZipsCmd} $out $in`,
diff --git a/java/app_test.go b/java/app_test.go
index 564211c..f2aaec3 100644
--- a/java/app_test.go
+++ b/java/app_test.go
@@ -1164,6 +1164,35 @@
}
}
+func TestAndroidAppImport_DefaultDevCert(t *testing.T) {
+ ctx, _ := testJava(t, `
+ android_app_import {
+ name: "foo",
+ apk: "prebuilts/apk/app.apk",
+ default_dev_cert: true,
+ dex_preopt: {
+ enabled: true,
+ },
+ }
+ `)
+
+ variant := ctx.ModuleForTests("foo", "android_common")
+
+ // Check dexpreopt outputs.
+ if variant.MaybeOutput("dexpreopt/oat/arm64/package.vdex").Rule == nil ||
+ variant.MaybeOutput("dexpreopt/oat/arm64/package.odex").Rule == nil {
+ t.Errorf("can't find dexpreopt outputs")
+ }
+
+ // Check cert signing flag.
+ signedApk := variant.Output("signed/foo.apk")
+ signingFlag := signedApk.Args["certificates"]
+ expected := "build/make/target/product/security/testkey.x509.pem build/make/target/product/security/testkey.pk8"
+ if expected != signingFlag {
+ t.Errorf("Incorrect signing flags, expected: %q, got: %q", expected, signingFlag)
+ }
+}
+
func TestAndroidAppImport_DpiVariants(t *testing.T) {
bp := `
android_app_import {
@@ -1177,7 +1206,7 @@
apk: "prebuilts/apk/app_xxhdpi.apk",
},
},
- certificate: "PRESIGNED",
+ presigned: true,
dex_preopt: {
enabled: true,
},
@@ -1307,7 +1336,7 @@
apk: "prebuilts/apk/app_arm64.apk",
},
},
- certificate: "PRESIGNED",
+ presigned: true,
dex_preopt: {
enabled: true,
},
@@ -1326,7 +1355,7 @@
apk: "prebuilts/apk/app_arm.apk",
},
},
- certificate: "PRESIGNED",
+ presigned: true,
dex_preopt: {
enabled: true,
},
@@ -1352,6 +1381,34 @@
}
}
+func TestAndroidTestImport(t *testing.T) {
+ ctx, config := testJava(t, `
+ android_test_import {
+ name: "foo",
+ apk: "prebuilts/apk/app.apk",
+ presigned: true,
+ data: [
+ "testdata/data",
+ ],
+ }
+ `)
+
+ test := ctx.ModuleForTests("foo", "android_common").Module().(*AndroidTestImport)
+
+ // Check android mks.
+ entries := android.AndroidMkEntriesForTest(t, config, "", test)
+ expected := []string{"tests"}
+ actual := entries.EntryMap["LOCAL_MODULE_TAGS"]
+ if !reflect.DeepEqual(expected, actual) {
+ t.Errorf("Unexpected module tags - expected: %q, actual: %q", expected, actual)
+ }
+ expected = []string{"testdata/data:testdata/data"}
+ actual = entries.EntryMap["LOCAL_COMPATIBILITY_SUPPORT_FILES"]
+ if !reflect.DeepEqual(expected, actual) {
+ t.Errorf("Unexpected test data - expected: %q, actual: %q", expected, actual)
+ }
+}
+
func TestStl(t *testing.T) {
ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+`
cc_library {
diff --git a/java/builder.go b/java/builder.go
index f174cf0..9e068fa 100644
--- a/java/builder.go
+++ b/java/builder.go
@@ -229,10 +229,9 @@
// Emits the rule to generate Xref input file (.kzip file) for the given set of source files and source jars
// to compile with given set of builder flags, etc.
-func emitXrefRule(ctx android.ModuleContext, xrefFile android.WritablePath,
+func emitXrefRule(ctx android.ModuleContext, xrefFile android.WritablePath, idx int,
srcFiles, srcJars android.Paths,
- flags javaBuilderFlags, deps android.Paths,
- intermediatesDir string) {
+ flags javaBuilderFlags, deps android.Paths) {
deps = append(deps, srcJars...)
@@ -260,6 +259,11 @@
processor = "-processor " + flags.processor
}
+ intermediatesDir := "xref"
+ if idx >= 0 {
+ intermediatesDir += strconv.Itoa(idx)
+ }
+
ctx.Build(pctx,
android.BuildParams{
Rule: kytheExtract,
diff --git a/java/config/config.go b/java/config/config.go
index b371cbf..ce62b93 100644
--- a/java/config/config.go
+++ b/java/config/config.go
@@ -29,7 +29,7 @@
DefaultBootclasspathLibraries = []string{"core.platform.api.stubs", "core-lambda-stubs"}
DefaultSystemModules = "core-platform-api-stubs-system-modules"
- DefaultLibraries = []string{"ext", "framework"}
+ DefaultLibraries = []string{"ext", "framework", "updatable_media_stubs"}
DefaultLambdaStubsLibrary = "core-lambda-stubs"
SdkLambdaStubsPath = "prebuilts/sdk/tools/core-lambda-stubs.jar"
@@ -45,6 +45,7 @@
"core-icu4j",
"core-oj",
"core-libart",
+ "updatable-media",
}
)
@@ -140,27 +141,66 @@
pctx.HostJavaToolVariable("JacocoCLIJar", "jacoco-cli.jar")
- hostBinToolVariableWithPrebuilt := func(name, prebuiltDir, tool string) {
- pctx.VariableFunc(name, func(ctx android.PackageVarContext) string {
- if ctx.Config().UnbundledBuild() || ctx.Config().IsPdkBuild() {
- return filepath.Join(prebuiltDir, runtime.GOOS, "bin", tool)
- } else {
- return pctx.HostBinToolPath(ctx, tool).String()
- }
- })
- }
-
- hostBinToolVariableWithPrebuilt("Aapt2Cmd", "prebuilts/sdk/tools", "aapt2")
-
pctx.HostBinToolVariable("ManifestCheckCmd", "manifest_check")
pctx.HostBinToolVariable("ManifestFixerCmd", "manifest_fixer")
pctx.HostBinToolVariable("ManifestMergerCmd", "manifest-merger")
- pctx.HostBinToolVariable("ZipAlign", "zipalign")
-
pctx.HostBinToolVariable("Class2Greylist", "class2greylist")
pctx.HostBinToolVariable("HiddenAPI", "hiddenapi")
+
+ hostBinToolVariableWithSdkToolsPrebuilt("Aapt2Cmd", "aapt2")
+ hostBinToolVariableWithBuildToolsPrebuilt("AidlCmd", "aidl")
+ hostBinToolVariableWithBuildToolsPrebuilt("ZipAlign", "zipalign")
+
+ hostJavaToolVariableWithSdkToolsPrebuilt("SignapkCmd", "signapk")
+ // TODO(ccross): this should come from the signapk dependencies, but we don't have any way
+ // to express host JNI dependencies yet.
+ hostJNIToolVariableWithSdkToolsPrebuilt("SignapkJniLibrary", "libconscrypt_openjdk_jni")
+}
+
+func hostBinToolVariableWithSdkToolsPrebuilt(name, tool string) {
+ pctx.VariableFunc(name, func(ctx android.PackageVarContext) string {
+ if ctx.Config().UnbundledBuild() || ctx.Config().IsPdkBuild() {
+ return filepath.Join("prebuilts/sdk/tools", runtime.GOOS, "bin", tool)
+ } else {
+ return pctx.HostBinToolPath(ctx, tool).String()
+ }
+ })
+}
+
+func hostJavaToolVariableWithSdkToolsPrebuilt(name, tool string) {
+ pctx.VariableFunc(name, func(ctx android.PackageVarContext) string {
+ if ctx.Config().UnbundledBuild() || ctx.Config().IsPdkBuild() {
+ return filepath.Join("prebuilts/sdk/tools/lib", tool+".jar")
+ } else {
+ return pctx.HostJavaToolPath(ctx, tool+".jar").String()
+ }
+ })
+}
+
+func hostJNIToolVariableWithSdkToolsPrebuilt(name, tool string) {
+ pctx.VariableFunc(name, func(ctx android.PackageVarContext) string {
+ if ctx.Config().UnbundledBuild() || ctx.Config().IsPdkBuild() {
+ ext := ".so"
+ if runtime.GOOS == "darwin" {
+ ext = ".dylib"
+ }
+ return filepath.Join("prebuilts/sdk/tools", runtime.GOOS, "lib64", tool+ext)
+ } else {
+ return pctx.HostJNIToolPath(ctx, tool).String()
+ }
+ })
+}
+
+func hostBinToolVariableWithBuildToolsPrebuilt(name, tool string) {
+ pctx.VariableFunc(name, func(ctx android.PackageVarContext) string {
+ if ctx.Config().UnbundledBuild() || ctx.Config().IsPdkBuild() {
+ return filepath.Join("prebuilts/build-tools", ctx.Config().PrebuiltOS(), "bin", tool)
+ } else {
+ return pctx.HostBinToolPath(ctx, tool).String()
+ }
+ })
}
// JavaCmd returns a SourcePath object with the path to the java command.
diff --git a/java/config/makevars.go b/java/config/makevars.go
index ead298a..c40f4fc 100644
--- a/java/config/makevars.go
+++ b/java/config/makevars.go
@@ -82,4 +82,17 @@
ctx.Strict("HIDDENAPI", "${HiddenAPI}")
ctx.Strict("DEX_FLAGS", "${DexFlags}")
+
+ ctx.Strict("AIDL", "${AidlCmd}")
+ ctx.Strict("AAPT2", "${Aapt2Cmd}")
+ ctx.Strict("ZIPALIGN", "${ZipAlign}")
+ ctx.Strict("SIGNAPK_JAR", "${SignapkCmd}")
+ ctx.Strict("SIGNAPK_JNI_LIBRARY_PATH", "${SignapkJniLibrary}")
+
+ ctx.Strict("SOONG_ZIP", "${SoongZipCmd}")
+ ctx.Strict("MERGE_ZIPS", "${MergeZipsCmd}")
+ ctx.Strict("ZIP2ZIP", "${Zip2ZipCmd}")
+
+ ctx.Strict("ZIPTIME", "${Ziptime}")
+
}
diff --git a/java/dexpreopt_bootjars_test.go b/java/dexpreopt_bootjars_test.go
index 4c38399..244bd52 100644
--- a/java/dexpreopt_bootjars_test.go
+++ b/java/dexpreopt_bootjars_test.go
@@ -48,7 +48,7 @@
pathCtx := android.PathContextForTesting(config, nil)
dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx)
- dexpreoptConfig.RuntimeApexJars = []string{"foo", "bar", "baz"}
+ dexpreoptConfig.ArtApexJars = []string{"foo", "bar", "baz"}
setDexpreoptTestGlobalConfig(config, dexpreoptConfig)
ctx := testContext(bp, nil)
diff --git a/java/dexpreopt_config.go b/java/dexpreopt_config.go
index 4a4d6d5..8c699b8 100644
--- a/java/dexpreopt_config.go
+++ b/java/dexpreopt_config.go
@@ -107,17 +107,17 @@
return ctx.Config().Once(defaultBootImageConfigKey, func() interface{} {
global := dexpreoptGlobalConfig(ctx)
- runtimeModules := global.RuntimeApexJars
- nonFrameworkModules := concat(runtimeModules, global.ProductUpdatableBootModules)
+ artModules := global.ArtApexJars
+ nonFrameworkModules := concat(artModules, global.ProductUpdatableBootModules)
frameworkModules := android.RemoveListFromList(global.BootJars, nonFrameworkModules)
var nonUpdatableBootModules []string
var nonUpdatableBootLocations []string
- for _, m := range runtimeModules {
+ for _, m := range artModules {
nonUpdatableBootModules = append(nonUpdatableBootModules, m)
nonUpdatableBootLocations = append(nonUpdatableBootLocations,
- filepath.Join("/apex/com.android.runtime/javalib", m+".jar"))
+ filepath.Join("/apex/com.android.art/javalib", m+".jar"))
}
for _, m := range frameworkModules {
@@ -176,16 +176,16 @@
return ctx.Config().Once(apexBootImageConfigKey, func() interface{} {
global := dexpreoptGlobalConfig(ctx)
- runtimeModules := global.RuntimeApexJars
- nonFrameworkModules := concat(runtimeModules, global.ProductUpdatableBootModules)
+ artModules := global.ArtApexJars
+ nonFrameworkModules := concat(artModules, global.ProductUpdatableBootModules)
frameworkModules := android.RemoveListFromList(global.BootJars, nonFrameworkModules)
- imageModules := concat(runtimeModules, frameworkModules)
+ imageModules := concat(artModules, frameworkModules)
var bootLocations []string
- for _, m := range runtimeModules {
+ for _, m := range artModules {
bootLocations = append(bootLocations,
- filepath.Join("/apex/com.android.runtime/javalib", m+".jar"))
+ filepath.Join("/apex/com.android.art/javalib", m+".jar"))
}
for _, m := range frameworkModules {
diff --git a/java/droiddoc.go b/java/droiddoc.go
index b474948..9eaa1b6 100644
--- a/java/droiddoc.go
+++ b/java/droiddoc.go
@@ -61,15 +61,6 @@
// list of java libraries that will be in the classpath.
Libs []string `android:"arch_variant"`
- // the java library (in classpath) for documentation that provides java srcs and srcjars.
- Srcs_lib *string
-
- // the base dirs under srcs_lib will be scanned for java srcs.
- Srcs_lib_whitelist_dirs []string
-
- // the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs.
- Srcs_lib_whitelist_pkgs []string
-
// If set to false, don't allow this module(-docs.zip) to be exported. Defaults to true.
Installable *bool
@@ -303,8 +294,10 @@
android.InitDefaultableModule(module)
}
-func apiCheckEnabled(apiToCheck ApiToCheck, apiVersionTag string) bool {
- if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
+func apiCheckEnabled(ctx android.ModuleContext, apiToCheck ApiToCheck, apiVersionTag string) bool {
+ if ctx.Config().IsEnvTrue("WITHOUT_CHECK_API") {
+ return false
+ } else if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" {
return true
} else if String(apiToCheck.Api_file) != "" {
panic("for " + apiVersionTag + " removed_api_file has to be non-empty!")
@@ -362,6 +355,8 @@
switch tag {
case "":
return android.Paths{j.stubsSrcJar}, nil
+ case ".docs.zip":
+ return android.Paths{j.docZip}, nil
default:
return nil, fmt.Errorf("unsupported module reference tag %q", tag)
}
@@ -423,22 +418,6 @@
}
ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
- if j.properties.Srcs_lib != nil {
- ctx.AddVariationDependencies(nil, srcsLibTag, *j.properties.Srcs_lib)
- }
-}
-
-func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) {
- for _, dir := range j.properties.Srcs_lib_whitelist_dirs {
- for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs {
- // convert foo.bar.baz to foo/bar/baz
- pkgAsPath := filepath.Join(strings.Split(pkg, ".")...)
- prefix := filepath.Join(dir, pkgAsPath)
- if _, found := whitelistPathPrefixes[prefix]; !found {
- whitelistPathPrefixes[prefix] = true
- }
- }
- }
}
func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags {
@@ -480,13 +459,12 @@
outSrcFiles := make(android.Paths, 0, len(srcFiles))
+ aidlIncludeFlags := genAidlIncludeFlags(srcFiles)
+
for _, srcFile := range srcFiles {
switch srcFile.Ext() {
case ".aidl":
- javaFile := genAidl(ctx, srcFile, flags.aidlFlags, flags.aidlDeps)
- outSrcFiles = append(outSrcFiles, javaFile)
- case ".sysprop":
- javaFile := genSysprop(ctx, srcFile)
+ javaFile := genAidl(ctx, srcFile, flags.aidlFlags+aidlIncludeFlags, flags.aidlDeps)
outSrcFiles = append(outSrcFiles, javaFile)
case ".logtags":
javaFile := genLogtags(ctx, srcFile)
@@ -533,28 +511,6 @@
default:
ctx.ModuleErrorf("depends on non-java module %q", otherName)
}
- case srcsLibTag:
- switch dep := module.(type) {
- case Dependency:
- srcs := dep.(SrcDependency).CompiledSrcs()
- whitelistPathPrefixes := make(map[string]bool)
- j.genWhitelistPathPrefixes(whitelistPathPrefixes)
- for _, src := range srcs {
- if _, ok := src.(android.WritablePath); ok { // generated sources
- deps.srcs = append(deps.srcs, src)
- } else { // select source path for documentation based on whitelist path prefixs.
- for k := range whitelistPathPrefixes {
- if strings.HasPrefix(src.Rel(), k) {
- deps.srcs = append(deps.srcs, src)
- break
- }
- }
- }
- }
- deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...)
- default:
- ctx.ModuleErrorf("depends on non-java module %q", otherName)
- }
case systemModulesTag:
if deps.systemModules != nil {
panic("Found two system module dependencies")
@@ -811,8 +767,8 @@
}
func (d *Droiddoc) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.WritablePath) {
- if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
- apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
+ if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
+ apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
String(d.properties.Api_filename) != "" {
d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
@@ -820,8 +776,8 @@
d.apiFilePath = d.apiFile
}
- if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
- apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
+ if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
+ apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
String(d.properties.Removed_api_filename) != "" {
d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
cmd.FlagWithOutput("-removedApi ", d.removedApiFile)
@@ -1039,7 +995,7 @@
rule.Build(pctx, ctx, "javadoc", desc)
- if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
+ if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") &&
!ctx.Config().IsPdkBuild() {
apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Current.Api_file))
@@ -1108,7 +1064,7 @@
rule.Build(pctx, ctx, "doclavaCurrentApiUpdate", "update current API")
}
- if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
+ if apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") &&
!ctx.Config().IsPdkBuild() {
apiFile := android.PathForModuleSrc(ctx, String(d.properties.Check_api.Last_released.Api_file))
@@ -1238,16 +1194,16 @@
}
func (d *Droidstubs) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.WritablePath) {
- if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
- apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
+ if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
+ apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
String(d.properties.Api_filename) != "" {
d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt")
cmd.FlagWithOutput("--api ", d.apiFile)
d.apiFilePath = d.apiFile
}
- if apiCheckEnabled(d.properties.Check_api.Current, "current") ||
- apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") ||
+ if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") ||
+ apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") ||
String(d.properties.Removed_api_filename) != "" {
d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt")
cmd.FlagWithOutput("--removed-api ", d.removedApiFile)
@@ -1504,7 +1460,7 @@
// Create rule for apicheck
- if apiCheckEnabled(d.properties.Check_api.Current, "current") &&
+ if apiCheckEnabled(ctx, d.properties.Check_api.Current, "current") &&
!ctx.Config().IsPdkBuild() {
if len(d.Javadoc.properties.Out) > 0 {
@@ -1589,7 +1545,7 @@
rule.Build(pctx, ctx, "metalavaCurrentApiUpdate", "update current API")
}
- if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") &&
+ if apiCheckEnabled(ctx, d.properties.Check_api.Last_released, "last_released") &&
!ctx.Config().IsPdkBuild() {
if len(d.Javadoc.properties.Out) > 0 {
diff --git a/java/gen.go b/java/gen.go
index 69965ec..a69e9a2 100644
--- a/java/gen.go
+++ b/java/gen.go
@@ -23,7 +23,6 @@
)
func init() {
- pctx.HostBinToolVariable("aidlCmd", "aidl")
pctx.HostBinToolVariable("syspropCmd", "sysprop_java")
pctx.SourcePathVariable("logtagsCmd", "build/make/tools/java-event-log-tags.py")
pctx.SourcePathVariable("mergeLogtagsCmd", "build/make/tools/merge-event-log-tags.py")
@@ -33,8 +32,8 @@
var (
aidl = pctx.AndroidStaticRule("aidl",
blueprint.RuleParams{
- Command: "$aidlCmd -d$depFile $aidlFlags $in $out",
- CommandDeps: []string{"$aidlCmd"},
+ Command: "${config.AidlCmd} -d$depFile $aidlFlags $in $out",
+ CommandDeps: []string{"${config.AidlCmd}"},
},
"depFile", "aidlFlags")
@@ -53,22 +52,18 @@
sysprop = pctx.AndroidStaticRule("sysprop",
blueprint.RuleParams{
Command: `rm -rf $out.tmp && mkdir -p $out.tmp && ` +
- `$syspropCmd --java-output-dir $out.tmp $in && ` +
+ `$syspropCmd --scope $scope --java-output-dir $out.tmp $in && ` +
`${config.SoongZipCmd} -jar -o $out -C $out.tmp -D $out.tmp && rm -rf $out.tmp`,
CommandDeps: []string{
"$syspropCmd",
"${config.SoongZipCmd}",
},
- })
+ }, "scope")
)
func genAidl(ctx android.ModuleContext, aidlFile android.Path, aidlFlags string, deps android.Paths) android.Path {
javaFile := android.GenPathWithExt(ctx, "aidl", aidlFile, "java")
depFile := javaFile.String() + ".d"
- baseDir := strings.TrimSuffix(aidlFile.String(), aidlFile.Rel())
- if baseDir != "" {
- aidlFlags += " -I" + baseDir
- }
ctx.Build(pctx, android.BuildParams{
Rule: aidl,
@@ -98,7 +93,7 @@
return javaFile
}
-func genSysprop(ctx android.ModuleContext, syspropFile android.Path) android.Path {
+func genSysprop(ctx android.ModuleContext, syspropFile android.Path, scope string) android.Path {
srcJarFile := android.GenPathWithExt(ctx, "sysprop", syspropFile, "srcjar")
ctx.Build(pctx, android.BuildParams{
@@ -106,20 +101,38 @@
Description: "sysprop_java " + syspropFile.Rel(),
Output: srcJarFile,
Input: syspropFile,
+ Args: map[string]string{
+ "scope": scope,
+ },
})
return srcJarFile
}
+func genAidlIncludeFlags(srcFiles android.Paths) string {
+ var baseDirs []string
+ for _, srcFile := range srcFiles {
+ if srcFile.Ext() == ".aidl" {
+ baseDir := strings.TrimSuffix(srcFile.String(), srcFile.Rel())
+ if baseDir != "" && !android.InList(baseDir, baseDirs) {
+ baseDirs = append(baseDirs, baseDir)
+ }
+ }
+ }
+ return android.JoinWithPrefix(baseDirs, " -I")
+}
+
func (j *Module) genSources(ctx android.ModuleContext, srcFiles android.Paths,
flags javaBuilderFlags) android.Paths {
outSrcFiles := make(android.Paths, 0, len(srcFiles))
+ aidlIncludeFlags := genAidlIncludeFlags(srcFiles)
+
for _, srcFile := range srcFiles {
switch srcFile.Ext() {
case ".aidl":
- javaFile := genAidl(ctx, srcFile, flags.aidlFlags, flags.aidlDeps)
+ javaFile := genAidl(ctx, srcFile, flags.aidlFlags+aidlIncludeFlags, flags.aidlDeps)
outSrcFiles = append(outSrcFiles, javaFile)
case ".logtags":
j.logtagsSrcs = append(j.logtagsSrcs, srcFile)
@@ -129,7 +142,27 @@
srcJarFile := genProto(ctx, srcFile, flags.proto)
outSrcFiles = append(outSrcFiles, srcJarFile)
case ".sysprop":
- srcJarFile := genSysprop(ctx, srcFile)
+ // internal scope contains all properties
+ // public scope only contains public properties
+ // use public if the owner is different from client
+ scope := "internal"
+ if j.properties.Sysprop.Platform != nil {
+ isProduct := ctx.ProductSpecific()
+ isVendor := ctx.SocSpecific()
+ isOwnerPlatform := Bool(j.properties.Sysprop.Platform)
+
+ if isProduct {
+ // product can't own any sysprop_library now, so product must use public scope
+ scope = "public"
+ } else if isVendor && !isOwnerPlatform {
+ // vendor and odm can't use system's internal property.
+ scope = "public"
+ }
+
+ // We don't care about clients under system.
+ // They can't use sysprop_library owned by other partitions.
+ }
+ srcJarFile := genSysprop(ctx, srcFile, scope)
outSrcFiles = append(outSrcFiles, srcJarFile)
default:
outSrcFiles = append(outSrcFiles, srcFile)
diff --git a/java/java.go b/java/java.go
index afb1218..b05d7bb 100644
--- a/java/java.go
+++ b/java/java.go
@@ -25,6 +25,7 @@
"strings"
"github.com/google/blueprint"
+ "github.com/google/blueprint/pathtools"
"github.com/google/blueprint/proptools"
"android/soong/android"
@@ -183,6 +184,10 @@
Output_params []string
}
+ Sysprop struct {
+ Platform *bool
+ } `blueprint:"mutated"`
+
Instrument bool `blueprint:"mutated"`
// List of files to include in the META-INF/services folder of the resulting jar.
@@ -400,29 +405,14 @@
SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths
}
-type SrcDependency interface {
- CompiledSrcs() android.Paths
- CompiledSrcJars() android.Paths
-}
-
type xref interface {
XrefJavaFiles() android.Paths
}
-func (j *Module) CompiledSrcs() android.Paths {
- return j.compiledJavaSrcs
-}
-
-func (j *Module) CompiledSrcJars() android.Paths {
- return j.compiledSrcJars
-}
-
func (j *Module) XrefJavaFiles() android.Paths {
return j.kytheFiles
}
-var _ SrcDependency = (*Module)(nil)
-
func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
android.InitAndroidArchModule(module, hod, android.MultilibCommon)
android.InitDefaultableModule(module)
@@ -546,9 +536,6 @@
} else if *j.deviceProperties.System_modules != "none" {
ctx.AddVariationDependencies(nil, systemModulesTag, *j.deviceProperties.System_modules)
}
- if (ctx.ModuleName() == "framework") || (ctx.ModuleName() == "framework-annotation-proc") {
- ctx.AddVariationDependencies(nil, frameworkResTag, "framework-res")
- }
if ctx.ModuleName() == "android_stubs_current" ||
ctx.ModuleName() == "android_system_stubs_current" ||
ctx.ModuleName() == "android_test_stubs_current" {
@@ -829,12 +816,6 @@
} else {
ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName)
}
- case frameworkResTag:
- if (ctx.ModuleName() == "framework") || (ctx.ModuleName() == "framework-annotation-proc") {
- // framework.jar has a one-off dependency on the R.java and Manifest.java files
- // generated by framework-res.apk
- deps.srcJars = append(deps.srcJars, dep.(*AndroidApp).aaptSrcJar)
- }
case frameworkApkTag:
if ctx.ModuleName() == "android_stubs_current" ||
ctx.ModuleName() == "android_system_stubs_current" ||
@@ -903,7 +884,7 @@
ctx.PropertyErrorf("sdk_version", "%s", err)
}
if javaVersion != "" {
- ret = javaVersion
+ ret = normalizeJavaVersion(ctx, javaVersion)
} else if ctx.Device() && sdk <= 23 {
ret = "1.7"
} else if ctx.Device() && sdk <= 29 || !ctx.Config().TargetOpenJDK9() {
@@ -922,6 +903,25 @@
return ret
}
+func normalizeJavaVersion(ctx android.ModuleContext, javaVersion string) string {
+ switch javaVersion {
+ case "1.6", "6":
+ return "1.6"
+ case "1.7", "7":
+ return "1.7"
+ case "1.8", "8":
+ return "1.8"
+ case "1.9", "9":
+ return "1.9"
+ case "10", "11":
+ ctx.PropertyErrorf("java_version", "Java language levels above 9 are not supported")
+ return "unsupported"
+ default:
+ ctx.PropertyErrorf("java_version", "Unrecognized Java language level")
+ return "unrecognized"
+ }
+}
+
func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
var flags javaBuilderFlags
@@ -1017,7 +1017,6 @@
}
func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
-
j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)
deps := j.collectDeps(ctx)
@@ -1039,8 +1038,7 @@
srcJars = append(srcJars, aaptSrcJar)
}
- // Collect source files from compiledJavaSrcs, compiledSrcJars and filter out Exclude_srcs
- // that IDEInfo struct will use
+ // Collect source files and filter out Exclude_srcs that IDEInfo struct will use
j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, srcFiles.Strings()...)
if j.properties.Jarjar_rules != nil {
@@ -1154,27 +1152,20 @@
if len(uniqueSrcFiles) > 0 {
shardSrcs = shardPaths(uniqueSrcFiles, shardSize)
for idx, shardSrc := range shardSrcs {
- classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(idx))
- TransformJavaToClasses(ctx, classes, idx, shardSrc, nil, flags, extraJarDeps)
+ classes := j.compileJavaClasses(ctx, jarName, idx, shardSrc,
+ nil, flags, extraJarDeps)
jars = append(jars, classes)
}
}
if len(srcJars) > 0 {
- classes := android.PathForModuleOut(ctx, "javac", jarName+strconv.Itoa(len(shardSrcs)))
- TransformJavaToClasses(ctx, classes, len(shardSrcs), nil, srcJars, flags, extraJarDeps)
+ classes := j.compileJavaClasses(ctx, jarName, len(shardSrcs),
+ nil, srcJars, flags, extraJarDeps)
jars = append(jars, classes)
}
} else {
- classes := android.PathForModuleOut(ctx, "javac", jarName)
- TransformJavaToClasses(ctx, classes, -1, uniqueSrcFiles, srcJars, flags, extraJarDeps)
+ classes := j.compileJavaClasses(ctx, jarName, -1, uniqueSrcFiles, srcJars, flags, extraJarDeps)
jars = append(jars, classes)
}
- if ctx.Config().EmitXrefRules() {
- extractionFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".kzip")
- emitXrefRule(ctx, extractionFile, uniqueSrcFiles, srcJars, flags, extraJarDeps, "xref")
- j.kytheFiles = append(j.kytheFiles, extractionFile)
-
- }
if ctx.Failed() {
return
}
@@ -1395,6 +1386,27 @@
j.outputFile = outputFile.WithoutRel()
}
+func (j *Module) compileJavaClasses(ctx android.ModuleContext, jarName string, idx int,
+ srcFiles, srcJars android.Paths, flags javaBuilderFlags, extraJarDeps android.Paths) android.WritablePath {
+
+ kzipName := pathtools.ReplaceExtension(jarName, "kzip")
+ if idx >= 0 {
+ kzipName = strings.TrimSuffix(jarName, filepath.Ext(jarName)) + strconv.Itoa(idx) + ".kzip"
+ jarName += strconv.Itoa(idx)
+ }
+
+ classes := android.PathForModuleOut(ctx, "javac", jarName)
+ TransformJavaToClasses(ctx, classes, idx, srcFiles, srcJars, flags, extraJarDeps)
+
+ if ctx.Config().EmitXrefRules() {
+ extractionFile := android.PathForModuleOut(ctx, kzipName)
+ emitXrefRule(ctx, extractionFile, idx, srcFiles, srcJars, flags, extraJarDeps)
+ j.kytheFiles = append(j.kytheFiles, extractionFile)
+ }
+
+ return classes
+}
+
// Check for invalid kotlinc flags. Only use this for flags explicitly passed by the user,
// since some of these flags may be used internally.
func CheckKotlincFlags(ctx android.ModuleContext, flags []string) {
diff --git a/java/java_test.go b/java/java_test.go
index 5fcdf96..a932319 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -66,6 +66,7 @@
ctx.RegisterModuleType("android_library", android.ModuleFactoryAdaptor(AndroidLibraryFactory))
ctx.RegisterModuleType("android_test", android.ModuleFactoryAdaptor(AndroidTestFactory))
ctx.RegisterModuleType("android_test_helper_app", android.ModuleFactoryAdaptor(AndroidTestHelperAppFactory))
+ ctx.RegisterModuleType("android_test_import", android.ModuleFactoryAdaptor(AndroidTestImportFactory))
ctx.RegisterModuleType("java_binary", android.ModuleFactoryAdaptor(BinaryFactory))
ctx.RegisterModuleType("java_binary_host", android.ModuleFactoryAdaptor(BinaryHostFactory))
ctx.RegisterModuleType("java_device_for_host", android.ModuleFactoryAdaptor(DeviceForHostFactory))
@@ -200,6 +201,8 @@
"cert/new_cert.x509.pem": nil,
"cert/new_cert.pk8": nil,
+
+ "testdata/data": nil,
}
for k, v := range fs {
@@ -1105,7 +1108,7 @@
checkPatchModuleFlag(t, ctx, "foo", "")
expected := "java.base=.:" + buildDir
checkPatchModuleFlag(t, ctx, "bar", expected)
- expected = "java.base=" + strings.Join([]string{".", buildDir, moduleToPath("ext"), moduleToPath("framework")}, ":")
+ expected = "java.base=" + strings.Join([]string{".", buildDir, moduleToPath("ext"), moduleToPath("framework"), moduleToPath("updatable_media_stubs")}, ":")
checkPatchModuleFlag(t, ctx, "baz", expected)
})
}
diff --git a/java/platform_compat_config.go b/java/platform_compat_config.go
index 792edf3..3d46077 100644
--- a/java/platform_compat_config.go
+++ b/java/platform_compat_config.go
@@ -23,8 +23,7 @@
}
type platformCompatConfigProperties struct {
- Src *string `android:"path"`
- Prefix *string
+ Src *string `android:"path"`
}
type platformCompatConfig struct {
@@ -38,13 +37,13 @@
func (p *platformCompatConfig) GenerateAndroidBuildActions(ctx android.ModuleContext) {
rule := android.NewRuleBuilder()
- configFileName := String(p.properties.Prefix) + "_platform_compat_config.xml"
+ configFileName := p.Name() + ".xml"
p.configFile = android.PathForModuleOut(ctx, configFileName).OutputPath
path := android.PathForModuleSrc(ctx, String(p.properties.Src))
// Use the empty config if the compat config file idoesn't exist (can happen if @ChangeId
// annotation is not used).
- emptyConfig := `<?xml version="1.0" encoding="UTF-8" standalone="no"?><config/>`
+ emptyConfig := `'<?xml version="1.0" encoding="UTF-8" standalone="no"?><config/>'`
configPath := `compat/compat_config.xml`
rule.Command().
@@ -61,13 +60,13 @@
Text(configPath).
Text(`>`).
Output(p.configFile).
- Text(`; else echo '`).
+ Text(`; else echo `).
Text(emptyConfig).
- Text(`' >`).
+ Text(`>`).
Output(p.configFile).
Text(`; fi`)
- p.installDirPath = android.PathForModuleInstall(ctx, "etc", "sysconfig")
+ p.installDirPath = android.PathForModuleInstall(ctx, "etc", "compatconfig")
rule.Build(pctx, ctx, configFileName, "Extract compat/compat_config.xml and install it")
}
@@ -77,9 +76,11 @@
Class: "ETC",
OutputFile: android.OptionalPathForPath(p.configFile),
Include: "$(BUILD_PREBUILT)",
- AddCustomEntries: func(name, prefix, moduleDir string, entries *android.AndroidMkEntries) {
- entries.SetString("LOCAL_MODULE_PATH", "$(OUT_DIR)/"+p.installDirPath.RelPathString())
- entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.configFile.Base())
+ ExtraEntries: []android.AndroidMkExtraEntriesFunc{
+ func(entries *android.AndroidMkEntries) {
+ entries.SetString("LOCAL_MODULE_PATH", "$(OUT_DIR)/"+p.installDirPath.RelPathString())
+ entries.SetString("LOCAL_INSTALLED_MODULE_STEM", p.configFile.Base())
+ },
},
}
}
diff --git a/java/robolectric.go b/java/robolectric.go
index 1de56a5..cbe3557 100644
--- a/java/robolectric.go
+++ b/java/robolectric.go
@@ -34,10 +34,17 @@
"truth-prebuilt",
}
+var (
+ roboCoverageLibsTag = dependencyTag{name: "roboSrcs"}
+)
+
type robolectricProperties struct {
// The name of the android_app module that the tests will run against.
Instrumentation_for *string
+ // Additional libraries for which coverage data should be generated
+ Coverage_libs []string
+
Test_options struct {
// Timeout in seconds when running the tests.
Timeout *int64
@@ -54,6 +61,8 @@
libs []string
tests []string
+
+ roboSrcJar android.Path
}
func (r *robolectricTest) DepsMutator(ctx android.BottomUpMutatorContext) {
@@ -66,11 +75,35 @@
}
ctx.AddVariationDependencies(nil, libTag, robolectricDefaultLibs...)
+
+ ctx.AddVariationDependencies(nil, roboCoverageLibsTag, r.robolectricProperties.Coverage_libs...)
}
func (r *robolectricTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ roboTestConfig := android.PathForModuleGen(ctx, "robolectric").
+ Join(ctx, "com/android/tools/test_config.properties")
+
+ // TODO: this inserts paths to built files into the test, it should really be inserting the contents.
+ instrumented := ctx.GetDirectDepsWithTag(instrumentationForTag)
+
+ if len(instrumented) != 1 {
+ panic(fmt.Errorf("expected exactly 1 instrumented dependency, got %d", len(instrumented)))
+ }
+
+ instrumentedApp, ok := instrumented[0].(*AndroidApp)
+ if !ok {
+ ctx.PropertyErrorf("instrumentation_for", "dependency must be an android_app")
+ }
+
+ generateRoboTestConfig(ctx, roboTestConfig, instrumentedApp)
+ r.extraResources = android.Paths{roboTestConfig}
+
r.Library.GenerateAndroidBuildActions(ctx)
+ roboSrcJar := android.PathForModuleGen(ctx, "robolectric", ctx.ModuleName()+".srcjar")
+ r.generateRoboSrcJar(ctx, roboSrcJar, instrumentedApp)
+ r.roboSrcJar = roboSrcJar
+
for _, dep := range ctx.GetDirectDepsWithTag(libTag) {
r.libs = append(r.libs, ctx.OtherModuleName(dep))
}
@@ -109,6 +142,41 @@
return ret
}
+func generateRoboTestConfig(ctx android.ModuleContext, outputFile android.WritablePath, instrumentedApp *AndroidApp) {
+ manifest := instrumentedApp.mergedManifestFile
+ resourceApk := instrumentedApp.outputFile
+
+ rule := android.NewRuleBuilder()
+
+ rule.Command().Text("rm -f").Output(outputFile)
+ rule.Command().
+ Textf(`echo "android_merged_manifest=%s" >>`, manifest.String()).Output(outputFile).Text("&&").
+ Textf(`echo "android_resource_apk=%s" >>`, resourceApk.String()).Output(outputFile).
+ // Make it depend on the files to which it points so the test file's timestamp is updated whenever the
+ // contents change
+ Implicit(manifest).
+ Implicit(resourceApk)
+
+ rule.Build(pctx, ctx, "generate_test_config", "generate test_config.properties")
+}
+
+func (r *robolectricTest) generateRoboSrcJar(ctx android.ModuleContext, outputFile android.WritablePath,
+ instrumentedApp *AndroidApp) {
+
+ srcJarArgs := copyOf(instrumentedApp.srcJarArgs)
+ srcJarDeps := append(android.Paths(nil), instrumentedApp.srcJarDeps...)
+
+ for _, m := range ctx.GetDirectDepsWithTag(roboCoverageLibsTag) {
+ if dep, ok := m.(Dependency); ok {
+ depSrcJarArgs, depSrcJarDeps := dep.SrcJarArgs()
+ srcJarArgs = append(srcJarArgs, depSrcJarArgs...)
+ srcJarDeps = append(srcJarDeps, depSrcJarDeps...)
+ }
+ }
+
+ TransformResourcesToJar(ctx, outputFile, srcJarArgs, srcJarDeps)
+}
+
func (r *robolectricTest) AndroidMk() android.AndroidMkData {
data := r.Library.AndroidMk()
@@ -144,6 +212,7 @@
fmt.Fprintln(w, "LOCAL_JAVA_LIBRARIES :=", module)
fmt.Fprintln(w, "LOCAL_JAVA_LIBRARIES += ", strings.Join(r.libs, " "))
fmt.Fprintln(w, "LOCAL_TEST_PACKAGE :=", String(r.robolectricProperties.Instrumentation_for))
+ fmt.Fprintln(w, "LOCAL_INSTRUMENT_SRCJARS :=", r.roboSrcJar.String())
fmt.Fprintln(w, "LOCAL_ROBOTEST_FILES :=", strings.Join(tests, " "))
if t := r.robolectricProperties.Test_options.Timeout; t != nil {
fmt.Fprintln(w, "LOCAL_ROBOTEST_TIMEOUT :=", *t)
diff --git a/java/sdk.go b/java/sdk.go
index d1e2ae4..3451774 100644
--- a/java/sdk.go
+++ b/java/sdk.go
@@ -19,7 +19,6 @@
"android/soong/java/config"
"fmt"
"path/filepath"
- "runtime"
"sort"
"strconv"
"strings"
@@ -349,15 +348,7 @@
cmd.Text("cat").
Inputs(android.PathsForSource(ctx, in)).
- Text("|")
-
- if runtime.GOOS == "darwin" {
- cmd.Text("md5")
- } else {
- cmd.Text("md5sum")
- }
-
- cmd.Text("| cut -d' ' -f1 >").
+ Text("| md5sum | cut -d' ' -f1 >").
Output(out)
} else {
// Unbundled build
diff --git a/java/sdk_library.go b/java/sdk_library.go
index d38088d..30fd1c4 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -100,16 +100,6 @@
// $(location <label>): the path to the droiddoc_option_files with name <label>
Droiddoc_options []string
- // the java library (in classpath) for documentation that provides java srcs and srcjars.
- Srcs_lib *string
-
- // the base dirs under srcs_lib will be scanned for java srcs.
- Srcs_lib_whitelist_dirs []string
-
- // the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs.
- // Defaults to "android.annotation".
- Srcs_lib_whitelist_pkgs []string
-
// a list of top-level directories containing files to merge qualifier annotations
// (i.e. those intended to be included in the stubs written) from.
Merge_annotations_dirs []string
@@ -442,9 +432,6 @@
Name *string
Srcs []string
Installable *bool
- Srcs_lib *string
- Srcs_lib_whitelist_dirs []string
- Srcs_lib_whitelist_pkgs []string
Sdk_version *string
Libs []string
Arg_files []string
@@ -534,9 +521,6 @@
props.Check_api.Last_released.Removed_api_file = proptools.StringPtr(
module.latestRemovedApiFilegroupName(apiScope))
props.Check_api.Ignore_missing_latest_api = proptools.BoolPtr(true)
- props.Srcs_lib = module.sdkLibraryProperties.Srcs_lib
- props.Srcs_lib_whitelist_dirs = module.sdkLibraryProperties.Srcs_lib_whitelist_dirs
- props.Srcs_lib_whitelist_pkgs = module.sdkLibraryProperties.Srcs_lib_whitelist_pkgs
mctx.CreateModule(android.ModuleFactoryAdaptor(DroidstubsFactory), &props)
}
@@ -550,9 +534,9 @@
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
-
+
http://www.apache.org/licenses/LICENSE-2.0
-
+
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
diff --git a/java/testing.go b/java/testing.go
index 5d116a7..a37c0a9 100644
--- a/java/testing.go
+++ b/java/testing.go
@@ -38,6 +38,7 @@
extraModules := []string{
"core-lambda-stubs",
"ext",
+ "updatable_media_stubs",
"android_stubs_current",
"android_system_stubs_current",
"android_test_stubs_current",
diff --git a/makedeps/Android.bp b/makedeps/Android.bp
new file mode 100644
index 0000000..b77b08f
--- /dev/null
+++ b/makedeps/Android.bp
@@ -0,0 +1,21 @@
+// Copyright 2019 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+bootstrap_go_package {
+ name: "soong-makedeps",
+ pkgPath: "android/soong/makedeps",
+ deps: ["androidmk-parser"],
+ srcs: ["deps.go"],
+ testSrcs: ["deps_test.go"],
+}
diff --git a/cmd/dep_fixer/deps.go b/makedeps/deps.go
similarity index 98%
rename from cmd/dep_fixer/deps.go
rename to makedeps/deps.go
index 64c97f5..e64e6f7 100644
--- a/cmd/dep_fixer/deps.go
+++ b/makedeps/deps.go
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package main
+package makedeps
import (
"bytes"
diff --git a/cmd/dep_fixer/deps_test.go b/makedeps/deps_test.go
similarity index 99%
rename from cmd/dep_fixer/deps_test.go
rename to makedeps/deps_test.go
index 0a779b7..a32df65 100644
--- a/cmd/dep_fixer/deps_test.go
+++ b/makedeps/deps_test.go
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package main
+package makedeps
import (
"bytes"
diff --git a/rust/androidmk.go b/rust/androidmk.go
new file mode 100644
index 0000000..c9056e1
--- /dev/null
+++ b/rust/androidmk.go
@@ -0,0 +1,155 @@
+// Copyright 2019 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package rust
+
+import (
+ "fmt"
+ "io"
+ "path/filepath"
+ "regexp"
+ "strings"
+
+ "android/soong/android"
+)
+
+type AndroidMkContext interface {
+ Name() string
+ Target() android.Target
+ subAndroidMk(*android.AndroidMkData, interface{})
+}
+
+type subAndroidMkProvider interface {
+ AndroidMk(AndroidMkContext, *android.AndroidMkData)
+}
+
+func (mod *Module) subAndroidMk(data *android.AndroidMkData, obj interface{}) {
+ if mod.subAndroidMkOnce == nil {
+ mod.subAndroidMkOnce = make(map[subAndroidMkProvider]bool)
+ }
+ if androidmk, ok := obj.(subAndroidMkProvider); ok {
+ if !mod.subAndroidMkOnce[androidmk] {
+ mod.subAndroidMkOnce[androidmk] = true
+ androidmk.AndroidMk(mod, data)
+ }
+ }
+}
+
+func (mod *Module) AndroidMk() android.AndroidMkData {
+ ret := android.AndroidMkData{
+ OutputFile: mod.outputFile,
+ Include: "$(BUILD_SYSTEM)/soong_rust_prebuilt.mk",
+ Extra: []android.AndroidMkExtraFunc{
+ func(w io.Writer, outputFile android.Path) {
+ if len(mod.Properties.AndroidMkRlibs) > 0 {
+ fmt.Fprintln(w, "LOCAL_RLIB_LIBRARIES := "+strings.Join(mod.Properties.AndroidMkRlibs, " "))
+ }
+ if len(mod.Properties.AndroidMkDylibs) > 0 {
+ fmt.Fprintln(w, "LOCAL_DYLIB_LIBRARIES := "+strings.Join(mod.Properties.AndroidMkDylibs, " "))
+ }
+ if len(mod.Properties.AndroidMkProcMacroLibs) > 0 {
+ fmt.Fprintln(w, "LOCAL_PROC_MACRO_LIBRARIES := "+strings.Join(mod.Properties.AndroidMkProcMacroLibs, " "))
+ }
+ if len(mod.Properties.AndroidMkSharedLibs) > 0 {
+ fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES := "+strings.Join(mod.Properties.AndroidMkSharedLibs, " "))
+ }
+ if len(mod.Properties.AndroidMkStaticLibs) > 0 {
+ fmt.Fprintln(w, "LOCAL_STATIC_LIBRARIES := "+strings.Join(mod.Properties.AndroidMkStaticLibs, " "))
+ }
+ },
+ },
+ }
+
+ mod.subAndroidMk(&ret, mod.compiler)
+
+ return ret
+}
+
+func (binary *binaryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
+ ctx.subAndroidMk(ret, binary.baseCompiler)
+
+ ret.Class = "EXECUTABLES"
+ ret.DistFile = binary.distFile
+ ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
+ fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", binary.unstrippedOutputFile.String())
+ })
+}
+
+func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
+ ctx.subAndroidMk(ret, library.baseCompiler)
+
+ if library.rlib() {
+ ret.Class = "RLIB_LIBRARIES"
+ } else if library.dylib() {
+ ret.Class = "DYLIB_LIBRARIES"
+ }
+ ret.DistFile = library.distFile
+ ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
+ if !library.rlib() {
+ fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", library.unstrippedOutputFile.String())
+ }
+ })
+}
+
+func (procMacro *procMacroDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
+ ctx.subAndroidMk(ret, procMacro.baseCompiler)
+
+ ret.Class = "PROC_MACRO_LIBRARIES"
+ ret.DistFile = procMacro.distFile
+
+}
+
+func (compiler *baseCompiler) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
+ // Soong installation is only supported for host modules. Have Make
+ // installation trigger Soong installation.
+ if ctx.Target().Os.Class == android.Host {
+ ret.OutputFile = android.OptionalPathForPath(compiler.path)
+ }
+ ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
+ path := compiler.path.RelPathString()
+ dir, file := filepath.Split(path)
+ stem, suffix, _ := splitFileExt(file)
+ fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix)
+ fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir))
+ fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem)
+ })
+}
+
+//TODO: splitFileExt copied from cc/util.go; move this to android/util.go and refactor usages.
+
+// splitFileExt splits a file name into root, suffix and ext. root stands for the file name without
+// the file extension and the version number (e.g. "libexample"). suffix stands for the
+// concatenation of the file extension and the version number (e.g. ".so.1.0"). ext stands for the
+// file extension after the version numbers are trimmed (e.g. ".so").
+var shlibVersionPattern = regexp.MustCompile("(?:\\.\\d+(?:svn)?)+")
+
+func splitFileExt(name string) (string, string, string) {
+ // Extract and trim the shared lib version number if the file name ends with dot digits.
+ suffix := ""
+ matches := shlibVersionPattern.FindAllStringIndex(name, -1)
+ if len(matches) > 0 {
+ lastMatch := matches[len(matches)-1]
+ if lastMatch[1] == len(name) {
+ suffix = name[lastMatch[0]:lastMatch[1]]
+ name = name[0:lastMatch[0]]
+ }
+ }
+
+ // Extract the file name root and the file extension.
+ ext := filepath.Ext(name)
+ root := strings.TrimSuffix(name, ext)
+ suffix = ext + suffix
+
+ return root, suffix, ext
+}
diff --git a/rust/binary.go b/rust/binary.go
new file mode 100644
index 0000000..279c6f5
--- /dev/null
+++ b/rust/binary.go
@@ -0,0 +1,110 @@
+// Copyright 2019 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package rust
+
+import (
+ "android/soong/android"
+ "android/soong/rust/config"
+)
+
+func init() {
+ android.RegisterModuleType("rust_binary", RustBinaryFactory)
+ android.RegisterModuleType("rust_binary_host", RustBinaryHostFactory)
+}
+
+type BinaryCompilerProperties struct {
+ // path to the main source file that contains the program entry point (e.g. src/main.rs)
+ Srcs []string `android:"path,arch_variant"`
+
+ // passes -C prefer-dynamic to rustc, which tells it to dynamically link the stdlib (assuming it has no dylib dependencies already)
+ Prefer_dynamic *bool
+}
+
+type binaryDecorator struct {
+ *baseCompiler
+
+ Properties BinaryCompilerProperties
+ distFile android.OptionalPath
+ unstrippedOutputFile android.Path
+}
+
+var _ compiler = (*binaryDecorator)(nil)
+
+// rust_binary produces a binary that is runnable on a device.
+func RustBinaryFactory() android.Module {
+ module, _ := NewRustBinary(android.HostAndDeviceSupported)
+ return module.Init()
+}
+
+func RustBinaryHostFactory() android.Module {
+ module, _ := NewRustBinary(android.HostSupported)
+ return module.Init()
+}
+
+func NewRustBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) {
+ module := newModule(hod, android.MultilibFirst)
+
+ binary := &binaryDecorator{
+ baseCompiler: NewBaseCompiler("bin", ""),
+ }
+
+ module.compiler = binary
+
+ return module, binary
+}
+
+func (binary *binaryDecorator) preferDynamic() bool {
+ return Bool(binary.Properties.Prefer_dynamic)
+}
+
+func (binary *binaryDecorator) compilerFlags(ctx ModuleContext, flags Flags) Flags {
+ flags = binary.baseCompiler.compilerFlags(ctx, flags)
+ if binary.preferDynamic() {
+ flags.RustFlags = append(flags.RustFlags, "-C prefer-dynamic")
+ }
+ return flags
+}
+
+func (binary *binaryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {
+ deps = binary.baseCompiler.compilerDeps(ctx, deps)
+
+ if binary.preferDynamic() || len(deps.Dylibs) > 0 {
+ for _, stdlib := range config.Stdlibs {
+ deps.Dylibs = append(deps.Dylibs, stdlib+"_"+ctx.toolchain().RustTriple())
+ }
+ }
+
+ return deps
+}
+
+func (binary *binaryDecorator) compilerProps() []interface{} {
+ return append(binary.baseCompiler.compilerProps(),
+ &binary.Properties)
+}
+
+func (binary *binaryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path {
+ fileName := binary.getStem(ctx) + ctx.toolchain().ExecutableSuffix()
+
+ srcPath := srcPathFromModuleSrcs(ctx, binary.Properties.Srcs)
+
+ outputFile := android.PathForModuleOut(ctx, fileName)
+ binary.unstrippedOutputFile = outputFile
+
+ flags.RustFlags = append(flags.RustFlags, deps.depFlags...)
+
+ TransformSrcToBinary(ctx, srcPath, deps, flags, outputFile, deps.linkDirs)
+
+ return outputFile
+}
diff --git a/rust/binary_test.go b/rust/binary_test.go
new file mode 100644
index 0000000..cd41fcf
--- /dev/null
+++ b/rust/binary_test.go
@@ -0,0 +1,46 @@
+// Copyright 2019 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package rust
+
+import (
+ "strings"
+ "testing"
+)
+
+// Test that the prefer_dynamic property is handled correctly.
+func TestPreferDynamicBinary(t *testing.T) {
+ ctx := testRust(t, `
+ rust_binary_host {
+ name: "fizz-buzz-dynamic",
+ srcs: ["foo.rs"],
+ prefer_dynamic: true,
+ }
+
+ rust_binary_host {
+ name: "fizz-buzz",
+ srcs: ["foo.rs"],
+ }`)
+
+ fizzBuzz := ctx.ModuleForTests("fizz-buzz", "linux_glibc_x86_64").Output("fizz-buzz")
+ fizzBuzzDynamic := ctx.ModuleForTests("fizz-buzz-dynamic", "linux_glibc_x86_64").Output("fizz-buzz-dynamic")
+
+ if !strings.Contains(fizzBuzzDynamic.Args["rustcFlags"], "prefer-dynamic") {
+ t.Errorf("missing prefer-dynamic flag, rustcFlags: %#v", fizzBuzzDynamic.Args["rustcFlags"])
+ }
+
+ if strings.Contains(fizzBuzz.Args["rustcFlags"], "prefer-dynamic") {
+ t.Errorf("unexpected prefer-dynamic flag, rustcFlags: %#v", fizzBuzz.Args["rustcFlags"])
+ }
+}
diff --git a/rust/builder.go b/rust/builder.go
new file mode 100644
index 0000000..64e387b
--- /dev/null
+++ b/rust/builder.go
@@ -0,0 +1,132 @@
+// Copyright 2019 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package rust
+
+import (
+ "strings"
+
+ "github.com/google/blueprint"
+
+ "android/soong/android"
+)
+
+var (
+ _ = pctx.SourcePathVariable("rustcCmd", "${config.RustBin}/rustc")
+ rustc = pctx.AndroidStaticRule("rustc",
+ blueprint.RuleParams{
+ Command: "$rustcCmd " +
+ "-C linker=${config.RustLinker} " +
+ "-C link-args=\"${config.RustLinkerArgs} ${linkFlags}\" " +
+ "-o $out $in ${libFlags} $rustcFlags " +
+ "&& $rustcCmd --emit=dep-info -o $out.d $in ${libFlags} $rustcFlags",
+ CommandDeps: []string{"$rustcCmd"},
+ Depfile: "$out.d",
+ Deps: blueprint.DepsGCC, // Rustc deps-info writes out make compatible dep files: https://github.com/rust-lang/rust/issues/7633
+ },
+ "rustcFlags", "linkFlags", "libFlags")
+)
+
+func init() {
+
+}
+
+func TransformSrcToBinary(ctx android.ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags, outputFile android.WritablePath, includeDirs []string) {
+ targetTriple := ctx.(ModuleContext).toolchain().RustTriple()
+
+ transformSrctoCrate(ctx, mainSrc, deps.RLibs, deps.DyLibs, deps.ProcMacros, deps.StaticLibs, deps.SharedLibs, flags, outputFile, "bin", includeDirs, targetTriple)
+}
+
+func TransformSrctoRlib(ctx android.ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags, outputFile android.WritablePath, includeDirs []string) {
+ targetTriple := ctx.(ModuleContext).toolchain().RustTriple()
+
+ transformSrctoCrate(ctx, mainSrc, deps.RLibs, deps.DyLibs, deps.ProcMacros, deps.StaticLibs, deps.SharedLibs, flags, outputFile, "rlib", includeDirs, targetTriple)
+}
+
+func TransformSrctoDylib(ctx android.ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags, outputFile android.WritablePath, includeDirs []string) {
+ targetTriple := ctx.(ModuleContext).toolchain().RustTriple()
+
+ transformSrctoCrate(ctx, mainSrc, deps.RLibs, deps.DyLibs, deps.ProcMacros, deps.StaticLibs, deps.SharedLibs, flags, outputFile, "dylib", includeDirs, targetTriple)
+}
+
+func TransformSrctoProcMacro(ctx android.ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags, outputFile android.WritablePath, includeDirs []string) {
+ // Proc macros are compiler plugins, and thus should target the host compiler
+ targetTriple := ""
+
+ transformSrctoCrate(ctx, mainSrc, deps.RLibs, deps.DyLibs, deps.ProcMacros, deps.StaticLibs, deps.SharedLibs, flags, outputFile, "proc-macro", includeDirs, targetTriple)
+}
+
+func rustLibsToPaths(libs RustLibraries) android.Paths {
+ var paths android.Paths
+ for _, lib := range libs {
+ paths = append(paths, lib.Path)
+ }
+ return paths
+}
+
+func transformSrctoCrate(ctx android.ModuleContext, main android.Path,
+ rlibs, dylibs, proc_macros RustLibraries, static_libs, shared_libs android.Paths, flags Flags, outputFile android.WritablePath, crate_type string, includeDirs []string, targetTriple string) {
+
+ var inputs android.Paths
+ var deps android.Paths
+ var libFlags, rustcFlags []string
+ crate_name := ctx.(ModuleContext).CrateName()
+
+ inputs = append(inputs, main)
+
+ // Collect rustc flags
+ rustcFlags = append(rustcFlags, flags.GlobalFlags...)
+ rustcFlags = append(rustcFlags, flags.RustFlags...)
+ rustcFlags = append(rustcFlags, "--crate-type="+crate_type)
+ rustcFlags = append(rustcFlags, "--crate-name="+crate_name)
+ if targetTriple != "" {
+ rustcFlags = append(rustcFlags, "--target="+targetTriple)
+ }
+
+ // Collect library/crate flags
+ for _, lib := range rlibs {
+ libFlags = append(libFlags, "--extern "+lib.CrateName+"="+lib.Path.String())
+ }
+ for _, lib := range dylibs {
+ libFlags = append(libFlags, "--extern "+lib.CrateName+"="+lib.Path.String())
+ }
+ for _, proc_macro := range proc_macros {
+ libFlags = append(libFlags, "--extern "+proc_macro.CrateName+"="+proc_macro.Path.String())
+ }
+
+ for _, path := range includeDirs {
+ libFlags = append(libFlags, "-L "+path)
+ }
+
+ // Collect dependencies
+ deps = append(deps, rustLibsToPaths(rlibs)...)
+ deps = append(deps, rustLibsToPaths(dylibs)...)
+ deps = append(deps, rustLibsToPaths(proc_macros)...)
+ deps = append(deps, static_libs...)
+ deps = append(deps, shared_libs...)
+
+ ctx.Build(pctx, android.BuildParams{
+ Rule: rustc,
+ Description: "rustc " + main.Rel(),
+ Output: outputFile,
+ Inputs: inputs,
+ Implicits: deps,
+ Args: map[string]string{
+ "rustcFlags": strings.Join(rustcFlags, " "),
+ "linkFlags": strings.Join(flags.LinkFlags, " "),
+ "libFlags": strings.Join(libFlags, " "),
+ },
+ })
+
+}
diff --git a/rust/compiler.go b/rust/compiler.go
new file mode 100644
index 0000000..87cf08b
--- /dev/null
+++ b/rust/compiler.go
@@ -0,0 +1,193 @@
+// Copyright 2019 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package rust
+
+import (
+ "fmt"
+ "path/filepath"
+
+ "android/soong/android"
+ "android/soong/rust/config"
+)
+
+func NewBaseCompiler(dir, dir64 string) *baseCompiler {
+ return &baseCompiler{
+ Properties: BaseCompilerProperties{
+ Edition: &config.DefaultEdition,
+ },
+ dir: dir,
+ dir64: dir64,
+ }
+}
+
+type BaseCompilerProperties struct {
+ // flags to pass to rustc
+ Flags []string `android:"path,arch_variant"`
+
+ // flags to pass to the linker
+ Ld_flags []string `android:"path,arch_variant"`
+
+ // list of rust rlib crate dependencies
+ Rlibs []string `android:"arch_variant"`
+
+ // list of rust dylib crate dependencies
+ Dylibs []string `android:"arch_variant"`
+
+ // list of rust proc_macro crate dependencies
+ Proc_macros []string `android:"arch_variant"`
+
+ // list of C shared library dependencies
+ Shared_libs []string `android:"arch_variant"`
+
+ // list of C static library dependencies
+ Static_libs []string `android:"arch_variant"`
+
+ // crate name (defaults to module name); if library, this must be the expected extern crate name
+ Crate_name string `android:"arch_variant"`
+
+ // list of features to enable for this crate
+ Features []string `android:"arch_variant"`
+
+ // specific rust edition that should be used if the default version is not desired
+ Edition *string `android:"arch_variant"`
+
+ // sets name of the output
+ Stem *string `android:"arch_variant"`
+
+ // append to name of output
+ Suffix *string `android:"arch_variant"`
+
+ // install to a subdirectory of the default install path for the module
+ Relative_install_path *string `android:"arch_variant"`
+}
+
+type baseCompiler struct {
+ Properties BaseCompilerProperties
+ pathDeps android.Paths
+ rustFlagsDeps android.Paths
+ linkFlagsDeps android.Paths
+ flags string
+ linkFlags string
+ depFlags []string
+ linkDirs []string
+ edition string
+ src android.Path //rustc takes a single src file
+
+ // Install related
+ dir string
+ dir64 string
+ subDir string
+ relative string
+ path android.OutputPath
+}
+
+var _ compiler = (*baseCompiler)(nil)
+
+func (compiler *baseCompiler) compilerProps() []interface{} {
+ return []interface{}{&compiler.Properties}
+}
+
+func (compiler *baseCompiler) featuresToFlags(features []string) []string {
+ flags := []string{}
+ for _, feature := range features {
+ flags = append(flags, "--cfg 'feature=\""+feature+"\"'")
+ }
+ return flags
+}
+
+func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flags {
+
+ flags.RustFlags = append(flags.RustFlags, compiler.Properties.Flags...)
+ flags.RustFlags = append(flags.RustFlags, compiler.featuresToFlags(compiler.Properties.Features)...)
+ flags.RustFlags = append(flags.RustFlags, "--edition="+*compiler.Properties.Edition)
+ flags.LinkFlags = append(flags.LinkFlags, compiler.Properties.Ld_flags...)
+ flags.GlobalFlags = append(flags.GlobalFlags, ctx.toolchain().ToolchainRustFlags())
+
+ if ctx.Host() && !ctx.Windows() {
+ rpath_prefix := `\$$ORIGIN/`
+ if ctx.Darwin() {
+ rpath_prefix = "@loader_path/"
+ }
+
+ var rpath string
+ if ctx.toolchain().Is64Bit() {
+ rpath = "lib64"
+ } else {
+ rpath = "lib"
+ }
+ flags.LinkFlags = append(flags.LinkFlags, "-Wl,-rpath,"+rpath_prefix+rpath)
+ flags.LinkFlags = append(flags.LinkFlags, "-Wl,-rpath,"+rpath_prefix+"../"+rpath)
+ }
+
+ return flags
+}
+
+func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path {
+ panic(fmt.Errorf("baseCrater doesn't know how to crate things!"))
+}
+
+func (compiler *baseCompiler) compilerDeps(ctx DepsContext, deps Deps) Deps {
+ deps.Rlibs = append(deps.Rlibs, compiler.Properties.Rlibs...)
+ deps.Dylibs = append(deps.Dylibs, compiler.Properties.Dylibs...)
+ deps.ProcMacros = append(deps.ProcMacros, compiler.Properties.Proc_macros...)
+ deps.StaticLibs = append(deps.StaticLibs, compiler.Properties.Static_libs...)
+ deps.SharedLibs = append(deps.SharedLibs, compiler.Properties.Shared_libs...)
+
+ return deps
+}
+
+func (compiler *baseCompiler) crateName() string {
+ return compiler.Properties.Crate_name
+}
+
+func (compiler *baseCompiler) installDir(ctx ModuleContext) android.OutputPath {
+ dir := compiler.dir
+ if ctx.toolchain().Is64Bit() && compiler.dir64 != "" {
+ dir = compiler.dir64
+ }
+ if (!ctx.Host() && !ctx.Arch().Native) || ctx.Target().NativeBridge == android.NativeBridgeEnabled {
+ dir = filepath.Join(dir, ctx.Arch().ArchType.String())
+ }
+ return android.PathForModuleInstall(ctx, dir, compiler.subDir,
+ compiler.relativeInstallPath(), compiler.relative)
+}
+
+func (compiler *baseCompiler) install(ctx ModuleContext, file android.Path) {
+ compiler.path = ctx.InstallFile(compiler.installDir(ctx), file.Base(), file)
+}
+
+func (compiler *baseCompiler) getStem(ctx ModuleContext) string {
+ return compiler.getStemWithoutSuffix(ctx) + String(compiler.Properties.Suffix)
+}
+
+func (compiler *baseCompiler) getStemWithoutSuffix(ctx BaseModuleContext) string {
+ stem := ctx.baseModuleName()
+ if String(compiler.Properties.Stem) != "" {
+ stem = String(compiler.Properties.Stem)
+ }
+
+ return stem
+}
+func (compiler *baseCompiler) relativeInstallPath() string {
+ return String(compiler.Properties.Relative_install_path)
+}
+
+func srcPathFromModuleSrcs(ctx ModuleContext, srcs []string) android.Path {
+ srcPaths := android.PathsForModuleSrc(ctx, srcs)
+ if len(srcPaths) != 1 {
+ ctx.PropertyErrorf("srcs", "srcs can only contain one path for rust modules")
+ }
+ return srcPaths[0]
+}
diff --git a/rust/compiler_test.go b/rust/compiler_test.go
new file mode 100644
index 0000000..5369096
--- /dev/null
+++ b/rust/compiler_test.go
@@ -0,0 +1,77 @@
+// Copyright 2019 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package rust
+
+import (
+ "strings"
+ "testing"
+)
+
+// Test that feature flags are being correctly generated.
+func TestFeaturesToFlags(t *testing.T) {
+ ctx := testRust(t, `
+ rust_library_host_dylib {
+ name: "libfoo",
+ srcs: ["foo.rs"],
+ crate_name: "foo",
+ features: [
+ "fizz",
+ "buzz"
+ ],
+ }`)
+
+ libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib").Rule("rustc")
+
+ if !strings.Contains(libfooDylib.Args["rustcFlags"], "cfg 'feature=\"fizz\"'") ||
+ !strings.Contains(libfooDylib.Args["rustcFlags"], "cfg 'feature=\"buzz\"'") {
+ t.Fatalf("missing fizz and buzz feature flags for libfoo dylib, rustcFlags: %#v", libfooDylib.Args["rustcFlags"])
+ }
+}
+
+// Test that we reject multiple source files.
+func TestEnforceSingleSourceFile(t *testing.T) {
+
+ singleSrcError := "srcs can only contain one path for rust modules"
+
+ // Test libraries
+ testRustError(t, singleSrcError, `
+ rust_library_host {
+ name: "foo-bar-library",
+ srcs: ["foo.rs", "src/bar.rs"],
+ }`)
+
+ // Test binaries
+ testRustError(t, singleSrcError, `
+ rust_binary_host {
+ name: "foo-bar-binary",
+ srcs: ["foo.rs", "src/bar.rs"],
+ }`)
+
+ // Test proc_macros
+ testRustError(t, singleSrcError, `
+ rust_proc_macro {
+ name: "foo-bar-proc-macro",
+ srcs: ["foo.rs", "src/bar.rs"],
+ host_supported: true,
+ }`)
+
+ // Test prebuilts
+ testRustError(t, singleSrcError, `
+ rust_prebuilt_dylib {
+ name: "foo-bar-prebuilt",
+ srcs: ["liby.so", "libz.so"],
+ host_supported: true,
+ }`)
+}
diff --git a/rust/config/global.go b/rust/config/global.go
new file mode 100644
index 0000000..2e08a8c
--- /dev/null
+++ b/rust/config/global.go
@@ -0,0 +1,65 @@
+// Copyright 2019 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package config
+
+import (
+ "android/soong/android"
+ _ "android/soong/cc/config"
+)
+
+var pctx = android.NewPackageContext("android/soong/rust/config")
+
+var (
+ RustDefaultVersion = "1.35.0"
+ RustDefaultBase = "prebuilts/rust/"
+ DefaultEdition = "2018"
+ Stdlibs = []string{
+ "libarena",
+ "libfmt_macros",
+ "libgraphviz",
+ "libserialize",
+ "libstd",
+ "libsyntax",
+ "libsyntax_ext",
+ "libsyntax_pos",
+ "libterm",
+ }
+)
+
+func init() {
+ pctx.SourcePathVariable("RustDefaultBase", RustDefaultBase)
+ pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
+
+ pctx.VariableFunc("RustBase", func(ctx android.PackageVarContext) string {
+ if override := ctx.Config().Getenv("RUST_PREBUILTS_BASE"); override != "" {
+ return override
+ }
+ return "${RustDefaultBase}"
+ })
+
+ pctx.VariableFunc("RustVersion", func(ctx android.PackageVarContext) string {
+ if override := ctx.Config().Getenv("RUST_PREBUILTS_VERSION"); override != "" {
+ return override
+ }
+ return RustDefaultVersion
+ })
+
+ pctx.StaticVariable("RustPath", "${RustBase}/${HostPrebuiltTag}/${RustVersion}")
+ pctx.StaticVariable("RustBin", "${RustPath}/bin")
+
+ pctx.ImportAs("ccConfig", "android/soong/cc/config")
+ pctx.StaticVariable("RustLinker", "${ccConfig.ClangBin}/clang++")
+ pctx.StaticVariable("RustLinkerArgs", "-B ${ccConfig.ClangBin} -fuse-ld=lld")
+}
diff --git a/rust/config/toolchain.go b/rust/config/toolchain.go
new file mode 100644
index 0000000..a36d61b
--- /dev/null
+++ b/rust/config/toolchain.go
@@ -0,0 +1,124 @@
+// Copyright 2019 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package config
+
+import (
+ "android/soong/android"
+)
+
+type Toolchain interface {
+ RustTriple() string
+ ToolchainRustFlags() string
+ ToolchainLinkFlags() string
+
+ SharedLibSuffix() string
+ StaticLibSuffix() string
+ RlibSuffix() string
+ DylibSuffix() string
+ ProcMacroSuffix() string
+ ExecutableSuffix() string
+
+ Is64Bit() bool
+ Supported() bool
+}
+
+type toolchainBase struct {
+}
+
+func (toolchainBase) RustTriple() string {
+ panic("toolchainBase does not define a triple.")
+}
+
+func (toolchainBase) ToolchainRustFlags() string {
+ panic("toolchainBase does not provide rust flags.")
+}
+
+func (toolchainBase) ToolchainLinkFlags() string {
+ panic("toolchainBase does not provide link flags.")
+}
+
+func (toolchainBase) Is64Bit() bool {
+ panic("toolchainBase cannot determine datapath width.")
+}
+
+type toolchain64Bit struct {
+ toolchainBase
+}
+
+func (toolchain64Bit) Is64Bit() bool {
+ return true
+}
+
+type toolchain32Bit struct {
+ toolchainBase
+}
+
+func (toolchain32Bit) Is64Bit() bool {
+ return false
+}
+
+func (toolchain32Bit) Bionic() bool {
+ return true
+}
+
+func (toolchainBase) ExecutableSuffix() string {
+ return ""
+}
+
+func (toolchainBase) SharedLibSuffix() string {
+ return ".so"
+}
+
+func (toolchainBase) StaticLibSuffix() string {
+ return ".a"
+}
+
+func (toolchainBase) RlibSuffix() string {
+ return ".rlib"
+}
+func (toolchainBase) DylibSuffix() string {
+ return ".so"
+}
+
+func (toolchainBase) ProcMacroSuffix() string {
+ return ".so"
+}
+
+func (toolchainBase) Supported() bool {
+ return false
+}
+
+func toolchainBaseFactory() Toolchain {
+ return &toolchainBase{}
+}
+
+type toolchainFactory func(arch android.Arch) Toolchain
+
+var toolchainFactories = make(map[android.OsType]map[android.ArchType]toolchainFactory)
+
+func registerToolchainFactory(os android.OsType, arch android.ArchType, factory toolchainFactory) {
+ if toolchainFactories[os] == nil {
+ toolchainFactories[os] = make(map[android.ArchType]toolchainFactory)
+ }
+ toolchainFactories[os][arch] = factory
+}
+
+func FindToolchain(os android.OsType, arch android.Arch) Toolchain {
+ factory := toolchainFactories[os][arch.ArchType]
+ if factory == nil {
+ return toolchainBaseFactory()
+ }
+ return factory(arch)
+}
diff --git a/rust/config/x86_64_device.go b/rust/config/x86_64_device.go
new file mode 100644
index 0000000..2aca56a
--- /dev/null
+++ b/rust/config/x86_64_device.go
@@ -0,0 +1,88 @@
+// Copyright 2019 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package config
+
+import (
+ "strings"
+
+ "android/soong/android"
+)
+
+var (
+ x86_64RustFlags = []string{}
+ x86_64ArchFeatureRustFlags = map[string][]string{}
+ x86_64LinkFlags = []string{}
+
+ x86_64ArchVariantRustFlags = map[string][]string{
+ "": []string{},
+ "broadwell": []string{"-C target-cpu=broadwell"},
+ "haswell": []string{"-C target-cpu=haswell"},
+ "ivybridge": []string{"-C target-cpu=ivybridge"},
+ "sandybridge": []string{"-C target-cpu=sandybridge"},
+ "silvermont": []string{"-C target-cpu=silvermont"},
+ "skylake": []string{"-C target-cpu=skylake"},
+ //TODO: Add target-cpu=stoneyridge when rustc supports it.
+ "stoneyridge": []string{""},
+ }
+)
+
+func init() {
+ registerToolchainFactory(android.Android, android.X86_64, x86_64ToolchainFactory)
+
+ pctx.StaticVariable("x86_64ToolchainRustFlags", strings.Join(x86_64RustFlags, " "))
+ pctx.StaticVariable("x86_64ToolchainLinkFlags", strings.Join(x86_64LinkFlags, " "))
+
+ for variant, rustFlags := range x86_64ArchVariantRustFlags {
+ pctx.StaticVariable("X86_64"+variant+"VariantRustFlags",
+ strings.Join(rustFlags, " "))
+ }
+
+}
+
+type toolchainX86_64 struct {
+ toolchain64Bit
+ toolchainRustFlags string
+}
+
+func (t *toolchainX86_64) RustTriple() string {
+ return "x86_64-unknown-linux-gnu"
+}
+
+func (t *toolchainX86_64) ToolchainLinkFlags() string {
+ return "${config.x86_64ToolchainLinkFlags}"
+}
+
+func (t *toolchainX86_64) ToolchainRustFlags() string {
+ return t.toolchainRustFlags
+}
+
+func (t *toolchainX86_64) RustFlags() string {
+ return "${config.x86_64ToolchainRustFlags}"
+}
+
+func x86_64ToolchainFactory(arch android.Arch) Toolchain {
+ toolchainRustFlags := []string{
+ "${config.x86_64ToolchainRustFlags}",
+ "${config.X86_64" + arch.ArchVariant + "VariantRustFlags}",
+ }
+
+ for _, feature := range arch.ArchFeatures {
+ toolchainRustFlags = append(toolchainRustFlags, x86_64ArchFeatureRustFlags[feature]...)
+ }
+
+ return &toolchainX86_64{
+ toolchainRustFlags: strings.Join(toolchainRustFlags, " "),
+ }
+}
diff --git a/rust/config/x86_linux_host.go b/rust/config/x86_linux_host.go
new file mode 100644
index 0000000..cb6bf1a
--- /dev/null
+++ b/rust/config/x86_linux_host.go
@@ -0,0 +1,109 @@
+// Copyright 2019 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package config
+
+import (
+ "strings"
+
+ "android/soong/android"
+)
+
+var (
+ LinuxRustFlags = []string{}
+ LinuxRustLinkFlags = []string{}
+ linuxX86Rustflags = []string{}
+ linuxX86Linkflags = []string{}
+ linuxX8664Rustflags = []string{}
+ linuxX8664Linkflags = []string{}
+)
+
+func init() {
+ registerToolchainFactory(android.Linux, android.X86_64, linuxX8664ToolchainFactory)
+ registerToolchainFactory(android.Linux, android.X86, linuxX86ToolchainFactory)
+
+ pctx.StaticVariable("LinuxToolchainRustFlags", strings.Join(LinuxRustFlags, " "))
+ pctx.StaticVariable("LinuxToolchainLinkFlags", strings.Join(LinuxRustLinkFlags, " "))
+ pctx.StaticVariable("LinuxToolchainX86RustFlags", strings.Join(linuxX86Rustflags, " "))
+ pctx.StaticVariable("LinuxToolchainX86LinkFlags", strings.Join(linuxX86Linkflags, " "))
+ pctx.StaticVariable("LinuxToolchainX8664RustFlags", strings.Join(linuxX8664Rustflags, " "))
+ pctx.StaticVariable("LinuxToolchainX8664LinkFlags", strings.Join(linuxX8664Linkflags, " "))
+
+}
+
+type toolchainLinux struct {
+ toolchainRustFlags string
+ toolchainLinkFlags string
+}
+
+type toolchainLinuxX86 struct {
+ toolchain32Bit
+ toolchainLinux
+}
+
+type toolchainLinuxX8664 struct {
+ toolchain64Bit
+ toolchainLinux
+}
+
+func (toolchainLinuxX8664) Supported() bool {
+ return true
+}
+
+func (t *toolchainLinuxX8664) Name() string {
+ return "x86_64"
+}
+
+func (t *toolchainLinuxX8664) RustTriple() string {
+ return "x86_64-unknown-linux-gnu"
+}
+
+func (t *toolchainLinuxX8664) ToolchainLinkFlags() string {
+ return "${config.LinuxToolchainLinkFlags} ${config.LinuxToolchainX8664LinkFlags}"
+}
+
+func (t *toolchainLinuxX8664) ToolchainRustFlags() string {
+ return "${config.LinuxToolchainRustFlags} ${config.LinuxToolchainX8664RustFlags}"
+}
+
+func linuxX8664ToolchainFactory(arch android.Arch) Toolchain {
+ return toolchainLinuxX8664Singleton
+}
+
+func (toolchainLinuxX86) Supported() bool {
+ return true
+}
+
+func (t *toolchainLinuxX86) Name() string {
+ return "x86"
+}
+
+func (t *toolchainLinuxX86) RustTriple() string {
+ return "i686-unknown-linux-gnu"
+}
+
+func (t *toolchainLinuxX86) ToolchainLinkFlags() string {
+ return "${config.LinuxToolchainLinkFlags} ${config.LinuxToolchainX86LinkFlags}"
+}
+
+func (t *toolchainLinuxX86) ToolchainRustFlags() string {
+ return "${config.LinuxToolchainRustFlags} ${config.LinuxToolchainX86RustFlags}"
+}
+
+func linuxX86ToolchainFactory(arch android.Arch) Toolchain {
+ return toolchainLinuxX86Singleton
+}
+
+var toolchainLinuxX8664Singleton Toolchain = &toolchainLinuxX8664{}
+var toolchainLinuxX86Singleton Toolchain = &toolchainLinuxX86{}
diff --git a/rust/library.go b/rust/library.go
new file mode 100644
index 0000000..5cf8ac7
--- /dev/null
+++ b/rust/library.go
@@ -0,0 +1,245 @@
+// Copyright 2019 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package rust
+
+import (
+ "android/soong/android"
+)
+
+func init() {
+ android.RegisterModuleType("rust_library", RustLibraryFactory)
+ android.RegisterModuleType("rust_library_dylib", RustLibraryDylibFactory)
+ android.RegisterModuleType("rust_library_rlib", RustLibraryRlibFactory)
+ android.RegisterModuleType("rust_library_host", RustLibraryHostFactory)
+ android.RegisterModuleType("rust_library_host_dylib", RustLibraryDylibHostFactory)
+ android.RegisterModuleType("rust_library_host_rlib", RustLibraryRlibHostFactory)
+
+ //TODO: Add support for generating standard shared/static libraries.
+}
+
+type VariantLibraryProperties struct {
+ Enabled *bool `android:"arch_variant"`
+}
+
+type LibraryCompilerProperties struct {
+ Rlib VariantLibraryProperties `android:"arch_variant"`
+ Dylib VariantLibraryProperties `android:"arch_variant"`
+
+ // path to the source file that is the main entry point of the program (e.g. src/lib.rs)
+ Srcs []string `android:"path,arch_variant"`
+}
+
+type LibraryMutatedProperties struct {
+ VariantName string `blueprint:"mutated"`
+
+ // Build a dylib variant
+ BuildDylib bool `blueprint:"mutated"`
+ // Build an rlib variant
+ BuildRlib bool `blueprint:"mutated"`
+
+ // This variant is a dylib
+ VariantIsDylib bool `blueprint:"mutated"`
+ // This variant is an rlib
+ VariantIsRlib bool `blueprint:"mutated"`
+}
+
+type libraryDecorator struct {
+ *baseCompiler
+
+ Properties LibraryCompilerProperties
+ MutatedProperties LibraryMutatedProperties
+ distFile android.OptionalPath
+ unstrippedOutputFile android.Path
+}
+
+type libraryInterface interface {
+ rlib() bool
+ dylib() bool
+
+ // Returns true if the build options for the module have selected a particular build type
+ buildRlib() bool
+ buildDylib() bool
+
+ // Sets a particular variant type
+ setRlib()
+ setDylib()
+}
+
+func (library *libraryDecorator) exportedDirs() []string {
+ return library.linkDirs
+}
+
+func (library *libraryDecorator) exportedDepFlags() []string {
+ return library.depFlags
+}
+
+func (library *libraryDecorator) reexportDirs(dirs ...string) {
+ library.linkDirs = android.FirstUniqueStrings(append(library.linkDirs, dirs...))
+}
+
+func (library *libraryDecorator) reexportDepFlags(flags ...string) {
+ library.depFlags = android.FirstUniqueStrings(append(library.depFlags, flags...))
+}
+
+func (library *libraryDecorator) rlib() bool {
+ return library.MutatedProperties.VariantIsRlib
+}
+
+func (library *libraryDecorator) dylib() bool {
+ return library.MutatedProperties.VariantIsDylib
+}
+
+func (library *libraryDecorator) buildRlib() bool {
+ return library.MutatedProperties.BuildRlib && BoolDefault(library.Properties.Rlib.Enabled, true)
+}
+
+func (library *libraryDecorator) buildDylib() bool {
+ return library.MutatedProperties.BuildDylib && BoolDefault(library.Properties.Dylib.Enabled, true)
+}
+
+func (library *libraryDecorator) setRlib() {
+ library.MutatedProperties.VariantIsRlib = true
+ library.MutatedProperties.VariantIsDylib = false
+}
+
+func (library *libraryDecorator) setDylib() {
+ library.MutatedProperties.VariantIsRlib = false
+ library.MutatedProperties.VariantIsDylib = true
+}
+
+var _ compiler = (*libraryDecorator)(nil)
+
+// rust_library produces all variants.
+func RustLibraryFactory() android.Module {
+ module, _ := NewRustLibrary(android.HostAndDeviceSupported)
+ return module.Init()
+}
+
+// rust_library_dylib produces a dylib.
+func RustLibraryDylibFactory() android.Module {
+ module, library := NewRustLibrary(android.HostAndDeviceSupported)
+ library.BuildOnlyDylib()
+ return module.Init()
+}
+
+// rust_library_rlib produces an rlib.
+func RustLibraryRlibFactory() android.Module {
+ module, library := NewRustLibrary(android.HostAndDeviceSupported)
+ library.BuildOnlyRlib()
+ return module.Init()
+}
+
+// rust_library_host produces all variants.
+func RustLibraryHostFactory() android.Module {
+ module, _ := NewRustLibrary(android.HostSupported)
+ return module.Init()
+}
+
+// rust_library_dylib_host produces a dylib.
+func RustLibraryDylibHostFactory() android.Module {
+ module, library := NewRustLibrary(android.HostSupported)
+ library.BuildOnlyDylib()
+ return module.Init()
+}
+
+// rust_library_rlib_host produces an rlib.
+func RustLibraryRlibHostFactory() android.Module {
+ module, library := NewRustLibrary(android.HostSupported)
+ library.BuildOnlyRlib()
+ return module.Init()
+}
+
+func (library *libraryDecorator) BuildOnlyDylib() {
+ library.MutatedProperties.BuildRlib = false
+}
+
+func (library *libraryDecorator) BuildOnlyRlib() {
+ library.MutatedProperties.BuildDylib = false
+}
+
+func NewRustLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
+ module := newModule(hod, android.MultilibFirst)
+
+ library := &libraryDecorator{
+ MutatedProperties: LibraryMutatedProperties{
+ BuildDylib: true,
+ BuildRlib: true,
+ },
+ baseCompiler: NewBaseCompiler("lib", "lib64"),
+ }
+
+ module.compiler = library
+
+ return module, library
+}
+
+func (library *libraryDecorator) compilerProps() []interface{} {
+ return append(library.baseCompiler.compilerProps(),
+ &library.Properties,
+ &library.MutatedProperties)
+}
+
+func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path {
+ var outputFile android.WritablePath
+
+ srcPath := srcPathFromModuleSrcs(ctx, library.Properties.Srcs)
+
+ flags.RustFlags = append(flags.RustFlags, deps.depFlags...)
+
+ if library.rlib() {
+ fileName := library.getStem(ctx) + ctx.toolchain().RlibSuffix()
+ outputFile = android.PathForModuleOut(ctx, fileName)
+
+ TransformSrctoRlib(ctx, srcPath, deps, flags, outputFile, deps.linkDirs)
+ } else if library.dylib() {
+ fileName := library.getStem(ctx) + ctx.toolchain().DylibSuffix()
+ outputFile = android.PathForModuleOut(ctx, fileName)
+
+ // We need prefer-dynamic for now to avoid linking in the static stdlib. See:
+ // https://github.com/rust-lang/rust/issues/19680
+ // https://github.com/rust-lang/rust/issues/34909
+ flags.RustFlags = append(flags.RustFlags, "-C prefer-dynamic")
+
+ TransformSrctoDylib(ctx, srcPath, deps, flags, outputFile, deps.linkDirs)
+ }
+
+ library.reexportDirs(deps.linkDirs...)
+ library.reexportDepFlags(deps.depFlags...)
+ library.unstrippedOutputFile = outputFile
+
+ return outputFile
+}
+
+func LibraryMutator(mctx android.BottomUpMutatorContext) {
+ if m, ok := mctx.Module().(*Module); ok && m.compiler != nil {
+ switch library := m.compiler.(type) {
+ case libraryInterface:
+ if library.buildRlib() && library.buildDylib() {
+ modules := mctx.CreateLocalVariations("rlib", "dylib")
+ rlib := modules[0].(*Module)
+ dylib := modules[1].(*Module)
+
+ rlib.compiler.(libraryInterface).setRlib()
+ dylib.compiler.(libraryInterface).setDylib()
+ } else if library.buildRlib() {
+ modules := mctx.CreateLocalVariations("rlib")
+ modules[0].(*Module).compiler.(libraryInterface).setRlib()
+ } else if library.buildDylib() {
+ modules := mctx.CreateLocalVariations("dylib")
+ modules[0].(*Module).compiler.(libraryInterface).setDylib()
+ }
+ }
+ }
+}
diff --git a/rust/library_test.go b/rust/library_test.go
new file mode 100644
index 0000000..bf8643e
--- /dev/null
+++ b/rust/library_test.go
@@ -0,0 +1,61 @@
+// Copyright 2019 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package rust
+
+import (
+ "strings"
+ "testing"
+)
+
+// Test that variants are being generated correctly, and that crate-types are correct.
+func TestLibraryVariants(t *testing.T) {
+
+ ctx := testRust(t, `
+ rust_library_host {
+ name: "libfoo",
+ srcs: ["foo.rs"],
+ crate_name: "foo",
+ }`)
+
+ // Test both variants are being built.
+ libfooRlib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_rlib").Output("libfoo.rlib")
+ libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib").Output("libfoo.so")
+
+ // Test crate type for rlib is correct.
+ if !strings.Contains(libfooRlib.Args["rustcFlags"], "crate-type=rlib") {
+ t.Errorf("missing crate-type for libfoo rlib, rustcFlags: %#v", libfooRlib.Args["rustcFlags"])
+ }
+
+ // Test crate type for dylib is correct.
+ if !strings.Contains(libfooDylib.Args["rustcFlags"], "crate-type=dylib") {
+ t.Errorf("missing crate-type for libfoo dylib, rustcFlags: %#v", libfooDylib.Args["rustcFlags"])
+ }
+}
+
+// Test that dylibs are not statically linking the standard library.
+func TestDylibPreferDynamic(t *testing.T) {
+ ctx := testRust(t, `
+ rust_library_host_dylib {
+ name: "libfoo",
+ srcs: ["foo.rs"],
+ crate_name: "foo",
+ }`)
+
+ libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib").Output("libfoo.so")
+
+ if !strings.Contains(libfooDylib.Args["rustcFlags"], "prefer-dynamic") {
+ t.Errorf("missing prefer-dynamic flag for libfoo dylib, rustcFlags: %#v", libfooDylib.Args["rustcFlags"])
+ }
+}
diff --git a/rust/prebuilt.go b/rust/prebuilt.go
new file mode 100644
index 0000000..d4e631b
--- /dev/null
+++ b/rust/prebuilt.go
@@ -0,0 +1,65 @@
+// Copyright 2019 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package rust
+
+import (
+ "android/soong/android"
+)
+
+func init() {
+ android.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
+}
+
+type PrebuiltProperties struct {
+ // path to the prebuilt file
+ Srcs []string `android:"path,arch_variant"`
+}
+
+type prebuiltLibraryDecorator struct {
+ *libraryDecorator
+ Properties PrebuiltProperties
+}
+
+var _ compiler = (*prebuiltLibraryDecorator)(nil)
+
+func PrebuiltDylibFactory() android.Module {
+ module, _ := NewPrebuiltDylib(android.HostAndDeviceSupported)
+ return module.Init()
+}
+
+func NewPrebuiltDylib(hod android.HostOrDeviceSupported) (*Module, *prebuiltLibraryDecorator) {
+ module, library := NewRustLibrary(hod)
+ library.BuildOnlyDylib()
+ library.setDylib()
+ prebuilt := &prebuiltLibraryDecorator{
+ libraryDecorator: library,
+ }
+ module.compiler = prebuilt
+ module.AddProperties(&library.Properties)
+ return module, prebuilt
+}
+
+func (prebuilt *prebuiltLibraryDecorator) compilerProps() []interface{} {
+ return append(prebuilt.baseCompiler.compilerProps(),
+ &prebuilt.Properties)
+}
+
+func (prebuilt *prebuiltLibraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path {
+ srcPath := srcPathFromModuleSrcs(ctx, prebuilt.Properties.Srcs)
+
+ prebuilt.unstrippedOutputFile = srcPath
+
+ return srcPath
+}
diff --git a/rust/proc_macro.go b/rust/proc_macro.go
new file mode 100644
index 0000000..4acb06f
--- /dev/null
+++ b/rust/proc_macro.go
@@ -0,0 +1,79 @@
+// Copyright 2019 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package rust
+
+import (
+ "android/soong/android"
+)
+
+func init() {
+ android.RegisterModuleType("rust_proc_macro", ProcMacroFactory)
+}
+
+type ProcMacroCompilerProperties struct {
+ // path to the source file that is the main entry point of the program (e.g. src/lib.rs)
+ Srcs []string `android:"path,arch_variant"`
+
+ // set name of the procMacro
+ Stem *string `android:"arch_variant"`
+ Suffix *string `android:"arch_variant"`
+}
+
+type procMacroDecorator struct {
+ *baseCompiler
+
+ Properties ProcMacroCompilerProperties
+ distFile android.OptionalPath
+ unstrippedOutputFile android.Path
+}
+
+type procMacroInterface interface {
+}
+
+var _ compiler = (*procMacroDecorator)(nil)
+
+func ProcMacroFactory() android.Module {
+ module, _ := NewProcMacro(android.HostAndDeviceSupported)
+ return module.Init()
+}
+
+func NewProcMacro(hod android.HostOrDeviceSupported) (*Module, *procMacroDecorator) {
+ module := newModule(hod, android.MultilibFirst)
+
+ procMacro := &procMacroDecorator{
+ baseCompiler: NewBaseCompiler("lib", "lib64"),
+ }
+
+ module.compiler = procMacro
+
+ return module, procMacro
+}
+
+func (procMacro *procMacroDecorator) compilerProps() []interface{} {
+ return append(procMacro.baseCompiler.compilerProps(),
+ &procMacro.Properties)
+}
+
+func (procMacro *procMacroDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path {
+ fileName := procMacro.getStem(ctx) + ctx.toolchain().ProcMacroSuffix()
+ outputFile := android.PathForModuleOut(ctx, fileName)
+
+ srcPath := srcPathFromModuleSrcs(ctx, procMacro.Properties.Srcs)
+
+ procMacro.unstrippedOutputFile = outputFile
+
+ TransformSrctoProcMacro(ctx, srcPath, deps, flags, outputFile, deps.linkDirs)
+ return outputFile
+}
diff --git a/rust/rust.go b/rust/rust.go
new file mode 100644
index 0000000..62ccfc7
--- /dev/null
+++ b/rust/rust.go
@@ -0,0 +1,516 @@
+// Copyright 2019 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package rust
+
+import (
+ "strings"
+
+ "github.com/google/blueprint"
+ "github.com/google/blueprint/proptools"
+
+ "android/soong/android"
+ "android/soong/cc"
+ "android/soong/rust/config"
+)
+
+var pctx = android.NewPackageContext("android/soong/rust")
+
+func init() {
+ // Only allow rust modules to be defined for certain projects
+ rustModuleTypes := []string{
+ "rust_binary",
+ "rust_binary_host",
+ "rust_library",
+ "rust_library_dylib",
+ "rust_library_rlib",
+ "rust_library_host",
+ "rust_library_host_dylib",
+ "rust_library_host_rlib",
+ "rust_proc_macro",
+ }
+
+ rustAllowedPaths := []string{
+ "external/rust/crates",
+ "external/crosvm",
+ "external/adhd",
+ }
+
+ android.AddNeverAllowRules(
+ android.NeverAllow().
+ NotIn(rustAllowedPaths...).
+ ModuleType(rustModuleTypes...))
+
+ android.RegisterModuleType("rust_defaults", defaultsFactory)
+ android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
+ ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
+ })
+ pctx.Import("android/soong/rust/config")
+}
+
+type Flags struct {
+ GlobalFlags []string // Flags that apply globally
+ RustFlags []string // Flags that apply to rust
+ LinkFlags []string // Flags that apply to linker
+ RustFlagsDeps android.Paths // Files depended on by compiler flags
+ Toolchain config.Toolchain
+}
+
+type BaseProperties struct {
+ AndroidMkRlibs []string
+ AndroidMkDylibs []string
+ AndroidMkProcMacroLibs []string
+ AndroidMkSharedLibs []string
+ AndroidMkStaticLibs []string
+}
+
+type Module struct {
+ android.ModuleBase
+ android.DefaultableModuleBase
+
+ Properties BaseProperties
+
+ hod android.HostOrDeviceSupported
+ multilib android.Multilib
+
+ compiler compiler
+ cachedToolchain config.Toolchain
+ subAndroidMkOnce map[subAndroidMkProvider]bool
+ outputFile android.OptionalPath
+}
+
+type Deps struct {
+ Dylibs []string
+ Rlibs []string
+ ProcMacros []string
+ SharedLibs []string
+ StaticLibs []string
+
+ CrtBegin, CrtEnd string
+}
+
+type PathDeps struct {
+ DyLibs RustLibraries
+ RLibs RustLibraries
+ SharedLibs android.Paths
+ StaticLibs android.Paths
+ ProcMacros RustLibraries
+ linkDirs []string
+ depFlags []string
+ //ReexportedDeps android.Paths
+}
+
+type RustLibraries []RustLibrary
+
+type RustLibrary struct {
+ Path android.Path
+ CrateName string
+}
+
+type compiler interface {
+ compilerFlags(ctx ModuleContext, flags Flags) Flags
+ compilerProps() []interface{}
+ compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path
+ compilerDeps(ctx DepsContext, deps Deps) Deps
+ crateName() string
+
+ install(ctx ModuleContext, path android.Path)
+ relativeInstallPath() string
+}
+
+func defaultsFactory() android.Module {
+ return DefaultsFactory()
+}
+
+type Defaults struct {
+ android.ModuleBase
+ android.DefaultsModuleBase
+}
+
+func DefaultsFactory(props ...interface{}) android.Module {
+ module := &Defaults{}
+
+ module.AddProperties(props...)
+ module.AddProperties(
+ &BaseProperties{},
+ &BaseCompilerProperties{},
+ &BinaryCompilerProperties{},
+ &LibraryCompilerProperties{},
+ &ProcMacroCompilerProperties{},
+ &PrebuiltProperties{},
+ )
+
+ android.InitDefaultsModule(module)
+ return module
+}
+
+func (mod *Module) CrateName() string {
+ if mod.compiler != nil && mod.compiler.crateName() != "" {
+ return mod.compiler.crateName()
+ }
+ // Default crate names replace '-' in the name to '_'
+ return strings.Replace(mod.BaseModuleName(), "-", "_", -1)
+}
+
+func (mod *Module) Init() android.Module {
+ mod.AddProperties(&mod.Properties)
+
+ if mod.compiler != nil {
+ mod.AddProperties(mod.compiler.compilerProps()...)
+ }
+ android.InitAndroidArchModule(mod, mod.hod, mod.multilib)
+
+ android.InitDefaultableModule(mod)
+
+ // Explicitly disable unsupported targets.
+ android.AddLoadHook(mod, func(ctx android.LoadHookContext) {
+ disableTargets := struct {
+ Target struct {
+ Darwin struct {
+ Enabled *bool
+ }
+ Linux_bionic struct {
+ Enabled *bool
+ }
+ }
+ }{}
+ disableTargets.Target.Darwin.Enabled = proptools.BoolPtr(false)
+ disableTargets.Target.Linux_bionic.Enabled = proptools.BoolPtr(false)
+
+ ctx.AppendProperties(&disableTargets)
+ })
+
+ return mod
+}
+
+func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
+ return &Module{
+ hod: hod,
+ multilib: multilib,
+ }
+}
+func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
+ module := newBaseModule(hod, multilib)
+ return module
+}
+
+type ModuleContext interface {
+ android.ModuleContext
+ ModuleContextIntf
+}
+
+type BaseModuleContext interface {
+ android.BaseModuleContext
+ ModuleContextIntf
+}
+
+type DepsContext interface {
+ android.BottomUpMutatorContext
+ ModuleContextIntf
+}
+
+type ModuleContextIntf interface {
+ toolchain() config.Toolchain
+ baseModuleName() string
+ CrateName() string
+}
+
+type depsContext struct {
+ android.BottomUpMutatorContext
+ moduleContextImpl
+}
+
+type moduleContext struct {
+ android.ModuleContext
+ moduleContextImpl
+}
+
+type moduleContextImpl struct {
+ mod *Module
+ ctx BaseModuleContext
+}
+
+func (ctx *moduleContextImpl) toolchain() config.Toolchain {
+ return ctx.mod.toolchain(ctx.ctx)
+}
+
+func (mod *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
+ if mod.cachedToolchain == nil {
+ mod.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
+ }
+ return mod.cachedToolchain
+}
+
+func (d *Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+}
+
+func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
+ ctx := &moduleContext{
+ ModuleContext: actx,
+ moduleContextImpl: moduleContextImpl{
+ mod: mod,
+ },
+ }
+ ctx.ctx = ctx
+
+ toolchain := mod.toolchain(ctx)
+
+ if !toolchain.Supported() {
+ // This toolchain's unsupported, there's nothing to do for this mod.
+ return
+ }
+
+ deps := mod.depsToPaths(ctx)
+ flags := Flags{
+ Toolchain: toolchain,
+ }
+
+ if mod.compiler != nil {
+ flags = mod.compiler.compilerFlags(ctx, flags)
+ outputFile := mod.compiler.compile(ctx, flags, deps)
+ mod.outputFile = android.OptionalPathForPath(outputFile)
+ mod.compiler.install(ctx, mod.outputFile.Path())
+ }
+}
+
+func (mod *Module) deps(ctx DepsContext) Deps {
+ deps := Deps{}
+
+ if mod.compiler != nil {
+ deps = mod.compiler.compilerDeps(ctx, deps)
+ }
+
+ deps.Rlibs = android.LastUniqueStrings(deps.Rlibs)
+ deps.Dylibs = android.LastUniqueStrings(deps.Dylibs)
+ deps.ProcMacros = android.LastUniqueStrings(deps.ProcMacros)
+ deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
+ deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
+
+ return deps
+
+}
+
+func (ctx *moduleContextImpl) baseModuleName() string {
+ return ctx.mod.ModuleBase.BaseModuleName()
+}
+
+func (ctx *moduleContextImpl) CrateName() string {
+ return ctx.mod.CrateName()
+}
+
+type dependencyTag struct {
+ blueprint.BaseDependencyTag
+ name string
+ library bool
+ proc_macro bool
+}
+
+var (
+ rlibDepTag = dependencyTag{name: "rlibTag", library: true}
+ dylibDepTag = dependencyTag{name: "dylib", library: true}
+ procMacroDepTag = dependencyTag{name: "procMacro", proc_macro: true}
+)
+
+func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
+ var depPaths PathDeps
+
+ directRlibDeps := []*Module{}
+ directDylibDeps := []*Module{}
+ directProcMacroDeps := []*Module{}
+ directSharedLibDeps := []*(cc.Module){}
+ directStaticLibDeps := []*(cc.Module){}
+
+ ctx.VisitDirectDeps(func(dep android.Module) {
+ depName := ctx.OtherModuleName(dep)
+ depTag := ctx.OtherModuleDependencyTag(dep)
+ if dep.Target().Os != ctx.Os() {
+ ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
+ return
+ }
+ if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
+ ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
+ return
+ }
+
+ if rustDep, ok := dep.(*Module); ok {
+ //Handle Rust Modules
+ linkFile := rustDep.outputFile
+ if !linkFile.Valid() {
+ ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName())
+ }
+
+ switch depTag {
+ case dylibDepTag:
+ dylib, ok := rustDep.compiler.(libraryInterface)
+ if !ok || !dylib.dylib() {
+ ctx.ModuleErrorf("mod %q not an dylib library", depName)
+ return
+ }
+ directDylibDeps = append(directDylibDeps, rustDep)
+ mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, depName)
+ case rlibDepTag:
+ rlib, ok := rustDep.compiler.(libraryInterface)
+ if !ok || !rlib.rlib() {
+ ctx.ModuleErrorf("mod %q not an rlib library", depName)
+ return
+ }
+ directRlibDeps = append(directRlibDeps, rustDep)
+ mod.Properties.AndroidMkRlibs = append(mod.Properties.AndroidMkRlibs, depName)
+ case procMacroDepTag:
+ directProcMacroDeps = append(directProcMacroDeps, rustDep)
+ mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, depName)
+ }
+
+ //Append the dependencies exportedDirs
+ if lib, ok := rustDep.compiler.(*libraryDecorator); ok {
+ depPaths.linkDirs = append(depPaths.linkDirs, lib.exportedDirs()...)
+ depPaths.depFlags = append(depPaths.depFlags, lib.exportedDepFlags()...)
+ } else if procMacro, ok := rustDep.compiler.(*libraryDecorator); ok {
+ depPaths.linkDirs = append(depPaths.linkDirs, procMacro.exportedDirs()...)
+ depPaths.depFlags = append(depPaths.depFlags, procMacro.exportedDepFlags()...)
+ }
+
+ // Append this dependencies output to this mod's linkDirs so they can be exported to dependencies
+ // This can be probably be refactored by defining a common exporter interface similar to cc's
+ if depTag == dylibDepTag || depTag == rlibDepTag || depTag == procMacroDepTag {
+ linkDir := linkPathFromFilePath(linkFile.Path())
+ if lib, ok := mod.compiler.(*libraryDecorator); ok {
+ lib.linkDirs = append(lib.linkDirs, linkDir)
+ } else if procMacro, ok := mod.compiler.(*procMacroDecorator); ok {
+ procMacro.linkDirs = append(procMacro.linkDirs, linkDir)
+ }
+ }
+
+ } else if ccDep, ok := dep.(*cc.Module); ok {
+
+ //Handle C dependencies
+ linkFile := ccDep.OutputFile()
+ linkPath := linkPathFromFilePath(linkFile.Path())
+ libName := libNameFromFilePath(linkFile.Path())
+ if !linkFile.Valid() {
+ ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName())
+ }
+
+ exportDep := false
+
+ switch depTag {
+ case cc.StaticDepTag():
+ depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
+ depPaths.depFlags = append(depPaths.depFlags, "-l"+libName)
+ directStaticLibDeps = append(directStaticLibDeps, ccDep)
+ mod.Properties.AndroidMkStaticLibs = append(mod.Properties.AndroidMkStaticLibs, depName)
+ case cc.SharedDepTag():
+ depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
+ depPaths.depFlags = append(depPaths.depFlags, "-l"+libName)
+ directSharedLibDeps = append(directSharedLibDeps, ccDep)
+ mod.Properties.AndroidMkSharedLibs = append(mod.Properties.AndroidMkSharedLibs, depName)
+ exportDep = true
+ }
+
+ // Make sure these dependencies are propagated
+ if lib, ok := mod.compiler.(*libraryDecorator); ok && (exportDep || lib.rlib()) {
+ lib.linkDirs = append(lib.linkDirs, linkPath)
+ lib.depFlags = append(lib.depFlags, "-l"+libName)
+ } else if procMacro, ok := mod.compiler.(*procMacroDecorator); ok && exportDep {
+ procMacro.linkDirs = append(procMacro.linkDirs, linkPath)
+ procMacro.depFlags = append(procMacro.depFlags, "-l"+libName)
+ }
+
+ }
+ })
+
+ var rlibDepFiles RustLibraries
+ for _, dep := range directRlibDeps {
+ rlibDepFiles = append(rlibDepFiles, RustLibrary{Path: dep.outputFile.Path(), CrateName: dep.CrateName()})
+ }
+ var dylibDepFiles RustLibraries
+ for _, dep := range directDylibDeps {
+ dylibDepFiles = append(dylibDepFiles, RustLibrary{Path: dep.outputFile.Path(), CrateName: dep.CrateName()})
+ }
+ var procMacroDepFiles RustLibraries
+ for _, dep := range directProcMacroDeps {
+ procMacroDepFiles = append(procMacroDepFiles, RustLibrary{Path: dep.outputFile.Path(), CrateName: dep.CrateName()})
+ }
+
+ var staticLibDepFiles android.Paths
+ for _, dep := range directStaticLibDeps {
+ staticLibDepFiles = append(staticLibDepFiles, dep.OutputFile().Path())
+ }
+
+ var sharedLibDepFiles android.Paths
+ for _, dep := range directSharedLibDeps {
+ sharedLibDepFiles = append(sharedLibDepFiles, dep.OutputFile().Path())
+ }
+
+ depPaths.RLibs = append(depPaths.RLibs, rlibDepFiles...)
+ depPaths.DyLibs = append(depPaths.DyLibs, dylibDepFiles...)
+ depPaths.SharedLibs = append(depPaths.SharedLibs, sharedLibDepFiles...)
+ depPaths.StaticLibs = append(depPaths.StaticLibs, staticLibDepFiles...)
+ depPaths.ProcMacros = append(depPaths.ProcMacros, procMacroDepFiles...)
+
+ // Dedup exported flags from dependencies
+ depPaths.linkDirs = android.FirstUniqueStrings(depPaths.linkDirs)
+ depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags)
+
+ return depPaths
+}
+
+func linkPathFromFilePath(filepath android.Path) string {
+ return strings.Split(filepath.String(), filepath.Base())[0]
+}
+func libNameFromFilePath(filepath android.Path) string {
+ libName := strings.Split(filepath.Base(), filepath.Ext())[0]
+ if strings.Contains(libName, "lib") {
+ libName = strings.Split(libName, "lib")[1]
+ }
+ return libName
+}
+func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
+ ctx := &depsContext{
+ BottomUpMutatorContext: actx,
+ moduleContextImpl: moduleContextImpl{
+ mod: mod,
+ },
+ }
+ ctx.ctx = ctx
+
+ deps := mod.deps(ctx)
+
+ actx.AddVariationDependencies([]blueprint.Variation{{Mutator: "rust_libraries", Variation: "rlib"}}, rlibDepTag, deps.Rlibs...)
+ actx.AddVariationDependencies([]blueprint.Variation{{Mutator: "rust_libraries", Variation: "dylib"}}, dylibDepTag, deps.Dylibs...)
+
+ ccDepVariations := []blueprint.Variation{}
+ ccDepVariations = append(ccDepVariations, blueprint.Variation{Mutator: "version", Variation: ""})
+ if !mod.Host() {
+ ccDepVariations = append(ccDepVariations, blueprint.Variation{Mutator: "image", Variation: "core"})
+ }
+ actx.AddVariationDependencies(append(ccDepVariations, blueprint.Variation{Mutator: "link", Variation: "shared"}), cc.SharedDepTag(), deps.SharedLibs...)
+ actx.AddVariationDependencies(append(ccDepVariations, blueprint.Variation{Mutator: "link", Variation: "static"}), cc.StaticDepTag(), deps.StaticLibs...)
+ actx.AddDependency(mod, procMacroDepTag, deps.ProcMacros...)
+}
+
+func (mod *Module) Name() string {
+ name := mod.ModuleBase.Name()
+ if p, ok := mod.compiler.(interface {
+ Name(string) string
+ }); ok {
+ name = p.Name(name)
+ }
+ return name
+}
+
+var Bool = proptools.Bool
+var BoolDefault = proptools.BoolDefault
+var String = proptools.String
+var StringPtr = proptools.StringPtr
diff --git a/rust/rust_test.go b/rust/rust_test.go
new file mode 100644
index 0000000..f7c96dd
--- /dev/null
+++ b/rust/rust_test.go
@@ -0,0 +1,178 @@
+// Copyright 2019 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package rust
+
+import (
+ "io/ioutil"
+ "os"
+ "runtime"
+ "testing"
+
+ "android/soong/android"
+)
+
+var (
+ buildDir string
+)
+
+func setUp() {
+ var err error
+ buildDir, err = ioutil.TempDir("", "soong_rust_test")
+ if err != nil {
+ panic(err)
+ }
+}
+
+func tearDown() {
+ os.RemoveAll(buildDir)
+}
+
+func TestMain(m *testing.M) {
+ run := func() int {
+ setUp()
+ defer tearDown()
+
+ return m.Run()
+ }
+
+ os.Exit(run())
+}
+
+func testRust(t *testing.T, bp string) *android.TestContext {
+ // TODO (b/140435149)
+ if runtime.GOOS != "linux" {
+ t.Skip("Only the Linux toolchain is supported for Rust")
+ }
+
+ t.Helper()
+ config := android.TestArchConfig(buildDir, nil)
+
+ t.Helper()
+ ctx := CreateTestContext(bp)
+ ctx.Register()
+
+ _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
+ android.FailIfErrored(t, errs)
+ _, errs = ctx.PrepareBuildActions(config)
+ android.FailIfErrored(t, errs)
+
+ return ctx
+}
+
+func testRustError(t *testing.T, pattern string, bp string) {
+ // TODO (b/140435149)
+ if runtime.GOOS != "linux" {
+ t.Skip("Only the Linux toolchain is supported for Rust")
+ }
+
+ t.Helper()
+ config := android.TestArchConfig(buildDir, nil)
+
+ ctx := CreateTestContext(bp)
+ ctx.Register()
+
+ _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
+ if len(errs) > 0 {
+ android.FailIfNoMatchingErrors(t, pattern, errs)
+ return
+ }
+
+ _, errs = ctx.PrepareBuildActions(config)
+ if len(errs) > 0 {
+ android.FailIfNoMatchingErrors(t, pattern, errs)
+ return
+ }
+
+ t.Fatalf("missing expected error %q (0 errors are returned)", pattern)
+}
+
+// Test that we can extract the lib name from a lib path.
+func TestLibNameFromFilePath(t *testing.T) {
+ barPath := android.PathForTesting("out/soong/.intermediates/external/libbar/libbar/linux_glibc_x86_64_shared/libbar.so")
+ libName := libNameFromFilePath(barPath)
+ expectedResult := "bar"
+
+ if libName != expectedResult {
+ t.Errorf("libNameFromFilePath returned the wrong name; expected '%#v', got '%#v'", expectedResult, libName)
+ }
+}
+
+// Test that we can extract the link path from a lib path.
+func TestLinkPathFromFilePath(t *testing.T) {
+ barPath := android.PathForTesting("out/soong/.intermediates/external/libbar/libbar/linux_glibc_x86_64_shared/libbar.so")
+ libName := linkPathFromFilePath(barPath)
+ expectedResult := "out/soong/.intermediates/external/libbar/libbar/linux_glibc_x86_64_shared/"
+
+ if libName != expectedResult {
+ t.Errorf("libNameFromFilePath returned the wrong name; expected '%#v', got '%#v'", expectedResult, libName)
+ }
+}
+
+// Test default crate names from module names are generated correctly.
+func TestDefaultCrateName(t *testing.T) {
+ ctx := testRust(t, `
+ rust_library_host_dylib {
+ name: "fizz-buzz",
+ srcs: ["foo.rs"],
+ }`)
+ module := ctx.ModuleForTests("fizz-buzz", "linux_glibc_x86_64_dylib").Module().(*Module)
+ crateName := module.CrateName()
+ expectedResult := "fizz_buzz"
+
+ if crateName != expectedResult {
+ t.Errorf("CrateName() returned the wrong default crate name; expected '%#v', got '%#v'", expectedResult, crateName)
+ }
+}
+
+// Test to make sure dependencies are being picked up correctly.
+func TestDepsTracking(t *testing.T) {
+ ctx := testRust(t, `
+ rust_library_host_dylib {
+ name: "libfoo",
+ srcs: ["foo.rs"],
+ }
+ rust_library_host_rlib {
+ name: "libbar",
+ srcs: ["foo.rs"],
+ }
+ rust_proc_macro {
+ name: "libpm",
+ srcs: ["foo.rs"],
+ host_supported: true,
+ }
+ rust_binary_host {
+ name: "fizz-buzz",
+ dylibs: ["libfoo"],
+ rlibs: ["libbar"],
+ proc_macros: ["libpm"],
+ srcs: ["foo.rs"],
+ }
+ `)
+ module := ctx.ModuleForTests("fizz-buzz", "linux_glibc_x86_64").Module().(*Module)
+
+ // Since dependencies are added to AndroidMk* properties, we can check these to see if they've been picked up.
+ if !android.InList("libfoo", module.Properties.AndroidMkDylibs) {
+ t.Errorf("Dylib dependency not detected (dependency missing from AndroidMkDylibs)")
+ }
+
+ if !android.InList("libbar", module.Properties.AndroidMkRlibs) {
+ t.Errorf("Rlib dependency not detected (dependency missing from AndroidMkRlibs)")
+ }
+
+ if !android.InList("libpm", module.Properties.AndroidMkProcMacroLibs) {
+ t.Errorf("Proc_macro dependency not detected (dependency missing from AndroidMkProcMacroLibs)")
+ }
+
+}
diff --git a/rust/testing.go b/rust/testing.go
new file mode 100644
index 0000000..a38697f
--- /dev/null
+++ b/rust/testing.go
@@ -0,0 +1,105 @@
+// Copyright (C) 2019 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package rust
+
+import (
+ "android/soong/android"
+)
+
+func GatherRequiredDepsForTest() string {
+ bp := `
+ rust_prebuilt_dylib {
+ name: "libarena_x86_64-unknown-linux-gnu",
+ srcs: [""],
+ host_supported: true,
+ }
+ rust_prebuilt_dylib {
+ name: "libfmt_macros_x86_64-unknown-linux-gnu",
+ srcs: [""],
+ host_supported: true,
+ }
+ rust_prebuilt_dylib {
+ name: "libgraphviz_x86_64-unknown-linux-gnu",
+ srcs: [""],
+ host_supported: true,
+ }
+ rust_prebuilt_dylib {
+ name: "libserialize_x86_64-unknown-linux-gnu",
+ srcs: [""],
+ host_supported: true,
+ }
+ rust_prebuilt_dylib {
+ name: "libstd_x86_64-unknown-linux-gnu",
+ srcs: [""],
+ host_supported: true,
+ }
+ rust_prebuilt_dylib {
+ name: "libsyntax_x86_64-unknown-linux-gnu",
+ srcs: [""],
+ host_supported: true,
+ }
+ rust_prebuilt_dylib {
+ name: "libsyntax_ext_x86_64-unknown-linux-gnu",
+ srcs: [""],
+ host_supported: true,
+ }
+ rust_prebuilt_dylib {
+ name: "libsyntax_pos_x86_64-unknown-linux-gnu",
+ srcs: [""],
+ host_supported: true,
+ }
+ rust_prebuilt_dylib {
+ name: "libterm_x86_64-unknown-linux-gnu",
+ srcs: [""],
+ host_supported: true,
+ }
+ rust_prebuilt_dylib {
+ name: "libtest_x86_64-unknown-linux-gnu",
+ srcs: [""],
+ host_supported: true,
+ }
+ `
+ return bp
+}
+
+func CreateTestContext(bp string) *android.TestContext {
+ ctx := android.NewTestArchContext()
+ ctx.RegisterModuleType("rust_binary", android.ModuleFactoryAdaptor(RustBinaryFactory))
+ ctx.RegisterModuleType("rust_binary_host", android.ModuleFactoryAdaptor(RustBinaryHostFactory))
+ ctx.RegisterModuleType("rust_library", android.ModuleFactoryAdaptor(RustLibraryFactory))
+ ctx.RegisterModuleType("rust_library_host", android.ModuleFactoryAdaptor(RustLibraryHostFactory))
+ ctx.RegisterModuleType("rust_library_host_rlib", android.ModuleFactoryAdaptor(RustLibraryRlibHostFactory))
+ ctx.RegisterModuleType("rust_library_host_dylib", android.ModuleFactoryAdaptor(RustLibraryDylibHostFactory))
+ ctx.RegisterModuleType("rust_library_rlib", android.ModuleFactoryAdaptor(RustLibraryRlibFactory))
+ ctx.RegisterModuleType("rust_library_dylib", android.ModuleFactoryAdaptor(RustLibraryDylibFactory))
+ ctx.RegisterModuleType("rust_proc_macro", android.ModuleFactoryAdaptor(ProcMacroFactory))
+ ctx.RegisterModuleType("rust_prebuilt_dylib", android.ModuleFactoryAdaptor(PrebuiltDylibFactory))
+ ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
+ ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
+ })
+ bp = bp + GatherRequiredDepsForTest()
+
+ mockFS := map[string][]byte{
+ "Android.bp": []byte(bp),
+ "foo.rs": nil,
+ "src/bar.rs": nil,
+ "liby.so": nil,
+ "libz.so": nil,
+ }
+
+ ctx.MockFileSystem(mockFS)
+
+ return ctx
+}
diff --git a/scripts/freeze-sysprop-api-files.sh b/scripts/freeze-sysprop-api-files.sh
new file mode 100755
index 0000000..1b2ff7c
--- /dev/null
+++ b/scripts/freeze-sysprop-api-files.sh
@@ -0,0 +1,39 @@
+#!/bin/bash -e
+
+# Copyright (C) 2019 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# This script freezes APIs of a sysprop_library after checking compatibility
+# between latest API and current API.
+#
+# Usage: freeze-sysprop-api-files.sh <modulePath> <moduleName>
+#
+# <modulePath>: the directory, either relative or absolute, which holds the
+# Android.bp file defining sysprop_library.
+#
+# <moduleName>: the name of sysprop_library to freeze API.
+#
+# Example:
+# $ . build/envsetup.sh && lunch aosp_arm64-user
+# $ . build/soong/scripts/freeze-sysprop-api-files.sh \
+# system/libsysprop/srcs PlatformProperties
+
+if [[ -z "$1" || -z "$2" ]]; then
+ echo "usage: $0 <modulePath> <moduleName>" >&2
+ exit 1
+fi
+
+api_dir=$1/api
+
+m "$2-check-api" && cp -f "${api_dir}/$2-current.txt" "${api_dir}/$2-latest.txt"
diff --git a/scripts/gen-sysprop-api-files.sh b/scripts/gen-sysprop-api-files.sh
new file mode 100755
index 0000000..a4cb506
--- /dev/null
+++ b/scripts/gen-sysprop-api-files.sh
@@ -0,0 +1,26 @@
+#!/bin/bash -e
+
+# Copyright (C) 2019 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+if [[ -z "$1" || -z "$2" ]]; then
+ echo "usage: $0 <modulePath> <moduleName>" >&2
+ exit 1
+fi
+
+api_dir=$1/api
+
+mkdir -p "$api_dir"
+touch "${api_dir}/$2-current.txt"
+touch "${api_dir}/$2-latest.txt"
diff --git a/scripts/strip.sh b/scripts/strip.sh
index abf997b..52f9366 100755
--- a/scripts/strip.sh
+++ b/scripts/strip.sh
@@ -84,17 +84,17 @@
}
do_strip_keep_symbol_list() {
- if [ -z "${use_gnu_strip}" ]; then
- echo "do_strip_keep_symbol_list does not work with llvm-objcopy"
- echo "http://b/131631155"
- usage
- fi
-
echo "${symbols_to_keep}" | tr ',' '\n' > "${outfile}.symbolList"
- KEEP_SYMBOLS="-w --strip-unneeded-symbol=* --keep-symbols="
- KEEP_SYMBOLS+="${outfile}.symbolList"
- "${CROSS_COMPILE}objcopy" "${infile}" "${outfile}.tmp" ${KEEP_SYMBOLS}
+ if [ -z "${use_gnu_strip}" ]; then
+ KEEP_SYMBOLS="--strip-unneeded-symbol=.* --keep-symbols="
+ KEEP_SYMBOLS+="${outfile}.symbolList"
+ "${CLANG_BIN}/llvm-objcopy" --regex "${infile}" "${outfile}.tmp" ${KEEP_SYMBOLS}
+ else
+ KEEP_SYMBOLS="--strip-unneeded-symbol=* --keep-symbols="
+ KEEP_SYMBOLS+="${outfile}.symbolList"
+ "${CROSS_COMPILE}objcopy" -w "${infile}" "${outfile}.tmp" ${KEEP_SYMBOLS}
+ fi
}
do_strip_keep_mini_debug_info() {
diff --git a/sysprop/sysprop_library.go b/sysprop/sysprop_library.go
index 86061c6..c7669bd 100644
--- a/sysprop/sysprop_library.go
+++ b/sysprop/sysprop_library.go
@@ -15,12 +15,16 @@
package sysprop
import (
- "android/soong/android"
- "android/soong/cc"
- "android/soong/java"
+ "fmt"
+ "io"
+ "path"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
+
+ "android/soong/android"
+ "android/soong/cc"
+ "android/soong/java"
)
type dependencyTag struct {
@@ -29,10 +33,14 @@
}
type syspropLibrary struct {
- java.SdkLibrary
+ android.ModuleBase
- commonProperties commonProperties
- syspropLibraryProperties syspropLibraryProperties
+ properties syspropLibraryProperties
+
+ checkApiFileTimeStamp android.WritablePath
+ latestApiFile android.Path
+ currentApiFile android.Path
+ dumpedApiFile android.WritablePath
}
type syspropLibraryProperties struct {
@@ -42,17 +50,22 @@
// list of package names that will be documented and publicized as API
Api_packages []string
-}
-type commonProperties struct {
- Srcs []string
- Recovery *bool
+ // If set to true, allow this module to be dexed and installed on devices.
+ Installable *bool
+
+ // Make this module available when building for recovery
Recovery_available *bool
- Vendor_available *bool
+
+ // Make this module available when building for vendor
+ Vendor_available *bool
+
+ // list of .sysprop files which defines the properties.
+ Srcs []string `android:"path"`
}
var (
- Bool = proptools.Bool
+ pctx = android.NewPackageContext("android/soong/sysprop")
syspropCcTag = dependencyTag{name: "syspropCc"}
)
@@ -60,56 +73,166 @@
android.RegisterModuleType("sysprop_library", syspropLibraryFactory)
}
-func (m *syspropLibrary) CcModuleName() string {
- return "lib" + m.Name()
+func (m *syspropLibrary) Name() string {
+ return m.BaseModuleName() + "_sysprop_library"
}
+func (m *syspropLibrary) CcModuleName() string {
+ return "lib" + m.BaseModuleName()
+}
+
+func (m *syspropLibrary) BaseModuleName() string {
+ return m.ModuleBase.Name()
+}
+
+func (m *syspropLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ m.currentApiFile = android.PathForSource(ctx, ctx.ModuleDir(), "api", m.BaseModuleName()+"-current.txt")
+ m.latestApiFile = android.PathForSource(ctx, ctx.ModuleDir(), "api", m.BaseModuleName()+"-latest.txt")
+
+ // dump API rule
+ rule := android.NewRuleBuilder()
+ m.dumpedApiFile = android.PathForModuleOut(ctx, "api-dump.txt")
+ rule.Command().
+ BuiltTool(ctx, "sysprop_api_dump").
+ Output(m.dumpedApiFile).
+ Inputs(android.PathsForModuleSrc(ctx, m.properties.Srcs))
+ rule.Build(pctx, ctx, m.BaseModuleName()+"_api_dump", m.BaseModuleName()+" api dump")
+
+ // check API rule
+ rule = android.NewRuleBuilder()
+
+ // 1. current.txt <-> api_dump.txt
+ msg := fmt.Sprintf(`\n******************************\n`+
+ `API of sysprop_library %s doesn't match with current.txt\n`+
+ `Please update current.txt by:\n`+
+ `rm -rf %q && cp -f %q %q\n`+
+ `******************************\n`, m.BaseModuleName(),
+ m.currentApiFile.String(), m.dumpedApiFile.String(), m.currentApiFile.String())
+
+ rule.Command().
+ Text("( cmp").Flag("-s").
+ Input(m.dumpedApiFile).
+ Input(m.currentApiFile).
+ Text("|| ( echo").Flag("-e").
+ Flag(`"` + msg + `"`).
+ Text("; exit 38) )")
+
+ // 2. current.txt <-> latest.txt
+ msg = fmt.Sprintf(`\n******************************\n`+
+ `API of sysprop_library %s doesn't match with latest version\n`+
+ `Please fix the breakage and rebuild.\n`+
+ `******************************\n`, m.BaseModuleName())
+
+ rule.Command().
+ Text("( ").
+ BuiltTool(ctx, "sysprop_api_checker").
+ Input(m.latestApiFile).
+ Input(m.currentApiFile).
+ Text(" || ( echo").Flag("-e").
+ Flag(`"` + msg + `"`).
+ Text("; exit 38) )")
+
+ m.checkApiFileTimeStamp = android.PathForModuleOut(ctx, "check_api.timestamp")
+
+ rule.Command().
+ Text("touch").
+ Output(m.checkApiFileTimeStamp)
+
+ rule.Build(pctx, ctx, m.BaseModuleName()+"_check_api", m.BaseModuleName()+" check api")
+}
+
+func (m *syspropLibrary) AndroidMk() android.AndroidMkData {
+ return android.AndroidMkData{
+ Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
+ // sysprop_library module itself is defined as a FAKE module to perform API check.
+ // Actual implementation libraries are created on LoadHookMutator
+ fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
+ fmt.Fprintf(w, "LOCAL_MODULE := %s\n", m.Name())
+ fmt.Fprintf(w, "LOCAL_MODULE_CLASS := FAKE\n")
+ fmt.Fprintf(w, "LOCAL_MODULE_TAGS := optional\n")
+ fmt.Fprintf(w, "include $(BUILD_SYSTEM)/base_rules.mk\n\n")
+ fmt.Fprintf(w, "$(LOCAL_BUILT_MODULE): %s\n", m.checkApiFileTimeStamp.String())
+ fmt.Fprintf(w, "\ttouch $@\n\n")
+ fmt.Fprintf(w, ".PHONY: %s-check-api\n\n", name)
+
+ // check API rule
+ fmt.Fprintf(w, "%s-check-api: %s\n\n", name, m.checkApiFileTimeStamp.String())
+
+ // "make {sysprop_library}" should also build the C++ library
+ fmt.Fprintf(w, "%s: %s\n\n", name, m.CcModuleName())
+ }}
+}
+
+// sysprop_library creates schematized APIs from sysprop description files (.sysprop).
+// Both Java and C++ modules can link against sysprop_library, and API stability check
+// against latest APIs (see build/soong/scripts/freeze-sysprop-api-files.sh)
+// is performed.
func syspropLibraryFactory() android.Module {
m := &syspropLibrary{}
m.AddProperties(
- &m.commonProperties,
- &m.syspropLibraryProperties,
+ &m.properties,
)
- m.InitSdkLibraryProperties()
- m.SetNoDist()
- android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, "common")
+ android.InitAndroidModule(m)
android.AddLoadHook(m, func(ctx android.LoadHookContext) { syspropLibraryHook(ctx, m) })
- android.AddLoadHook(m, func(ctx android.LoadHookContext) { m.SdkLibrary.CreateInternalModules(ctx) })
return m
}
func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) {
- if len(m.commonProperties.Srcs) == 0 {
+ if len(m.properties.Srcs) == 0 {
ctx.PropertyErrorf("srcs", "sysprop_library must specify srcs")
}
- if len(m.syspropLibraryProperties.Api_packages) == 0 {
- ctx.PropertyErrorf("api_packages", "sysprop_library must specify api_packages")
+ missing_api := false
+
+ for _, txt := range []string{"-current.txt", "-latest.txt"} {
+ path := path.Join(ctx.ModuleDir(), "api", m.BaseModuleName()+txt)
+ file := android.ExistentPathForSource(ctx, path)
+ if !file.Valid() {
+ ctx.ModuleErrorf("API file %#v doesn't exist", path)
+ missing_api = true
+ }
+ }
+
+ if missing_api {
+ script := "build/soong/scripts/gen-sysprop-api-files.sh"
+ p := android.ExistentPathForSource(ctx, script)
+
+ if !p.Valid() {
+ panic(fmt.Sprintf("script file %s doesn't exist", script))
+ }
+
+ ctx.ModuleErrorf("One or more api files are missing. "+
+ "You can create them by:\n"+
+ "%s %q %q", script, ctx.ModuleDir(), m.BaseModuleName())
+ return
}
socSpecific := ctx.SocSpecific()
deviceSpecific := ctx.DeviceSpecific()
productSpecific := ctx.ProductSpecific()
- owner := m.syspropLibraryProperties.Property_owner
+ owner := m.properties.Property_owner
+ stub := "sysprop-library-stub-"
switch owner {
case "Platform":
// Every partition can access platform-defined properties
- break
+ stub += "platform"
case "Vendor":
// System can't access vendor's properties
if !socSpecific && !deviceSpecific && !productSpecific {
ctx.ModuleErrorf("None of soc_specific, device_specific, product_specific is true. " +
"System can't access sysprop_library owned by Vendor")
}
+ stub += "vendor"
case "Odm":
// Only vendor can access Odm-defined properties
if !socSpecific && !deviceSpecific {
ctx.ModuleErrorf("Neither soc_speicifc nor device_specific is true. " +
"Odm-defined properties should be accessed only in Vendor or Odm")
}
+ stub += "vendor"
default:
ctx.PropertyErrorf("property_owner",
"Unknown value %s: must be one of Platform, Vendor or Odm", owner)
@@ -117,17 +240,23 @@
ccProps := struct {
Name *string
+ Srcs []string
Soc_specific *bool
Device_specific *bool
Product_specific *bool
Sysprop struct {
Platform *bool
}
- Header_libs []string
- Shared_libs []string
+ Header_libs []string
+ Shared_libs []string
+ Required []string
+ Recovery *bool
+ Recovery_available *bool
+ Vendor_available *bool
}{}
ccProps.Name = proptools.StringPtr(m.CcModuleName())
+ ccProps.Srcs = m.properties.Srcs
ccProps.Soc_specific = proptools.BoolPtr(socSpecific)
ccProps.Device_specific = proptools.BoolPtr(deviceSpecific)
ccProps.Product_specific = proptools.BoolPtr(productSpecific)
@@ -135,5 +264,41 @@
ccProps.Header_libs = []string{"libbase_headers"}
ccProps.Shared_libs = []string{"liblog"}
- ctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &m.commonProperties, &ccProps)
+ // add sysprop_library module to perform check API
+ ccProps.Required = []string{m.Name()}
+ ccProps.Sysprop.Platform = proptools.BoolPtr(owner == "Platform")
+ ccProps.Recovery_available = m.properties.Recovery_available
+ ccProps.Vendor_available = m.properties.Vendor_available
+
+ ctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &ccProps)
+
+ javaProps := struct {
+ Name *string
+ Srcs []string
+ Soc_specific *bool
+ Device_specific *bool
+ Product_specific *bool
+ Sysprop struct {
+ Platform *bool
+ }
+ Required []string
+ Sdk_version *string
+ Installable *bool
+ Libs []string
+ }{}
+
+ javaProps.Name = proptools.StringPtr(m.BaseModuleName())
+ javaProps.Srcs = m.properties.Srcs
+ javaProps.Soc_specific = proptools.BoolPtr(socSpecific)
+ javaProps.Device_specific = proptools.BoolPtr(deviceSpecific)
+ javaProps.Product_specific = proptools.BoolPtr(productSpecific)
+ javaProps.Installable = m.properties.Installable
+
+ // add sysprop_library module to perform check API
+ javaProps.Required = []string{m.Name()}
+ javaProps.Sdk_version = proptools.StringPtr("core_current")
+ javaProps.Sysprop.Platform = proptools.BoolPtr(owner == "Platform")
+ javaProps.Libs = []string{stub}
+
+ ctx.CreateModule(android.ModuleFactoryAdaptor(java.LibraryFactory), &javaProps)
}
diff --git a/sysprop/sysprop_test.go b/sysprop/sysprop_test.go
index 0566036..5345770 100644
--- a/sysprop/sysprop_test.go
+++ b/sysprop/sysprop_test.go
@@ -57,16 +57,11 @@
ctx := android.NewTestArchContext()
ctx.RegisterModuleType("android_app", android.ModuleFactoryAdaptor(java.AndroidAppFactory))
- ctx.RegisterModuleType("droiddoc_template", android.ModuleFactoryAdaptor(java.ExportedDroiddocDirFactory))
ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(java.LibraryFactory))
ctx.RegisterModuleType("java_system_modules", android.ModuleFactoryAdaptor(java.SystemModulesFactory))
- ctx.RegisterModuleType("prebuilt_apis", android.ModuleFactoryAdaptor(java.PrebuiltApisFactory))
ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators)
ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators)
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
- ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
- ctx.TopDown("prebuilt_apis", java.PrebuiltApisMutator).Parallel()
- })
ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory))
ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(cc.LibraryHeaderFactory))
@@ -91,45 +86,20 @@
bp += cc.GatherRequiredDepsForTest(android.Android)
mockFS := map[string][]byte{
- "Android.bp": []byte(bp),
- "a.java": nil,
- "b.java": nil,
- "c.java": nil,
- "d.cpp": nil,
- "api/current.txt": nil,
- "api/removed.txt": nil,
- "api/system-current.txt": nil,
- "api/system-removed.txt": nil,
- "api/test-current.txt": nil,
- "api/test-removed.txt": nil,
- "framework/aidl/a.aidl": nil,
-
- "prebuilts/sdk/current/core/android.jar": nil,
- "prebuilts/sdk/current/public/android.jar": nil,
- "prebuilts/sdk/current/public/framework.aidl": nil,
- "prebuilts/sdk/current/public/core.jar": nil,
- "prebuilts/sdk/current/system/android.jar": nil,
- "prebuilts/sdk/current/test/android.jar": nil,
- "prebuilts/sdk/28/public/api/sysprop-platform.txt": nil,
- "prebuilts/sdk/28/system/api/sysprop-platform.txt": nil,
- "prebuilts/sdk/28/test/api/sysprop-platform.txt": nil,
- "prebuilts/sdk/28/public/api/sysprop-platform-removed.txt": nil,
- "prebuilts/sdk/28/system/api/sysprop-platform-removed.txt": nil,
- "prebuilts/sdk/28/test/api/sysprop-platform-removed.txt": nil,
- "prebuilts/sdk/28/public/api/sysprop-platform-on-product.txt": nil,
- "prebuilts/sdk/28/system/api/sysprop-platform-on-product.txt": nil,
- "prebuilts/sdk/28/test/api/sysprop-platform-on-product.txt": nil,
- "prebuilts/sdk/28/public/api/sysprop-platform-on-product-removed.txt": nil,
- "prebuilts/sdk/28/system/api/sysprop-platform-on-product-removed.txt": nil,
- "prebuilts/sdk/28/test/api/sysprop-platform-on-product-removed.txt": nil,
- "prebuilts/sdk/28/public/api/sysprop-vendor.txt": nil,
- "prebuilts/sdk/28/system/api/sysprop-vendor.txt": nil,
- "prebuilts/sdk/28/test/api/sysprop-vendor.txt": nil,
- "prebuilts/sdk/28/public/api/sysprop-vendor-removed.txt": nil,
- "prebuilts/sdk/28/system/api/sysprop-vendor-removed.txt": nil,
- "prebuilts/sdk/28/test/api/sysprop-vendor-removed.txt": nil,
- "prebuilts/sdk/tools/core-lambda-stubs.jar": nil,
- "prebuilts/sdk/Android.bp": []byte(`prebuilt_apis { name: "sdk", api_dirs: ["28", "current"],}`),
+ "Android.bp": []byte(bp),
+ "a.java": nil,
+ "b.java": nil,
+ "c.java": nil,
+ "d.cpp": nil,
+ "api/sysprop-platform-current.txt": nil,
+ "api/sysprop-platform-latest.txt": nil,
+ "api/sysprop-platform-on-product-current.txt": nil,
+ "api/sysprop-platform-on-product-latest.txt": nil,
+ "api/sysprop-vendor-current.txt": nil,
+ "api/sysprop-vendor-latest.txt": nil,
+ "api/sysprop-odm-current.txt": nil,
+ "api/sysprop-odm-latest.txt": nil,
+ "framework/aidl/a.aidl": nil,
// For framework-res, which is an implicit dependency for framework
"AndroidManifest.xml": nil,
@@ -155,6 +125,7 @@
"android/sysprop/PlatformProperties.sysprop": nil,
"com/android/VendorProperties.sysprop": nil,
+ "com/android2/OdmProperties.sysprop": nil,
}
for k, v := range fs {
@@ -168,7 +139,7 @@
func run(t *testing.T, ctx *android.TestContext, config android.Config) {
t.Helper()
- _, errs := ctx.ParseFileList(".", []string{"Android.bp", "prebuilts/sdk/Android.bp"})
+ _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
android.FailIfErrored(t, errs)
_, errs = ctx.PrepareBuildActions(config)
android.FailIfErrored(t, errs)
@@ -221,6 +192,14 @@
vendor_available: true,
}
+ sysprop_library {
+ name: "sysprop-odm",
+ srcs: ["com/android2/OdmProperties.sysprop"],
+ api_packages: ["com.android2"],
+ property_owner: "Odm",
+ device_specific: true,
+ }
+
java_library {
name: "java-platform",
srcs: ["c.java"],
@@ -288,20 +267,40 @@
name: "liblog",
symbol_file: "",
}
+
+ java_library {
+ name: "sysprop-library-stub-platform",
+ sdk_version: "core_current",
+ }
+
+ java_library {
+ name: "sysprop-library-stub-vendor",
+ soc_specific: true,
+ sdk_version: "core_current",
+ }
`)
+ // Check for generated cc_library
+ for _, variant := range []string{
+ "android_arm_armv7-a-neon_vendor_shared",
+ "android_arm_armv7-a-neon_vendor_static",
+ "android_arm64_armv8-a_vendor_shared",
+ "android_arm64_armv8-a_vendor_static",
+ } {
+ ctx.ModuleForTests("libsysprop-platform", variant)
+ ctx.ModuleForTests("libsysprop-vendor", variant)
+ ctx.ModuleForTests("libsysprop-odm", variant)
+ }
+
for _, variant := range []string{
"android_arm_armv7-a-neon_core_shared",
"android_arm_armv7-a-neon_core_static",
- "android_arm_armv7-a-neon_vendor_shared",
- "android_arm_armv7-a-neon_vendor_static",
"android_arm64_armv8-a_core_shared",
"android_arm64_armv8-a_core_static",
- "android_arm64_armv8-a_vendor_shared",
- "android_arm64_armv8-a_vendor_static",
} {
- // Check for generated cc_library
ctx.ModuleForTests("libsysprop-platform", variant)
+
+ // core variant of vendor-owned sysprop_library is for product
ctx.ModuleForTests("libsysprop-vendor", variant)
}
diff --git a/tradefed/autogen.go b/tradefed/autogen.go
index 952b022..7cd7c5a 100644
--- a/tradefed/autogen.go
+++ b/tradefed/autogen.go
@@ -24,6 +24,8 @@
"android/soong/android"
)
+const test_xml_indent = " "
+
func getTestConfigTemplate(ctx android.ModuleContext, prop *string) android.OptionalPath {
return ctx.ExpandOptionalSource(prop, "test_config_template")
}
@@ -72,13 +74,25 @@
}
type Preparer struct {
- Class string
+ Class string
+ Options []Option
}
var _ Config = Preparer{}
func (p Preparer) Config() string {
- return fmt.Sprintf(`<target_preparer class="%s" />`, p.Class)
+ var optionStrings []string
+ for _, option := range p.Options {
+ optionStrings = append(optionStrings, option.Config())
+ }
+ var options string
+ if len(p.Options) == 0 {
+ options = ""
+ } else {
+ optionDelimiter := fmt.Sprintf("\\n%s%s", test_xml_indent, test_xml_indent)
+ options = optionDelimiter + strings.Join(optionStrings, optionDelimiter)
+ }
+ return fmt.Sprintf(`<target_preparer class="%s">%s\n%s</target_preparer>`, p.Class, options, test_xml_indent)
}
func autogenTemplate(ctx android.ModuleContext, output android.WritablePath, template string, configs []Config) {
@@ -86,7 +100,7 @@
for _, config := range configs {
configStrings = append(configStrings, config.Config())
}
- extraConfigs := strings.Join(configStrings, "\n ")
+ extraConfigs := strings.Join(configStrings, fmt.Sprintf("\\n%s", test_xml_indent))
extraConfigs = proptools.NinjaAndShellEscape(extraConfigs)
ctx.Build(pctx, android.BuildParams{
diff --git a/ui/build/cleanbuild.go b/ui/build/cleanbuild.go
index 8e7f96a..bfe2c36 100644
--- a/ui/build/cleanbuild.go
+++ b/ui/build/cleanbuild.go
@@ -99,6 +99,7 @@
productOut("*.img"),
productOut("*.zip"),
productOut("android-info.txt"),
+ productOut("apex"),
productOut("kernel"),
productOut("data"),
productOut("skin"),
diff --git a/ui/build/paths/config.go b/ui/build/paths/config.go
index 100cc65..786e7d3 100644
--- a/ui/build/paths/config.go
+++ b/ui/build/paths/config.go
@@ -118,72 +118,21 @@
"ld.gold": Forbidden,
"pkg-config": Forbidden,
- // On Linux we'll use the toybox versions of these instead.
- "basename": LinuxOnlyPrebuilt,
- "cat": LinuxOnlyPrebuilt,
- "chmod": LinuxOnlyPrebuilt,
- "cmp": LinuxOnlyPrebuilt,
- "cp": LinuxOnlyPrebuilt,
- "comm": LinuxOnlyPrebuilt,
- "cut": LinuxOnlyPrebuilt,
- "date": LinuxOnlyPrebuilt,
- "dirname": LinuxOnlyPrebuilt,
- "du": LinuxOnlyPrebuilt,
- "echo": LinuxOnlyPrebuilt,
- "egrep": LinuxOnlyPrebuilt,
- "env": LinuxOnlyPrebuilt,
- "getconf": LinuxOnlyPrebuilt,
- "grep": LinuxOnlyPrebuilt,
- "head": LinuxOnlyPrebuilt,
- "hostname": LinuxOnlyPrebuilt,
- "id": LinuxOnlyPrebuilt,
- "ln": LinuxOnlyPrebuilt,
- "ls": LinuxOnlyPrebuilt,
- "md5sum": LinuxOnlyPrebuilt,
- "mkdir": LinuxOnlyPrebuilt,
- "mktemp": LinuxOnlyPrebuilt,
- "mv": LinuxOnlyPrebuilt,
- "od": LinuxOnlyPrebuilt,
- "paste": LinuxOnlyPrebuilt,
- "pgrep": LinuxOnlyPrebuilt,
- "pkill": LinuxOnlyPrebuilt,
- "ps": LinuxOnlyPrebuilt,
- "pwd": LinuxOnlyPrebuilt,
- "readlink": LinuxOnlyPrebuilt,
- "rm": LinuxOnlyPrebuilt,
- "rmdir": LinuxOnlyPrebuilt,
- "sed": LinuxOnlyPrebuilt,
- "seq": LinuxOnlyPrebuilt,
- "setsid": LinuxOnlyPrebuilt,
- "sha1sum": LinuxOnlyPrebuilt,
- "sha256sum": LinuxOnlyPrebuilt,
- "sha512sum": LinuxOnlyPrebuilt,
- "sleep": LinuxOnlyPrebuilt,
- "sort": LinuxOnlyPrebuilt,
- "stat": LinuxOnlyPrebuilt,
- "tail": LinuxOnlyPrebuilt,
- "tar": LinuxOnlyPrebuilt,
- "tee": LinuxOnlyPrebuilt,
- "timeout": LinuxOnlyPrebuilt,
- "touch": LinuxOnlyPrebuilt,
- "true": LinuxOnlyPrebuilt,
- "uname": LinuxOnlyPrebuilt,
- "uniq": LinuxOnlyPrebuilt,
- "unix2dos": LinuxOnlyPrebuilt,
- "wc": LinuxOnlyPrebuilt,
- "whoami": LinuxOnlyPrebuilt,
- "which": LinuxOnlyPrebuilt,
- "xargs": LinuxOnlyPrebuilt,
- "xxd": LinuxOnlyPrebuilt,
+ // These are currently Linux-only toybox tools (but can be switched now).
+ "date": LinuxOnlyPrebuilt,
+
+ // These are toybox tools that only work on Linux.
+ "pgrep": LinuxOnlyPrebuilt,
+ "pkill": LinuxOnlyPrebuilt,
+ "ps": LinuxOnlyPrebuilt,
}
func init() {
if runtime.GOOS == "darwin" {
- Configuration["md5"] = Allowed
Configuration["sw_vers"] = Allowed
Configuration["xcrun"] = Allowed
- // We don't have darwin prebuilts for some tools (like toybox),
+ // We don't have darwin prebuilts for some tools,
// so allow the host versions.
for name, config := range Configuration {
if config.LinuxOnlyPrebuilt {