diff --git a/.bazelproject b/.bazelproject new file mode 100644 index 0000000..5202bc1 --- /dev/null +++ b/.bazelproject @@ -0,0 +1,11 @@ +# The project view file (.bazelproject) is used to import targets into the IDE. +# +# See: https://ij.bazel.build/docs/project-views.html +# +# This files provides a default experience for developers working with the project. +# You should customize it to suite your needs. + +directories: + . + +derive_targets_from_directories: true diff --git a/.bazelrc b/.bazelrc index 93e85b8..19b5959 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,3 +1,6 @@ common --announce_rc +common --nojava_header_compilation common --experimental_java_classpath=bazel common --experimental_strict_java_deps=error + +build --extra_toolchains=@bazel_jdt_java_toolchain//jdt:all diff --git a/.bazelversion b/.bazelversion index da0eb35..91e4a9f 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -8828015bb6d07f7b962b05c54c65c0c9ed8aa528 +6.3.2 diff --git a/.eclipse/.bazelproject b/.eclipse/.bazelproject new file mode 100644 index 0000000..6fd289b --- /dev/null +++ b/.eclipse/.bazelproject @@ -0,0 +1 @@ +import .bazelproject diff --git a/.gitignore b/.gitignore index b7a214e..6e2cce7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /bazel-* /disk_cache +*.log diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e0f15db --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.configuration.updateBuildConfiguration": "automatic" +} \ No newline at end of file diff --git a/B.java b/B.java index b9ad084..c0fda83 100644 --- a/B.java +++ b/B.java @@ -1,4 +1,4 @@ -public class B { +public class B extends lib.ABase { public static String getPublic() { return lib.A.getPublic() + "\n" + getPrivate(); } diff --git a/WORKSPACE b/WORKSPACE index e69de29..7b6afa5 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -0,0 +1,11 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +http_archive( + name = "bazel_jdt_java_toolchain", + urls = [ + "https://github.com/salesforce/bazel-jdt-java-toolchain/releases/download/0.1.9/rules_jdt-0.1.9.tar.gz", + ], + sha256 = "e36506597dc57192115ad2a554c4c11734052cafb6364f630d314231e15d5f69", +) +load("@bazel_jdt_java_toolchain//jdt:repositories.bzl", "rules_jdt_dependencies", "rules_jdt_toolchains") +rules_jdt_dependencies() +rules_jdt_toolchains() diff --git a/lib/A.java b/lib/A.java index 6642f49..b350a94 100644 --- a/lib/A.java +++ b/lib/A.java @@ -6,6 +6,6 @@ public static String getPublic() { } private static String getPrivate() { - return "Hello from A!"; + return A3.getPublic(); } } diff --git a/lib/A2.java b/lib/A2.java new file mode 100644 index 0000000..6ec44d6 --- /dev/null +++ b/lib/A2.java @@ -0,0 +1,11 @@ +package lib; + +public class A2 { + public static String getPublic() { + return getPrivate(); + } + + private static String getPrivate() { + return "Hello from A2!"; + } +} diff --git a/lib/A3.java b/lib/A3.java new file mode 100644 index 0000000..5d8212c --- /dev/null +++ b/lib/A3.java @@ -0,0 +1,11 @@ +package lib; + +public class A3 { + public static String getPublic() { + return getPrivate(); + } + + private static String getPrivate() { + return "Hello from A3!"; + } +} diff --git a/lib/ABase.java b/lib/ABase.java new file mode 100644 index 0000000..910dfb5 --- /dev/null +++ b/lib/ABase.java @@ -0,0 +1,7 @@ +package lib; + +public abstract class ABase { + protected String baseMethod() { + return "ABase.baseMethod()"; + } +} \ No newline at end of file diff --git a/lib/BUILD.bazel b/lib/BUILD.bazel index 19d97a1..2ea38d4 100644 --- a/lib/BUILD.bazel +++ b/lib/BUILD.bazel @@ -1,6 +1,16 @@ java_library( name = "A", - srcs = ["A.java"], + srcs = ["A.java", "ABase.java"], + deps = ["A2", "A3"], visibility = ["//visibility:public"], ) +java_library( + name = "A2", + srcs = ["A2.java"], +) + +java_library( + name = "A3", + srcs = ["A3.java"], +) diff --git a/patches/internal-deps-change-in-public.patch b/patches/internal-deps-change-in-public.patch new file mode 100644 index 0000000..5c2c2f2 --- /dev/null +++ b/patches/internal-deps-change-in-public.patch @@ -0,0 +1,13 @@ +diff --git a/lib/A.java b/lib/A.java +index b350a94..946330c 100644 +--- a/lib/A.java ++++ b/lib/A.java +@@ -2,7 +2,7 @@ package lib; + + public class A { + public static String getPublic() { +- return getPrivate(); ++ return A2.getPublic(); + } + + private static String getPrivate() { diff --git a/patches/internal-deps-change.patch b/patches/internal-deps-change.patch new file mode 100644 index 0000000..2c9a6ae --- /dev/null +++ b/patches/internal-deps-change.patch @@ -0,0 +1,12 @@ +diff --git a/lib/A.java b/lib/A.java +index b350a94..07ff48e 100644 +--- a/lib/A.java ++++ b/lib/A.java +@@ -6,6 +6,6 @@ public class A { + } + + private static String getPrivate() { +- return A3.getPublic(); ++ return A2.getPublic(); + } + } diff --git a/patches/new-public-method-in-A.patch b/patches/new-public-method-in-A.patch new file mode 100644 index 0000000..8d36184 --- /dev/null +++ b/patches/new-public-method-in-A.patch @@ -0,0 +1,15 @@ +diff --git a/lib/A.java b/lib/A.java +index b350a94..0b35a5c 100644 +--- a/lib/A.java ++++ b/lib/A.java +@@ -2,6 +2,10 @@ package lib; + + public class A { + public static String getPublic() { ++ return getPublic2(); ++ } ++ ++ public static String getPublic2() { + return getPrivate(); + } + diff --git a/patches/private-B-change-removes-B-to-A-dep.patch b/patches/private-B-change-removes-B-to-A-dep.patch new file mode 100644 index 0000000..5f5d59f --- /dev/null +++ b/patches/private-B-change-removes-B-to-A-dep.patch @@ -0,0 +1,13 @@ +diff --git a/B.java b/B.java +index b9ad084..3c9e131 100644 +--- a/B.java ++++ b/B.java +@@ -1,6 +1,7 @@ + public class B { + public static String getPublic() { +- return lib.A.getPublic() + "\n" + getPrivate(); ++ // return lib.A.getPublic() + "\n" + getPrivate(); ++ return getPrivate(); + } + + private static String getPrivate() { diff --git a/patches/public-B-change-removes-B-to-A-dep.patch b/patches/public-B-change-removes-B-to-A-dep.patch new file mode 100644 index 0000000..c3e2779 --- /dev/null +++ b/patches/public-B-change-removes-B-to-A-dep.patch @@ -0,0 +1,13 @@ +diff --git a/B.java b/B.java +index c0fda83..d368697 100644 +--- a/B.java ++++ b/B.java +@@ -1,6 +1,6 @@ +-public class B extends lib.ABase { ++public class B { + public static String getPublic() { +- return lib.A.getPublic() + "\n" + getPrivate(); ++ return "\n" + getPrivate(); + } + + private static String getPrivate() { diff --git a/script.sh b/script.sh index b71e37b..28e8aa7 100755 --- a/script.sh +++ b/script.sh @@ -2,7 +2,7 @@ set -eu -git checkout -- *.java +git reset --hard rm -rf disk_cache "${BAZEL:-bazel}" --nohome_rc --nosystem_rc clean --expunge @@ -12,42 +12,17 @@ rm -rf disk_cache time=$(date +%s%3N) -echo "==================================================" -echo "Modify the implementation of a private method in A" -echo "Only rebuilds A " -echo "==================================================" -sed -i -e "s/Hello from A\![0-9]*/Hello from A\!$(date +%s%3N)/g" lib/A.java -"${BAZEL:-bazel}" --nohome_rc --nosystem_rc run //:main --disk_cache=$(pwd)/disk_cache "$@" +run_bazel_with_patch() +{ + PATCH_FILE=$1 + shift; + git apply "patches/$PATCH_FILE.patch" + "${BAZEL:-bazel}" --nohome_rc --nosystem_rc run //:main --disk_cache=$(pwd)/disk_cache --verbose_explanations --explain=patches/$PATCH_FILE.explain.log "$@" + git reset --hard +} -echo "=============================================" -echo "Modify the signature of a private method in A" -echo "Only rebuilds A " -echo "=============================================" -sed -i -e "s/getPrivate/getPrivate$(date +%s%3N)/g" lib/A.java -"${BAZEL:-bazel}" --nohome_rc --nosystem_rc run //:main --disk_cache=$(pwd)/disk_cache "$@" - -echo "==============================================================" -echo "Modify the signature of a public method in A " -echo "Only rebuilds A and B with --experimental_java_classpath=bazel" -echo "Otherwise rebuilds A, B, and C " -echo "==============================================================" -suffix=$(date +%s%3N) -sed -i -e "s/getPublic/getPublic${suffix}/g" lib/A.java -sed -i -e "s/lib\\.A\\.getPublic/lib\\.A\\.getPublic${suffix}/g" B.java -"${BAZEL:-bazel}" --nohome_rc --nosystem_rc run //:main --disk_cache=$(pwd)/disk_cache "$@" -echo "=================================" -echo "Make the direct dep A of B unused" -echo "Only rebuilds B " -echo "=================================" -sed -i -e "s/lib\\.A\\.getPublic[0-9]*()/\"Inlined Hello from A\"/g" B.java -"${BAZEL:-bazel}" --nohome_rc --nosystem_rc run //:main --disk_cache=$(pwd)/disk_cache "$@" - -echo "=================================================================" -echo "Modify the signature of a public method in the (now unused) dep A" -echo "Only rebuilds A and B with --experimental_java_classpath=bazel " -echo "Otherwise rebuilds A, B, and C " -echo "Would ideally only rebuild A since A wasn't used to compile B " -echo "=================================================================" -sed -i -e "s/getPublic[0-9]*/getPublic$(date +%s%3N)/g" lib/A.java -"${BAZEL:-bazel}" --nohome_rc --nosystem_rc run //:main --disk_cache=$(pwd)/disk_cache "$@" +echo "==================================================" +echo "patch: $1 " +echo "==================================================" +run_bazel_with_patch $@