Merge "Upgrade Windows default build version from Vista to 7"
diff --git a/apex/apex.go b/apex/apex.go
index 0445c20..f412d86 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -136,7 +136,7 @@
 	pctx.HostBinToolVariable("zip2zip", "zip2zip")
 	pctx.HostBinToolVariable("zipalign", "zipalign")
 
-	android.RegisterModuleType("apex", apexBundleFactory)
+	android.RegisterModuleType("apex", ApexBundleFactory)
 
 	android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
 		ctx.TopDown("apex_deps", apexDepsMutator)
@@ -367,6 +367,7 @@
 		{Mutator: "arch", Variation: arch},
 		{Mutator: "image", Variation: "core"},
 		{Mutator: "link", Variation: "shared"},
+		{Mutator: "version", Variation: ""}, // "" is the non-stub variant
 	}, sharedLibTag, native_shared_libs...)
 
 	ctx.AddFarVariationDependencies([]blueprint.Variation{
@@ -456,6 +457,10 @@
 	}
 }
 
+func (a *apexBundle) Srcs() android.Paths {
+	return android.Paths{a.outputFiles[imageApex]}
+}
+
 func getCopyManifestForNativeLibrary(cc *cc.Module) (fileToCopy android.Path, dirInApex string) {
 	// Decide the APEX-local directory by the multilib of the library
 	// In the future, we may query this to the module.
@@ -684,8 +689,14 @@
 			} else {
 				readOnlyPaths = append(readOnlyPaths, pathInApex)
 			}
-			if !android.InList(f.installDir, executablePaths) {
-				executablePaths = append(executablePaths, f.installDir)
+			dir := f.installDir
+			for !android.InList(dir, executablePaths) && dir != "" {
+				executablePaths = append(executablePaths, dir)
+				dir, _ = filepath.Split(dir) // move up to the parent
+				if len(dir) > 0 {
+					// remove trailing slash
+					dir = dir[:len(dir)-1]
+				}
 			}
 		}
 		sort.Strings(readOnlyPaths)
@@ -871,7 +882,7 @@
 	}
 }
 
-func apexBundleFactory() android.Module {
+func ApexBundleFactory() android.Module {
 	module := &apexBundle{
 		outputFiles: map[apexPackaging]android.WritablePath{},
 	}
diff --git a/apex/apex_test.go b/apex/apex_test.go
index d1794ee..c01c40a 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -28,7 +28,7 @@
 	defer teardown(buildDir)
 
 	ctx := android.NewTestArchContext()
-	ctx.RegisterModuleType("apex", android.ModuleFactoryAdaptor(apexBundleFactory))
+	ctx.RegisterModuleType("apex", android.ModuleFactoryAdaptor(ApexBundleFactory))
 	ctx.RegisterModuleType("apex_key", android.ModuleFactoryAdaptor(apexKeyFactory))
 
 	ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
@@ -40,6 +40,7 @@
 	ctx.RegisterModuleType("cc_library_shared", android.ModuleFactoryAdaptor(cc.LibrarySharedFactory))
 	ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory))
 	ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory))
+	ctx.RegisterModuleType("prebuilt_etc", android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory))
 	ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
 		ctx.BottomUp("link", cc.LinkageMutator).Parallel()
 		ctx.BottomUp("version", cc.VersionMutator).Parallel()
@@ -94,6 +95,7 @@
 		"apex_manifest.json":                        nil,
 		"system/sepolicy/apex/myapex-file_contexts": nil,
 		"mylib.cpp":                                 nil,
+		"myprebuilt":                                nil,
 	})
 	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
 	android.FailIfErrored(t, errs)
@@ -274,13 +276,21 @@
 
 		cc_library {
 			name: "mylib3",
-				srcs: ["mylib.cpp"],
-				system_shared_libs: [],
+			srcs: ["mylib.cpp"],
+			shared_libs: ["mylib4"],
+			system_shared_libs: [],
 			stl: "none",
 			stubs: {
 				versions: ["10", "11", "12"],
 			},
 		}
