diff options
author | Jiyong Park <jiyong@google.com> | 2019-01-19 19:24:06 +0900 |
---|---|---|
committer | Jiyong Park <jiyong@google.com> | 2019-01-28 20:02:27 +0900 |
commit | 58e364a373ede0bd6b798645c8d271ee71255af3 (patch) | |
tree | ca3330b181e78b7a5273ff25f03772cad7d46d80 /apex | |
parent | ee0413915438f2cfe1b84ae4be64d3974e80be85 (diff) | |
download | build_soong-58e364a373ede0bd6b798645c8d271ee71255af3.tar.gz build_soong-58e364a373ede0bd6b798645c8d271ee71255af3.tar.bz2 build_soong-58e364a373ede0bd6b798645c8d271ee71255af3.zip |
Add __ANDROID_APEX__
A module can be built multiple times when it is referenced from one
or more APEXes. Sometimes, it is required for the module to behave
differently depending on the context; e.g., do A when built form
APEX M, do B when built for APEX N, and do C when built for platform.
The idea is to have a macro __ANDROID_APEX__ which is set to the
name of the apex that the module is built for. It is undefined when
the module is built for platform.
Bug: 122714993
Test: m (apex_test amended)
Change-Id: I11a89c6a0e799f4810194de7ef9ee472a71ca498
Diffstat (limited to 'apex')
-rw-r--r-- | apex/apex_test.go | 65 |
1 files changed, 55 insertions, 10 deletions
diff --git a/apex/apex_test.go b/apex/apex_test.go index dbc85d92..699ef6d1 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -123,16 +123,17 @@ func testApex(t *testing.T, bp string) *android.TestContext { ` ctx.MockFileSystem(map[string][]byte{ - "Android.bp": []byte(bp), - "build/target/product/security": nil, - "apex_manifest.json": nil, - "system/sepolicy/apex/myapex-file_contexts": nil, - "mylib.cpp": nil, - "myprebuilt": nil, - "vendor/foo/devkeys/test.x509.pem": nil, - "vendor/foo/devkeys/test.pk8": nil, - "vendor/foo/devkeys/testkey.avbpubkey": nil, - "vendor/foo/devkeys/testkey.pem": nil, + "Android.bp": []byte(bp), + "build/target/product/security": nil, + "apex_manifest.json": nil, + "system/sepolicy/apex/myapex-file_contexts": nil, + "system/sepolicy/apex/otherapex-file_contexts": nil, + "mylib.cpp": nil, + "myprebuilt": nil, + "vendor/foo/devkeys/test.x509.pem": nil, + "vendor/foo/devkeys/test.pk8": nil, + "vendor/foo/devkeys/testkey.avbpubkey": nil, + "vendor/foo/devkeys/testkey.pem": nil, }) _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) android.FailIfErrored(t, errs) @@ -729,3 +730,47 @@ func TestKeys(t *testing.T) { "vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8") } } + +func TestMacro(t *testing.T) { + ctx := testApex(t, ` + apex { + name: "myapex", + key: "myapex.key", + native_shared_libs: ["mylib"], + } + + apex { + name: "otherapex", + 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"], + system_shared_libs: [], + stl: "none", + } + `) + + // non-APEX variant does not have __ANDROID__APEX__ defined + mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"] + ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex") + ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex") + + // APEX variant has __ANDROID_APEX__=<apexname> defined + mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"] + ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex") + ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex") + + // APEX variant has __ANDROID_APEX__=<apexname> defined + mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_otherapex").Rule("cc").Args["cFlags"] + ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex") + ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex") +} |