Merge "Allow all of libcore to have NewApi warnings"
diff --git a/.gitignore b/.gitignore
index 45884c4..5d2bc0d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,5 @@
 /.idea
 *.iml
+*.ipr
+*.iws
+
diff --git a/android/bazel_handler.go b/android/bazel_handler.go
index f16ee60..e829326 100644
--- a/android/bazel_handler.go
+++ b/android/bazel_handler.go
@@ -577,7 +577,7 @@
 		"HOME=" + paths.homeDir,
 		pwdPrefix(),
 		"BUILD_DIR=" + absolutePath(paths.soongOutDir),
-		// Make OUT_DIR absolute here so tools/bazel.sh uses the correct
+		// Make OUT_DIR absolute here so build/bazel/bin/bazel uses the correct
 		// OUT_DIR at <root>/out, instead of <root>/out/soong/workspace/out.
 		"OUT_DIR=" + absolutePath(paths.outDir()),
 		// Disables local host detection of gcc; toolchain information is defined
diff --git a/bp2build/symlink_forest.go b/bp2build/symlink_forest.go
index 63b6e9e..092b240 100644
--- a/bp2build/symlink_forest.go
+++ b/bp2build/symlink_forest.go
@@ -278,17 +278,9 @@
 			// Neither is a directory. Merge them.
 			srcBuildFile := shared.JoinPath(topdir, srcChild)
 			generatedBuildFile := shared.JoinPath(topdir, buildFilesChild)
-			// Add the src and generated build files as dependencies so that bp2build
-			// is rerun when they change. Currently, this is only really necessary
-			// for srcBuildFile, because if we regenerate the generated build files
-			// we will always rerun the symlink forest generation as well. If that
-			// is later split up into separate, fully dependency-tracing steps, then
-			// we'll need srcBuildFile as well. Adding srcBuildFile here today
-			// technically makes it a dependency of bp2build_workspace_marker, which
-			// also implicitly outputs that file, but since bp2build_workspace_marker
-			// will always have a newer timestamp than the generatedBuildFile it
-			// shouldn't be a problem.
-			*acc = append(*acc, srcBuildFile, generatedBuildFile)
+			// The Android.bp file that codegen used to produce `buildFilesChild` is
+			// already a dependency, we can ignore `buildFilesChild`.
+			*acc = append(*acc, srcChild)
 			err = mergeBuildFiles(shared.JoinPath(topdir, forestChild), srcBuildFile, generatedBuildFile, cfg.IsEnvTrue("BP2BUILD_VERBOSE"))
 			if err != nil {
 				fmt.Fprintf(os.Stderr, "Error merging %s and %s: %s",
diff --git a/build_test.bash b/build_test.bash
index 92819a1..eda4beb 100755
--- a/build_test.bash
+++ b/build_test.bash
@@ -48,8 +48,10 @@
 
 case $(uname) in
   Linux)
-    export LD_PRELOAD=/lib/x86_64-linux-gnu/libSegFault.so
-    export SEGFAULT_USE_ALTSTACK=1
+    if [[ -f /lib/x86_64-linux-gnu/libSegFault.so ]]; then
+      export LD_PRELOAD=/lib/x86_64-linux-gnu/libSegFault.so
+      export SEGFAULT_USE_ALTSTACK=1
+    fi
     ulimit -a
     ;;
 esac
@@ -62,7 +64,7 @@
 
 echo
 echo "Running Bazel smoke test..."
-STANDALONE_BAZEL=true "${TOP}/tools/bazel" --batch --max_idle_secs=1 help
+STANDALONE_BAZEL=true "${TOP}/build/bazel/bin/bazel" --batch --max_idle_secs=1 help
 
 echo
 echo "Running Soong test..."
diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go
index 5174570..87710c0 100644
--- a/cmd/soong_build/main.go
+++ b/cmd/soong_build/main.go
@@ -519,6 +519,12 @@
 	}
 }
 
