From 2b02c6f817cc182d142ab3e244a5ac80d4ad8843 Mon Sep 17 00:00:00 2001 From: Gunnar Wagenknecht Date: Thu, 24 Aug 2023 13:06:42 +0200 Subject: [PATCH 01/10] Add IDE settings --- .bazelproject | 11 +++++++++++ .eclipse/.bazelproject | 1 + .vscode/settings.json | 3 +++ 3 files changed, 15 insertions(+) create mode 100644 .bazelproject create mode 100644 .eclipse/.bazelproject create mode 100644 .vscode/settings.json 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/.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/.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 From d27b4ba670bb4c36777a65c64fb375d5bfbf8aaf Mon Sep 17 00:00:00 2001 From: Gunnar Wagenknecht Date: Thu, 24 Aug 2023 13:07:07 +0200 Subject: [PATCH 02/10] Update for scenario --- .bazelrc | 2 ++ .gitignore | 1 + lib/A.java | 2 +- lib/A2.java | 11 +++++++++++ lib/A3.java | 11 +++++++++++ lib/BUILD.bazel | 10 ++++++++++ 6 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 lib/A2.java create mode 100644 lib/A3.java diff --git a/.bazelrc b/.bazelrc index 93e85b8..0a72638 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,3 +1,5 @@ common --announce_rc +common --nojava_header_compilation common --experimental_java_classpath=bazel common --experimental_strict_java_deps=error + 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/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/BUILD.bazel b/lib/BUILD.bazel index 19d97a1..09d6f88 100644 --- a/lib/BUILD.bazel +++ b/lib/BUILD.bazel @@ -1,6 +1,16 @@ java_library( name = "A", srcs = ["A.java"], + deps = ["A2", "A3"], visibility = ["//visibility:public"], ) +java_library( + name = "A2", + srcs = ["A2.java"], +) + +java_library( + name = "A3", + srcs = ["A3.java"], +) From e1daaa32fee6cd0a055eede2de625c74764e670c Mon Sep 17 00:00:00 2001 From: Gunnar Wagenknecht Date: Thu, 24 Aug 2023 13:08:04 +0200 Subject: [PATCH 03/10] prepare for scenario --- script.sh | 35 +---------------------------------- 1 file changed, 1 insertion(+), 34 deletions(-) diff --git a/script.sh b/script.sh index b71e37b..86b0b45 100755 --- a/script.sh +++ b/script.sh @@ -17,37 +17,4 @@ 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 "$@" - -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 "$@" +#"${BAZEL:-bazel}" --nohome_rc --nosystem_rc run //:main --disk_cache=$(pwd)/disk_cache --verbose_explanations --explain=explain-Apriv1.txt "$@" From 2ad5ae72b3c123689123b6185fbfb10ada2af968 Mon Sep 17 00:00:00 2001 From: Gunnar Wagenknecht Date: Thu, 24 Aug 2023 13:11:56 +0200 Subject: [PATCH 04/10] Add patch for scenario 1 --- patches/internal-deps-change.patch | 12 ++++++++++++ script.sh | 10 ++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 patches/internal-deps-change.patch 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/script.sh b/script.sh index 86b0b45..e250e64 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 @@ -14,7 +14,9 @@ time=$(date +%s%3N) echo "==================================================" echo "Modify the implementation of a private method in A" -echo "Only rebuilds A " +echo "to use another dependency " +echo " " +echo "expected: Rebuild only 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 --verbose_explanations --explain=explain-Apriv1.txt "$@" +git apply patches/internal-deps-change.patch +"${BAZEL:-bazel}" --nohome_rc --nosystem_rc run //:main --disk_cache=$(pwd)/disk_cache --verbose_explanations --explain=patches/internal-deps-change.explain.log "$@" From dbc8b68453a48f02358738128eacffa91f96f3c9 Mon Sep 17 00:00:00 2001 From: Gunnar Wagenknecht Date: Thu, 24 Aug 2023 13:21:21 +0200 Subject: [PATCH 05/10] Use a function --- script.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/script.sh b/script.sh index e250e64..efae5be 100755 --- a/script.sh +++ b/script.sh @@ -12,11 +12,20 @@ rm -rf disk_cache time=$(date +%s%3N) +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 implementation of a private method in A" echo "to use another dependency " echo " " echo "expected: Rebuild only A " echo "==================================================" -git apply patches/internal-deps-change.patch -"${BAZEL:-bazel}" --nohome_rc --nosystem_rc run //:main --disk_cache=$(pwd)/disk_cache --verbose_explanations --explain=patches/internal-deps-change.explain.log "$@" +run_bazel_with_patch internal-deps-change "$@" From 77b7bed341ff3429eaabbaeac44a7f402ac092b4 Mon Sep 17 00:00:00 2001 From: Gunnar Wagenknecht Date: Thu, 24 Aug 2023 14:57:38 +0200 Subject: [PATCH 06/10] Use JDT compiler --- .bazelrc | 1 + WORKSPACE | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/.bazelrc b/.bazelrc index 0a72638..19b5959 100644 --- a/.bazelrc +++ b/.bazelrc @@ -3,3 +3,4 @@ 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/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() From 702f672f52b48e1733d04668d3a9179320fc9ae0 Mon Sep 17 00:00:00 2001 From: Gunnar Wagenknecht Date: Thu, 24 Aug 2023 15:04:42 +0200 Subject: [PATCH 07/10] new scenario --- patches/internal-deps-change-in-public.patch | 13 +++++++++++++ script.sh | 9 ++++----- 2 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 patches/internal-deps-change-in-public.patch 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/script.sh b/script.sh index efae5be..eb654cc 100755 --- a/script.sh +++ b/script.sh @@ -23,9 +23,8 @@ run_bazel_with_patch() echo "==================================================" -echo "Modify the implementation of a private method in A" -echo "to use another dependency " -echo " " -echo "expected: Rebuild only A " +echo "patch: $1 " echo "==================================================" -run_bazel_with_patch internal-deps-change "$@" +run_bazel_with_patch $@ + + From 914d327ea763e504fa87f397b474f4fb2c835b34 Mon Sep 17 00:00:00 2001 From: Gunnar Wagenknecht Date: Thu, 24 Aug 2023 15:06:55 +0200 Subject: [PATCH 08/10] new scenario --- patches/new-public-method-in-A.patch | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 patches/new-public-method-in-A.patch 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(); + } + From 1eee39e66e234b401682a12f14e104a6113209c6 Mon Sep 17 00:00:00 2001 From: Roman Salvador Date: Mon, 28 Aug 2023 15:35:52 +0200 Subject: [PATCH 09/10] Add private-B-change-removes-B-to-A-dep --- patches/private-B-change-removes-B-to-A-dep.patch | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 patches/private-B-change-removes-B-to-A-dep.patch 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() { From 8f739b76edeebd83f905fc3ba27b7a68ddec9555 Mon Sep 17 00:00:00 2001 From: Roman Salvador Date: Tue, 29 Aug 2023 17:16:54 +0200 Subject: [PATCH 10/10] Add public-B-change-remotes-B-to-A-dep --- .bazelversion | 2 +- B.java | 2 +- lib/ABase.java | 7 +++++++ lib/BUILD.bazel | 2 +- patches/public-B-change-removes-B-to-A-dep.patch | 13 +++++++++++++ script.sh | 2 -- 6 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 lib/ABase.java create mode 100644 patches/public-B-change-removes-B-to-A-dep.patch diff --git a/.bazelversion b/.bazelversion index da0eb35..91e4a9f 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -8828015bb6d07f7b962b05c54c65c0c9ed8aa528 +6.3.2 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/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 09d6f88..2ea38d4 100644 --- a/lib/BUILD.bazel +++ b/lib/BUILD.bazel @@ -1,6 +1,6 @@ java_library( name = "A", - srcs = ["A.java"], + srcs = ["A.java", "ABase.java"], deps = ["A2", "A3"], visibility = ["//visibility:public"], ) 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 eb654cc..28e8aa7 100755 --- a/script.sh +++ b/script.sh @@ -26,5 +26,3 @@ echo "==================================================" echo "patch: $1 " echo "==================================================" run_bazel_with_patch $@ - -