Merge "Test for dangling rules in make checkbuild"
diff --git a/android/register.go b/android/register.go
index 51089f7..81a266d 100644
--- a/android/register.go
+++ b/android/register.go
@@ -31,6 +31,7 @@
 }
 
 var singletons []singleton
+var preSingletons []singleton
 
 type mutator struct {
 	name            string
@@ -60,6 +61,10 @@
 	singletons = append(singletons, singleton{name, factory})
 }
 
+func RegisterPreSingletonType(name string, factory blueprint.SingletonFactory) {
+	preSingletons = append(preSingletons, singleton{name, factory})
+}
+
 type Context struct {
 	*blueprint.Context
 }
@@ -69,6 +74,10 @@
 }
 
 func (ctx *Context) Register() {
+	for _, t := range preSingletons {
+		ctx.RegisterPreSingletonType(t.name, t.factory)
+	}
+
 	for _, t := range moduleTypes {
 		ctx.RegisterModuleType(t.name, t.factory)
 	}
diff --git a/cc/config/clang.go b/cc/config/clang.go
index 6f08fa9..2345ebc 100644
--- a/cc/config/clang.go
+++ b/cc/config/clang.go
@@ -100,9 +100,6 @@
 		// http://b/68236239 Allow 0/NULL instead of using nullptr everywhere.
 		"-Wno-zero-as-null-pointer-constant",
 
-		// http://b/68236396 Allow unknown warning options.
-		"-Wno-unknown-warning-option",
-
 		// http://b/36463318 Clang executes with an absolute path, so clang-provided
 		// headers are now absolute.
 		"-fdebug-prefix-map=$$PWD/=",
diff --git a/cc/ndk_headers.go b/cc/ndk_headers.go
index 8f1ecbd..0458fb6 100644
--- a/cc/ndk_headers.go
+++ b/cc/ndk_headers.go
@@ -156,13 +156,13 @@
 	//
 	// Will install $SYSROOT/usr/include/foo/bar/baz.h. If `from` were instead
 	// "include/foo", it would have installed $SYSROOT/usr/include/bar/baz.h.
-	From string
+	From *string
 
 	// Install path within the sysroot. This is relative to usr/include.
-	To string
+	To *string
 
 	// Path to the NOTICE file associated with the headers.
-	License string
+	License *string
 }
 
 // Like ndk_headers, but preprocesses the headers with the bionic versioner:
@@ -185,25 +185,25 @@
 }
 
 func (m *preprocessedHeaderModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
-	if m.properties.License == "" {
+	if String(m.properties.License) == "" {
 		ctx.PropertyErrorf("license", "field is required")
 	}
 
-	m.licensePath = android.PathForModuleSrc(ctx, m.properties.License)
+	m.licensePath = android.PathForModuleSrc(ctx, String(m.properties.License))
 
-	fromSrcPath := android.PathForModuleSrc(ctx, m.properties.From)
-	toOutputPath := getCurrentIncludePath(ctx).Join(ctx, m.properties.To)
+	fromSrcPath := android.PathForModuleSrc(ctx, String(m.properties.From))
+	toOutputPath := getCurrentIncludePath(ctx).Join(ctx, String(m.properties.To))
 	srcFiles := ctx.Glob(filepath.Join(fromSrcPath.String(), "**/*.h"), nil)
 	var installPaths []android.WritablePath
 	for _, header := range srcFiles {
-		installDir := getHeaderInstallDir(ctx, header, m.properties.From, m.properties.To)
+		installDir := getHeaderInstallDir(ctx, header, String(m.properties.From), String(m.properties.To))
 		installPath := installDir.Join(ctx, header.Base())
 		installPaths = append(installPaths, installPath)
 		m.installPaths = append(m.installPaths, installPath.String())
 	}
 
 	if len(m.installPaths) == 0 {
-		ctx.ModuleErrorf("glob %q matched zero files", m.properties.From)
+		ctx.ModuleErrorf("glob %q matched zero files", String(m.properties.From))
 	}
 
 	processHeadersWithVersioner(ctx, fromSrcPath, toOutputPath, srcFiles, installPaths)
diff --git a/cmd/multiproduct_kati/main.go b/cmd/multiproduct_kati/main.go
index e4a05fc..183f800 100644
--- a/cmd/multiproduct_kati/main.go
+++ b/cmd/multiproduct_kati/main.go
@@ -15,7 +15,6 @@
 package main
 
 import (
-	"bytes"
 	"context"
 	"flag"
 	"fmt"
@@ -280,7 +279,7 @@
 				log.Fatalf("Error creating std.log: %v", err)
 			}
 
-			productLog := logger.New(&bytes.Buffer{})
+			productLog := logger.New(f)
 			productLog.SetOutput(filepath.Join(productLogDir, "soong.log"))
 
 			productCtx := build.Context{&build.ContextImpl{
diff --git a/cmd/pom2mk/pom2mk.go b/cmd/pom2mk/pom2mk.go
index ac29a2a..4596db9 100644
--- a/cmd/pom2mk/pom2mk.go
+++ b/cmd/pom2mk/pom2mk.go
@@ -83,6 +83,7 @@
 
 var extraDeps = make(ExtraDeps)
 
+var sdkVersion string
 var useVersion string
 
 type Dependency struct {
@@ -127,6 +128,10 @@
 	return ret
 }
 
+func (p Pom) SdkVersion() string {
+	return sdkVersion
+}
+
 func (p *Pom) FixDepTypes(modules map[string]*Pom) {
 	for _, d := range p.Dependencies {
 		if d.Type != "" {
@@ -147,6 +152,7 @@
 LOCAL_BUILT_MODULE_STEM := javalib.jar
 LOCAL_MODULE_SUFFIX := .{{.Packaging}}
 LOCAL_USE_AAPT2 := true
+LOCAL_SDK_VERSION := {{.SdkVersion}}
 LOCAL_STATIC_ANDROID_LIBRARIES := \
 {{range .MkDeps}}  {{.}} \
 {{end}}
@@ -196,6 +202,8 @@
      Some Android.mk modules have transitive dependencies that must be specified when they are
      depended upon (like android-support-v7-mediarouter requires android-support-v7-appcompat).
      This may be specified multiple times to declare these dependencies.
+  -sdk-version <version>
+     Sets LOCAL_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 makefiles for a specific version of those artifacts.
@@ -208,6 +216,7 @@
 
 	flag.Var(&extraDeps, "extra-deps", "Extra dependencies needed when depending on a module")
 	flag.Var(&rewriteNames, "rewrite", "Regex(es) to rewrite artifact names")
+	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.Parse()
 
diff --git a/genrule/genrule.go b/genrule/genrule.go
index 7602ee7..c5b7e1d 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -343,7 +343,7 @@
 		outFiles := android.WritablePaths{}
 		genPath := android.PathForModuleGen(ctx).String()
 		for _, in := range srcFiles {
-			outFile := android.GenPathWithExt(ctx, "", in, properties.Output_extension)
+			outFile := android.GenPathWithExt(ctx, "", in, String(properties.Output_extension))
 			outFiles = append(outFiles, outFile)
 
 			// replace "out" with "__SBOX_OUT_DIR__/<the value of ${out}>"
@@ -390,7 +390,7 @@
 
 type genSrcsProperties struct {
 	// extension that will be substituted for each output file
-	Output_extension string
+	Output_extension *string
 }
 
 func NewGenRule() *Module {