aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--android/config.go24
-rw-r--r--android/onceper.go16
-rw-r--r--android/onceper_test.go40
-rw-r--r--android/prebuilt_etc.go10
-rw-r--r--android/prebuilt_etc_test.go16
-rw-r--r--android/util.go25
-rw-r--r--android/variable.go2
-rw-r--r--cc/cc.go6
-rw-r--r--cc/cc_test.go49
-rw-r--r--cc/ndk_library.go4
-rw-r--r--cc/sanitize.go5
-rw-r--r--cc/vndk.go353
-rw-r--r--java/android_manifest.go2
-rw-r--r--java/app.go18
-rw-r--r--java/device_host_converter.go6
-rw-r--r--java/java.go4
-rw-r--r--java/kotlin.go18
-rwxr-xr-xscripts/gen-kotlin-build-file.sh9
-rwxr-xr-xscripts/manifest_fixer_test.py2
19 files changed, 531 insertions, 78 deletions
diff --git a/android/config.go b/android/config.go
index 15e2ad4c..a18feb6d 100644
--- a/android/config.go
+++ b/android/config.go
@@ -288,6 +288,10 @@ func TestArchConfig(buildDir string, env map[string]string) Config {
288 288
289 config.BuildOsVariant = config.Targets[BuildOs][0].String() 289 config.BuildOsVariant = config.Targets[BuildOs][0].String()
290 config.BuildOsCommonVariant = getCommonTargets(config.Targets[BuildOs])[0].String() 290 config.BuildOsCommonVariant = getCommonTargets(config.Targets[BuildOs])[0].String()
291 config.TestProductVariables.DeviceArch = proptools.StringPtr("arm64")
292 config.TestProductVariables.DeviceArchVariant = proptools.StringPtr("armv8-a")
293 config.TestProductVariables.DeviceSecondaryArch = proptools.StringPtr("arm")
294 config.TestProductVariables.DeviceSecondaryArchVariant = proptools.StringPtr("armv7-a-neon")
291 295
292 return testConfig 296 return testConfig
293} 297}
@@ -1100,3 +1104,23 @@ func (c *config) ProductPrivateSepolicyDirs() []string {
1100func (c *config) ProductCompatibleProperty() bool { 1104func (c *config) ProductCompatibleProperty() bool {
1101 return Bool(c.productVariables.ProductCompatibleProperty) 1105 return Bool(c.productVariables.ProductCompatibleProperty)
1102} 1106}
1107
1108func (c *deviceConfig) BoardVndkRuntimeDisable() bool {
1109 return Bool(c.config.productVariables.BoardVndkRuntimeDisable)
1110}
1111
1112func (c *deviceConfig) DeviceArch() string {
1113 return String(c.config.productVariables.DeviceArch)
1114}
1115
1116func (c *deviceConfig) DeviceArchVariant() string {
1117 return String(c.config.productVariables.DeviceArchVariant)
1118}
1119
1120func (c *deviceConfig) DeviceSecondaryArch() string {
1121 return String(c.config.productVariables.DeviceSecondaryArch)
1122}
1123
1124func (c *deviceConfig) DeviceSecondaryArchVariant() string {
1125 return String(c.config.productVariables.DeviceSecondaryArchVariant)
1126}
diff --git a/android/onceper.go b/android/onceper.go
index 5ad17fa9..ff865c2e 100644
--- a/android/onceper.go
+++ b/android/onceper.go
@@ -40,7 +40,8 @@ func (once *OncePer) maybeWaitFor(key OnceKey, value interface{}) interface{} {
40} 40}
41 41
42// Once computes a value the first time it is called with a given key per OncePer, and returns the 42// Once computes a value the first time it is called with a given key per OncePer, and returns the
43// value without recomputing when called with the same key. key must be hashable. 43// value without recomputing when called with the same key. key must be hashable. If value panics
44// the panic will be propagated but the next call to Once with the same key will return nil.
44func (once *OncePer) Once(key OnceKey, value func() interface{}) interface{} { 45func (once *OncePer) Once(key OnceKey, value func() interface{}) interface{} {
45 // Fast path: check if the key is already in the map 46 // Fast path: check if the key is already in the map
46 if v, ok := once.values.Load(key); ok { 47 if v, ok := once.values.Load(key); ok {
@@ -54,10 +55,15 @@ func (once *OncePer) Once(key OnceKey, value func() interface{}) interface{} {
54 return once.maybeWaitFor(key, v) 55 return once.maybeWaitFor(key, v)
55 } 56 }
56 57
57 // The waiter is inserted, call the value constructor, store it, and signal the waiter 58 // The waiter is inserted, call the value constructor, store it, and signal the waiter. Use defer in case
58 v := value() 59 // the function panics.
59 once.values.Store(key, v) 60 var v interface{}
60 close(waiter) 61 defer func() {
62 once.values.Store(key, v)
63 close(waiter)
64 }()
65
66 v = value()
61 67
62 return v 68 return v
63} 69}
diff --git a/android/onceper_test.go b/android/onceper_test.go
index 95303baf..1a55ff4b 100644
--- a/android/onceper_test.go
+++ b/android/onceper_test.go
@@ -175,3 +175,43 @@ func TestOncePerReentrant(t *testing.T) {
175 t.Errorf(`reentrant Once should return "a": %q`, a) 175 t.Errorf(`reentrant Once should return "a": %q`, a)
176 } 176 }
177} 177}
178
179// Test that a recovered panic in a Once function doesn't deadlock
180func TestOncePerPanic(t *testing.T) {
181 once := OncePer{}
182 key := NewOnceKey("key")
183
184 ch := make(chan interface{})
185
186 var a interface{}
187
188 go func() {
189 defer func() {
190 ch <- recover()
191 }()
192
193 a = once.Once(key, func() interface{} {
194 panic("foo")
195 })
196 }()
197
198 p := <-ch
199
200 if p.(string) != "foo" {
201 t.Errorf(`expected panic with "foo", got %#v`, p)
202 }
203
204 if a != nil {
205 t.Errorf(`expected a to be nil, got %#v`, a)
206 }
207
208 // If the call to Once that panicked leaves the key in a bad state this will deadlock
209 b := once.Once(key, func() interface{} {
210 return "bar"
211 })
212
213 // The second call to Once should return nil inserted by the first call that panicked.
214 if b != nil {
215 t.Errorf(`expected b to be nil, got %#v`, b)
216 }
217}
diff --git a/android/prebuilt_etc.go b/android/prebuilt_etc.go
index bec24c77..b13ce2a9 100644
--- a/android/prebuilt_etc.go
+++ b/android/prebuilt_etc.go
@@ -23,6 +23,7 @@ func init() {
23 RegisterModuleType("prebuilt_etc_host", PrebuiltEtcHostFactory) 23 RegisterModuleType("prebuilt_etc_host", PrebuiltEtcHostFactory)
24 RegisterModuleType("prebuilt_usr_share", PrebuiltUserShareFactory) 24 RegisterModuleType("prebuilt_usr_share", PrebuiltUserShareFactory)
25 RegisterModuleType("prebuilt_usr_share_host", PrebuiltUserShareHostFactory) 25 RegisterModuleType("prebuilt_usr_share_host", PrebuiltUserShareHostFactory)
26 RegisterModuleType("prebuilt_font", PrebuiltFontFactory)
26 27
27 PreDepsMutators(func(ctx RegisterMutatorsContext) { 28 PreDepsMutators(func(ctx RegisterMutatorsContext) {
28 ctx.BottomUp("prebuilt_etc", prebuiltEtcMutator).Parallel() 29 ctx.BottomUp("prebuilt_etc", prebuiltEtcMutator).Parallel()
@@ -240,3 +241,12 @@ func prebuiltEtcMutator(mctx BottomUpMutatorContext) {
240 } 241 }
241 } 242 }
242} 243}
244
245// prebuilt_font installs a font in <partition>/fonts directory.
246func PrebuiltFontFactory() Module {
247 module := &PrebuiltEtc{installDirBase: "fonts"}
248 InitPrebuiltEtcModule(module)
249 // This module is device-only
250 InitAndroidArchModule(module, DeviceSupported, MultilibFirst)
251 return module
252}
diff --git a/android/prebuilt_etc_test.go b/android/prebuilt_etc_test.go
index 08700ae5..a5c44809 100644
--- a/android/prebuilt_etc_test.go
+++ b/android/prebuilt_etc_test.go
@@ -30,6 +30,7 @@ func testPrebuiltEtc(t *testing.T, bp string) (*TestContext, Config) {
30 ctx.RegisterModuleType("prebuilt_etc_host", ModuleFactoryAdaptor(PrebuiltEtcHostFactory)) 30 ctx.RegisterModuleType("prebuilt_etc_host", ModuleFactoryAdaptor(PrebuiltEtcHostFactory))
31 ctx.RegisterModuleType("prebuilt_usr_share", ModuleFactoryAdaptor(PrebuiltUserShareFactory)) 31 ctx.RegisterModuleType("prebuilt_usr_share", ModuleFactoryAdaptor(PrebuiltUserShareFactory))
32 ctx.RegisterModuleType("prebuilt_usr_share_host", ModuleFactoryAdaptor(PrebuiltUserShareHostFactory)) 32 ctx.RegisterModuleType("prebuilt_usr_share_host", ModuleFactoryAdaptor(PrebuiltUserShareHostFactory))
33 ctx.RegisterModuleType("prebuilt_font", ModuleFactoryAdaptor(PrebuiltFontFactory))
33 ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) { 34 ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
34 ctx.BottomUp("prebuilt_etc", prebuiltEtcMutator).Parallel() 35 ctx.BottomUp("prebuilt_etc", prebuiltEtcMutator).Parallel()
35 }) 36 })
@@ -219,3 +220,18 @@ func TestPrebuiltUserShareHostInstallDirPath(t *testing.T) {
219 t.Errorf("expected %q, got %q", expected, p.installDirPath.RelPathString()) 220 t.Errorf("expected %q, got %q", expected, p.installDirPath.RelPathString())
220 } 221 }
221} 222}
223
224func TestPrebuiltFontInstallDirPath(t *testing.T) {
225 ctx, _ := testPrebuiltEtc(t, `
226 prebuilt_font {
227 name: "foo.conf",
228 src: "foo.conf",
229 }
230 `)
231
232 p := ctx.ModuleForTests("foo.conf", "android_arm64_armv8-a_core").Module().(*PrebuiltEtc)
233 expected := "target/product/test_device/system/fonts"
234 if p.installDirPath.RelPathString() != expected {
235 t.Errorf("expected %q, got %q", expected, p.installDirPath.RelPathString())
236 }
237}
diff --git a/android/util.go b/android/util.go
index f9dce6fe..f7a3437c 100644
--- a/android/util.go
+++ b/android/util.go
@@ -52,6 +52,31 @@ func JoinWithPrefix(strs []string, prefix string) string {
52 return string(ret) 52 return string(ret)
53} 53}
54 54
55func JoinWithSuffix(strs []string, suffix string, separator string) string {
56 if len(strs) == 0 {
57 return ""
58 }
59
60 if len(strs) == 1 {
61 return strs[0] + suffix
62 }
63
64 n := len(" ") * (len(strs) - 1)
65 for _, s := range strs {
66 n += len(suffix) + len(s)
67 }
68
69 ret := make([]byte, 0, n)
70 for i, s := range strs {
71 if i != 0 {
72 ret = append(ret, separator...)
73 }
74 ret = append(ret, s...)
75 ret = append(ret, suffix...)
76 }
77 return string(ret)
78}
79
55func sortedKeys(m map[string][]string) []string { 80func sortedKeys(m map[string][]string) []string {
56 s := make([]string, 0, len(m)) 81 s := make([]string, 0, len(m))
57 for k := range m { 82 for k := range m {
diff --git a/android/variable.go b/android/variable.go
index c5006716..ff3ebaf0 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -279,6 +279,8 @@ type productVariables struct {
279 BoardPlatPrivateSepolicyDirs []string `json:",omitempty"` 279 BoardPlatPrivateSepolicyDirs []string `json:",omitempty"`
280 BoardSepolicyM4Defs []string `json:",omitempty"` 280 BoardSepolicyM4Defs []string `json:",omitempty"`
281 281
282 BoardVndkRuntimeDisable *bool `json:",omitempty"`
283
282 VendorVars map[string]map[string]string `json:",omitempty"` 284 VendorVars map[string]map[string]string `json:",omitempty"`
283 285
284 Ndk_abis *bool `json:",omitempty"` 286 Ndk_abis *bool `json:",omitempty"`
diff --git a/cc/cc.go b/cc/cc.go
index eaf41d88..a3b9a92d 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -1011,7 +1011,7 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
1011 } 1011 }
1012 } 1012 }
1013 1013
1014 if c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid() { 1014 if c.installable() {
1015 c.installer.install(ctx, c.outputFile.Path()) 1015 c.installer.install(ctx, c.outputFile.Path())
1016 if ctx.Failed() { 1016 if ctx.Failed() {
1017 return 1017 return
@@ -1968,6 +1968,10 @@ func (c *Module) IsInstallableToApex() bool {
1968 return false 1968 return false
1969} 1969}
1970 1970
1971func (c *Module) installable() bool {
1972 return c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid()
1973}
1974
1971func (c *Module) imageVariation() string { 1975func (c *Module) imageVariation() string {
1972 variation := "core" 1976 variation := "core"
1973 if c.useVndk() { 1977 if c.useVndk() {
diff --git a/cc/cc_test.go b/cc/cc_test.go
index f3d5e60d..36d8aa41 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -20,6 +20,7 @@ import (
20 "fmt" 20 "fmt"
21 "io/ioutil" 21 "io/ioutil"
22 "os" 22 "os"
23 "path/filepath"
23 "reflect" 24 "reflect"
24 "sort" 25 "sort"
25 "strings" 26 "strings"
@@ -75,6 +76,7 @@ func createTestContext(t *testing.T, config android.Config, bp string, os androi
75 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { 76 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
76 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel() 77 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
77 }) 78 })
79 ctx.RegisterSingletonType("vndk-snapshot", android.SingletonFactoryAdaptor(VndkSnapshotSingleton))
78 ctx.Register() 80 ctx.Register()
79 81
80 // add some modules that are required by the compiler and/or linker 82 // add some modules that are required by the compiler and/or linker
@@ -286,8 +288,28 @@ func checkVndkModule(t *testing.T, ctx *android.TestContext, name, subDir string
286 } 288 }
287} 289}
288 290
291func checkVndkSnapshot(t *testing.T, ctx *android.TestContext, name, subDir, variant string) {
292 vndkSnapshot := ctx.SingletonForTests("vndk-snapshot")
293
294 snapshotPath := filepath.Join(subDir, name+".so")
295 mod := ctx.ModuleForTests(name, variant).Module().(*Module)
296 if !mod.outputFile.Valid() {
297 t.Errorf("%q must have output\n", name)
298 return
299 }
300
301 out := vndkSnapshot.Output(snapshotPath)
302 if out.Input != mod.outputFile.Path() {
303 t.Errorf("The input of VNDK snapshot must be %q, but %q", out.Input.String(), mod.outputFile.String())
304 }
305}
306
289func TestVndk(t *testing.T) { 307func TestVndk(t *testing.T) {
290 ctx := testCc(t, ` 308 config := android.TestArchConfig(buildDir, nil)
309 config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
310 config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
311
312 ctx := testCcWithConfig(t, `
291 cc_library { 313 cc_library {
292 name: "libvndk", 314 name: "libvndk",
293 vendor_available: true, 315 vendor_available: true,
@@ -325,12 +347,35 @@ func TestVndk(t *testing.T) {
325 }, 347 },
326 nocrt: true, 348 nocrt: true,
327 } 349 }
328 `) 350 `, config)
329 351
330 checkVndkModule(t, ctx, "libvndk", "vndk-VER", false, "") 352 checkVndkModule(t, ctx, "libvndk", "vndk-VER", false, "")
331 checkVndkModule(t, ctx, "libvndk_private", "vndk-VER", false, "") 353 checkVndkModule(t, ctx, "libvndk_private", "vndk-VER", false, "")
332 checkVndkModule(t, ctx, "libvndk_sp", "vndk-sp-VER", true, "") 354 checkVndkModule(t, ctx, "libvndk_sp", "vndk-sp-VER", true, "")
333 checkVndkModule(t, ctx, "libvndk_sp_private", "vndk-sp-VER", true, "") 355 checkVndkModule(t, ctx, "libvndk_sp_private", "vndk-sp-VER", true, "")
356
357 // Check VNDK snapshot output.
358
359 snapshotDir := "vndk-snapshot"
360 snapshotVariantPath := filepath.Join(buildDir, snapshotDir, "arm64")
361
362 vndkLibPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
363 "arm64", "armv8-a"))
364 vndkLib2ndPath := filepath.Join(snapshotVariantPath, fmt.Sprintf("arch-%s-%s",
365 "arm", "armv7-a-neon"))
366
367 vndkCoreLibPath := filepath.Join(vndkLibPath, "shared", "vndk-core")
368 vndkSpLibPath := filepath.Join(vndkLibPath, "shared", "vndk-sp")
369 vndkCoreLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-core")
370 vndkSpLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-sp")
371
372 variant := "android_arm64_armv8-a_vendor_shared"
373 variant2nd := "android_arm_armv7-a-neon_vendor_shared"
374
375 checkVndkSnapshot(t, ctx, "libvndk", vndkCoreLibPath, variant)
376 checkVndkSnapshot(t, ctx, "libvndk", vndkCoreLib2ndPath, variant2nd)
377 checkVndkSnapshot(t, ctx, "libvndk_sp", vndkSpLibPath, variant)
378 checkVndkSnapshot(t, ctx, "libvndk_sp", vndkSpLib2ndPath, variant2nd)
334} 379}
335 380
336func TestVndkDepError(t *testing.T) { 381func TestVndkDepError(t *testing.T) {
diff --git a/cc/ndk_library.go b/cc/ndk_library.go
index 57fad7ca..ff990b5f 100644
--- a/cc/ndk_library.go
+++ b/cc/ndk_library.go
@@ -38,9 +38,12 @@ var (
38 ndkLibrarySuffix = ".ndk" 38 ndkLibrarySuffix = ".ndk"
39 39
40 ndkPrebuiltSharedLibs = []string{ 40 ndkPrebuiltSharedLibs = []string{
41 "aaudio",
42 "amidi",
41 "android", 43 "android",
42 "binder_ndk", 44 "binder_ndk",
43 "c", 45 "c",
46 "camera2ndk",
44 "dl", 47 "dl",
45 "EGL", 48 "EGL",
46 "GLESv1_CM", 49 "GLESv1_CM",
@@ -49,6 +52,7 @@ var (
49 "jnigraphics", 52 "jnigraphics",
50 "log", 53 "log",
51 "mediandk", 54 "mediandk",
55 "nativewindow",
52 "m", 56 "m",
53 "OpenMAXAL", 57 "OpenMAXAL",
54 "OpenSLES", 58 "OpenSLES",
diff --git a/cc/sanitize.go b/cc/sanitize.go
index acf2befd..4486d2ef 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -392,6 +392,11 @@ func (sanitize *sanitize) deps(ctx BaseModuleContext, deps Deps) Deps {
392 if ctx.Device() { 392 if ctx.Device() {
393 if Bool(sanitize.Properties.Sanitize.Address) { 393 if Bool(sanitize.Properties.Sanitize.Address) {
394 deps.StaticLibs = append(deps.StaticLibs, asanLibs...) 394 deps.StaticLibs = append(deps.StaticLibs, asanLibs...)
395 // Compiling asan and having libc_scudo in the same
396 // executable will cause the executable to crash.
397 // Remove libc_scudo since it is only used to override
398 // allocation functions which asan already overrides.
399 _, deps.SharedLibs = removeFromList("libc_scudo", deps.SharedLibs)
395 } 400 }
396 } 401 }
397 402
diff --git a/cc/vndk.go b/cc/vndk.go
index 7859fa21..a1d67af1 100644
--- a/cc/vndk.go
+++ b/cc/vndk.go
@@ -16,6 +16,8 @@ package cc
16 16
17import ( 17import (
18 "errors" 18 "errors"
19 "fmt"
20 "path/filepath"
19 "sort" 21 "sort"
20 "strings" 22 "strings"
21 "sync" 23 "sync"
@@ -197,9 +199,20 @@ var (
197 llndkLibrariesKey = android.NewOnceKey("llndkLibrarires") 199 llndkLibrariesKey = android.NewOnceKey("llndkLibrarires")
198 vndkPrivateLibrariesKey = android.NewOnceKey("vndkPrivateLibrarires") 200 vndkPrivateLibrariesKey = android.NewOnceKey("vndkPrivateLibrarires")
199 vndkUsingCoreVariantLibrariesKey = android.NewOnceKey("vndkUsingCoreVariantLibrarires") 201 vndkUsingCoreVariantLibrariesKey = android.NewOnceKey("vndkUsingCoreVariantLibrarires")
202 modulePathsKey = android.NewOnceKey("modulePaths")
203 vndkSnapshotOutputsKey = android.NewOnceKey("vndkSnapshotOutputs")
200 vndkLibrariesLock sync.Mutex 204 vndkLibrariesLock sync.Mutex
201) 205)
202 206
207type vndkSnapshotOutputPaths struct {
208 configs android.Paths
209 notices android.Paths
210 vndkCoreLibs android.Paths
211 vndkCoreLibs2nd android.Paths
212 vndkSpLibs android.Paths
213 vndkSpLibs2nd android.Paths
214}
215
203func vndkCoreLibraries(config android.Config) *[]string { 216func vndkCoreLibraries(config android.Config) *[]string {
204 return config.Once(vndkCoreLibrariesKey, func() interface{} { 217 return config.Once(vndkCoreLibrariesKey, func() interface{} {
205 return &[]string{} 218 return &[]string{}
@@ -230,66 +243,296 @@ func vndkUsingCoreVariantLibraries(config android.Config) *[]string {
230 }).(*[]string) 243 }).(*[]string)
231} 244}
232 245
246func modulePaths(config android.Config) map[string]string {
247 return config.Once(modulePathsKey, func() interface{} {
248 return make(map[string]string)
249 }).(map[string]string)
250}
251
252func vndkSnapshotOutputs(config android.Config) *vndkSnapshotOutputPaths {
253 return config.Once(vndkSnapshotOutputsKey, func() interface{} {
254 return &vndkSnapshotOutputPaths{}
255 }).(*vndkSnapshotOutputPaths)
256}
257
258func processLlndkLibrary(mctx android.BottomUpMutatorContext, m *Module) {
259 lib := m.linker.(*llndkStubDecorator)
260 name := strings.TrimSuffix(m.Name(), llndkLibrarySuffix)
261
262 vndkLibrariesLock.Lock()
263 defer vndkLibrariesLock.Unlock()
264
265 llndkLibraries := llndkLibraries(mctx.Config())
266 if !inList(name, *llndkLibraries) {
267 *llndkLibraries = append(*llndkLibraries, name)
268 sort.Strings(*llndkLibraries)
269 }
270 if !Bool(lib.Properties.Vendor_available) {
271 vndkPrivateLibraries := vndkPrivateLibraries(mctx.Config())
272 if !inList(name, *vndkPrivateLibraries) {
273 *vndkPrivateLibraries = append(*vndkPrivateLibraries, name)
274 sort.Strings(*vndkPrivateLibraries)
275 }
276 }
277}
278
279func processVndkLibrary(mctx android.BottomUpMutatorContext, m *Module) {
280 name := strings.TrimPrefix(m.Name(), "prebuilt_")
281
282 vndkLibrariesLock.Lock()
283 defer vndkLibrariesLock.Unlock()
284
285 modulePaths := modulePaths(mctx.Config())
286 if mctx.DeviceConfig().VndkUseCoreVariant() && !inList(name, config.VndkMustUseVendorVariantList) {
287 vndkUsingCoreVariantLibraries := vndkUsingCoreVariantLibraries(mctx.Config())
288 if !inList(name, *vndkUsingCoreVariantLibraries) {
289 *vndkUsingCoreVariantLibraries = append(*vndkUsingCoreVariantLibraries, name)
290 sort.Strings(*vndkUsingCoreVariantLibraries)
291 }
292 }
293 if m.vndkdep.isVndkSp() {
294 vndkSpLibraries := vndkSpLibraries(mctx.Config())
295 if !inList(name, *vndkSpLibraries) {
296 *vndkSpLibraries = append(*vndkSpLibraries, name)
297 sort.Strings(*vndkSpLibraries)
298 modulePaths[name] = mctx.ModuleDir()
299 }
300 } else {
301 vndkCoreLibraries := vndkCoreLibraries(mctx.Config())
302 if !inList(name, *vndkCoreLibraries) {
303 *vndkCoreLibraries = append(*vndkCoreLibraries, name)
304 sort.Strings(*vndkCoreLibraries)
305 modulePaths[name] = mctx.ModuleDir()
306 }
307 }
308 if !Bool(m.VendorProperties.Vendor_available) {
309 vndkPrivateLibraries := vndkPrivateLibraries(mctx.Config())
310 if !inList(name, *vndkPrivateLibraries) {
311 *vndkPrivateLibraries = append(*vndkPrivateLibraries, name)
312 sort.Strings(*vndkPrivateLibraries)
313 }
314 }
315}
316
233// gather list of vndk-core, vndk-sp, and ll-ndk libs 317// gather list of vndk-core, vndk-sp, and ll-ndk libs
234func VndkMutator(mctx android.BottomUpMutatorContext) { 318func VndkMutator(mctx android.BottomUpMutatorContext) {
235 if m, ok := mctx.Module().(*Module); ok && m.Enabled() { 319 m, ok := mctx.Module().(*Module)
236 if lib, ok := m.linker.(*llndkStubDecorator); ok { 320 if !ok {
237 vndkLibrariesLock.Lock() 321 return
238 defer vndkLibrariesLock.Unlock() 322 }
239 323
240 llndkLibraries := llndkLibraries(mctx.Config()) 324 if !m.Enabled() {
241 vndkPrivateLibraries := vndkPrivateLibraries(mctx.Config()) 325 return
242 326 }
243 name := strings.TrimSuffix(m.Name(), llndkLibrarySuffix) 327
244 if !inList(name, *llndkLibraries) { 328 if _, ok := m.linker.(*llndkStubDecorator); ok {
245 *llndkLibraries = append(*llndkLibraries, name) 329 processLlndkLibrary(mctx, m)
246 sort.Strings(*llndkLibraries) 330 return
331 }
332
333 lib, is_lib := m.linker.(*libraryDecorator)
334 prebuilt_lib, is_prebuilt_lib := m.linker.(*prebuiltLibraryLinker)
335
336 if (is_lib && lib.shared()) || (is_prebuilt_lib && prebuilt_lib.shared()) {
337 if m.vndkdep.isVndk() && !m.vndkdep.isVndkExt() {
338 processVndkLibrary(mctx, m)
339 return
340 }
341 }
342}
343
344func init() {
345 android.RegisterSingletonType("vndk-snapshot", VndkSnapshotSingleton)
346 android.RegisterMakeVarsProvider(pctx, func(ctx android.MakeVarsContext) {
347 outputs := vndkSnapshotOutputs(ctx.Config())
348
349 ctx.Strict("SOONG_VNDK_SNAPSHOT_CONFIGS", strings.Join(outputs.configs.Strings(), " "))
350 ctx.Strict("SOONG_VNDK_SNAPSHOT_NOTICES", strings.Join(outputs.notices.Strings(), " "))
351 ctx.Strict("SOONG_VNDK_SNAPSHOT_CORE_LIBS", strings.Join(outputs.vndkCoreLibs.Strings(), " "))
352 ctx.Strict("SOONG_VNDK_SNAPSHOT_SP_LIBS", strings.Join(outputs.vndkSpLibs.Strings(), " "))
353 ctx.Strict("SOONG_VNDK_SNAPSHOT_CORE_LIBS_2ND", strings.Join(outputs.vndkCoreLibs2nd.Strings(), " "))
354 ctx.Strict("SOONG_VNDK_SNAPSHOT_SP_LIBS_2ND", strings.Join(outputs.vndkSpLibs2nd.Strings(), " "))
355 })
356}
357
358func VndkSnapshotSingleton() android.Singleton {
359 return &vndkSnapshotSingleton{}
360}
361
362type vndkSnapshotSingleton struct{}
363
364func installVndkSnapshotLib(ctx android.SingletonContext, name string, module *Module, dir string) android.Path {
365 if !module.outputFile.Valid() {
366 panic(fmt.Errorf("module %s has no outputFile\n", name))
367 }
368
369 out := android.PathForOutput(ctx, dir, name+".so")
370
371 ctx.Build(pctx, android.BuildParams{
372 Rule: android.Cp,
373 Input: module.outputFile.Path(),
374 Output: out,
375 Description: "vndk snapshot " + dir + "/" + name + ".so",
376 Args: map[string]string{
377 "cpFlags": "-f -L",
378 },
379 })
380
381 return out
382}
383
384func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) {
385 // BOARD_VNDK_VERSION must be set to 'current' in order to generate a VNDK snapshot.
386 if ctx.DeviceConfig().VndkVersion() != "current" {
387 return
388 }
389
390 if ctx.DeviceConfig().PlatformVndkVersion() == "" {
391 return
392 }
393
394 if ctx.DeviceConfig().BoardVndkRuntimeDisable() {
395 return
396 }
397
398 outputs := vndkSnapshotOutputs(ctx.Config())
399
400 snapshotDir := "vndk-snapshot"
401
402 var vndkLibPath, vndkLib2ndPath string
403
404 snapshotVariantPath := filepath.Join(snapshotDir, ctx.DeviceConfig().DeviceArch())
405 if ctx.DeviceConfig().BinderBitness() == "32" {
406 vndkLibPath = filepath.Join(snapshotVariantPath, "binder32", fmt.Sprintf(
407 "arch-%s-%s", ctx.DeviceConfig().DeviceArch(), ctx.DeviceConfig().DeviceArchVariant()))
408 vndkLib2ndPath = filepath.Join(snapshotVariantPath, "binder32", fmt.Sprintf(
409 "arch-%s-%s", ctx.DeviceConfig().DeviceSecondaryArch(), ctx.DeviceConfig().DeviceSecondaryArchVariant()))
410 } else {
411 vndkLibPath = filepath.Join(snapshotVariantPath, fmt.Sprintf(
412 "arch-%s-%s", ctx.DeviceConfig().DeviceArch(), ctx.DeviceConfig().DeviceArchVariant()))
413 vndkLib2ndPath = filepath.Join(snapshotVariantPath, fmt.Sprintf(
414 "arch-%s-%s", ctx.DeviceConfig().DeviceSecondaryArch(), ctx.DeviceConfig().DeviceSecondaryArchVariant()))
415 }
416
417 vndkCoreLibPath := filepath.Join(vndkLibPath, "shared", "vndk-core")
418 vndkSpLibPath := filepath.Join(vndkLibPath, "shared", "vndk-sp")
419 vndkCoreLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-core")
420 vndkSpLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-sp")
421 noticePath := filepath.Join(snapshotVariantPath, "NOTICE_FILES")
422 noticeBuilt := make(map[string]bool)
423
424 tryBuildNotice := func(m *Module) {
425 name := ctx.ModuleName(m)
426
427 if _, ok := noticeBuilt[name]; ok {
428 return
429 }
430
431 noticeBuilt[name] = true
432
433 if m.NoticeFile().Valid() {
434 out := android.PathForOutput(ctx, noticePath, name+".so.txt")
435 ctx.Build(pctx, android.BuildParams{
436 Rule: android.Cp,
437 Input: m.NoticeFile().Path(),
438 Output: out,
439 Description: "vndk snapshot notice " + name + ".so.txt",
440 Args: map[string]string{
441 "cpFlags": "-f -L",
442 },
443 })
444 outputs.notices = append(outputs.notices, out)
445 }
446 }
447
448 vndkCoreLibraries := vndkCoreLibraries(ctx.Config())
449 vndkSpLibraries := vndkSpLibraries(ctx.Config())
450 vndkPrivateLibraries := vndkPrivateLibraries(ctx.Config())
451
452 ctx.VisitAllModules(func(module android.Module) {
453 m, ok := module.(*Module)
454 if !ok || !m.Enabled() || !m.useVndk() || !m.installable() {
455 return
456 }
457
458 lib, is_lib := m.linker.(*libraryDecorator)
459 prebuilt_lib, is_prebuilt_lib := m.linker.(*prebuiltLibraryLinker)
460
461 if !(is_lib && lib.shared()) && !(is_prebuilt_lib && prebuilt_lib.shared()) {
462 return
463 }
464
465 is_2nd := m.Target().Arch.ArchType != ctx.Config().DevicePrimaryArchType()
466
467 name := ctx.ModuleName(module)
468
469 if inList(name, *vndkCoreLibraries) {
470 if is_2nd {
471 out := installVndkSnapshotLib(ctx, name, m, vndkCoreLib2ndPath)
472 outputs.vndkCoreLibs2nd = append(outputs.vndkCoreLibs2nd, out)
473 } else {
474 out := installVndkSnapshotLib(ctx, name, m, vndkCoreLibPath)
475 outputs.vndkCoreLibs = append(outputs.vndkCoreLibs, out)
247 } 476 }
248 if !Bool(lib.Properties.Vendor_available) { 477 tryBuildNotice(m)
249 if !inList(name, *vndkPrivateLibraries) { 478 } else if inList(name, *vndkSpLibraries) {
250 *vndkPrivateLibraries = append(*vndkPrivateLibraries, name) 479 if is_2nd {
251 sort.Strings(*vndkPrivateLibraries) 480 out := installVndkSnapshotLib(ctx, name, m, vndkSpLib2ndPath)
252 } 481 outputs.vndkSpLibs2nd = append(outputs.vndkSpLibs2nd, out)
482 } else {
483 out := installVndkSnapshotLib(ctx, name, m, vndkSpLibPath)
484 outputs.vndkSpLibs = append(outputs.vndkSpLibs, out)
253 } 485 }
486 tryBuildNotice(m)
487 }
488 })
489
490 configsPath := filepath.Join(snapshotVariantPath, "configs")
491 vndkCoreTxt := android.PathForOutput(ctx, configsPath, "vndkcore.libraries.txt")
492 vndkPrivateTxt := android.PathForOutput(ctx, configsPath, "vndkprivate.libraries.txt")
493 modulePathTxt := android.PathForOutput(ctx, configsPath, "module_paths.txt")
494
495 ctx.Build(pctx, android.BuildParams{
496 Rule: android.WriteFile,
497 Output: vndkCoreTxt,
498 Description: "vndk snapshot vndkcore.libraries.txt",
499 Args: map[string]string{
500 "content": android.JoinWithSuffix(*vndkCoreLibraries, ".so", "\\n"),
501 },
502 })
503 outputs.configs = append(outputs.configs, vndkCoreTxt)
504
505 ctx.Build(pctx, android.BuildParams{
506 Rule: android.WriteFile,
507 Output: vndkPrivateTxt,
508 Description: "vndk snapshot vndkprivate.libraries.txt",
509 Args: map[string]string{
510 "content": android.JoinWithSuffix(*vndkPrivateLibraries, ".so", "\\n"),
511 },
512 })
513 outputs.configs = append(outputs.configs, vndkPrivateTxt)
514
515 var modulePathTxtBuilder strings.Builder
516
517 first := true
518 for lib, dir := range modulePaths(ctx.Config()) {
519 if first {
520 first = false
254 } else { 521 } else {
255 lib, is_lib := m.linker.(*libraryDecorator) 522 modulePathTxtBuilder.WriteString("\\n")
256 prebuilt_lib, is_prebuilt_lib := m.linker.(*prebuiltLibraryLinker)
257 if (is_lib && lib.shared()) || (is_prebuilt_lib && prebuilt_lib.shared()) {
258 name := strings.TrimPrefix(m.Name(), "prebuilt_")
259 if m.vndkdep.isVndk() && !m.vndkdep.isVndkExt() {
260 vndkLibrariesLock.Lock()
261 defer vndkLibrariesLock.Unlock()
262
263 vndkUsingCoreVariantLibraries := vndkUsingCoreVariantLibraries(mctx.Config())
264 vndkSpLibraries := vndkSpLibraries(mctx.Config())
265 vndkCoreLibraries := vndkCoreLibraries(mctx.Config())
266 vndkPrivateLibraries := vndkPrivateLibraries(mctx.Config())
267
268 if mctx.DeviceConfig().VndkUseCoreVariant() && !inList(name, config.VndkMustUseVendorVariantList) {
269 if !inList(name, *vndkUsingCoreVariantLibraries) {
270 *vndkUsingCoreVariantLibraries = append(*vndkUsingCoreVariantLibraries, name)
271 sort.Strings(*vndkUsingCoreVariantLibraries)
272 }
273 }
274 if m.vndkdep.isVndkSp() {
275 if !inList(name, *vndkSpLibraries) {
276 *vndkSpLibraries = append(*vndkSpLibraries, name)
277 sort.Strings(*vndkSpLibraries)
278 }
279 } else {
280 if !inList(name, *vndkCoreLibraries) {
281 *vndkCoreLibraries = append(*vndkCoreLibraries, name)
282 sort.Strings(*vndkCoreLibraries)
283 }
284 }
285 if !Bool(m.VendorProperties.Vendor_available) {
286 if !inList(name, *vndkPrivateLibraries) {
287 *vndkPrivateLibraries = append(*vndkPrivateLibraries, name)
288 sort.Strings(*vndkPrivateLibraries)
289 }
290 }
291 }
292 }
293 } 523 }
524 modulePathTxtBuilder.WriteString(lib)
525 modulePathTxtBuilder.WriteString(".so ")
526 modulePathTxtBuilder.WriteString(dir)
294 } 527 }
528
529 ctx.Build(pctx, android.BuildParams{
530 Rule: android.WriteFile,
531 Output: modulePathTxt,
532 Description: "vndk snapshot module_paths.txt",
533 Args: map[string]string{
534 "content": modulePathTxtBuilder.String(),
535 },
536 })
537 outputs.configs = append(outputs.configs, modulePathTxt)
295} 538}
diff --git a/java/android_manifest.go b/java/android_manifest.go
index 7b378cdf..5d3cfa5e 100644
--- a/java/android_manifest.go
+++ b/java/android_manifest.go
@@ -66,7 +66,7 @@ func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext
66 } 66 }
67 67
68 if useEmbeddedDex { 68 if useEmbeddedDex {
69 args = append(args, "--use-embedded-dex=true") 69 args = append(args, "--use-embedded-dex")
70 } 70 }
71 71
72 var deps android.Paths 72 var deps android.Paths
diff --git a/java/app.go b/java/app.go
index 849af5b9..db9c5ddf 100644
--- a/java/app.go
+++ b/java/app.go
@@ -764,6 +764,19 @@ func (a *AndroidAppImport) shouldUncompressDex(ctx android.ModuleContext) bool {
764 return shouldUncompressDex(ctx, &a.dexpreopter) 764 return shouldUncompressDex(ctx, &a.dexpreopter)
765} 765}
766 766
767func (a *AndroidAppImport) uncompressDex(
768 ctx android.ModuleContext, inputPath android.Path, outputPath android.OutputPath) {
769 rule := android.NewRuleBuilder()
770 rule.Command().
771 Textf(`if (zipinfo %s '*.dex' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then`, inputPath).
772 Tool(ctx.Config().HostToolPath(ctx, "zip2zip")).
773 FlagWithInput("-i ", inputPath).
774 FlagWithOutput("-o ", outputPath).
775 FlagWithArg("-0 ", "'classes*.dex'").
776 Textf(`; else cp -f %s %s; fi`, inputPath, outputPath)
777 rule.Build(pctx, ctx, "uncompress-dex", "Uncompress dex files")
778}
779
767func (a *AndroidAppImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { 780func (a *AndroidAppImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
768 if String(a.properties.Certificate) == "" && !Bool(a.properties.Presigned) { 781 if String(a.properties.Certificate) == "" && !Bool(a.properties.Presigned) {
769 ctx.PropertyErrorf("certificate", "No certificate specified for prebuilt") 782 ctx.PropertyErrorf("certificate", "No certificate specified for prebuilt")
@@ -791,6 +804,11 @@ func (a *AndroidAppImport) GenerateAndroidBuildActions(ctx android.ModuleContext
791 a.dexpreopter.isPresignedPrebuilt = Bool(a.properties.Presigned) 804 a.dexpreopter.isPresignedPrebuilt = Bool(a.properties.Presigned)
792 a.dexpreopter.uncompressedDex = a.shouldUncompressDex(ctx) 805 a.dexpreopter.uncompressedDex = a.shouldUncompressDex(ctx)
793 dexOutput := a.dexpreopter.dexpreopt(ctx, jnisUncompressed) 806 dexOutput := a.dexpreopter.dexpreopt(ctx, jnisUncompressed)
807 if a.dexpreopter.uncompressedDex {
808 dexUncompressed := android.PathForModuleOut(ctx, "dex-uncompressed", ctx.ModuleName()+".apk")
809 a.uncompressDex(ctx, dexOutput, dexUncompressed.OutputPath)
810 dexOutput = dexUncompressed
811 }
794 812
795 // Sign or align the package 813 // Sign or align the package
796 // TODO: Handle EXTERNAL 814 // TODO: Handle EXTERNAL
diff --git a/java/device_host_converter.go b/java/device_host_converter.go
index b92f4d73..030b0106 100644
--- a/java/device_host_converter.go
+++ b/java/device_host_converter.go
@@ -53,7 +53,7 @@ type DeviceForHost struct {
53// java_device_for_host makes the classes.jar output of a device java_library module available to host 53// java_device_for_host makes the classes.jar output of a device java_library module available to host
54// java_library modules. 54// java_library modules.
55// 55//
56// It is rarely necessary, and its used is restricted to a few whitelisted projects. 56// It is rarely necessary, and its usage is restricted to a few whitelisted projects.
57func DeviceForHostFactory() android.Module { 57func DeviceForHostFactory() android.Module {
58 module := &DeviceForHost{} 58 module := &DeviceForHost{}
59 59
@@ -70,7 +70,7 @@ type HostForDevice struct {
70// java_host_for_device makes the classes.jar output of a host java_library module available to device 70// java_host_for_device makes the classes.jar output of a host java_library module available to device
71// java_library modules. 71// java_library modules.
72// 72//
73// It is rarely necessary, and its used is restricted to a few whitelisted projects. 73// It is rarely necessary, and its usage is restricted to a few whitelisted projects.
74func HostForDeviceFactory() android.Module { 74func HostForDeviceFactory() android.Module {
75 module := &HostForDevice{} 75 module := &HostForDevice{}
76 76
@@ -126,7 +126,7 @@ func (d *DeviceHostConverter) GenerateAndroidBuildActions(ctx android.ModuleCont
126 if len(d.headerJars) > 1 { 126 if len(d.headerJars) > 1 {
127 outputFile := android.PathForModuleOut(ctx, "turbine-combined", jarName) 127 outputFile := android.PathForModuleOut(ctx, "turbine-combined", jarName)
128 TransformJarsToJar(ctx, outputFile, "turbine combine", d.headerJars, 128 TransformJarsToJar(ctx, outputFile, "turbine combine", d.headerJars,
129 android.OptionalPath{}, false, nil, nil) 129 android.OptionalPath{}, false, nil, []string{"META-INF/TRANSITIVE"})
130 d.combinedHeaderJar = outputFile 130 d.combinedHeaderJar = outputFile
131 } else { 131 } else {
132 d.combinedHeaderJar = d.headerJars[0] 132 d.combinedHeaderJar = d.headerJars[0]
diff --git a/java/java.go b/java/java.go
index e764ec30..866b33c0 100644
--- a/java/java.go
+++ b/java/java.go
@@ -639,7 +639,7 @@ func getLinkType(m *Module, name string) (ret linkType, stubs bool) {
639 switch { 639 switch {
640 case name == "core.current.stubs" || name == "core.platform.api.stubs" || 640 case name == "core.current.stubs" || name == "core.platform.api.stubs" ||
641 name == "stub-annotations" || name == "private-stub-annotations-jar" || 641 name == "stub-annotations" || name == "private-stub-annotations-jar" ||
642 name == "core-lambda-stubs": 642 name == "core-lambda-stubs" || name == "core-generated-annotation-stubs":
643 return javaCore, true 643 return javaCore, true
644 case ver == "core_current": 644 case ver == "core_current":
645 return javaCore, false 645 return javaCore, false
@@ -1380,7 +1380,7 @@ func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars
1380 // since we have to strip META-INF/TRANSITIVE dir from turbine.jar 1380 // since we have to strip META-INF/TRANSITIVE dir from turbine.jar
1381 combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName) 1381 combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName)
1382 TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{}, 1382 TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{},
1383 false, nil, []string{"META-INF"}) 1383 false, nil, []string{"META-INF/TRANSITIVE"})
1384 headerJar = combinedJar 1384 headerJar = combinedJar
1385 1385
1386 if j.expandJarjarRules != nil { 1386 if j.expandJarjarRules != nil {
diff --git a/java/kotlin.go b/java/kotlin.go
index 54c6b0ee..33167baf 100644
--- a/java/kotlin.go
+++ b/java/kotlin.go
@@ -18,6 +18,7 @@ import (
18 "bytes" 18 "bytes"
19 "encoding/base64" 19 "encoding/base64"
20 "encoding/binary" 20 "encoding/binary"
21 "path/filepath"
21 "strings" 22 "strings"
22 23
23 "android/soong/android" 24 "android/soong/android"
@@ -30,7 +31,7 @@ var kotlinc = pctx.AndroidGomaStaticRule("kotlinc",
30 Command: `rm -rf "$classesDir" "$srcJarDir" "$kotlinBuildFile" "$emptyDir" && ` + 31 Command: `rm -rf "$classesDir" "$srcJarDir" "$kotlinBuildFile" "$emptyDir" && ` +
31 `mkdir -p "$classesDir" "$srcJarDir" "$emptyDir" && ` + 32 `mkdir -p "$classesDir" "$srcJarDir" "$emptyDir" && ` +
32 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` + 33 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
33 `${config.GenKotlinBuildFileCmd} $classpath $classesDir $out.rsp $srcJarDir/list > $kotlinBuildFile &&` + 34 `${config.GenKotlinBuildFileCmd} $classpath "$name" $classesDir $out.rsp $srcJarDir/list > $kotlinBuildFile &&` +
34 `${config.KotlincCmd} ${config.JavacHeapFlags} $kotlincFlags ` + 35 `${config.KotlincCmd} ${config.JavacHeapFlags} $kotlincFlags ` +
35 `-jvm-target $kotlinJvmTarget -Xbuild-file=$kotlinBuildFile -kotlin-home $emptyDir && ` + 36 `-jvm-target $kotlinJvmTarget -Xbuild-file=$kotlinBuildFile -kotlin-home $emptyDir && ` +
36 `${config.SoongZipCmd} -jar -o $out -C $classesDir -D $classesDir && ` + 37 `${config.SoongZipCmd} -jar -o $out -C $classesDir -D $classesDir && ` +
@@ -50,7 +51,8 @@ var kotlinc = pctx.AndroidGomaStaticRule("kotlinc",
50 Rspfile: "$out.rsp", 51 Rspfile: "$out.rsp",
51 RspfileContent: `$in`, 52 RspfileContent: `$in`,
52 }, 53 },
53 "kotlincFlags", "classpath", "srcJars", "srcJarDir", "classesDir", "kotlinJvmTarget", "kotlinBuildFile", "emptyDir") 54 "kotlincFlags", "classpath", "srcJars", "srcJarDir", "classesDir", "kotlinJvmTarget", "kotlinBuildFile",
55 "emptyDir", "name")
54 56
55// kotlinCompile takes .java and .kt sources and srcJars, and compiles the .kt sources into a classes jar in outputFile. 57// kotlinCompile takes .java and .kt sources and srcJars, and compiles the .kt sources into a classes jar in outputFile.
56func kotlinCompile(ctx android.ModuleContext, outputFile android.WritablePath, 58func kotlinCompile(ctx android.ModuleContext, outputFile android.WritablePath,
@@ -61,6 +63,9 @@ func kotlinCompile(ctx android.ModuleContext, outputFile android.WritablePath,
61 deps = append(deps, flags.kotlincClasspath...) 63 deps = append(deps, flags.kotlincClasspath...)
62 deps = append(deps, srcJars...) 64 deps = append(deps, srcJars...)
63 65
66 kotlinName := filepath.Join(ctx.ModuleDir(), ctx.ModuleSubDir(), ctx.ModuleName())
67 kotlinName = strings.ReplaceAll(kotlinName, "/", "__")
68
64 ctx.Build(pctx, android.BuildParams{ 69 ctx.Build(pctx, android.BuildParams{
65 Rule: kotlinc, 70 Rule: kotlinc,
66 Description: "kotlinc", 71 Description: "kotlinc",
@@ -77,6 +82,7 @@ func kotlinCompile(ctx android.ModuleContext, outputFile android.WritablePath,
77 "emptyDir": android.PathForModuleOut(ctx, "kotlinc", "empty").String(), 82 "emptyDir": android.PathForModuleOut(ctx, "kotlinc", "empty").String(),
78 // http://b/69160377 kotlinc only supports -jvm-target 1.6 and 1.8 83 // http://b/69160377 kotlinc only supports -jvm-target 1.6 and 1.8
79 "kotlinJvmTarget": "1.8", 84 "kotlinJvmTarget": "1.8",
85 "name": kotlinName,
80 }, 86 },
81 }) 87 })
82} 88}
@@ -85,7 +91,7 @@ var kapt = pctx.AndroidGomaStaticRule("kapt",
85 blueprint.RuleParams{ 91 blueprint.RuleParams{
86 Command: `rm -rf "$srcJarDir" "$kotlinBuildFile" "$kaptDir" && mkdir -p "$srcJarDir" "$kaptDir" && ` + 92 Command: `rm -rf "$srcJarDir" "$kotlinBuildFile" "$kaptDir" && mkdir -p "$srcJarDir" "$kaptDir" && ` +
87 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` + 93 `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
88 `${config.GenKotlinBuildFileCmd} $classpath "" $out.rsp $srcJarDir/list > $kotlinBuildFile &&` + 94 `${config.GenKotlinBuildFileCmd} $classpath "$name" "" $out.rsp $srcJarDir/list > $kotlinBuildFile &&` +
89 `${config.KotlincCmd} ${config.KotlincSuppressJDK9Warnings} ${config.JavacHeapFlags} $kotlincFlags ` + 95 `${config.KotlincCmd} ${config.KotlincSuppressJDK9Warnings} ${config.JavacHeapFlags} $kotlincFlags ` +
90 `-Xplugin=${config.KotlinKaptJar} ` + 96 `-Xplugin=${config.KotlinKaptJar} ` +
91 `-P plugin:org.jetbrains.kotlin.kapt3:sources=$kaptDir/sources ` + 97 `-P plugin:org.jetbrains.kotlin.kapt3:sources=$kaptDir/sources ` +
@@ -111,7 +117,7 @@ var kapt = pctx.AndroidGomaStaticRule("kapt",
111 RspfileContent: `$in`, 117 RspfileContent: `$in`,
112 }, 118 },
113 "kotlincFlags", "encodedJavacFlags", "kaptProcessorPath", "kaptProcessor", 119 "kotlincFlags", "encodedJavacFlags", "kaptProcessorPath", "kaptProcessor",
114 "classpath", "srcJars", "srcJarDir", "kaptDir", "kotlinJvmTarget", "kotlinBuildFile") 120 "classpath", "srcJars", "srcJarDir", "kaptDir", "kotlinJvmTarget", "kotlinBuildFile", "name")
115 121
116// kotlinKapt performs Kotlin-compatible annotation processing. It takes .kt and .java sources and srcjars, and runs 122// kotlinKapt performs Kotlin-compatible annotation processing. It takes .kt and .java sources and srcjars, and runs
117// annotation processors over all of them, producing a srcjar of generated code in outputFile. The srcjar should be 123// annotation processors over all of them, producing a srcjar of generated code in outputFile. The srcjar should be
@@ -138,6 +144,9 @@ func kotlinKapt(ctx android.ModuleContext, outputFile android.WritablePath,
138 {"-target", flags.javaVersion}, 144 {"-target", flags.javaVersion},
139 }) 145 })
140 146
147 kotlinName := filepath.Join(ctx.ModuleDir(), ctx.ModuleSubDir(), ctx.ModuleName())
148 kotlinName = strings.ReplaceAll(kotlinName, "/", "__")
149
141 ctx.Build(pctx, android.BuildParams{ 150 ctx.Build(pctx, android.BuildParams{
142 Rule: kapt, 151 Rule: kapt,
143 Description: "kapt", 152 Description: "kapt",
@@ -154,6 +163,7 @@ func kotlinKapt(ctx android.ModuleContext, outputFile android.WritablePath,
154 "kaptProcessor": kaptProcessor, 163 "kaptProcessor": kaptProcessor,
155 "kaptDir": android.PathForModuleOut(ctx, "kapt/gen").String(), 164 "kaptDir": android.PathForModuleOut(ctx, "kapt/gen").String(),
156 "encodedJavacFlags": encodedJavacFlags, 165 "encodedJavacFlags": encodedJavacFlags,
166 "name": kotlinName,
157 }, 167 },
158 }) 168 })
159} 169}
diff --git a/scripts/gen-kotlin-build-file.sh b/scripts/gen-kotlin-build-file.sh
index 1e03f72e..177ca1b0 100755
--- a/scripts/gen-kotlin-build-file.sh
+++ b/scripts/gen-kotlin-build-file.sh
@@ -17,7 +17,7 @@
17# Generates kotlinc module xml file to standard output based on rsp files 17# Generates kotlinc module xml file to standard output based on rsp files
18 18
19if [[ -z "$1" ]]; then 19if [[ -z "$1" ]]; then
20 echo "usage: $0 <classpath> <outDir> <rspFiles>..." >&2 20 echo "usage: $0 <classpath> <name> <outDir> <rspFiles>..." >&2
21 exit 1 21 exit 1
22fi 22fi
23 23
@@ -27,8 +27,9 @@ if [[ $1 == "-classpath" ]]; then
27fi; 27fi;
28 28
29classpath=$1 29classpath=$1
30out_dir=$2 30name=$2
31shift 2 31out_dir=$3
32shift 3
32 33
33# Path in the build file may be relative to the build file, we need to make them 34# Path in the build file may be relative to the build file, we need to make them
34# absolute 35# absolute
@@ -44,7 +45,7 @@ get_abs_path () {
44} 45}
45 46
46# Print preamble 47# Print preamble
47echo "<modules><module name=\"name\" type=\"java-production\" outputDir=\"${out_dir}\">" 48echo "<modules><module name=\"${name}\" type=\"java-production\" outputDir=\"${out_dir}\">"
48 49
49# Print classpath entries 50# Print classpath entries
50for file in $(echo "$classpath" | tr ":" "\n"); do 51for file in $(echo "$classpath" | tr ":" "\n"); do
diff --git a/scripts/manifest_fixer_test.py b/scripts/manifest_fixer_test.py
index 4ad9afaf..7ec89999 100755
--- a/scripts/manifest_fixer_test.py
+++ b/scripts/manifest_fixer_test.py
@@ -231,7 +231,7 @@ class AddUsesLibrariesTest(unittest.TestCase):
231 231
232 def run_test(self, input_manifest, new_uses_libraries): 232 def run_test(self, input_manifest, new_uses_libraries):
233 doc = minidom.parseString(input_manifest) 233 doc = minidom.parseString(input_manifest)
234 manifest_fixer.add_uses_libraries(doc, new_uses_libraries) 234 manifest_fixer.add_uses_libraries(doc, new_uses_libraries, True)
235 output = StringIO.StringIO() 235 output = StringIO.StringIO()
236 manifest_fixer.write_xml(output, doc) 236 manifest_fixer.write_xml(output, doc)
237 return output.getvalue() 237 return output.getvalue()