Merge "Remove 6 directories from WarningAllowed*Projects."
diff --git a/androidmk/cmd/androidmk/android.go b/androidmk/cmd/androidmk/android.go
index 18756a9..bb9d140 100644
--- a/androidmk/cmd/androidmk/android.go
+++ b/androidmk/cmd/androidmk/android.go
@@ -94,6 +94,8 @@
 			"LOCAL_NOTICE_FILE":             "notice",
 			"LOCAL_JAVA_LANGUAGE_VERSION":   "java_version",
 			"LOCAL_INSTRUMENTATION_FOR":     "instrumentation_for",
+
+			"LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING": "dex_preopt.profile",
 		})
 	addStandardProperties(bpparser.ListType,
 		map[string]string{
@@ -151,7 +153,10 @@
 			"LOCAL_PROPRIETARY_MODULE":       "proprietary",
 			"LOCAL_VENDOR_MODULE":            "vendor",
 			"LOCAL_EXPORT_PACKAGE_RESOURCES": "export_package_resources",
-			"LOCAL_DEX_PREOPT":               "dex_preopt",
+
+			"LOCAL_DEX_PREOPT":                  "dex_preopt.enabled",
+			"LOCAL_DEX_PREOPT_APP_IMAGE":        "dex_preopt.app_image",
+			"LOCAL_DEX_PREOPT_GENERATE_PROFILE": "dex_preopt.profile_guided",
 		})
 }
 
diff --git a/cc/androidmk.go b/cc/androidmk.go
index 6d1c44f..7311263 100644
--- a/cc/androidmk.go
+++ b/cc/androidmk.go
@@ -368,4 +368,4 @@
 		fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir))
 		fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem)
 	})
-}
\ No newline at end of file
+}
diff --git a/cc/vndk_prebuilt.go b/cc/vndk_prebuilt.go
index a1a164f..9ccab03 100644
--- a/cc/vndk_prebuilt.go
+++ b/cc/vndk_prebuilt.go
@@ -137,4 +137,4 @@
 
 func init() {
 	android.RegisterModuleType("vndk_prebuilt_shared", vndkPrebuiltSharedFactory)
-}
\ No newline at end of file
+}
diff --git a/cmd/pom2mk/pom2mk.go b/cmd/pom2mk/pom2mk.go
index 4596db9..33d7ff9 100644
--- a/cmd/pom2mk/pom2mk.go
+++ b/cmd/pom2mk/pom2mk.go
@@ -55,13 +55,15 @@
 	return nil
 }
 
-func (r *RewriteNames) Rewrite(name string) string {
+func (r *RewriteNames) MavenToMk(groupId string, artifactId string) string {
 	for _, r := range *r {
-		if r.regexp.MatchString(name) {
-			return r.regexp.ReplaceAllString(name, r.repl)
+		if r.regexp.MatchString(groupId + ":" + artifactId) {
+			return r.regexp.ReplaceAllString(groupId+":"+artifactId, r.repl)
+		} else if r.regexp.MatchString(artifactId) {
+			return r.regexp.ReplaceAllString(artifactId, r.repl)
 		}
 	}
-	return name
+	return artifactId
 }
 
 var rewriteNames = RewriteNames{}
@@ -102,6 +104,7 @@
 
 	PomFile      string `xml:"-"`
 	ArtifactFile string `xml:"-"`
+	MakeTarget   string `xml:"-"`
 
 	GroupId    string `xml:"groupId"`
 	ArtifactId string `xml:"artifactId"`
@@ -112,7 +115,10 @@
 }
 
 func (p Pom) MkName() string {
-	return rewriteNames.Rewrite(p.ArtifactId)
+	if p.MakeTarget == "" {
+		p.MakeTarget = rewriteNames.MavenToMk(p.GroupId, p.ArtifactId)
+	}
+	return p.MakeTarget
 }
 
 func (p Pom) MkDeps() []string {
@@ -121,7 +127,7 @@
 		if d.Type != "aar" {
 			continue
 		}
-		name := rewriteNames.Rewrite(d.ArtifactId)
+		name := rewriteNames.MavenToMk(d.GroupId, d.ArtifactId)
 		ret = append(ret, name)
 		ret = append(ret, extraDeps[name]...)
 	}
@@ -137,7 +143,7 @@
 		if d.Type != "" {
 			continue
 		}
-		if depPom, ok := modules[d.ArtifactId]; ok {
+		if depPom, ok := modules[p.MkName()]; ok {
 			d.Type = depPom.Packaging
 		}
 	}
@@ -195,9 +201,11 @@
 Usage: %s [--rewrite <regex>=<replace>] [--extra-deps <module>=<module>[,<module>]] <dir>
 
   -rewrite <regex>=<replace>
-     rewrite can be used to specify mappings between the artifactId in the pom files and module
-     names in the Android.mk files. This can be specified multiple times, the first matching
-     regex will be used.
+     rewrite can be used to specify mappings between Maven projects and Make modules. The -rewrite
+     option can be specified multiple times. When determining the Make module for a given Maven
+     project, mappings are searched in the order they were specified. The first <regex> matching
+     either the Maven project's <groupId>:<artifactId> or <artifactId> will be used to generate
+     the Make module name using <replace>. If no matches are found, <artifactId> is used.
   -extra-deps <module>=<module>[,<module>]
      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).
