Merge "Enable coverage universally if COVERAGE_PATHS includes "*""
diff --git a/README.md b/README.md
index 44a98f3..2957940 100644
--- a/README.md
+++ b/README.md
@@ -34,7 +34,7 @@
 all Android.bp files.
 
 For a list of valid module types and their properties see
-[$OUT_DIR/soong/docs/soong_build.html](http://go/Android.bp).
+[$OUT_DIR/soong/docs/soong_build.html](https://ci.android.com/builds/latest/branches/aosp-build-tools/targets/linux/view/soong_build.html).
 
 ### Globs
 
diff --git a/android/variable.go b/android/variable.go
index 5ee888f..1c17e5a 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -87,6 +87,7 @@
 			Cflags   []string
 			Cppflags []string
 			Init_rc  []string
+			Required []string
 		}
 
 		// eng is true for -eng builds, and can be used to turn on additionaly heavyweight debugging
diff --git a/androidmk/cmd/androidmk/android.go b/androidmk/cmd/androidmk/android.go
index c66acdc..1d66ab7 100644
--- a/androidmk/cmd/androidmk/android.go
+++ b/androidmk/cmd/androidmk/android.go
@@ -42,26 +42,24 @@
 
 var rewriteProperties = map[string](func(variableAssignmentContext) error){
 	// custom functions
-	"LOCAL_32_BIT_ONLY":             local32BitOnly,
-	"LOCAL_ADDITIONAL_CERTIFICATES": localizePathList("additional_certificates"),
-	"LOCAL_AIDL_INCLUDES":           localAidlIncludes,
-	"LOCAL_ASSET_DIR":               localizePathList("asset_dirs"),
-	"LOCAL_C_INCLUDES":              localIncludeDirs,
-	"LOCAL_CERTIFICATE":             localizePath("certificate"),
-	"LOCAL_EXPORT_C_INCLUDE_DIRS":   exportIncludeDirs,
-	"LOCAL_JARJAR_RULES":            localizePath("jarjar_rules"),
-	"LOCAL_LDFLAGS":                 ldflags,
-	"LOCAL_MODULE_CLASS":            prebuiltClass,
-	"LOCAL_MODULE_STEM":             stem,
-	"LOCAL_MODULE_HOST_OS":          hostOs,
-	"LOCAL_RESOURCE_DIR":            localizePathList("resource_dirs"),
-	"LOCAL_SANITIZE":                sanitize(""),
-	"LOCAL_SANITIZE_DIAG":           sanitize("diag."),
-	"LOCAL_STRIP_MODULE":            strip(),
-	"LOCAL_CFLAGS":                  cflags,
-	"LOCAL_UNINSTALLABLE_MODULE":    invert("installable"),
-	"LOCAL_PROGUARD_ENABLED":        proguardEnabled,
-	"LOCAL_MODULE_PATH":             prebuiltModulePath,
+	"LOCAL_32_BIT_ONLY":           local32BitOnly,
+	"LOCAL_AIDL_INCLUDES":         localAidlIncludes,
+	"LOCAL_ASSET_DIR":             localizePathList("asset_dirs"),
+	"LOCAL_C_INCLUDES":            localIncludeDirs,
+	"LOCAL_EXPORT_C_INCLUDE_DIRS": exportIncludeDirs,
+	"LOCAL_JARJAR_RULES":          localizePath("jarjar_rules"),
+	"LOCAL_LDFLAGS":               ldflags,
+	"LOCAL_MODULE_CLASS":          prebuiltClass,
+	"LOCAL_MODULE_STEM":           stem,
+	"LOCAL_MODULE_HOST_OS":        hostOs,
+	"LOCAL_RESOURCE_DIR":          localizePathList("resource_dirs"),
+	"LOCAL_SANITIZE":              sanitize(""),
+	"LOCAL_SANITIZE_DIAG":         sanitize("diag."),
+	"LOCAL_STRIP_MODULE":          strip(),
+	"LOCAL_CFLAGS":                cflags,
+	"LOCAL_UNINSTALLABLE_MODULE":  invert("installable"),
+	"LOCAL_PROGUARD_ENABLED":      proguardEnabled,
+	"LOCAL_MODULE_PATH":           prebuiltModulePath,
 
 	// composite functions
 	"LOCAL_MODULE_TAGS": includeVariableIf(bpVariable{"tags", bpparser.ListType}, not(valueDumpEquals("optional"))),
@@ -98,6 +96,7 @@
 			"LOCAL_MIN_SDK_VERSION":         "min_sdk_version",
 			"LOCAL_NDK_STL_VARIANT":         "stl",
 			"LOCAL_JAR_MANIFEST":            "manifest",
+			"LOCAL_CERTIFICATE":             "certificate",
 			"LOCAL_PACKAGE_NAME":            "name",
 			"LOCAL_MODULE_RELATIVE_PATH":    "relative_install_path",
 			"LOCAL_PROTOC_OPTIMIZE_TYPE":    "proto.type",
@@ -163,6 +162,7 @@
 			// java_library_static to android_library.
 			"LOCAL_SHARED_ANDROID_LIBRARIES": "android_libs",
 			"LOCAL_STATIC_ANDROID_LIBRARIES": "android_static_libs",
+			"LOCAL_ADDITIONAL_CERTIFICATES":  "additional_certificates",
 
 			// Jacoco filters:
 			"LOCAL_JACK_COVERAGE_INCLUDE_FILTER": "jacoco.include_filter",
@@ -918,6 +918,7 @@
 	"BUILD_HOST_DALVIK_JAVA_LIBRARY": "java_library_host_dalvik",
 	"BUILD_PACKAGE":                  "android_app",
 
+	"BUILD_CTS_EXECUTABLE":          "cc_binary",               // will be further massaged by bpfix depending on the output path
 	"BUILD_CTS_SUPPORT_PACKAGE":     "cts_support_package",     // will be rewritten to android_test by bpfix
 	"BUILD_CTS_PACKAGE":             "cts_package",             // will be rewritten to android_test by bpfix
 	"BUILD_CTS_TARGET_JAVA_LIBRARY": "cts_target_java_library", // will be rewritten to java_library by bpfix
diff --git a/androidmk/cmd/androidmk/androidmk_test.go b/androidmk/cmd/androidmk/androidmk_test.go
index bc249d0..8ba3181 100644
--- a/androidmk/cmd/androidmk/androidmk_test.go
+++ b/androidmk/cmd/androidmk/androidmk_test.go
@@ -118,8 +118,6 @@
 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res $(LOCAL_PATH)/res2
 LOCAL_ASSET_DIR := $(LOCAL_PATH)/asset
 LOCAL_JARJAR_RULES := $(LOCAL_PATH)/jarjar-rules.txt
-LOCAL_CERTIFICATE := $(LOCAL_PATH)/cert
-LOCAL_ADDITIONAL_CERTIFICATES := $(LOCAL_PATH)/cert1 $(LOCAL_PATH)/cert2
 include $(BUILD_PACKAGE)
 	`,
 		expected: `
@@ -130,11 +128,6 @@
 	],
 	asset_dirs: ["asset"],
 	jarjar_rules: "jarjar-rules.txt",
-	certificate: "cert",
-	additional_certificates: [
-		"cert1",
-		"cert2",
-	],
 }`,
 	},
 	{
diff --git a/cc/cc.go b/cc/cc.go
index ddc47ea..117bbc2 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -1911,6 +1911,10 @@
 	return variation
 }
 
+func (c *Module) IDEInfo(dpInfo *android.IdeInfo) {
+	dpInfo.Srcs = append(dpInfo.Srcs, c.Srcs().Strings()...)
+}
+
 //
 // Defaults
 //
diff --git a/cc/test.go b/cc/test.go
index e9f0944..8e49fac 100644
--- a/cc/test.go
+++ b/cc/test.go
@@ -243,8 +243,13 @@
 
 func (test *testBinary) install(ctx ModuleContext, file android.Path) {
 	test.data = ctx.ExpandSources(test.Properties.Data, nil)
+	optionsMap := map[string]string{}
+	if Bool(test.testDecorator.Properties.Isolated) {
+		optionsMap["not-shardable"] = "true"
+	}
 	test.testConfig = tradefed.AutoGenNativeTestConfig(ctx, test.Properties.Test_config,
-		test.Properties.Test_config_template, test.Properties.Test_suites)
+		test.Properties.Test_config_template,
+		test.Properties.Test_suites, optionsMap)
 
 	test.binaryDecorator.baseInstaller.dir = "nativetest"
 	test.binaryDecorator.baseInstaller.dir64 = "nativetest64"
diff --git a/java/droiddoc.go b/java/droiddoc.go
index 85e4797..5611791 100644
--- a/java/droiddoc.go
+++ b/java/droiddoc.go
@@ -307,6 +307,10 @@
 		Last_released ApiToCheck
 
 		Current ApiToCheck
+
+		// do not perform API check against Last_released, in the case that both two specified API
+		// files by Last_released are modules which don't exist.
+		Ignore_missing_latest_api *bool `blueprint:"mutated"`
 	}
 
 	// if set to true, generate docs through Dokka instead of Doclava.
@@ -349,6 +353,10 @@
 		Last_released ApiToCheck
 
 		Current ApiToCheck
+
+		// do not perform API check against Last_released, in the case that both two specified API
+		// files by Last_released are modules which don't exist.
+		Ignore_missing_latest_api *bool `blueprint:"mutated"`
 	}
 
 	// user can specify the version of previous released API file in order to do compatibility check.
@@ -427,6 +435,25 @@
 	return false
 }
 
+func ignoreMissingModules(ctx android.BottomUpMutatorContext, apiToCheck *ApiToCheck) {
+	api_file := String(apiToCheck.Api_file)
+	removed_api_file := String(apiToCheck.Removed_api_file)
+
+	api_module := android.SrcIsModule(api_file)
+	removed_api_module := android.SrcIsModule(removed_api_file)
+
+	if api_module == "" || removed_api_module == "" {
+		return
+	}
+
+	if ctx.OtherModuleExists(api_module) || ctx.OtherModuleExists(removed_api_module) {
+		return
+	}
+
+	apiToCheck.Api_file = nil
+	apiToCheck.Removed_api_file = nil
+}
+
 type ApiFilePath interface {
 	ApiFilePath() android.Path
 }
@@ -839,6 +866,10 @@
 func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) {
 	d.Javadoc.addDeps(ctx)
 
+	if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
+		ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
+	}
+
 	if String(d.properties.Custom_template) != "" {
 		ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template))
 	}
@@ -1283,6 +1314,10 @@
 func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) {
 	d.Javadoc.addDeps(ctx)
 
+	if Bool(d.properties.Check_api.Ignore_missing_latest_api) {
+		ignoreMissingModules(ctx, &d.properties.Check_api.Last_released)
+	}
+
 	if apiCheckEnabled(d.properties.Check_api.Current, "current") {
 		android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file)
 		android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file)
diff --git a/java/java.go b/java/java.go
index ecc3608..d230810 100644
--- a/java/java.go
+++ b/java/java.go
@@ -1133,7 +1133,6 @@
 	}
 
 	jars = append(jars, deps.staticJars...)
-	jars = append(jars, deps.staticResourceJars...)
 
 	manifest := j.overrideManifest
 	if !manifest.Valid() && j.properties.Manifest != nil {
diff --git a/java/sdk_library.go b/java/sdk_library.go
index df4e08b..6441c63 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -454,8 +454,9 @@
 		Merge_annotations_dirs           []string
 		Merge_inclusion_annotations_dirs []string
 		Check_api                        struct {
-			Current       ApiToCheck
-			Last_released ApiToCheck
+			Current                   ApiToCheck
+			Last_released             ApiToCheck
+			Ignore_missing_latest_api *bool
 		}
 		Aidl struct {
 			Include_dirs       []string
@@ -524,6 +525,7 @@
 		module.latestApiFilegroupName(apiScope))
 	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
diff --git a/tradefed/autogen.go b/tradefed/autogen.go
index cfa7164..6d9c200 100644
--- a/tradefed/autogen.go
+++ b/tradefed/autogen.go
@@ -15,7 +15,12 @@
 package tradefed
 
 import (
+	"fmt"
+	"sort"
+	"strings"
+
 	"github.com/google/blueprint"
+	"github.com/google/blueprint/proptools"
 
 	"android/soong/android"
 )
@@ -34,9 +39,9 @@
 }
 
 var autogenTestConfig = pctx.StaticRule("autogenTestConfig", blueprint.RuleParams{
-	Command:     "sed 's&{MODULE}&${name}&g' $template > $out",
+	Command:     "sed 's&{MODULE}&${name}&g;s&{EXTRA_OPTIONS}&'${extraOptions}'&g' $template > $out",
 	CommandDeps: []string{"$template"},
-}, "name", "template")
+}, "name", "template", "extraOptions")
 
 func testConfigPath(ctx android.ModuleContext, prop *string, testSuites []string) (path android.Path, autogenPath android.WritablePath) {
 	if p := getTestConfig(ctx, prop); p != nil {
@@ -52,30 +57,45 @@
 	}
 }
 
-func autogenTemplate(ctx android.ModuleContext, output android.WritablePath, template string) {
+func autogenTemplate(ctx android.ModuleContext, output android.WritablePath, template string, optionsMap map[string]string) {
+	// If no test option found, delete {EXTRA_OPTIONS} line.
+	var options []string
+	for optionName, value := range optionsMap {
+		if value != "" {
+			options = append(options, fmt.Sprintf(`<option name="%s" value="%s" />`, optionName, value))
+		}
+	}
+	sort.Strings(options)
+	extraOptions := strings.Join(options, "\n        ")
+	extraOptions = proptools.NinjaAndShellEscape([]string{extraOptions})[0]
+
 	ctx.Build(pctx, android.BuildParams{
 		Rule:        autogenTestConfig,
 		Description: "test config",
 		Output:      output,
 		Args: map[string]string{
-			"name":     ctx.ModuleName(),
-			"template": template,
+			"name":         ctx.ModuleName(),
+			"template":     template,
+			"extraOptions": extraOptions,
 		},
 	})
 }
 
 func AutoGenNativeTestConfig(ctx android.ModuleContext, testConfigProp *string,
-	testConfigTemplateProp *string, testSuites []string) android.Path {
+	testConfigTemplateProp *string, testSuites []string,
+	optionsMap map[string]string) android.Path {
 	path, autogenPath := testConfigPath(ctx, testConfigProp, testSuites)
 	if autogenPath != nil {
 		templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp)
 		if templatePath.Valid() {
-			autogenTemplate(ctx, autogenPath, templatePath.String())
+			autogenTemplate(ctx, autogenPath, templatePath.String(), optionsMap)
 		} else {
 			if ctx.Device() {
-				autogenTemplate(ctx, autogenPath, "${NativeTestConfigTemplate}")
+				autogenTemplate(ctx, autogenPath, "${NativeTestConfigTemplate}",
+					optionsMap)
 			} else {
-				autogenTemplate(ctx, autogenPath, "${NativeHostTestConfigTemplate}")
+				autogenTemplate(ctx, autogenPath, "${NativeHostTestConfigTemplate}",
+					optionsMap)
 			}
 		}
 		return autogenPath
@@ -89,9 +109,9 @@
 	if autogenPath != nil {
 		templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp)
 		if templatePath.Valid() {
-			autogenTemplate(ctx, autogenPath, templatePath.String())
+			autogenTemplate(ctx, autogenPath, templatePath.String(), nil)
 		} else {
-			autogenTemplate(ctx, autogenPath, "${NativeBenchmarkTestConfigTemplate}")
+			autogenTemplate(ctx, autogenPath, "${NativeBenchmarkTestConfigTemplate}", nil)
 		}
 		return autogenPath
 	}
@@ -103,12 +123,12 @@
 	if autogenPath != nil {
 		templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp)
 		if templatePath.Valid() {
-			autogenTemplate(ctx, autogenPath, templatePath.String())
+			autogenTemplate(ctx, autogenPath, templatePath.String(), nil)
 		} else {
 			if ctx.Device() {
-				autogenTemplate(ctx, autogenPath, "${JavaTestConfigTemplate}")
+				autogenTemplate(ctx, autogenPath, "${JavaTestConfigTemplate}", nil)
 			} else {
-				autogenTemplate(ctx, autogenPath, "${JavaHostTestConfigTemplate}")
+				autogenTemplate(ctx, autogenPath, "${JavaHostTestConfigTemplate}", nil)
 			}
 		}
 		return autogenPath
@@ -123,9 +143,9 @@
 	if autogenPath != nil {
 		templatePath := getTestConfigTemplate(ctx, testConfigTemplateProp)
 		if templatePath.Valid() {
-			autogenTemplate(ctx, autogenPath, templatePath.String())
+			autogenTemplate(ctx, autogenPath, templatePath.String(), nil)
 		} else {
-			autogenTemplate(ctx, autogenPath, "${PythonBinaryHostTestConfigTemplate}")
+			autogenTemplate(ctx, autogenPath, "${PythonBinaryHostTestConfigTemplate}", nil)
 		}
 		return autogenPath
 	}