Merge changes I047d103b,I35de5d93,I3327d275

* changes:
  Add prebuilts/misc to root.bp
  Export java modules to make
  Fix java prebuilts
diff --git a/android/api_levels.go b/android/api_levels.go
index 70b251b..370d553 100644
--- a/android/api_levels.go
+++ b/android/api_levels.go
@@ -55,8 +55,20 @@
 
 func (a *apiLevelsSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
 	baseApiLevel := 9000
-	apiLevelsMap := map[string]int{}
-	for i, codename := range ctx.Config().(Config).PlatformVersionAllCodenames() {
+	apiLevelsMap := map[string]int{
+		"G":     9,
+		"I":     14,
+		"J":     16,
+		"J-MR1": 17,
+		"J-MR2": 18,
+		"K":     19,
+		"L":     21,
+		"L-MR1": 22,
+		"M":     23,
+		"N":     24,
+		"N-MR1": 25,
+	}
+	for i, codename := range ctx.Config().(Config).PlatformVersionCombinedCodenames() {
 		apiLevelsMap[codename] = baseApiLevel + i
 	}
 
diff --git a/android/config.go b/android/config.go
index 5dcc59b..ee2f40f 100644
--- a/android/config.go
+++ b/android/config.go
@@ -378,8 +378,25 @@
 	return strconv.Itoa(c.PlatformSdkVersionInt())
 }
 
-func (c *config) PlatformVersionAllCodenames() []string {
-	return c.ProductVariables.Platform_version_all_codenames
+// Codenames that are active in the current lunch target.
+func (c *config) PlatformVersionActiveCodenames() []string {
+	return c.ProductVariables.Platform_version_active_codenames
+}
+
+// Codenames that are available in the branch but not included in the current
+// lunch target.
+func (c *config) PlatformVersionFutureCodenames() []string {
+	return c.ProductVariables.Platform_version_future_codenames
+}
+
+// All possible codenames in the current branch. NB: Not named AllCodenames
+// because "all" has historically meant "active" in make, and still does in
+// build.prop.
+func (c *config) PlatformVersionCombinedCodenames() []string {
+	combined := []string{}
+	combined = append(combined, c.PlatformVersionActiveCodenames()...)
+	combined = append(combined, c.PlatformVersionFutureCodenames()...)
+	return combined
 }
 
 func (c *config) BuildNumber() string {
diff --git a/android/variable.go b/android/variable.go
index 8462d0d..74fa868 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -102,8 +102,9 @@
 	// Suffix to add to generated Makefiles
 	Make_suffix *string `json:",omitempty"`
 
-	Platform_sdk_version           *int     `json:",omitempty"`
-	Platform_version_all_codenames []string `json:",omitempty"`
+	Platform_sdk_version              *int     `json:",omitempty"`
+	Platform_version_active_codenames []string `json:",omitempty"`
+	Platform_version_future_codenames []string `json:",omitempty"`
 
 	DeviceName        *string   `json:",omitempty"`
 	DeviceArch        *string   `json:",omitempty"`
diff --git a/cc/gen_stub_libs.py b/cc/gen_stub_libs.py
index bed718c..abb39c2 100755
--- a/cc/gen_stub_libs.py
+++ b/cc/gen_stub_libs.py
@@ -347,10 +347,16 @@
                 if section_versioned and emit_version:
                     self.version_script.write('        ' + symbol.name + ';\n')
 
+                weak = ''
+                if 'weak' in symbol.tags:
+                    weak = '__attribute__((weak)) '
+
                 if 'var' in symbol.tags:
-                    self.src_file.write('int {} = 0;\n'.format(symbol.name))
+                    self.src_file.write('{}int {} = 0;\n'.format(
+                        weak, symbol.name))
                 else:
-                    self.src_file.write('void {}() {{}}\n'.format(symbol.name))
+                    self.src_file.write('{}void {}() {{}}\n'.format(
+                        weak, symbol.name))
 
             if not version_empty and section_versioned:
                 base = '' if version.base is None else ' ' + version.base
diff --git a/cc/ndk_library.go b/cc/ndk_library.go
index dbfc5be..8fbffcf 100644
--- a/cc/ndk_library.go
+++ b/cc/ndk_library.go
@@ -205,7 +205,7 @@
 	for version := firstGenVersion; version <= platformVersion; version++ {
 		versionStrs = append(versionStrs, strconv.Itoa(version))
 	}
-	versionStrs = append(versionStrs, mctx.AConfig().PlatformVersionAllCodenames()...)
+	versionStrs = append(versionStrs, mctx.AConfig().PlatformVersionActiveCodenames()...)
 	versionStrs = append(versionStrs, "current")
 
 	modules := mctx.CreateVariations(versionStrs...)
diff --git a/cc/test_gen_stub_libs.py b/cc/test_gen_stub_libs.py
index 4df6cf8..b20a5c7 100755
--- a/cc/test_gen_stub_libs.py
+++ b/cc/test_gen_stub_libs.py
@@ -430,6 +430,8 @@
             gsl.Version('VERSION_1', None, [], [
                 gsl.Symbol('foo', []),
                 gsl.Symbol('bar', ['var']),
+                gsl.Symbol('woodly', ['weak']),
+                gsl.Symbol('doodly', ['weak', 'var']),
             ]),
             gsl.Version('VERSION_2', 'VERSION_1', [], [
                 gsl.Symbol('baz', []),
@@ -443,6 +445,8 @@
         expected_src = textwrap.dedent("""\
             void foo() {}
             int bar = 0;
+            __attribute__((weak)) void woodly() {}
+            __attribute__((weak)) int doodly = 0;
             void baz() {}
             void qux() {}
         """)
@@ -453,6 +457,8 @@
                 global:
                     foo;
                     bar;
+                    woodly;
+                    doodly;
             };
             VERSION_2 {
                 global:
diff --git a/scripts/build-ndk-prebuilts.sh b/scripts/build-ndk-prebuilts.sh
index 65a2329..2a1c7df 100755
--- a/scripts/build-ndk-prebuilts.sh
+++ b/scripts/build-ndk-prebuilts.sh
@@ -9,6 +9,12 @@
 
 source build/envsetup.sh
 PLATFORM_SDK_VERSION=$(get_build_var PLATFORM_SDK_VERSION)
+PLATFORM_VERSION_ALL_CODENAMES=$(get_build_var PLATFORM_VERSION_ALL_CODENAMES)
+
+# PLATFORM_VERSION_ALL_CODESNAMES is a comma separated list like O,P. We need to
+# turn this into ["O","P"].
+PLATFORM_VERSION_ALL_CODENAMES=${PLATFORM_VERSION_ALL_CODENAMES/,/","}
+PLATFORM_VERSION_ALL_CODENAMES="[\"${PLATFORM_VERSION_ALL_CODENAMES}\"]"
 
 SOONG_OUT=${OUT_DIR}/soong
 SOONG_NDK_OUT=${OUT_DIR}/soong/ndk
@@ -16,8 +22,36 @@
 mkdir -p ${SOONG_OUT}
 cat > ${SOONG_OUT}/soong.config << EOF
 {
-    "Ndk_abis": true,
-    "Platform_sdk_version": ${PLATFORM_SDK_VERSION}
+    "Ndk_abis": true
+}
+EOF
+
+# We only really need to set some of these variables, but soong won't merge this
+# with the defaults, so we need to write out all the defaults with our values
+# added.
+cat > ${SOONG_OUT}/soong.variables << EOF
+{
+    "Platform_sdk_version": ${PLATFORM_SDK_VERSION},
+    "Platform_version_active_codenames": ${PLATFORM_VERSION_ALL_CODENAMES},
+
+    "DeviceName": "flounder",
+    "DeviceArch": "arm64",
+    "DeviceArchVariant": "armv8-a",
+    "DeviceCpuVariant": "denver64",
+    "DeviceAbi": [
+        "arm64-v8a"
+    ],
+    "DeviceUsesClang": true,
+    "DeviceSecondaryArch": "arm",
+    "DeviceSecondaryArchVariant": "armv7-a-neon",
+    "DeviceSecondaryCpuVariant": "denver",
+    "DeviceSecondaryAbi": [
+        "armeabi-v7a"
+    ],
+    "HostArch": "x86_64",
+    "HostSecondaryArch": "x86",
+    "Malloc_not_svelte": false,
+    "Safestack": false
 }
 EOF
 BUILDDIR=${SOONG_OUT} ./bootstrap.bash