Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .bazelproject
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8828015bb6d07f7b962b05c54c65c0c9ed8aa528
6.3.2
1 change: 1 addition & 0 deletions .eclipse/.bazelproject
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import .bazelproject
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/bazel-*
/disk_cache
*.log
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "automatic"
}
2 changes: 1 addition & 1 deletion B.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public class B {
public class B extends lib.ABase {
public static String getPublic() {
return lib.A.getPublic() + "\n" + getPrivate();
}
Expand Down
11 changes: 11 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 1 addition & 1 deletion lib/A.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ public static String getPublic() {
}

private static String getPrivate() {
return "Hello from A!";
return A3.getPublic();
}
}
11 changes: 11 additions & 0 deletions lib/A2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package lib;

public class A2 {
public static String getPublic() {
return getPrivate();
}

private static String getPrivate() {
return "Hello from A2!";
}
}
11 changes: 11 additions & 0 deletions lib/A3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package lib;

public class A3 {
public static String getPublic() {
return getPrivate();
}

private static String getPrivate() {
return "Hello from A3!";
}
}
7 changes: 7 additions & 0 deletions lib/ABase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package lib;

public abstract class ABase {
protected String baseMethod() {
return "ABase.baseMethod()";
}
}
12 changes: 11 additions & 1 deletion lib/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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"],
)
13 changes: 13 additions & 0 deletions patches/internal-deps-change-in-public.patch
Original file line number Diff line number Diff line change
@@ -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() {
12 changes: 12 additions & 0 deletions patches/internal-deps-change.patch
Original file line number Diff line number Diff line change
@@ -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();
}
}
15 changes: 15 additions & 0 deletions patches/new-public-method-in-A.patch
Original file line number Diff line number Diff line change
@@ -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();
}

13 changes: 13 additions & 0 deletions patches/private-B-change-removes-B-to-A-dep.patch
Original file line number Diff line number Diff line change
@@ -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() {
13 changes: 13 additions & 0 deletions patches/public-B-change-removes-B-to-A-dep.patch
Original file line number Diff line number Diff line change
@@ -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() {
51 changes: 13 additions & 38 deletions script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -eu

git checkout -- *.java
git reset --hard

rm -rf disk_cache
"${BAZEL:-bazel}" --nohome_rc --nosystem_rc clean --expunge
Expand All @@ -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 $@