Merge "Set targetSdkVersion in manifest_fixer"
diff --git a/android/config_test.go b/android/config_test.go
index 72942eb..274d59f 100644
--- a/android/config_test.go
+++ b/android/config_test.go
@@ -50,7 +50,7 @@
 }
 
 type configType struct {
-	populateMe *bool `json:"omitempty"`
+	PopulateMe *bool `json:"omitempty"`
 }
 
 func (c *configType) SetDefaultConfig() {
@@ -60,7 +60,7 @@
 func TestValidateConfigAnnotations(t *testing.T) {
 	config := configType{}
 	err := validateConfigAnnotations(&config)
-	expectedError := `Field configType.populateMe has tag json:"omitempty" which specifies to change its json field name to "omitempty".
+	expectedError := `Field configType.PopulateMe has tag json:"omitempty" which specifies to change its json field name to "omitempty".
 Did you mean to use an annotation of ",omitempty"?
 (Alternatively, to change the json name of the field, rename the field in source instead.)`
 	if err.Error() != expectedError {
diff --git a/android/makevars.go b/android/makevars.go
index accc4d3..3a7ec6e 100644
--- a/android/makevars.go
+++ b/android/makevars.go
@@ -153,7 +153,7 @@
 func (s *makeVarsSingleton) writeVars(vars []makeVarsVariable) []byte {
 	buf := &bytes.Buffer{}
 
-	fmt.Fprintln(buf, `# Autogenerated file
+	fmt.Fprint(buf, `# Autogenerated file
 
 # Compares SOONG_$(1) against $(1), and warns if they are not equal.
 #
@@ -201,7 +201,7 @@
 		fmt.Fprintf(buf, "$(eval $(call soong-compare-var,%s,%s,my_check_failed := true))\n\n", v.name, sort)
 	}
 
-	fmt.Fprintln(buf, `
+	fmt.Fprint(buf, `
 ifneq ($(my_check_failed),false)
   $(error Soong variable check failed)
 endif
diff --git a/android/namespace.go b/android/namespace.go
index 0230524..b027ceb 100644
--- a/android/namespace.go
+++ b/android/namespace.go
@@ -94,10 +94,8 @@
 }
 
 func NewNameResolver(namespaceExportFilter func(*Namespace) bool) *NameResolver {
-	namespacesByDir := sync.Map{}
-
 	r := &NameResolver{
-		namespacesByDir:       namespacesByDir,
+		namespacesByDir:       sync.Map{},
 		namespaceExportFilter: namespaceExportFilter,
 	}
 	r.rootNamespace = r.newNamespace(".")
diff --git a/bpfix/bpfix/bpfix.go b/bpfix/bpfix/bpfix.go
index 056a01b..24a38c9 100644
--- a/bpfix/bpfix/bpfix.go
+++ b/bpfix/bpfix/bpfix.go
@@ -141,7 +141,6 @@
 		i++
 		if i >= maxNumIterations {
 			return nil, fmt.Errorf("Applied fixes %d times and yet the tree continued to change. Is there an infinite loop?", i)
-			break
 		}
 	}
 	return f.tree, err
diff --git a/cc/cc.go b/cc/cc.go
index 89d45a9..bde8041 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -159,9 +159,12 @@
 
 // Properties used to compile all C or C++ modules
 type BaseProperties struct {
-	// compile module with clang instead of gcc
+	// Deprecated. true is the default, false is invalid.
 	Clang *bool `android:"arch_variant"`
 
+	// Some internals still need GCC (toolchain_library)
+	Gcc bool `blueprint:"mutated"`
+
 	// Minimum sdk version supported when compiling against the ndk
 	Sdk_version *string
 
@@ -991,33 +994,41 @@
 		actx.AddVariationDependencies(nil, depTag, lib)
 	}
 
-	actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
-		deps.WholeStaticLibs...)
+	actx.AddVariationDependencies([]blueprint.Variation{
+		{Mutator: "link", Variation: "static"},
+	}, wholeStaticDepTag, deps.WholeStaticLibs...)
 
 	for _, lib := range deps.StaticLibs {
 		depTag := staticDepTag
 		if inList(lib, deps.ReexportStaticLibHeaders) {
 			depTag = staticExportDepTag
 		}
-		actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
+		actx.AddVariationDependencies([]blueprint.Variation{
+			{Mutator: "link", Variation: "static"},
+		}, depTag, lib)
 	}
 
-	actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
-		deps.LateStaticLibs...)
+	actx.AddVariationDependencies([]blueprint.Variation{
+		{Mutator: "link", Variation: "static"},
+	}, lateStaticDepTag, deps.LateStaticLibs...)
 
 	for _, lib := range deps.SharedLibs {
 		depTag := sharedDepTag
 		if inList(lib, deps.ReexportSharedLibHeaders) {
 			depTag = sharedExportDepTag
 		}
-		actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
+		actx.AddVariationDependencies([]blueprint.Variation{
+			{Mutator: "link", Variation: "shared"},
+		}, depTag, lib)
 	}
 
-	actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
-		deps.LateSharedLibs...)
+	actx.AddVariationDependencies([]blueprint.Variation{
+		{Mutator: "link", Variation: "shared"},
+	}, lateSharedDepTag, deps.LateSharedLibs...)
 
-	actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, runtimeDepTag,
-		deps.RuntimeLibs...)
+	actx.AddVariationDependencies([]blueprint.Variation{
+		{Mutator: "link", Variation: "shared"},
+	}, runtimeDepTag, deps.RuntimeLibs...)
 
 	actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
 
@@ -1043,9 +1054,13 @@
 
 	version := ctx.sdkVersion()
 	actx.AddVariationDependencies([]blueprint.Variation{
-		{"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
+		{Mutator: "ndk_api", Variation: version},
+		{Mutator: "link", Variation: "shared"},
+	}, ndkStubDepTag, variantNdkLibs...)
 	actx.AddVariationDependencies([]blueprint.Variation{
-		{"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
+		{Mutator: "ndk_api", Variation: version},
+		{Mutator: "link", Variation: "shared"},
+	}, ndkLateStubDepTag, variantLateNdkLibs...)
 
 	if vndkdep := c.vndkdep; vndkdep != nil {
 		if vndkdep.isVndkExt() {
@@ -1054,8 +1069,9 @@
 				baseModuleMode = coreMode
 			}
 			actx.AddVariationDependencies([]blueprint.Variation{
-				{"image", baseModuleMode}, {"link", "shared"}}, vndkExtDepTag,
-				vndkdep.getVndkExtendsModuleName())
+				{Mutator: "image", Variation: baseModuleMode},
+				{Mutator: "link", Variation: "shared"},
+			}, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
 		}
 	}
 }
@@ -1067,17 +1083,15 @@
 }
 
 func (c *Module) clang(ctx BaseModuleContext) bool {
-	clang := Bool(c.Properties.Clang)
-
-	if c.Properties.Clang == nil {
-		clang = true
+	if c.Properties.Clang != nil && *c.Properties.Clang == false {
+		ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
 	}
 
 	if !c.toolchain(ctx).ClangSupported() {
-		clang = false
+		panic("GCC is no longer supported")
 	}
 
-	return clang
+	return !c.Properties.Gcc
 }
 
 // Whether a module can link to another module, taking into
diff --git a/cc/compiler.go b/cc/compiler.go
index 8d034c9..f3cf040 100644
--- a/cc/compiler.go
+++ b/cc/compiler.go
@@ -73,7 +73,7 @@
 
 	// list of directories relative to the Blueprints file that will
 	// be added to the include path using -I
-	Local_include_dirs []string `android:"arch_variant,variant_prepend",`
+	Local_include_dirs []string `android:"arch_variant,variant_prepend"`
 
 	// list of generated sources to compile. These are the names of gensrcs or
 	// genrule modules.
diff --git a/cc/config/toolchain.go b/cc/config/toolchain.go
index ea8397d..a360a17 100644
--- a/cc/config/toolchain.go
+++ b/cc/config/toolchain.go
@@ -36,7 +36,6 @@
 	factory := toolchainFactories[os][arch.ArchType]
 	if factory == nil {
 		panic(fmt.Errorf("Toolchain not found for %s arch %q", os.String(), arch.String()))
-		return nil
 	}
 	return factory(arch)
 }
diff --git a/cc/ndk_library.go b/cc/ndk_library.go
index db96325..3bffacd 100644
--- a/cc/ndk_library.go
+++ b/cc/ndk_library.go
@@ -157,10 +157,10 @@
 }
 
 func shouldUseVersionScript(ctx android.BaseContext, stub *stubDecorator) (bool, error) {
-	// https://github.com/android-ndk/ndk/issues/622
-	// The loader spews warnings to stderr on L-MR1 when loading a library that
-	// has symbol versioning.
-	firstVersionSupportingRelease := 23
+	// unversioned_until is normally empty, in which case we should use the version script.
+	if String(stub.properties.Unversioned_until) == "" {
+		return true, nil
+	}
 
 	if String(stub.properties.Unversioned_until) == "current" {
 		if stub.properties.ApiLevel == "current" {
@@ -174,29 +174,14 @@
 		return true, nil
 	}
 
-	version, err := android.ApiStrToNum(ctx, stub.properties.ApiLevel)
-	if err != nil {
-		return true, err
-	}
-
-	// unversioned_until is normally empty, in which case we use the version
-	// script as long as we are on a supported API level.
-	if String(stub.properties.Unversioned_until) == "" {
-		return version >= firstVersionSupportingRelease, nil
-	}
-
 	unversionedUntil, err := android.ApiStrToNum(ctx, String(stub.properties.Unversioned_until))
 	if err != nil {
 		return true, err
 	}
 
-	if unversionedUntil < firstVersionSupportingRelease {
-		return true, fmt.Errorf("unversioned_until must be at least %d",
-			firstVersionSupportingRelease)
-	}
-
-	if version < firstVersionSupportingRelease {
-		return false, nil
+	version, err := android.ApiStrToNum(ctx, stub.properties.ApiLevel)
+	if err != nil {
+		return true, err
 	}
 
 	return version >= unversionedUntil, nil
diff --git a/cc/test_data_test.go b/cc/test_data_test.go
index 56c3e38..eead25b 100644
--- a/cc/test_data_test.go
+++ b/cc/test_data_test.go
@@ -15,7 +15,6 @@
 package cc
 
 import (
-	"fmt"
 	"io/ioutil"
 	"os"
 	"path/filepath"
@@ -154,7 +153,7 @@
 				path := filepath.Join(test.data[i].path, test.data[i].file)
 				if test.data[i].file != got[i].Rel() ||
 					path != got[i].String() {
-					fmt.Errorf("expected %s:%s got %s:%s",
+					t.Errorf("expected %s:%s got %s:%s",
 						path, test.data[i].file,
 						got[i].String(), got[i].Rel())
 				}
diff --git a/cc/toolchain_library.go b/cc/toolchain_library.go
index 2bb4018..2b117b3 100644
--- a/cc/toolchain_library.go
+++ b/cc/toolchain_library.go
@@ -43,7 +43,7 @@
 	}
 	module.compiler = toolchainLibrary
 	module.linker = toolchainLibrary
-	module.Properties.Clang = BoolPtr(false)
+	module.Properties.Gcc = true
 	module.stl = nil
 	module.sanitize = nil
 	module.installer = nil
diff --git a/cmd/multiproduct_kati/main.go b/cmd/multiproduct_kati/main.go
index 9fb400f..a6bc8d5 100644
--- a/cmd/multiproduct_kati/main.go
+++ b/cmd/multiproduct_kati/main.go
@@ -159,7 +159,7 @@
 		stat.Finish()
 	})
 
-	buildCtx := build.Context{&build.ContextImpl{
+	buildCtx := build.Context{ContextImpl: &build.ContextImpl{
 		Context: ctx,
 		Logger:  log,
 		Tracer:  trace,
@@ -297,7 +297,7 @@
 			productLog := logger.New(f)
 			productLog.SetOutput(filepath.Join(productLogDir, "soong.log"))
 
-			productCtx := build.Context{&build.ContextImpl{
+			productCtx := build.Context{ContextImpl: &build.ContextImpl{
 				Context: ctx,
 				Logger:  productLog,
 				Tracer:  trace,
diff --git a/cmd/soong_ui/main.go b/cmd/soong_ui/main.go
index 47682ff..b603571 100644
--- a/cmd/soong_ui/main.go
+++ b/cmd/soong_ui/main.go
@@ -84,7 +84,7 @@
 		stat.Finish()
 	})
 
-	buildCtx := build.Context{&build.ContextImpl{
+	buildCtx := build.Context{ContextImpl: &build.ContextImpl{
 		Context: ctx,
 		Logger:  log,
 		Tracer:  trace,
diff --git a/finder/fs/fs.go b/finder/fs/fs.go
index 9c138cd..071f764 100644
--- a/finder/fs/fs.go
+++ b/finder/fs/fs.go
@@ -243,7 +243,6 @@
 	if parentPath == path {
 		err = fmt.Errorf("Internal error: %v yields itself as a parent", path)
 		panic(err.Error())
-		return "", fmt.Errorf("Internal error: %v yields itself as a parent", path)
 	}
 
 	parentPath, err = m.followLinks(parentPath, true, count)
diff --git a/genrule/genrule.go b/genrule/genrule.go
index 03d4ea6..8fedc60 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -142,7 +142,7 @@
 	if g, ok := ctx.Module().(*Module); ok {
 		if len(g.properties.Tools) > 0 {
 			ctx.AddFarVariationDependencies([]blueprint.Variation{
-				{"arch", ctx.Config().BuildOsVariant},
+				{Mutator: "arch", Variation: ctx.Config().BuildOsVariant},
 			}, hostToolDepTag, g.properties.Tools...)
 		}
 	}
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..cc328e0
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,9 @@
+module android/soong
+
+require github.com/golang/protobuf v0.0.0
+
+require github.com/google/blueprint v0.0.0
+
+replace github.com/golang/protobuf v0.0.0 => ../../external/golang-protobuf
+
+replace github.com/google/blueprint v0.0.0 => ../blueprint
diff --git a/java/androidmk.go b/java/androidmk.go
index 5740eca..40711f6 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -304,6 +304,9 @@
 				if ddoc.Javadoc.stubsSrcJar != nil {
 					fmt.Fprintln(w, "LOCAL_DROIDDOC_STUBS_SRCJAR := ", ddoc.Javadoc.stubsSrcJar.String())
 				}
+				if ddoc.annotationsZip != nil {
+					fmt.Fprintln(w, "LOCAL_DROIDDOC_ANNOTATIONS_ZIP := ", ddoc.annotationsZip.String())
+				}
 				if ddoc.checkCurrentApiTimestamp != nil {
 					fmt.Fprintln(w, ".PHONY:", ddoc.Name()+"-check-current-api")
 					fmt.Fprintln(w, ddoc.Name()+"-check-current-api:",
@@ -317,7 +320,7 @@
 					fmt.Fprintln(w, "droidcore: checkapi")
 				}
 				if ddoc.updateCurrentApiTimestamp != nil {
-					fmt.Fprintln(w, ".PHONY:", ddoc.Name(), "-update-current-api")
+					fmt.Fprintln(w, ".PHONY:", ddoc.Name()+"-update-current-api")
 					fmt.Fprintln(w, ddoc.Name()+"-update-current-api:",
 						ddoc.updateCurrentApiTimestamp.String())
 
diff --git a/java/droiddoc.go b/java/droiddoc.go
index 53c75b5..bdf7f53 100644
--- a/java/droiddoc.go
+++ b/java/droiddoc.go
@@ -262,8 +262,8 @@
 	// is set to true, Metalava will allow framework SDK to contain annotations.
 	Metalava_annotations_enabled *bool
 
-	// a top level directory contains XML files set to merge annotations.
-	Metalava_merge_annotations_dir *string
+	// a list of top-level directories containing files to merge annotations from.
+	Metalava_merge_annotations_dirs []string
 }
 
 type Javadoc struct {
@@ -302,6 +302,14 @@
 	checkCurrentApiTimestamp      android.WritablePath
 	updateCurrentApiTimestamp     android.WritablePath
 	checkLastReleasedApiTimestamp android.WritablePath
+
+	annotationsZip android.WritablePath
+
+	apiFilePath android.Path
+}
+
+type ApiFilePath interface {
+	ApiFilePath() android.Path
 }
 
 func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
@@ -811,6 +819,7 @@
 		args = args + " -api " + d.apiFile.String()
 		metalavaArgs = metalavaArgs + " --api " + d.apiFile.String()
 		implicitOutputs = append(implicitOutputs, d.apiFile)
+		d.apiFilePath = d.apiFile
 	}
 
 	if d.checkCurrentApi() || d.checkLastReleasedApi() || String(d.properties.Removed_api_filename) != "" {
@@ -965,17 +974,19 @@
 			}
 			opts += " --include-annotations --migrate-nullness"
 
-			annotationsZip := android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
-			implicitOutputs = append(implicitOutputs, annotationsZip)
+			d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip")
+			implicitOutputs = append(implicitOutputs, d.annotationsZip)
 
-			if String(d.properties.Metalava_merge_annotations_dir) == "" {
-				ctx.PropertyErrorf("metalava_merge_annotations",
+			if len(d.properties.Metalava_merge_annotations_dirs) == 0 {
+				ctx.PropertyErrorf("metalava_merge_annotations_dirs",
 					"has to be non-empty if annotations was enabled!")
 			}
+			mergeAnnotationsDirs := android.PathsForSource(ctx, d.properties.Metalava_merge_annotations_dirs)
 
-			mergeAnnotationsDir := android.PathForSource(ctx, String(d.properties.Metalava_merge_annotations_dir))
-
-			opts += " --extract-annotations " + annotationsZip.String() + " --merge-annotations " + mergeAnnotationsDir.String()
+			opts += " --extract-annotations " + d.annotationsZip.String()
+			for _, mergeAnnotationsDir := range mergeAnnotationsDirs {
+				opts += " --merge-annotations " + mergeAnnotationsDir.String()
+			}
 			// TODO(tnorbye): find owners to fix these warnings when annotation was enabled.
 			opts += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction"
 		}
@@ -1087,6 +1098,10 @@
 	}
 }
 
+func (d *Droiddoc) ApiFilePath() android.Path {
+	return d.apiFilePath
+}
+
 var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"}
 
 type DroiddocTemplateProperties struct {
diff --git a/java/java.go b/java/java.go
index 99af2f5..38c89f4 100644
--- a/java/java.go
+++ b/java/java.go
@@ -574,7 +574,7 @@
 	ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
 	ctx.AddDependency(ctx.Module(), staticLibTag, j.properties.Static_libs...)
 	ctx.AddFarVariationDependencies([]blueprint.Variation{
-		{"arch", ctx.Config().BuildOsCommonVariant},
+		{Mutator: "arch", Variation: ctx.Config().BuildOsCommonVariant},
 	}, annoTag, j.properties.Annotation_processors...)
 	android.ExtractSourcesDeps(ctx, j.properties.Srcs)
 	android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
@@ -631,7 +631,8 @@
 	aidlIncludes = append(aidlIncludes,
 		android.PathsForSource(ctx, j.deviceProperties.Aidl.Include_dirs)...)
 
-	var flags []string
+	flags := []string{"-b"}
+
 	if aidlPreprocess.Valid() {
 		flags = append(flags, "-p"+aidlPreprocess.String())
 	} else {
@@ -693,7 +694,8 @@
 	ver := m.sdkVersion()
 	noStdLibs := Bool(m.properties.No_standard_libs)
 	switch {
-	case name == "core.current.stubs" || ver == "core_current" || noStdLibs || name == "stub-annotations":
+	case name == "core.current.stubs" || ver == "core_current" || noStdLibs || name == "stub-annotations" ||
+		name == "private-stub-annotations-jar":
 		return javaCore
 	case name == "android_system_stubs_current" || strings.HasPrefix(ver, "system_") || name == "metalava_android_system_stubs_current":
 		return javaSystem
diff --git a/java/sdk_library.go b/java/sdk_library.go
index 3bac8f6..57a0c3a 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -47,6 +47,9 @@
 	systemApiStubsTag = dependencyTag{name: "system"}
 	testApiStubsTag   = dependencyTag{name: "test"}
 	implLibTag        = dependencyTag{name: "platform"}
+	publicApiFileTag  = dependencyTag{name: "publicApi"}
+	systemApiFileTag  = dependencyTag{name: "systemApi"}
+	testApiFileTag    = dependencyTag{name: "testApi"}
 )
 
 type apiScope int
@@ -134,6 +137,10 @@
 	systemApiStubsImplPath android.Paths
 	testApiStubsImplPath   android.Paths
 	implLibImplPath        android.Paths
+
+	publicApiFilePath android.Path
+	systemApiFilePath android.Path
+	testApiFilePath   android.Path
 }
 
 func (module *sdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
@@ -142,6 +149,10 @@
 	ctx.AddDependency(ctx.Module(), systemApiStubsTag, module.stubsName(apiScopeSystem))
 	ctx.AddDependency(ctx.Module(), testApiStubsTag, module.stubsName(apiScopeTest))
 	ctx.AddDependency(ctx.Module(), implLibTag, module.implName())
+
+	ctx.AddDependency(ctx.Module(), publicApiFileTag, module.docsName(apiScopePublic))
+	ctx.AddDependency(ctx.Module(), systemApiFileTag, module.docsName(apiScopeSystem))
+	ctx.AddDependency(ctx.Module(), testApiFileTag, module.docsName(apiScopeTest))
 }
 
 func (module *sdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
@@ -170,6 +181,18 @@
 				ctx.ModuleErrorf("depends on module %q of unknown tag %q", otherName, tag)
 			}
 		}
+		if doc, ok := to.(ApiFilePath); ok {
+			switch tag {
+			case publicApiFileTag:
+				module.publicApiFilePath = doc.ApiFilePath()
+			case systemApiFileTag:
+				module.systemApiFilePath = doc.ApiFilePath()
+			case testApiFileTag:
+				module.testApiFilePath = doc.ApiFilePath()
+			default:
+				ctx.ModuleErrorf("depends on module %q of unknown tag %q", otherName, tag)
+			}
+		}
 	})
 }
 
@@ -199,6 +222,24 @@
 					module.testApiStubsPath.Strings()[0]+
 					":"+path.Join("apistubs", "test", module.BaseModuleName()+".jar")+")")
 			}
+			if module.publicApiFilePath != nil {
+				fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
+					module.publicApiFilePath.String()+
+					":"+path.Join("apistubs", "public", "api",
+					module.BaseModuleName()+".txt")+")")
+			}
+			if module.systemApiFilePath != nil {
+				fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
+					module.systemApiFilePath.String()+
+					":"+path.Join("apistubs", "system", "api",
+					module.BaseModuleName()+".txt")+")")
+			}
+			if module.testApiFilePath != nil {
+				fmt.Fprintln(w, "$(call dist-for-goals,sdk win_sdk,"+
+					module.testApiFilePath.String()+
+					":"+path.Join("apistubs", "test", "api",
+					module.BaseModuleName()+".txt")+")")
+			}
 		},
 	}
 }
diff --git a/java/system_modules.go b/java/system_modules.go
index 73a5131..d98e0ab 100644
--- a/java/system_modules.go
+++ b/java/system_modules.go
@@ -134,6 +134,7 @@
 			fmt.Fprintln(w, makevar, ":=", system.outputFile.String())
 			fmt.Fprintln(w, ".KATI_READONLY", ":=", makevar)
 			fmt.Fprintln(w, name+":", "$("+makevar+")")
+			fmt.Fprintln(w, ".PHONY:", name)
 			fmt.Fprintln(w)
 			makevar = "SOONG_SYSTEM_MODULES_LIBS_" + name
 			fmt.Fprintln(w, makevar, ":=", strings.Join(system.properties.Libs, " "))
diff --git a/python/python.go b/python/python.go
index feb17da..e8b4713 100644
--- a/python/python.go
+++ b/python/python.go
@@ -306,7 +306,7 @@
 		if p.bootstrapper != nil && p.isEmbeddedLauncherEnabled(pyVersion2) {
 			ctx.AddVariationDependencies(nil, pythonLibTag, "py2-stdlib")
 			ctx.AddFarVariationDependencies([]blueprint.Variation{
-				{"arch", ctx.Target().String()},
+				{Mutator: "arch", Variation: ctx.Target().String()},
 			}, launcherTag, "py2-launcher")
 		}
 
diff --git a/ui/build/dumpvars.go b/ui/build/dumpvars.go
index 06bd74f..8f9d8f2 100644
--- a/ui/build/dumpvars.go
+++ b/ui/build/dumpvars.go
@@ -195,5 +195,5 @@
 	config.SetTargetDeviceDir(make_vars["TARGET_DEVICE_DIR"])
 
 	config.SetPdkBuild(make_vars["TARGET_BUILD_PDK"] == "true")
-	config.SetBuildBrokenDupRules(make_vars["BUILD_BROKEN_DUP_RULES"] != "false")
+	config.SetBuildBrokenDupRules(make_vars["BUILD_BROKEN_DUP_RULES"] == "true")
 }
diff --git a/ui/build/environment.go b/ui/build/environment.go
index 8589937..cbeeb4b 100644
--- a/ui/build/environment.go
+++ b/ui/build/environment.go
@@ -134,7 +134,7 @@
 		if cmd[0] == "unset" {
 			str, ok := singleUnquote(cmd[1])
 			if !ok {
-				fmt.Errorf("Failed to unquote kati line: %q", text)
+				return fmt.Errorf("Failed to unquote kati line: %q", text)
 			}
 			e.Unset(str)
 		} else if cmd[0] == "export" {
diff --git a/ui/build/kati.go b/ui/build/kati.go
index 7cfa1cf..de8dbf4 100644
--- a/ui/build/kati.go
+++ b/ui/build/kati.go
@@ -78,6 +78,8 @@
 		"--werror_find_emulator",
 		"--no_builtin_rules",
 		"--werror_suffix_rules",
+		"--warn_real_to_phony",
+		"--warn_phony_looks_real",
 		"--kati_stats",
 		"-f", "build/make/core/main.mk",
 	}
diff --git a/ui/status/ninja.go b/ui/status/ninja.go
index 7d330f9..4ceb5ef 100644
--- a/ui/status/ninja.go
+++ b/ui/status/ninja.go
@@ -43,7 +43,7 @@
 func ninjaReader(status ToolStatus, fifo string) {
 	f, err := os.Open(fifo)
 	if err != nil {
-		status.Error(fmt.Sprintf("Failed to open fifo:", err))
+		status.Error(fmt.Sprintf("Failed to open fifo: %v", err))
 	}
 	defer f.Close()