+func touchIfDoesNotExist(path string) {
+	if _, err := os.Stat(path); os.IsNotExist(err) {
+		touch(path)
+	}
+}
+
 // Find BUILD files in the srcDir which are not in the allowlist
 // (android.Bp2BuildConversionAllowlist#ShouldKeepExistingBuildFileForDir)
 // and return their paths so they can be left out of the Bazel workspace dir (i.e. ignored)
@@ -674,8 +680,9 @@
 
 		writeDepFile(bp2buildMarker, eventHandler, ninjaDeps)
 
-		// Create an empty bp2build marker file.
-		touch(shared.JoinPath(topDir, bp2buildMarker))
+		// Create an empty bp2build marker file, if it does not already exist.
+		// Note the relevant rule has `restat = true`
+		touchIfDoesNotExist(shared.JoinPath(topDir, bp2buildMarker))
 	})
 
 	// Only report metrics when in bp2build mode. The metrics aren't relevant
diff --git a/tests/apex_comparison_tests.sh b/tests/apex_comparison_tests.sh
index 61d131b..5fbbd0f 100755
--- a/tests/apex_comparison_tests.sh
+++ b/tests/apex_comparison_tests.sh
@@ -34,7 +34,7 @@
 BAZEL_OUTPUT_DIR="$OUTPUT_DIR/bazel"
 
 function call_bazel() {
-  tools/bazel --output_base="$BAZEL_OUTPUT_DIR" $@
+  build/bazel/bin/bazel --output_base="$BAZEL_OUTPUT_DIR" $@
 }
 
 function cleanup {
diff --git a/tests/lib.sh b/tests/lib.sh
index 4b4d908..7dd2bf3 100644
--- a/tests/lib.sh
+++ b/tests/lib.sh
@@ -128,7 +128,6 @@
 
   symlink_file WORKSPACE
   symlink_file BUILD
-  symlink_file tools/bazel
 }
 
 function run_bazel {
@@ -136,7 +135,7 @@
   # output should not be parsed as such.
   rm -rf out/ninja_build
 
-  tools/bazel "$@"
+  build/bazel/bin/bazel "$@"
 }
 
 function run_ninja {
diff --git a/ui/build/bazel.go b/ui/build/bazel.go
index 0ebfcd8..bd469a4 100644
--- a/ui/build/bazel.go
+++ b/ui/build/bazel.go
@@ -85,9 +85,9 @@
 
 	bazelEnv["SHELL"] = "/bin/bash"
 
-	// `tools/bazel` is the default entry point for executing Bazel in the AOSP
+	// `build/bazel/bin/bazel` is the default entry point for executing Bazel in the AOSP
 	// source tree.
-	bazelExecutable := filepath.Join("tools", "bazel")
+	bazelExecutable := filepath.Join("build", "bazel", "bin", "bazel")
 	cmd := Command(ctx, config, "bazel", bazelExecutable)
 
 	// Append custom startup flags to the Bazel command. Startup flags affect
diff --git a/ui/build/soong.go b/ui/build/soong.go
index 00e0497..88e5592 100644
--- a/ui/build/soong.go
+++ b/ui/build/soong.go
@@ -399,7 +399,7 @@
 	soongBuildEnv := config.Environment().Copy()
 	soongBuildEnv.Set("TOP", os.Getenv("TOP"))
 	// For Bazel mixed builds.
-	soongBuildEnv.Set("BAZEL_PATH", "./tools/bazel")
+	soongBuildEnv.Set("BAZEL_PATH", "./build/bazel/bin/bazel")
 	// Bazel's HOME var is set to an output subdirectory which doesn't exist. This
 	// prevents Bazel from file I/O in the actual user HOME directory.
 	soongBuildEnv.Set("BAZEL_HOME", absPath(ctx, filepath.Join(config.BazelOutDir(), "bazelhome")))