@@ -282,13 +290,14 @@
 
 		if pom != nil {
 			poms = append(poms, pom)
+			key := pom.MkName()
 
-			if old, ok := modules[pom.ArtifactId]; ok {
-				fmt.Fprintln(os.Stderr, "Module", pom.ArtifactId, "defined twice:", old.PomFile, pom.PomFile)
+			if old, ok := modules[key]; ok {
+				fmt.Fprintln(os.Stderr, "Module", key, "defined twice:", old.PomFile, pom.PomFile)
 				os.Exit(1)
 			}
 
-			modules[pom.ArtifactId] = pom
+			modules[key] = pom
 		}
 	}
 
diff --git a/java/androidmk.go b/java/androidmk.go
index f52d5e9..acf597b 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -36,8 +36,18 @@
 				}
 				if library.dexJarFile != nil {
 					fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String())
-					if library.deviceProperties.Dex_preopt != nil && *library.deviceProperties.Dex_preopt == false {
-						fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false")
+					if library.deviceProperties.Dex_preopt.Enabled != nil {
+						fmt.Fprintln(w, "LOCAL_DEX_PREOPT :=", *library.deviceProperties.Dex_preopt.Enabled)
+					}
+					if library.deviceProperties.Dex_preopt.App_image != nil {
+						fmt.Fprintln(w, "LOCAL_DEX_PREOPT_APP_IMAGE :=", *library.deviceProperties.Dex_preopt.App_image)
+					}
+					if library.deviceProperties.Dex_preopt.Profile_guided != nil {
+						fmt.Fprintln(w, "LOCAL_DEX_PREOPT_GENERATE_PROFILE :=", *library.deviceProperties.Dex_preopt.Profile_guided)
+					}
+					if library.deviceProperties.Dex_preopt.Profile != nil {
+						fmt.Fprintln(w, "LOCAL_DEX_PREOPT_GENERATE_PROFILE := true")
+						fmt.Fprintln(w, "LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING := $(LOCAL_PATH)/"+*library.deviceProperties.Dex_preopt.Profile)
 					}
 				}
 				fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", String(library.deviceProperties.Sdk_version))
diff --git a/java/java.go b/java/java.go
index 0e54e3c..3663253 100644
--- a/java/java.go
+++ b/java/java.go
@@ -167,9 +167,24 @@
 	// If true, export a copy of the module as a -hostdex module for host testing.
 	Hostdex *bool
 
-	// If false, prevent dexpreopting and stripping the dex file from the final jar.  Defaults to
-	// true.
-	Dex_preopt *bool
+	Dex_preopt struct {
+		// If false, prevent dexpreopting and stripping the dex file from the final jar.  Defaults to
+		// true.
+		Enabled *bool
+
+		// If true, generate an app image (.art file) for this module.
+		App_image *bool
+
+		// If true, use a checked-in profile to guide optimization.  Defaults to false unless
+		// a matching profile is set or a profile is found in PRODUCT_DEX_PREOPT_PROFILE_DIR
+		// that matches the name of this module, in which case it is defaulted to true.
+		Profile_guided *bool
+
+		// If set, provides the path to profile relative to the Android.bp file.  If not set,
+		// defaults to searching for a file that matches the name of this module in the default
+		// profile location set by PRODUCT_DEX_PREOPT_PROFILE_DIR, or empty if not found.
+		Profile *string
+	}
 
 	// When targeting 1.9, override the modules to use with --system
 	System_modules *string
diff --git a/python/python.go b/python/python.go
index 05efbea..9a3b1bb 100644
--- a/python/python.go
+++ b/python/python.go
@@ -242,6 +242,14 @@
 	}
 }
 
+func (p *Module) HostToolPath() android.OptionalPath {
+	if p.installer == nil {
+		// python_library is just meta module, and doesn't have any installer.
+		return android.OptionalPath{}
+	}
+	return android.OptionalPathForPath(p.installer.(*binaryDecorator).path)
+}
+
 func (p *Module) isEmbeddedLauncherEnabled(actual_version string) bool {
 	switch actual_version {
 	case pyVersion2: