Merge "Allow codename.fingerprint format for targetSdkVersion"
diff --git a/android/config.go b/android/config.go
index 4c7356a..ca376db 100644
--- a/android/config.go
+++ b/android/config.go
@@ -1053,6 +1053,6 @@
 	return c.productVariables.ProductHiddenAPIStubsTest
 }
 
-func (c *deviceConfig) TargetFSConfigGen() *string {
+func (c *deviceConfig) TargetFSConfigGen() []string {
 	return c.config.productVariables.TargetFSConfigGen
 }
diff --git a/android/module.go b/android/module.go
index 93966e1..b12f0c1 100644
--- a/android/module.go
+++ b/android/module.go
@@ -1042,6 +1042,39 @@
 	return aModule
 }
 
+func (a *androidModuleContext) getDirectDepInternal(name string, tag blueprint.DependencyTag) (blueprint.Module, blueprint.DependencyTag) {
+	type dep struct {
+		mod blueprint.Module
+		tag blueprint.DependencyTag
+	}
+	var deps []dep
+	a.VisitDirectDepsBlueprint(func(m blueprint.Module) {
+		if aModule, _ := m.(Module); aModule != nil && aModule.base().BaseModuleName() == name {
+			returnedTag := a.ModuleContext.OtherModuleDependencyTag(aModule)
+			if tag == nil || returnedTag == tag {
+				deps = append(deps, dep{aModule, returnedTag})
+			}
+		}
+	})
+	if len(deps) == 1 {
+		return deps[0].mod, deps[0].tag
+	} else if len(deps) >= 2 {
+		panic(fmt.Errorf("Multiple dependencies having same BaseModuleName() %q found from %q",
+			name, a.ModuleName()))
+	} else {
+		return nil, nil
+	}
+}
+
+func (a *androidModuleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module {
+	m, _ := a.getDirectDepInternal(name, tag)
+	return m
+}
+
+func (a *androidModuleContext) GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) {
+	return a.getDirectDepInternal(name, nil)
+}
+
 func (a *androidModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) {
 	a.ModuleContext.VisitDirectDeps(visit)
 }
diff --git a/android/prebuilt_test.go b/android/prebuilt_test.go
index 319c15d..e182641 100644
--- a/android/prebuilt_test.go
+++ b/android/prebuilt_test.go
@@ -41,7 +41,7 @@
 			prebuilt {
 				name: "bar",
 				prefer: false,
-				srcs: ["prebuilt"],
+				srcs: ["prebuilt_file"],
 			}`,
 		prebuilt: true,
 	},
@@ -51,7 +51,7 @@
 			prebuilt {
 				name: "bar",
 				prefer: true,
-				srcs: ["prebuilt"],
+				srcs: ["prebuilt_file"],
 			}`,
 		prebuilt: true,
 	},
@@ -65,7 +65,7 @@
 			prebuilt {
 				name: "bar",
 				prefer: false,
-				srcs: ["prebuilt"],
+				srcs: ["prebuilt_file"],
 			}`,
 		prebuilt: false,
 	},
@@ -79,7 +79,7 @@
 			prebuilt {
 				name: "bar",
 				prefer: true,
-				srcs: ["prebuilt"],
+				srcs: ["prebuilt_file"],
 			}`,
 		prebuilt: true,
 	},
@@ -114,6 +114,7 @@
 		modules: `
 			filegroup {
 				name: "fg",
+				srcs: ["prebuilt_file"],
 			}
 			prebuilt {
 				name: "bar",
@@ -143,10 +144,12 @@
 			ctx.RegisterModuleType("source", ModuleFactoryAdaptor(newSourceModule))
 			ctx.Register()
 			ctx.MockFileSystem(map[string][]byte{
+				"prebuilt_file": nil,
+				"source_file":   nil,
 				"Blueprints": []byte(`
 					source {
 						name: "foo",
-						deps: ["bar"],
+						deps: [":bar"],
 					}
 					` + test.modules),
 			})
@@ -171,21 +174,45 @@
 				}
 			})
 
+			deps := foo.Module().(*sourceModule).deps
+			if deps == nil || len(deps) != 1 {
+				t.Errorf("deps does not have single path, but is %v", deps)
+			}
+			var usingSourceFile, usingPrebuiltFile bool
+			if deps[0].String() == "source_file" {
+				usingSourceFile = true
+			}
+			if deps[0].String() == "prebuilt_file" {
+				usingPrebuiltFile = true
+			}
+
 			if test.prebuilt {
 				if !dependsOnPrebuiltModule {
 					t.Errorf("doesn't depend on prebuilt module")
 				}
+				if !usingPrebuiltFile {
+					t.Errorf("doesn't use prebuilt_file")
+				}
 
 				if dependsOnSourceModule {
 					t.Errorf("depends on source module")
 				}
+				if usingSourceFile {
+					t.Errorf("using source_file")
+				}
 			} else {
 				if dependsOnPrebuiltModule {
 					t.Errorf("depends on prebuilt module")
 				}
+				if usingPrebuiltFile {
+					t.Errorf("using prebuilt_file")
+				}
 
 				if !dependsOnSourceModule {
-					t.Errorf("doens't depend on source module")
+					t.Errorf("doesn't depend on source module")
+				}
+				if !usingSourceFile {
+					t.Errorf("doesn't use source_file")
 				}
 			}
 		})
@@ -198,6 +225,7 @@
 	properties struct {
 		Srcs []string `android:"path"`
 	}
+	src Path
 }
 
 func newPrebuiltModule() Module {
@@ -212,19 +240,28 @@
 	return p.prebuilt.Name(p.ModuleBase.Name())
 }
 
-func (p *prebuiltModule) GenerateAndroidBuildActions(ModuleContext) {
+func (p *prebuiltModule) GenerateAndroidBuildActions(ctx ModuleContext) {
+	if len(p.properties.Srcs) >= 1 {
+		p.src = p.prebuilt.SingleSourcePath(ctx)
+	}
 }
 
 func (p *prebuiltModule) Prebuilt() *Prebuilt {
 	return &p.prebuilt
 }
 
+func (p *prebuiltModule) Srcs() Paths {
+	return Paths{p.src}
+}
+
 type sourceModule struct {
 	ModuleBase
 	properties struct {
-		Deps []string
+		Deps []string `android:"path"`
 	}
 	dependsOnSourceModule, dependsOnPrebuiltModule bool
+	deps                                           Paths
+	src                                            Path
 }
 
 func newSourceModule() Module {
@@ -235,10 +272,15 @@
 }
 
 func (s *sourceModule) DepsMutator(ctx BottomUpMutatorContext) {
-	for _, d := range s.properties.Deps {
-		ctx.AddDependency(ctx.Module(), nil, d)
-	}
+	// s.properties.Deps are annotated with android:path, so they are
+	// automatically added to the dependency by pathDeps mutator
 }
 
 func (s *sourceModule) GenerateAndroidBuildActions(ctx ModuleContext) {
+	s.deps = PathsForModuleSrc(ctx, s.properties.Deps)
+	s.src = PathForModuleSrc(ctx, "source_file")
+}
+
+func (s *sourceModule) Srcs() Paths {
+	return Paths{s.src}
 }
diff --git a/android/variable.go b/android/variable.go
index 666f29f..f3da66d 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -288,7 +288,7 @@
 	ProductHiddenAPIStubsSystem []string `json:",omitempty"`
 	ProductHiddenAPIStubsTest   []string `json:",omitempty"`
 
-	TargetFSConfigGen *string `json:",omitempty"`
+	TargetFSConfigGen []string `json:",omitempty"`
 }
 
 func boolPtr(v bool) *bool {
diff --git a/cc/binary.go b/cc/binary.go
index 35c3d85..51e68fc 100644
--- a/cc/binary.go
+++ b/cc/binary.go
@@ -384,7 +384,7 @@
 
 	TransformObjToDynamicBinary(ctx, objs.objFiles, sharedLibs, deps.StaticLibs,
 		deps.LateStaticLibs, deps.WholeStaticLibs, linkerDeps, deps.CrtBegin, deps.CrtEnd, true,
-		builderFlags, outputFile)
+		builderFlags, outputFile, nil)
 
 	objs.coverageFiles = append(objs.coverageFiles, deps.StaticLibObjs.coverageFiles...)
 	objs.coverageFiles = append(objs.coverageFiles, deps.WholeStaticLibObjs.coverageFiles...)
diff --git a/cc/builder.go b/cc/builder.go
index 87db645..7b26d51 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -26,6 +26,7 @@
 	"strings"
 
 	"github.com/google/blueprint"
+	"github.com/google/blueprint/pathtools"
 
 	"android/soong/android"
 	"android/soong/cc/config"
@@ -596,7 +597,7 @@
 // and shared libraries, to a shared library (.so) or dynamic executable
 func TransformObjToDynamicBinary(ctx android.ModuleContext,
 	objFiles, sharedLibs, staticLibs, lateStaticLibs, wholeStaticLibs, deps android.Paths,
-	crtBegin, crtEnd android.OptionalPath, groupLate bool, flags builderFlags, outputFile android.WritablePath) {
+	crtBegin, crtEnd android.OptionalPath, groupLate bool, flags builderFlags, outputFile android.WritablePath, implicitOutputs android.WritablePaths) {
 
 	ldCmd := "${config.ClangBin}/clang++"
 
@@ -633,7 +634,11 @@
 	}
 
 	for _, lib := range sharedLibs {
-		libFlagsList = append(libFlagsList, lib.String())
+		libFile := lib.String()
+		if ctx.Windows() {
+			libFile = pathtools.ReplaceExtension(libFile, "lib")
+		}
+		libFlagsList = append(libFlagsList, libFile)
 	}
 
 	deps = append(deps, staticLibs...)
@@ -644,11 +649,12 @@
 	}
 
 	ctx.Build(pctx, android.BuildParams{
-		Rule:        ld,
-		Description: "link " + outputFile.Base(),
-		Output:      outputFile,
-		Inputs:      objFiles,
-		Implicits:   deps,
+		Rule:            ld,
+		Description:     "link " + outputFile.Base(),
+		Output:          outputFile,
+		ImplicitOutputs: implicitOutputs,
+		Inputs:          objFiles,
+		Implicits:       deps,
 		Args: map[string]string{
 			"ldCmd":    ldCmd,
 			"crtBegin": crtBegin.String(),
diff --git a/cc/config/global.go b/cc/config/global.go
index 8fc9ff2..0a7d984 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -121,8 +121,8 @@
 
 	// prebuilts/clang default settings.
 	ClangDefaultBase         = "prebuilts/clang/host"
-	ClangDefaultVersion      = "clang-r353983b"
-	ClangDefaultShortVersion = "9.0.2"
+	ClangDefaultVersion      = "clang-r353983c"
+	ClangDefaultShortVersion = "9.0.3"
 
 	// Directories with warnings from Android.bp files.
 	WarningAllowedProjects = []string{
diff --git a/cc/library.go b/cc/library.go
index a594b91..13972cc 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -357,9 +357,10 @@
 				)
 			}
 		} else {
-			f = append(f,
-				"-shared",
-				"-Wl,-soname,"+libName+flags.Toolchain.ShlibSuffix())
+			f = append(f, "-shared")
+			if !ctx.Windows() {
+				f = append(f, "-Wl,-soname,"+libName+flags.Toolchain.ShlibSuffix())
+			}
 		}
 
 		flags.LdFlags = append(f, flags.LdFlags...)
@@ -683,6 +684,14 @@
 	outputFile := android.PathForModuleOut(ctx, fileName)
 	ret := outputFile
 
+	var implicitOutputs android.WritablePaths
+	if ctx.Windows() {
+		importLibraryPath := android.PathForModuleOut(ctx, pathtools.ReplaceExtension(fileName, "lib"))
+
+		flags.LdFlags = append(flags.LdFlags, "-Wl,--out-implib="+importLibraryPath.String())
+		implicitOutputs = append(implicitOutputs, importLibraryPath)
+	}
+
 	builderFlags := flagsToBuilderFlags(flags)
 
 	// Optimize out relinking against shared libraries whose interface hasn't changed by
@@ -734,7 +743,7 @@
 
 	TransformObjToDynamicBinary(ctx, objs.objFiles, sharedLibs,
 		deps.StaticLibs, deps.LateStaticLibs, deps.WholeStaticLibs,
-		linkerDeps, deps.CrtBegin, deps.CrtEnd, false, builderFlags, outputFile)
+		linkerDeps, deps.CrtBegin, deps.CrtEnd, false, builderFlags, outputFile, implicitOutputs)
 
 	objs.coverageFiles = append(objs.coverageFiles, deps.StaticLibObjs.coverageFiles...)
 	objs.coverageFiles = append(objs.coverageFiles, deps.WholeStaticLibObjs.coverageFiles...)
diff --git a/cc/linker.go b/cc/linker.go
index b279c06..e724df6 100644
--- a/cc/linker.go
+++ b/cc/linker.go
@@ -301,10 +301,6 @@
 	if ctx.Darwin() {
 		return false
 	}
-	// http://b/110800681 - lld cannot link Android's Windows modules yet.
-	if ctx.Windows() {
-		return false
-	}
 	if linker.Properties.Use_clang_lld != nil {
 		return Bool(linker.Properties.Use_clang_lld)
 	}
@@ -358,7 +354,7 @@
 			// darwin defaults to treating undefined symbols as errors
 			flags.LdFlags = append(flags.LdFlags, "-Wl,-undefined,dynamic_lookup")
 		}
-	} else if !ctx.Darwin() {
+	} else if !ctx.Darwin() && !ctx.Windows() {
 		flags.LdFlags = append(flags.LdFlags, "-Wl,--no-undefined")
 	}
 
@@ -395,7 +391,7 @@
 
 	flags.LdFlags = append(flags.LdFlags, proptools.NinjaAndShellEscapeList(linker.Properties.Ldflags)...)
 
-	if ctx.Host() {
+	if ctx.Host() && !ctx.Windows() {
 		rpath_prefix := `\$$ORIGIN/`
 		if ctx.Darwin() {
 			rpath_prefix = "@loader_path/"
diff --git a/cmd/pom2bp/pom2bp.go b/cmd/pom2bp/pom2bp.go
index 2de0f7d..2dfa546 100644
--- a/cmd/pom2bp/pom2bp.go
+++ b/cmd/pom2bp/pom2bp.go
@@ -126,6 +126,7 @@
 
 var sdkVersion string
 var useVersion string
+var jetifier bool
 
 func InList(s string, list []string) bool {
 	for _, l := range list {
@@ -257,6 +258,10 @@
 	return sdkVersion
 }
 
+func (p Pom) Jetifier() bool {
+	return jetifier
+}
+
 func (p *Pom) FixDeps(modules map[string]*Pom) {
 	for _, d := range p.Dependencies {
 		if d.Type == "" {
@@ -331,6 +336,9 @@
     name: "{{.BpName}}-nodeps",
     {{.ImportProperty}}: ["{{.ArtifactFile}}"],
     sdk_version: "{{.SdkVersion}}",
+    {{- if .Jetifier}}
+    jetifier: true,
+    {{- end}}
     {{- if .IsAar}}
     min_sdk_version: "{{.MinSdkVersion}}",
     static_libs: [
@@ -500,10 +508,12 @@
      are depended upon (like androidx.test.rules requires android.test.base).
      This may be specified multiple times to declare these dependencies.
   -sdk-version <version>
-     Sets LOCAL_SDK_VERSION := <version> for all modules.
+     Sets sdk_version: "<version>" for all modules.
   -use-version <version>
      If the maven directory contains multiple versions of artifacts and their pom files,
      -use-version can be used to only write Android.bp files for a specific version of those artifacts.
+  -jetifier
+     Sets jetifier: true for all modules.
   <dir>
      The directory to search for *.pom files under.
      The contents are written to stdout, to be put in the current directory (often as Android.bp)
@@ -521,8 +531,9 @@
 	flag.Var(&extraLibs, "extra-libs", "Extra runtime dependencies needed when depending on a module")
 	flag.Var(&rewriteNames, "rewrite", "Regex(es) to rewrite artifact names")
 	flag.Var(&hostModuleNames, "host", "Specifies that the corresponding module (specified in the form 'module.group:module.artifact') is a host module")
-	flag.StringVar(&sdkVersion, "sdk-version", "", "What to write to LOCAL_SDK_VERSION")
+	flag.StringVar(&sdkVersion, "sdk-version", "", "What to write to sdk_version")
 	flag.StringVar(&useVersion, "use-version", "", "Only read artifacts of a specific version")
+	flag.BoolVar(&jetifier, "jetifier", false, "Sets jetifier: true on all modules")
 	flag.Bool("static-deps", false, "Ignored")
 	flag.StringVar(&regen, "regen", "", "Rewrite specified file")
 	flag.Parse()
diff --git a/cmd/pom2mk/pom2mk.go b/cmd/pom2mk/pom2mk.go
index 94e5619..b347155 100644
--- a/cmd/pom2mk/pom2mk.go
+++ b/cmd/pom2mk/pom2mk.go
@@ -104,6 +104,7 @@
 var sdkVersion string
 var useVersion string
 var staticDeps bool
+var jetifier bool
 
 func InList(s string, list []string) bool {
 	for _, l := range list {
@@ -195,6 +196,10 @@
 	return sdkVersion
 }
 
+func (p Pom) Jetifier() bool {
+	return jetifier
+}
+
 func (p *Pom) FixDeps(modules map[string]*Pom) {
 	for _, d := range p.Dependencies {
 		if d.Type == "" {
@@ -229,6 +234,7 @@
   {{.}}{{end}}
 LOCAL_STATIC_ANDROID_LIBRARIES :={{range .MkAarDeps}} \
   {{.}}{{end}}
+LOCAL_JETIFIER_ENABLED := {{if .Jetifier}}true{{end}}
 include $(BUILD_PREBUILT)
 `))
 
