Merge "Remove -Wsign-promo." into main
diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go
index 64cb2fa..8bc9ba6 100644
--- a/android/allowlists/allowlists.go
+++ b/android/allowlists/allowlists.go
@@ -503,6 +503,7 @@
"prebuilts/clang-tools":/* recursive = */ true,
"prebuilts/gcc":/* recursive = */ true,
"prebuilts/build-tools":/* recursive = */ true,
+ "prebuilts/jdk/jdk8":/* recursive = */ true,
"prebuilts/jdk/jdk17":/* recursive = */ true,
"prebuilts/misc":/* recursive = */ false, // not recursive because we need bp2build converted build files in prebuilts/misc/common/asm
"prebuilts/sdk":/* recursive = */ false,
@@ -938,6 +939,7 @@
"libopenjdkjvmti_headers",
// tradefed deps
+ "apache-commons-compress",
"tradefed-protos",
"grpc-java",
"grpc-java-api",
diff --git a/android/filegroup.go b/android/filegroup.go
index 5a8c4b9..b6e37a5 100644
--- a/android/filegroup.go
+++ b/android/filegroup.go
@@ -22,7 +22,6 @@
"android/soong/bazel"
"android/soong/bazel/cquery"
"android/soong/ui/metrics/bp2build_metrics_proto"
-
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
)
@@ -106,8 +105,10 @@
if f.Label == fg.Name() {
if len(srcs.Value.Includes) > 1 {
ctx.ModuleErrorf("filegroup '%s' cannot contain a file with the same name", fg.Name())
+ ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_SRC_NAME_COLLISION, "")
+ } else {
+ panic("This situation should have been handled by FileGroupFactory's call to InitBazelModuleAsHandcrafted")
}
- ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_SRC_NAME_COLLISION, "")
return
}
}
@@ -253,6 +254,16 @@
module.AddProperties(&module.properties)
InitAndroidModule(module)
InitBazelModule(module)
+ AddBazelHandcraftedHook(module, func(ctx LoadHookContext) string {
+ // If there is a single src with the same name as the filegroup module name,
+ // then don't generate this filegroup. It will be OK for other targets
+ // to depend on this source file by name directly.
+ fg := ctx.Module().(*fileGroup)
+ if len(fg.properties.Srcs) == 1 && fg.Name() == fg.properties.Srcs[0] {
+ return fg.Name()
+ }
+ return ""
+ })
InitDefaultableModule(module)
return module
}
diff --git a/bp2build/filegroup_conversion_test.go b/bp2build/filegroup_conversion_test.go
index cb2e207..9c49dac 100644
--- a/bp2build/filegroup_conversion_test.go
+++ b/bp2build/filegroup_conversion_test.go
@@ -40,7 +40,9 @@
srcs: ["foo"],
}
`,
- ExpectedBazelTargets: []string{}})
+ ExpectedBazelTargets: []string{},
+ ExpectedHandcraftedModules: []string{"foo"}},
+ )
}
func TestFilegroupSameNameAsFile_MultipleFiles(t *testing.T) {
diff --git a/bp2build/symlink_forest.go b/bp2build/symlink_forest.go
index 966b94a..06e63ca 100644
--- a/bp2build/symlink_forest.go
+++ b/bp2build/symlink_forest.go
@@ -22,7 +22,6 @@
"regexp"
"sort"
"strconv"
- "strings"
"sync"
"sync/atomic"
@@ -32,19 +31,12 @@
)
// A tree structure that describes what to do at each directory in the created
-// symlink tree. Currently it is used to enumerate which files/directories
+// symlink tree. Currently, it is used to enumerate which files/directories
// should be excluded from symlinking. Each instance of "node" represents a file
// or a directory. If excluded is true, then that file/directory should be
// excluded from symlinking. Otherwise, the node is not excluded, but one of its
// descendants is (otherwise the node in question would not exist)
-// This is a version int written to a file called symlink_forest_version at the root of the
-// symlink forest. If the version here does not match the version in the file, then we'll
-// clean the whole symlink forest and recreate it. This number can be bumped whenever there's
-// an incompatible change to the forest layout or a bug in incrementality that needs to be fixed
-// on machines that may still have the bug present in their forest.
-const symlinkForestVersion = 2
-
type instructionsNode struct {
name string
excluded bool // If false, this is just an intermediate node
@@ -193,7 +185,7 @@
srcPath := shared.JoinPath(topdir, src)
dstPath := shared.JoinPath(topdir, dst)
- // Check if a symlink already exists.
+ // Check whether a symlink already exists.
if dstInfo, err := os.Lstat(dstPath); err != nil {
if !os.IsNotExist(err) {
fmt.Fprintf(os.Stderr, "Failed to lstat '%s': %s", dst, err)
@@ -240,44 +232,49 @@
return false
}
-// maybeCleanSymlinkForest will remove the whole symlink forest directory if the version recorded
-// in the symlink_forest_version file is not equal to symlinkForestVersion.
-func maybeCleanSymlinkForest(topdir, forest string, verbose bool) error {
- versionFilePath := shared.JoinPath(topdir, forest, "symlink_forest_version")
- versionFileContents, err := os.ReadFile(versionFilePath)
+// Returns the hash of the soong_build binary to determine whether we should
+// force symlink_forest to re-execute
+// This is similar to a version number increment - but that shouldn't be required
+// for every update to this file
+func getSoongBuildMTime() int64 {
+ binaryPath, err := os.Executable()
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "error finding executable path %s\n", err)
+ os.Exit(1)
+ }
+
+ info, err := os.Stat(binaryPath)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "error stating executable path %s\n", err)
+ }
+
+ return info.ModTime().UnixMilli()
+}
+
+// maybeCleanSymlinkForest will remove the whole symlink forest directory if the soong_build
+// binary has changed since the last execution.
+func maybeCleanSymlinkForest(topdir, forest string, verbose bool, soongBuildMTime int64) error {
+ mtimeFilePath := shared.JoinPath(topdir, forest, "soong_build_mtime")
+ mtimeFileContents, err := os.ReadFile(mtimeFilePath)
if err != nil && !os.IsNotExist(err) {
return err
}
- versionFileString := strings.TrimSpace(string(versionFileContents))
- symlinkForestVersionString := strconv.Itoa(symlinkForestVersion)
- if err != nil || versionFileString != symlinkForestVersionString {
- if verbose {
- fmt.Fprintf(os.Stderr, "Old symlink_forest_version was %q, current is %q. Cleaning symlink forest before recreating...\n", versionFileString, symlinkForestVersionString)
- }
+
+ if string(soongBuildMTime) != string(mtimeFileContents) {
err = os.RemoveAll(shared.JoinPath(topdir, forest))
if err != nil {
return err
}
}
+
return nil
}
-// maybeWriteVersionFile will write the symlink_forest_version file containing symlinkForestVersion
-// if it doesn't exist already. If it exists we know it must contain symlinkForestVersion because
-// we checked for that already in maybeCleanSymlinkForest
-func maybeWriteVersionFile(topdir, forest string) error {
- versionFilePath := shared.JoinPath(topdir, forest, "symlink_forest_version")
- _, err := os.Stat(versionFilePath)
- if err != nil {
- if !os.IsNotExist(err) {
- return err
- }
- err = os.WriteFile(versionFilePath, []byte(strconv.Itoa(symlinkForestVersion)+"\n"), 0666)
- if err != nil {
- return err
- }
- }
- return nil
+func writeSoongBuildMTimeFile(topdir, forest string, mtime int64) error {
+ hashFilePath := shared.JoinPath(topdir, forest, "soong_build_mtime")
+ contents := []byte(strconv.FormatInt(mtime, 10))
+
+ return os.WriteFile(hashFilePath, contents, 0666)
}
// Recursively plants a symlink forest at forestDir. The symlink tree will
@@ -473,7 +470,10 @@
symlinkCount: atomic.Uint64{},
}
- err := maybeCleanSymlinkForest(topdir, forest, verbose)
+ // Check whether soong_build has been modified since the last run
+ soongBuildMTime := getSoongBuildMTime()
+
+ err := maybeCleanSymlinkForest(topdir, forest, verbose, soongBuildMTime)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
@@ -491,11 +491,10 @@
deps = append(deps, dep)
}
- err = maybeWriteVersionFile(topdir, forest)
+ err = writeSoongBuildMTimeFile(topdir, forest, soongBuildMTime)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
-
return deps, context.mkdirCount.Load(), context.symlinkCount.Load()
}
diff --git a/cc/config/global.go b/cc/config/global.go
index 985c8c0..62b008b 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -29,83 +29,112 @@
// Flags used by lots of devices. Putting them in package static variables
// will save bytes in build.ninja so they aren't repeated for every file
commonGlobalCflags = []string{
- "-DANDROID",
- "-fmessage-length=0",
- "-W",
+ // Enable some optimization by default.
+ "-O2",
+
+ // Warnings enabled by default. Reference:
+ // https://clang.llvm.org/docs/DiagnosticsReference.html
"-Wall",
- "-Wno-unused",
+ "-Wextra",
"-Winit-self",
"-Wpointer-arith",
- "-Wunreachable-code-loop-increment",
+ "-Wunguarded-availability",
- // Make paths in deps files relative
- "-no-canonical-prefixes",
+ // Warnings treated as errors by default.
+ // See also noOverrideGlobalCflags for errors that cannot be disabled
+ // from Android.bp files.
- "-DNDEBUG",
- "-UDEBUG",
-
- "-fno-exceptions",
-
- "-O2",
- "-fdebug-default-version=5",
-
- "-fno-strict-aliasing",
-
+ // Using __DATE__/__TIME__ causes build nondeterminism.
"-Werror=date-time",
+ // Detects forgotten */& that usually cause a crash
+ "-Werror=int-conversion",
+ // Detects unterminated alignment modification pragmas, which often lead
+ // to ABI mismatch between modules and hard-to-debug crashes.
"-Werror=pragma-pack",
+ // Same as above, but detects alignment pragmas around a header
+ // inclusion.
"-Werror=pragma-pack-suspicious-include",
+ // Detects dividing an array size by itself, which is a common typo that
+ // leads to bugs.
+ "-Werror=sizeof-array-div",
+ // Detects a typo that cuts off a prefix from a string literal.
"-Werror=string-plus-int",
+ // Detects for loops that will never execute more than once (for example
+ // due to unconditional break), but have a non-empty loop increment
+ // clause. Often a mistake/bug.
"-Werror=unreachable-code-loop-increment",
- // Force deprecation warnings to be warnings for code that compiles with -Werror.
- // Making deprecated usages an error causes extreme pain when trying to deprecate anything.
- "-Wno-error=deprecated-declarations",
+ // Warnings that should not be errors even for modules with -Werror.
+ // Making deprecated usages an error causes extreme pain when trying to
+ // deprecate anything.
+ "-Wno-error=deprecated-declarations",
+ // This rarely indicates a bug. http://b/145210666
+ "-Wno-error=reorder-init-list",
+
+ // Warnings disabled by default.
+
+ // Designated initializer syntax is recommended by the Google C++ style
+ // and is OK to use even if not formally supported by the chosen C++
+ // version.
+ "-Wno-c99-designator",
+ // Detects uses of a GNU C extension equivalent to a limited form of
+ // constexpr. Enabling this would require replacing many constants with
+ // macros, which is not a good trade-off.
+ "-Wno-gnu-folding-constant",
+ // AIDL generated code redeclares pure virtual methods in each
+ // subsequent version of an interface, so this warning is currently
+ // infeasible to enable.
+ "-Wno-inconsistent-missing-override",
+ // Incompatible with the Google C++ style guidance to use 'int' for loop
+ // indices; poor signal to noise ratio.
+ "-Wno-sign-compare",
+ // Poor signal to noise ratio.
+ "-Wno-unused",
+
+ // Global preprocessor constants.
+
+ "-DANDROID",
+ "-DNDEBUG",
+ "-UDEBUG",
"-D__compiler_offsetof=__builtin_offsetof",
+ // Allows the bionic versioning.h to indirectly determine whether the
+ // option -Wunguarded-availability is on or not.
+ "-D__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__",
+
+ // -f and -g options.
// Emit address-significance table which allows linker to perform safe ICF. Clang does
// not emit the table by default on Android since NDK still uses GNU binutils.
"-faddrsig",
- // Help catch common 32/64-bit errors.
- "-Werror=int-conversion",
+ // Emit debugging data in a modern format (DWARF v5).
+ "-fdebug-default-version=5",
// Force clang to always output color diagnostics. Ninja will strip the ANSI
// color codes if it is not running in a terminal.
"-fcolor-diagnostics",
- // -Wno-sign-compare is incompatible with the Google C++ style guidance
- // to use 'int' for loop indices, and the signal to noise ratio is poor
- // anyway.
- "-Wno-sign-compare",
-
- // AIDL generated code redeclares pure virtual methods in each
- // subsequent version of an interface, so this is currently infeasible
- // to enable.
- "-Wno-inconsistent-missing-override",
-
- // Designated initializer syntax is recommended by the Google C++ style
- // guide and should not be a warning, at least by default.
- "-Wno-c99-designator",
-
- // Warnings from clang-12
- "-Wno-gnu-folding-constant",
-
- // http://b/145210666
- "-Wno-error=reorder-init-list",
-
- // Calls to the APIs that are newer than the min sdk version of the caller should be
- // guarded with __builtin_available.
- "-Wunguarded-availability",
- // This macro allows the bionic versioning.h to indirectly determine whether the
- // option -Wunguarded-availability is on or not.
- "-D__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__",
-
// Turn off FMA which got enabled by default in clang-r445002 (http://b/218805949)
"-ffp-contract=off",
+ // Google C++ style does not allow exceptions, turn them off by default.
+ "-fno-exceptions",
+
+ // Disable optimizations based on strict aliasing by default.
+ // The performance benefit of enabling them currently does not outweigh
+ // the risk of hard-to-reproduce bugs.
+ "-fno-strict-aliasing",
+
+ // Disable line wrapping for error messages - it interferes with
+ // displaying logs in web browsers.
+ "-fmessage-length=0",
+
// Using simple template names reduces the size of debug builds.
"-gsimple-template-names",
+
+ // Make paths in deps files relative.
+ "-no-canonical-prefixes",
}
commonGlobalConlyflags = []string{}
@@ -117,6 +146,7 @@
"-fdebug-default-version=4",
}
+ // Compilation flags for device code; not applied to host code.
deviceGlobalCflags = []string{
"-ffunction-sections",
"-fdata-sections",
@@ -152,6 +182,7 @@
"-fvisibility-inlines-hidden",
}
+ // Linking flags for device code; not applied to host binaries.
deviceGlobalLdflags = []string{
"-Wl,-z,noexecstack",
"-Wl,-z,relro",
@@ -192,6 +223,14 @@
// These flags are appended after the module's cflags, so they cannot be
// overridden from Android.bp files.
+ //
+ // NOTE: if you need to disable a warning to unblock a compiler upgrade
+ // and it is only triggered by third party code, add it to
+ // extraExternalCflags (if possible) or noOverrideExternalGlobalCflags
+ // (if the former doesn't work). If the new warning also occurs in first
+ // party code, try adding it to commonGlobalCflags first. Adding it here
+ // should be the last resort, because it prevents all code in Android from
+ // opting into the warning.
noOverrideGlobalCflags = []string{
"-Werror=bool-operation",
"-Werror=format-insufficient-args",
@@ -243,35 +282,9 @@
noOverride64GlobalCflags = []string{}
- // Similar to noOverrideGlobalCflags, but applies only to third-party code
- // (anything for which IsThirdPartyPath() in build/soong/android/paths.go
- // returns true - includes external/, most of vendor/ and most of hardware/)
- noOverrideExternalGlobalCflags = []string{
- // http://b/151457797
- "-fcommon",
- // http://b/191699019
- "-Wno-format-insufficient-args",
- // http://b/296321145
- // Indicates potential memory or stack corruption, so should be changed
- // to a hard error. Currently triggered by some vendor code.
- "-Wno-incompatible-function-pointer-types",
- // http://b/296321508
- // Introduced in response to a critical security vulnerability and
- // should be a hard error - it requires only whitespace changes to fix.
- "-Wno-misleading-indentation",
- // Triggered by old LLVM code in external/llvm. Likely not worth
- // enabling since it's a cosmetic issue.
- "-Wno-bitwise-instead-of-logical",
-
- "-Wno-unused-but-set-variable",
- "-Wno-unused-but-set-parameter",
- "-Wno-unqualified-std-cast-call",
- "-Wno-array-parameter",
- "-Wno-gnu-offsetof-extensions",
- }
-
- // Extra cflags for external third-party projects to disable warnings that
- // are infeasible to fix in all the external projects and their upstream repos.
+ // Extra cflags applied to third-party code (anything for which
+ // IsThirdPartyPath() in build/soong/android/paths.go returns true;
+ // includes external/, most of vendor/ and most of hardware/)
extraExternalCflags = []string{
"-Wno-enum-compare",
"-Wno-enum-compare-switch",
@@ -301,11 +314,41 @@
"-Wno-deprecated-non-prototype",
}
+ // Similar to noOverrideGlobalCflags, but applies only to third-party code
+ // (see extraExternalCflags).
+ // This section can unblock compiler upgrades when a third party module that
+ // enables -Werror and some group of warnings explicitly triggers newly
+ // added warnings.
+ noOverrideExternalGlobalCflags = []string{
+ // http://b/151457797
+ "-fcommon",
+ // http://b/191699019
+ "-Wno-format-insufficient-args",
+ // http://b/296321145
+ // Indicates potential memory or stack corruption, so should be changed
+ // to a hard error. Currently triggered by some vendor code.
+ "-Wno-incompatible-function-pointer-types",
+ // http://b/296321508
+ // Introduced in response to a critical security vulnerability and
+ // should be a hard error - it requires only whitespace changes to fix.
+ "-Wno-misleading-indentation",
+ // Triggered by old LLVM code in external/llvm. Likely not worth
+ // enabling since it's a cosmetic issue.
+ "-Wno-bitwise-instead-of-logical",
+
+ "-Wno-unused-but-set-variable",
+ "-Wno-unused-but-set-parameter",
+ "-Wno-unqualified-std-cast-call",
+ "-Wno-array-parameter",
+ "-Wno-gnu-offsetof-extensions",
+ }
+
llvmNextExtraCommonGlobalCflags = []string{
// Do not report warnings when testing with the top of trunk LLVM.
"-Wno-error",
}
+ // Flags that must not appear in any command line.
IllegalFlags = []string{
"-w",
}
diff --git a/tests/run_integration_tests.sh b/tests/run_integration_tests.sh
index 6b9ff8b..2349993 100755
--- a/tests/run_integration_tests.sh
+++ b/tests/run_integration_tests.sh
@@ -10,6 +10,7 @@
"$TOP/build/soong/tests/persistent_bazel_test.sh"
"$TOP/build/soong/tests/soong_test.sh"
"$TOP/build/soong/tests/stale_metrics_files_test.sh"
+"$TOP/build/soong/tests/symlink_forest_rerun_test.sh"
"$TOP/prebuilts/build-tools/linux-x86/bin/py3-cmd" "$TOP/build/bazel/ci/rbc_dashboard.py" aosp_arm64-userdebug
# The following tests build against the full source tree and don't rely on the
diff --git a/tests/sbom_test.sh b/tests/sbom_test.sh
index 73fbeab..8dc1630 100755
--- a/tests/sbom_test.sh
+++ b/tests/sbom_test.sh
@@ -35,14 +35,15 @@
}
function run_soong {
- target_product="$1";shift
- out_dir="$1"; shift
- targets="$1"; shift
+ local out_dir="$1"; shift
+ local targets="$1"; shift
if [ "$#" -ge 1 ]; then
- apps=$1; shift
- TARGET_PRODUCT="${target_product}" TARGET_BUILD_VARIANT=userdebug OUT_DIR="${out_dir}" TARGET_BUILD_UNBUNDLED=true TARGET_BUILD_APPS=$apps build/soong/soong_ui.bash --make-mode ${targets}
+ local apps=$1; shift
+ TARGET_PRODUCT="${target_product}" TARGET_RELEASE="${target_release}" TARGET_BUILD_VARIANT="${target_build_variant}" OUT_DIR="${out_dir}" TARGET_BUILD_UNBUNDLED=true TARGET_BUILD_APPS=$apps \
+ build/soong/soong_ui.bash --make-mode ${targets}
else
- TARGET_PRODUCT="${target_product}" TARGET_BUILD_VARIANT=userdebug OUT_DIR="${out_dir}" build/soong/soong_ui.bash --make-mode ${targets}
+ TARGET_PRODUCT="${target_product}" TARGET_RELEASE="${target_release}" TARGET_BUILD_VARIANT="${target_build_variant}" OUT_DIR="${out_dir}" \
+ build/soong/soong_ui.bash --make-mode ${targets}
fi
}
@@ -67,7 +68,7 @@
# Test
# m droid, build sbom later in case additional dependencies might be built and included in partition images.
- run_soong "aosp_cf_x86_64_phone" "${out_dir}" "droid dump.erofs lz4"
+ run_soong "${out_dir}" "droid dump.erofs lz4"
product_out=$out_dir/target/product/vsoc_x86_64
sbom_test=$product_out/sbom_test
@@ -75,7 +76,7 @@
cp $product_out/*.img $sbom_test
# m sbom
- run_soong "aosp_cf_x86_64_phone" "${out_dir}" sbom
+ run_soong "${out_dir}" sbom
# Generate installed file list from .img files in PRODUCT_OUT
dump_erofs=$out_dir/host/linux-x86/bin/dump.erofs
@@ -217,7 +218,7 @@
out_dir="$(setup)"
# run_soong to build com.android.adbd.apex
- run_soong "module_arm64" "${out_dir}" "sbom deapexer" "com.android.adbd"
+ run_soong "${out_dir}" "sbom deapexer" "com.android.adbd"
deapexer=${out_dir}/host/linux-x86/bin/deapexer
debugfs=${out_dir}/host/linux-x86/bin/debugfs_static
@@ -249,7 +250,7 @@
out_dir="$(setup)"
# run_soong to build Browser2.apk
- run_soong "module_arm64" "${out_dir}" "sbom" "Browser2"
+ run_soong "${out_dir}" "sbom" "Browser2"
sbom_file=${out_dir}/target/product/module_arm64/system/product/app/Browser2/Browser2.apk.spdx.json
echo "============ Diffing files in Browser2.apk and SBOM"
@@ -271,6 +272,41 @@
cleanup "${out_dir}"
}
-test_sbom_aosp_cf_x86_64_phone
-test_sbom_unbundled_apex
-test_sbom_unbundled_apk
\ No newline at end of file
+target_product=aosp_cf_x86_64_phone
+target_release=trunk_staging
+target_build_variant=userdebug
+for i in "$@"; do
+ case $i in
+ TARGET_PRODUCT=*)
+ target_product=${i#*=}
+ shift
+ ;;
+ TARGET_RELEASE=*)
+ target_release=${i#*=}
+ shift
+ ;;
+ TARGET_BUILD_VARIANT=*)
+ target_build_variant=${i#*=}
+ shift
+ ;;
+ *)
+ echo "Unknown command line arguments: $i"
+ exit 1
+ ;;
+ esac
+done
+
+echo "target product: $target_product, target_release: $target_release, target build variant: $target_build_variant"
+case $target_product in
+ aosp_cf_x86_64_phone)
+ test_sbom_aosp_cf_x86_64_phone
+ ;;
+ module_arm64)
+ test_sbom_unbundled_apex
+ test_sbom_unbundled_apk
+ ;;
+ *)
+ echo "Unknown TARGET_PRODUCT: $target_product"
+ exit 1
+ ;;
+esac
\ No newline at end of file
diff --git a/tests/symlink_forest_rerun_test.sh b/tests/symlink_forest_rerun_test.sh
new file mode 100755
index 0000000..b704222
--- /dev/null
+++ b/tests/symlink_forest_rerun_test.sh
@@ -0,0 +1,42 @@
+#!/bin/bash -eu
+
+set -o pipefail
+
+# Tests that symlink_Forest will rerun if soong_build has schanged
+
+source "$(dirname "$0")/lib.sh"
+
+function test_symlink_forest_reruns {
+ setup
+
+ mkdir -p a
+ touch a/g.txt
+ cat > a/Android.bp <<'EOF'
+filegroup {
+ name: "g",
+ srcs: ["g.txt"],
+ }
+EOF
+
+ run_soong g
+
+ mtime=`cat out/soong/workspace/soong_build_mtime`
+ # rerun with no changes - ensure that it hasn't changed
+ run_soong g
+ newmtime=`cat out/soong/workspace/soong_build_mtime`
+ if [[ ! "$mtime" == "$mtime" ]]; then
+ fail "symlink forest reran when it shouldn't have"
+ fi
+
+ # change exit codes to force a soong_build rebuild.
+ sed -i 's/os.Exit(1)/os.Exit(2)/g' build/soong/bp2build/symlink_forest.go
+
+ run_soong g
+ newmtime=`cat out/soong/workspace/soong_build_mtime`
+ if [[ "$mtime" == "$newmtime" ]]; then
+ fail "symlink forest did not rerun when it should have"
+ fi
+
+}
+
+scan_and_run_tests