+
+		cc_library {
+			name: "mylib4",
+			srcs: ["mylib.cpp"],
+			system_shared_libs: [],
+			stl: "none",
+		}
 	`)
 
 	apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule")
@@ -415,3 +425,33 @@
 	ensureContains(t, mylibCFlags, "__LIBDL_API__=27")
 	ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27")
 }
+
+func TestFilesInSubDir(t *testing.T) {
+	ctx := testApex(t, `
+		apex {
+			name: "myapex",
+			key: "myapex.key",
+			prebuilts: ["myetc"],
+		}
+
+		apex_key {
+			name: "myapex.key",
+			public_key: "testkey.avbpubkey",
+			private_key: "testkey.pem",
+		}
+
+		prebuilt_etc {
+			name: "myetc",
+			src: "myprebuilt",
+			sub_dir: "foo/bar",
+		}
+	`)
+
+	generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("generateFsConfig")
+	dirs := strings.Split(generateFsRule.Args["exec_paths"], " ")
+
+	// Ensure that etc, etc/foo, and etc/foo/bar are all listed
+	ensureListContains(t, dirs, "etc")
+	ensureListContains(t, dirs, "etc/foo")
+	ensureListContains(t, dirs, "etc/foo/bar")
+}
diff --git a/cc/compiler.go b/cc/compiler.go
index ea64b6a..63d2ade 100644
--- a/cc/compiler.go
+++ b/cc/compiler.go
@@ -75,6 +75,10 @@
 	// be added to the include path using -I
 	Local_include_dirs []string `android:"arch_variant,variant_prepend"`
 
+	// Add the directory containing the Android.bp file to the list of include
+	// directories. Defaults to true.
+	Include_build_directory *bool
+
 	// list of generated sources to compile. These are the names of gensrcs or
 	// genrule modules.
 	Generated_sources []string `android:"arch_variant"`
@@ -288,8 +292,11 @@
 		flags.YasmFlags = append(flags.YasmFlags, f)
 	}
 
-	flags.GlobalFlags = append(flags.GlobalFlags, "-I"+android.PathForModuleSrc(ctx).String())
-	flags.YasmFlags = append(flags.YasmFlags, "-I"+android.PathForModuleSrc(ctx).String())
+	if compiler.Properties.Include_build_directory == nil ||
+		*compiler.Properties.Include_build_directory {
+		flags.GlobalFlags = append(flags.GlobalFlags, "-I"+android.PathForModuleSrc(ctx).String())
+		flags.YasmFlags = append(flags.YasmFlags, "-I"+android.PathForModuleSrc(ctx).String())
+	}
 
 	if !(ctx.useSdk() || ctx.useVndk()) || ctx.Host() {
 		flags.SystemIncludeFlags = append(flags.SystemIncludeFlags,
diff --git a/cc/config/clang.go b/cc/config/clang.go
index 0b2190c..c070bf2 100644
--- a/cc/config/clang.go
+++ b/cc/config/clang.go
@@ -91,9 +91,7 @@
 	"-Wl,-m,aarch64_elf64_le_vec",
 })
 
-var ClangLibToolingUnknownCflags = sorted([]string{
-	"-fno-sanitize=implicit-integer-sign-change",
-})
+var ClangLibToolingUnknownCflags = sorted([]string{})
 
 func init() {
 	pctx.StaticVariable("ClangExtraCflags", strings.Join([]string{
@@ -122,14 +120,10 @@
 		// color codes if it is not running in a terminal.
 		"-fcolor-diagnostics",
 
-		// http://b/29823425 Disable -Wexpansion-to-defined for Clang update to r271374
-		"-Wno-expansion-to-defined",
-
 		// http://b/68236239 Allow 0/NULL instead of using nullptr everywhere.
 		"-Wno-zero-as-null-pointer-constant",
 
 		// Warnings from clang-7.0
-		"-Wno-deprecated-register",
 		"-Wno-sign-compare",
 
 		// Warnings from clang-8.0
@@ -188,9 +182,6 @@
 
 		// Disable this warning because we don't care about behavior with older compilers.
 		"-Wno-return-std-move-in-c++11",
-
-		// Disable this warning until we can fix all instances where it fails.
-		"-Wno-dangling-field",
 	}, " "))
 
 	// Extra cflags for projects under external/ directory
diff --git a/cc/config/global.go b/cc/config/global.go
index 92969b0..13ad27c 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -120,8 +120,8 @@
 
 	// prebuilts/clang default settings.
 	ClangDefaultBase         = "prebuilts/clang/host"
-	ClangDefaultVersion      = "clang-r346389"
-	ClangDefaultShortVersion = "8.0.5"
+	ClangDefaultVersion      = "clang-r346389b"
+	ClangDefaultShortVersion = "8.0.6"
 
 	// Directories with warnings from Android.bp files.
 	WarningAllowedProjects = []string{
diff --git a/cc/library.go b/cc/library.go
index 2257e2d..2fd423b 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -1053,6 +1053,8 @@
 					l.MutatedProperties.BuildStubs = true
 					l.MutatedProperties.StubsVersion = versions[i]
 					m.(*Module).Properties.HideFromMake = true
+					m.(*Module).sanitize = nil
+					m.(*Module).stl = nil
 				}
 			}
 		} else {
diff --git a/cc/sanitize.go b/cc/sanitize.go
index 08c672c..37d0a49 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -36,7 +36,7 @@
 	asanLdflags = []string{"-Wl,-u,__asan_preinit"}
 	asanLibs    = []string{"libasan"}
 
-	hwasanCflags = []string{"-mllvm", "-hwasan-with-ifunc=0", "-fno-omit-frame-pointer", "-Wno-frame-larger-than="}
+	hwasanCflags = []string{"-mllvm", "-hwasan-with-ifunc=0", "-fno-omit-frame-pointer", "-Wno-frame-larger-than=", "-mllvm", "-hwasan-create-frame-descriptions=0"}
 
 	cfiCflags = []string{"-flto", "-fsanitize-cfi-cross-dso",
 		"-fsanitize-blacklist=external/compiler-rt/lib/cfi/cfi_blacklist.txt"}
diff --git a/cc/tidy.go b/cc/tidy.go
index ddb445a..6bac846 100644
--- a/cc/tidy.go
+++ b/cc/tidy.go
@@ -108,6 +108,12 @@
 	if len(tidy.Properties.Tidy_checks) > 0 {
 		tidyChecks = tidyChecks + "," + strings.Join(esc(tidy.Properties.Tidy_checks), ",")
 	}
+	if ctx.Windows() {
+		// https://b.corp.google.com/issues/120614316
+		// mingw32 has cert-dcl16-c warning in NO_ERROR,
+		// which is used in many Android files.
+		tidyChecks = tidyChecks + ",-cert-dcl16-c"
+	}
 	flags.TidyFlags = append(flags.TidyFlags, tidyChecks)
 
 	return flags
diff --git a/ui/build/paths/config.go b/ui/build/paths/config.go
index 8e11331..e2e4368 100644
--- a/ui/build/paths/config.go
+++ b/ui/build/paths/config.go
@@ -80,11 +80,9 @@
 	"bzip2":     Allowed,
 	"chmod":     Allowed,
 	"cp":        Allowed,
-	"cut":       Allowed,
 	"date":      Allowed,
 	"dd":        Allowed,
 	"diff":      Allowed,
-	"dirname":   Allowed,
 	"du":        Allowed,
 	"echo":      Allowed,
 	"egrep":     Allowed,
@@ -96,7 +94,6 @@
 	"git":       Allowed,
 	"grep":      Allowed,
 	"gzip":      Allowed,
-	"head":      Allowed,
 	"hexdump":   Allowed,
 	"hostname":  Allowed,
 	"jar":       Allowed,
@@ -107,7 +104,6 @@
 	"lsof":      Allowed,
 	"m4":        Allowed,
 	"md5sum":    Allowed,
-	"mkdir":     Allowed,
 	"mktemp":    Allowed,
 	"mv":        Allowed,
 	"openssl":   Allowed,
@@ -132,10 +128,7 @@
 	"stat":      Allowed,
 	"tar":       Allowed,
 	"timeout":   Allowed,
-	"todos":     Allowed,
-	"touch":     Allowed,
 	"tr":        Allowed,
-	"unix2dos":  Allowed,
 	"unzip":     Allowed,
 	"wc":        Allowed,
 	"which":     Allowed,
@@ -163,8 +156,12 @@
 	"cat":      Toybox,
 	"cmp":      Toybox,
 	"comm":     Toybox,
+	"cut":      Toybox,
+	"dirname":  Toybox,
 	"env":      Toybox,
+	"head":     Toybox,
 	"id":       Toybox,
+	"mkdir":    Toybox,
 	"od":       Toybox,
 	"paste":    Toybox,
 	"pwd":      Toybox,
@@ -173,9 +170,11 @@
 	"sleep":    Toybox,
 	"tail":     Toybox,
 	"tee":      Toybox,
+	"touch":    Toybox,
 	"true":     Toybox,
 	"uname":    Toybox,
 	"uniq":     Toybox,
+	"unix2dos": Toybox,
 	"whoami":   Toybox,
 	"xxd":      Toybox,
 }