@@ -367,6 +373,8 @@
      -use-version can be used to only write makefiles for a specific version of those artifacts.
   -static-deps
      Whether to statically include direct dependencies.
+  -jetifier
+     Enable jetifier in order to use androidx
   <dir>
      The directory to search for *.pom files under.
      The makefile is written to stdout, to be put in the current directory (often as Android.mk)
@@ -383,6 +391,7 @@
 	flag.StringVar(&sdkVersion, "sdk-version", "", "What to write to LOCAL_SDK_VERSION")
 	flag.StringVar(&useVersion, "use-version", "", "Only read artifacts of a specific version")
 	flag.BoolVar(&staticDeps, "static-deps", false, "Statically include direct dependencies")
+	flag.BoolVar(&jetifier, "jetifier", false, "Enable jetifier in order to use androidx")
 	flag.StringVar(&regen, "regen", "", "Rewrite specified file")
 	flag.Parse()
 
diff --git a/java/app.go b/java/app.go
index ab623e2..da8024f 100644
--- a/java/app.go
+++ b/java/app.go
@@ -438,7 +438,7 @@
 func AndroidAppFactory() android.Module {
 	module := &AndroidApp{}
 
-	module.Module.deviceProperties.Optimize.Enabled = proptools.BoolPtr(true)
+	module.Module.deviceProperties.Optimize.EnabledByDefault = true
 	module.Module.deviceProperties.Optimize.Shrink = proptools.BoolPtr(true)
 
 	module.Module.properties.Instrument = true
@@ -508,7 +508,7 @@
 func AndroidTestFactory() android.Module {
 	module := &AndroidTest{}
 
-	module.Module.deviceProperties.Optimize.Enabled = proptools.BoolPtr(true)
+	module.Module.deviceProperties.Optimize.EnabledByDefault = true
 
 	module.Module.properties.Instrument = true
 	module.Module.properties.Installable = proptools.BoolPtr(true)
@@ -550,7 +550,7 @@
 func AndroidTestHelperAppFactory() android.Module {
 	module := &AndroidTestHelperApp{}
 
-	module.Module.deviceProperties.Optimize.Enabled = proptools.BoolPtr(true)
+	module.Module.deviceProperties.Optimize.EnabledByDefault = true
 
 	module.Module.properties.Installable = proptools.BoolPtr(true)
 	module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true)
diff --git a/java/dex.go b/java/dex.go
index 987129e..c8a4fa8 100644
--- a/java/dex.go
+++ b/java/dex.go
@@ -171,7 +171,7 @@
 func (j *Module) compileDex(ctx android.ModuleContext, flags javaBuilderFlags,
 	classesJar android.Path, jarName string) android.ModuleOutPath {
 
-	useR8 := Bool(j.deviceProperties.Optimize.Enabled)
+	useR8 := j.deviceProperties.EffectiveOptimizeEnabled()
 
 	// Compile classes.jar into classes.dex and then javalib.jar
 	javalibJar := android.PathForModuleOut(ctx, "dex", jarName)
diff --git a/java/java.go b/java/java.go
index 7c5d841..d6c759b 100644
--- a/java/java.go
+++ b/java/java.go
@@ -228,6 +228,8 @@
 		// If false, disable all optimization.  Defaults to true for android_app and android_test
 		// modules, false for java_library and java_test modules.
 		Enabled *bool
+		// True if the module containing this has it set by default.
+		EnabledByDefault bool `blueprint:"mutated"`
 
 		// If true, optimize for size by removing unused code.  Defaults to true for apps,
 		// false for libraries and tests.
@@ -257,6 +259,10 @@
 	IsSDKLibrary  bool `blueprint:"mutated"`
 }
 
+func (me *CompilerDeviceProperties) EffectiveOptimizeEnabled() bool {
+	return BoolDefault(me.Optimize.Enabled, me.Optimize.EnabledByDefault)
+}
+
 // Module contains the properties and members used by all java module types
 type Module struct {
 	android.ModuleBase
@@ -460,7 +466,7 @@
 			} else if sdkDep.useModule {
 				ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
 				ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...)
-				if Bool(j.deviceProperties.Optimize.Enabled) {
+				if j.deviceProperties.EffectiveOptimizeEnabled() {
 					ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultBootclasspathLibraries...)
 					ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultLibraries...)
 				}
diff --git a/java/java_test.go b/java/java_test.go
index 1a4db21..3fab43d 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -378,6 +378,7 @@
 			srcs: ["a.java"],
 			libs: ["bar"],
 			static_libs: ["baz"],
+			optimize: {enabled: false},
 		}
 
 		java_library {
@@ -394,6 +395,22 @@
 			name: "baz",
 			srcs: ["c.java"],
 		}
+
+		android_test {
+			name: "atestOptimize",
+			defaults: ["defaults"],
+			optimize: {enabled: true},
+		}
+
+		android_test {
+			name: "atestNoOptimize",
+			defaults: ["defaults"],
+		}
+
+		android_test {
+			name: "atestDefault",
+			srcs: ["a.java"],
+		}
 		`)
 
 	javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
@@ -412,6 +429,21 @@
 	if len(combineJar.Inputs) != 2 || combineJar.Inputs[1].String() != baz {
 		t.Errorf("foo combineJar inputs %v does not contain %q", combineJar.Inputs, baz)
 	}
+
+	atestOptimize := ctx.ModuleForTests("atestOptimize", "android_common").MaybeRule("r8")
+	if atestOptimize.Output == nil {
+		t.Errorf("atestOptimize should optimize APK")
+	}
+
+	atestNoOptimize := ctx.ModuleForTests("atestNoOptimize", "android_common").MaybeRule("d8")
+	if atestNoOptimize.Output == nil {
+		t.Errorf("atestNoOptimize should not optimize APK")
+	}
+
+	atestDefault := ctx.ModuleForTests("atestDefault", "android_common").MaybeRule("r8")
+	if atestDefault.Output == nil {
+		t.Errorf("atestDefault should optimize APK")
+	}
 }
 
 func TestResources(t *testing.T) {
diff --git a/scripts/build_broken_logs.go b/scripts/build_broken_logs.go
index f081f26..4f3e0de 100644
--- a/scripts/build_broken_logs.go
+++ b/scripts/build_broken_logs.go
@@ -60,32 +60,18 @@
 	warnings []string
 }{
 	{
-		name:     "BUILD_BROKEN_DUP_COPY_HEADERS",
-		behavior: DefaultDeprecated,
-		warnings: []string{"Duplicate header copy:"},
-	},
-	{
 		name:     "BUILD_BROKEN_DUP_RULES",
 		behavior: DefaultFalse,
 		warnings: []string{"overriding commands for target"},
 	},
 	{
 		name:     "BUILD_BROKEN_ANDROIDMK_EXPORTS",
-		behavior: DefaultFalse,
+		behavior: DefaultDeprecated,
 		warnings: []string{"export_keyword"},
 	},
 	{
-		name:     "BUILD_BROKEN_PHONY_TARGETS",
-		behavior: DefaultFalse,
-		warnings: []string{
-			"depends on PHONY target",
-			"looks like a real file",
-			"writing to readonly directory",
-		},
-	},
-	{
 		name:     "BUILD_BROKEN_ENG_DEBUG_TAGS",
-		behavior: DefaultTrue,
+		behavior: DefaultDeprecated,
 		warnings: []string{
 			"Changes.md#LOCAL_MODULE_TAGS",
 		},
diff --git a/ui/build/config.go b/ui/build/config.go
index 7eb3a72..c298f00 100644
--- a/ui/build/config.go
+++ b/ui/build/config.go
@@ -53,9 +53,8 @@
 
 	pdkBuild bool
 
-	brokenDupRules     bool
-	brokenPhonyTargets bool
-	brokenUsesNetwork  bool
+	brokenDupRules    bool
+	brokenUsesNetwork bool
 
 	pathReplaced bool
 }
@@ -615,14 +614,6 @@
 	return c.brokenDupRules
 }
 
-func (c *configImpl) SetBuildBrokenPhonyTargets(val bool) {
-	c.brokenPhonyTargets = val
-}
-
-func (c *configImpl) BuildBrokenPhonyTargets() bool {
-	return c.brokenPhonyTargets
-}
-
 func (c *configImpl) SetBuildBrokenUsesNetwork(val bool) {
 	c.brokenUsesNetwork = val
 }
diff --git a/ui/build/dumpvars.go b/ui/build/dumpvars.go
index 3e387c1..483c273 100644
--- a/ui/build/dumpvars.go
+++ b/ui/build/dumpvars.go
@@ -200,17 +200,49 @@
 		// Whether --werror_overriding_commands will work
 		"BUILD_BROKEN_DUP_RULES",
 
-		// Used to turn on --werror_ options in Kati
-		"BUILD_BROKEN_PHONY_TARGETS",
-
 		// Whether to enable the network during the build
 		"BUILD_BROKEN_USES_NETWORK",
 
 		// Not used, but useful to be in the soong.log
 		"BOARD_VNDK_VERSION",
 		"BUILD_BROKEN_ANDROIDMK_EXPORTS",
-		"BUILD_BROKEN_DUP_COPY_HEADERS",
 		"BUILD_BROKEN_ENG_DEBUG_TAGS",
+
+		"DEFAULT_WARNING_BUILD_MODULE_TYPES",
+		"DEFAULT_ERROR_BUILD_MODULE_TYPES",
+		"BUILD_BROKEN_USES_BUILD_AUX_EXECUTABLE",
+		"BUILD_BROKEN_USES_BUILD_AUX_STATIC_LIBRARY",
+		"BUILD_BROKEN_USES_BUILD_COPY_HEADERS",
+		"BUILD_BROKEN_USES_BUILD_EXECUTABLE",
+		"BUILD_BROKEN_USES_BUILD_FUZZ_TEST",
+		"BUILD_BROKEN_USES_BUILD_HEADER_LIBRARY",
+		"BUILD_BROKEN_USES_BUILD_HOST_DALVIK_JAVA_LIBRARY",
+		"BUILD_BROKEN_USES_BUILD_HOST_DALVIK_STATIC_JAVA_LIBRARY",
+		"BUILD_BROKEN_USES_BUILD_HOST_EXECUTABLE",
+		"BUILD_BROKEN_USES_BUILD_HOST_FUZZ_TEST",
+		"BUILD_BROKEN_USES_BUILD_HOST_JAVA_LIBRARY",
+		"BUILD_BROKEN_USES_BUILD_HOST_NATIVE_TEST",
+		"BUILD_BROKEN_USES_BUILD_HOST_PREBUILT",
+		"BUILD_BROKEN_USES_BUILD_HOST_SHARED_LIBRARY",
+		"BUILD_BROKEN_USES_BUILD_HOST_SHARED_TEST_LIBRARY",
+		"BUILD_BROKEN_USES_BUILD_HOST_STATIC_LIBRARY",
+		"BUILD_BROKEN_USES_BUILD_HOST_STATIC_TEST_LIBRARY",
+		"BUILD_BROKEN_USES_BUILD_HOST_TEST_CONFIG",
+		"BUILD_BROKEN_USES_BUILD_JAVA_LIBRARY",
+		"BUILD_BROKEN_USES_BUILD_MULTI_PREBUILT",
+		"BUILD_BROKEN_USES_BUILD_NATIVE_BENCHMARK",
+		"BUILD_BROKEN_USES_BUILD_NATIVE_TEST",
+		"BUILD_BROKEN_USES_BUILD_NOTICE_FILE",
+		"BUILD_BROKEN_USES_BUILD_PACKAGE",
+		"BUILD_BROKEN_USES_BUILD_PHONY_PACKAGE",
+		"BUILD_BROKEN_USES_BUILD_PREBUILT",
+		"BUILD_BROKEN_USES_BUILD_RRO_PACKAGE",
+		"BUILD_BROKEN_USES_BUILD_SHARED_LIBRARY",
+		"BUILD_BROKEN_USES_BUILD_SHARED_TEST_LIBRARY",
+		"BUILD_BROKEN_USES_BUILD_STATIC_JAVA_LIBRARY",
+		"BUILD_BROKEN_USES_BUILD_STATIC_LIBRARY",
+		"BUILD_BROKEN_USES_BUILD_STATIC_TEST_LIBRARY",
+		"BUILD_BROKEN_USES_BUILD_TARGET_TEST_CONFIG",
 	}, exportEnvVars...), BannerVars...)
 
 	make_vars, err := dumpMakeVars(ctx, config, config.Arguments(), allVars, true)
@@ -240,6 +272,5 @@
 
 	config.SetPdkBuild(make_vars["TARGET_BUILD_PDK"] == "true")
 	config.SetBuildBrokenDupRules(make_vars["BUILD_BROKEN_DUP_RULES"] == "true")
-	config.SetBuildBrokenPhonyTargets(make_vars["BUILD_BROKEN_PHONY_TARGETS"] == "true")
 	config.SetBuildBrokenUsesNetwork(make_vars["BUILD_BROKEN_USES_NETWORK"] == "true")
 }
diff --git a/ui/build/kati.go b/ui/build/kati.go
index 959d0bd..5ad966a 100644
--- a/ui/build/kati.go
+++ b/ui/build/kati.go
@@ -81,6 +81,9 @@
 		"--werror_suffix_rules",
 		"--warn_real_to_phony",
 		"--warn_phony_looks_real",
+		"--werror_real_to_phony",
+		"--werror_phony_looks_real",
+		"--werror_writable",
 		"--top_level_phony",
 		"--kati_stats",
 	}, args...)
@@ -138,13 +141,6 @@
 		args = append(args, "--werror_overriding_commands")
 	}
 
-	if !config.BuildBrokenPhonyTargets() {
-		args = append(args,
-			"--werror_real_to_phony",
-			"--werror_phony_looks_real",
-			"--werror_writable")
-	}
-
 	args = append(args, config.KatiArgs()...)
 
 	args = append(args,
@@ -162,11 +158,8 @@
 
 	args := []string{
 		"--writable", config.DistDir() + "/",
-		"--werror_writable",
 		"--werror_implicit_rules",
 		"--werror_overriding_commands",
-		"--werror_real_to_phony",
-		"--werror_phony_looks_real",
 		"-f", "build/make/packaging/main.mk",
 		"KATI_PACKAGE_MK_DIR=" + config.KatiPackageMkDir(),
 	}
@@ -202,11 +195,8 @@
 	defer ctx.EndTrace()
 
 	runKati(ctx, config, katiCleanspecSuffix, []string{
-		"--werror_writable",
 		"--werror_implicit_rules",
 		"--werror_overriding_commands",
-		"--werror_real_to_phony",
-		"--werror_phony_looks_real",
 		"-f", "build/make/core/cleanbuild.mk",
 		"SOONG_MAKEVARS_MK=" + config.SoongMakeVarsMk(),
 		"TARGET_DEVICE_DIR=" + config.TargetDeviceDir(),
diff --git a/zip/cmd/main.go b/zip/cmd/main.go
index b4f75f7..6f40a3e 100644
--- a/zip/cmd/main.go
+++ b/zip/cmd/main.go
@@ -105,12 +105,6 @@
 	nonDeflatedFiles = make(uniqueSet)
 )
 
-func usage() {
-	fmt.Fprintf(os.Stderr, "usage: soong_zip -o zipfile [-m manifest] [-C dir] [-f|-l file] [-D dir]...\n")
-	flag.PrintDefaults()
-	os.Exit(2)
-}
-
 func main() {
 	var expandedArgs []string
 	for _, arg := range os.Args {
@@ -128,7 +122,11 @@
 	}
 
 	flags := flag.NewFlagSet("flags", flag.ExitOnError)
-	flags.Usage = usage
+	flags.Usage = func() {
+		fmt.Fprintf(os.Stderr, "usage: soong_zip -o zipfile [-m manifest] [-C dir] [-f|-l file] [-D dir]...\n")
+		flags.PrintDefaults()
+		os.Exit(2)
+	}
 
 	out := flags.String("o", "", "file to write zip file to")
 	manifest := flags.String("m", "", "input jar manifest file name")