Skip to content

Commit 06a75b8

Browse files
authored
Rework in Kotlin (#123)
* fix(generate-hashes): fix infrequent NPE There is an edge-case where the rules are depending on each other's digests, but they're hashed in parallel, so threads will not see the result of a previous hashing iteration. To overcome this we synchronise access using ConcurrentHashMap for the ruleHashes * fix(generate-hashes): attempt to fix the nested generatino deadlock * fix(generate-hashes): fix recursing into already calculated hashes * fix(generate-hashes): rework code a bit * fix(generate-hashes): warn and fail on problems instead of masking the error * feat(all): rewrite to kotlin * separate concerns * parallelise as much as possible * rework CLI interface (generate-hashes is not a subcommand of root command really) * remove redundant interfaces (there is only 1 implementation for each, no need for abstractions) * preprocess arguments * fix(test): bring back the tests * feat(test): reimplement integration test * fix(test): use just bazel instead of hardcoded path to bazel in e2e test * fix(all): fix warnings * feat(build): remove deprecated jcenter repository * fix(ci): test logs and coverage report as an artifact * separate matrix jobs into jre8 and jre11. JRE8 doesn't support coverage with the latest bazel (coverage reporter class is compiled for JRE11) * latest upstream bazel breaks code coverage even for JRE11. use latest stable version * fix(hashing): fix for NoSuchMethodError on ByteBuffer when running JRE9+ code on JRE8 * fix(ci): fix for bytebuddy mock macker
1 parent 1e43c22 commit 06a75b8

File tree

75 files changed

+1894
-2385
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1894
-2385
lines changed

.bazelrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
run -c opt --show_loading_progress=false --show_progress=false --ui_event_filters='ERROR'
22
run:verbose -c dbg --show_loading_progress=true --show_progress=true --ui_event_filters='INFO,ERROR,DEBUG'
3+
# https://github.com/mockito/mockito/issues/1879
4+
test --sandbox_tmpfs_path=/tmp

.github/workflows/cd.yaml

Lines changed: 0 additions & 36 deletions
This file was deleted.

.github/workflows/ci.yaml

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,78 @@ on:
77
branches: [ master ]
88

99
jobs:
10-
Tests:
10+
test-jre8:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Setup Java JDK
14+
uses: actions/setup-java@v3
15+
with:
16+
distribution: 'temurin'
17+
java-version: '8'
18+
id: java
19+
- name: Setup Go environment
20+
uses: actions/setup-go@v2
21+
with:
22+
go-version: ^1.17
23+
id: go
24+
- name: Setup Bazelisk
25+
run: go install github.com/bazelbuild/bazelisk@latest && export PATH=$PATH:$(go env GOPATH)/bin
26+
- uses: actions/checkout@v2
27+
- name: Run bazel-diff tests
28+
run: USE_BAZEL_VERSION=latest ~/go/bin/bazelisk test //cli/...
29+
- name: archive testlogs
30+
if: always()
31+
run: cp -R $(~/go/bin/bazelisk info bazel-testlogs) ./test-logs; (cd test-logs; zip -r -X ../test-logs.zip .)
32+
- name: Save test logs
33+
uses: actions/upload-artifact@master
34+
if: always()
35+
with:
36+
name: test-logs-jre8
37+
path: test-logs.zip
38+
test-jre11:
39+
runs-on: ubuntu-latest
40+
steps:
41+
- name: Setup Java JDK
42+
uses: actions/setup-java@v3
43+
with:
44+
distribution: 'temurin'
45+
java-version: '11'
46+
- name: Setup Go environment
47+
uses: actions/setup-go@v2
48+
with:
49+
go-version: ^1.17
50+
id: go
51+
- name: Setup Bazelisk
52+
run: go install github.com/bazelbuild/bazelisk@latest && export PATH=$PATH:$(go env GOPATH)/bin
53+
- uses: actions/checkout@v2
54+
- name: Run bazel-diff tests
55+
run: USE_BAZEL_VERSION=latest ~/go/bin/bazelisk coverage --combined_report=lcov //cli/...
56+
- name: archive testlogs
57+
if: always()
58+
run: cp -R $(~/go/bin/bazelisk info bazel-testlogs) ./test-logs; (cd test-logs; zip -r -X ../test-logs.zip .)
59+
- name: Save test logs
60+
uses: actions/upload-artifact@master
61+
if: always()
62+
with:
63+
name: test-logs-jre11
64+
path: test-logs.zip
65+
- name: Generate code coverage
66+
run: |
67+
sudo apt-get install -y lcov
68+
genhtml $(~/go/bin/bazelisk info output_path)/_coverage/_coverage_report.dat -o coverage/html
69+
(cd coverage/html; zip -r -X ../../coverage-jre11.zip .)
70+
- name: Save code coverage
71+
uses: actions/upload-artifact@master
72+
if: always()
73+
with:
74+
name: coverage-jre11-jre11
75+
path: coverage-jre11.zip
76+
deploy:
77+
needs: [test-jre8, test-jre11]
1178
runs-on: ubuntu-latest
1279
strategy:
1380
matrix:
14-
java: [ '8', '11' ]
81+
java: [ '8' ]
1582
steps:
1683
- name: Setup Java JDK
1784
uses: actions/setup-java@v3
@@ -27,5 +94,10 @@ jobs:
2794
- name: Setup Bazelisk
2895
run: go install github.com/bazelbuild/bazelisk@latest && export PATH=$PATH:$(go env GOPATH)/bin
2996
- uses: actions/checkout@v2
30-
- name: Run bazel-diff tests
31-
run: USE_BAZEL_VERSION=last_downstream_green ~/go/bin/bazelisk test //test/...
97+
- name: Build deployable JAR
98+
run: USE_BAZEL_VERSION=latest ~/go/bin/bazelisk build //cli:bazel-diff_deploy.jar
99+
- uses: actions/upload-artifact@v3
100+
with:
101+
name: bazel-diff_deploy.jar
102+
path: bazel-bin/cli/bazel-diff_deploy.jar
103+
if-no-files-found: error

.github/workflows/integration.yaml

Lines changed: 0 additions & 25 deletions
This file was deleted.

BUILD

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
alias(
2-
name = "bazel-diff",
3-
actual = "//src/main/java/com/bazel_diff:bazel-diff"
4-
)
1+
#alias(
2+
# name = "bazel-diff",
3+
# actual = "//bazel-diff",
4+
#)
5+
#
6+
#alias(
7+
# name = "tests",
8+
# actual = "//bazel-diff:tests",
9+
#)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ load("@rules_java//java:defs.bzl", "java_binary")
167167

168168
java_binary(
169169
name = "bazel-diff",
170-
main_class = "com.bazel_diff.BazelDiff",
170+
main_class = "com.bazel_diff.cli.BazelDiff",
171171
runtime_deps = ["@bazel_diff//jar"],
172172
)
173173
```

WORKSPACE

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,25 @@ bazel_diff_dependencies()
77
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
88

99
rules_proto_dependencies()
10+
1011
rules_proto_toolchains()
1112

1213
load("@rules_jvm_external//:defs.bzl", "maven_install")
1314
load("//:artifacts.bzl", "BAZEL_DIFF_MAVEN_ARTIFACTS")
15+
load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories")
16+
17+
kotlin_repositories()
18+
19+
load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_register_toolchains")
20+
21+
kt_register_toolchains()
1422

1523
maven_install(
1624
name = "bazel_diff_maven",
1725
artifacts = BAZEL_DIFF_MAVEN_ARTIFACTS,
26+
fetch_sources = True,
27+
generate_compat_repositories = True,
1828
repositories = [
19-
"http://uk.maven.org/maven2",
20-
"https://jcenter.bintray.com/",
21-
]
29+
"https://repo1.maven.org/maven2/",
30+
],
2231
)

artifacts.bzl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
load("@rules_jvm_external//:specs.bzl", "maven")
44

55
BAZEL_DIFF_MAVEN_ARTIFACTS = [
6-
maven.artifact("junit", "junit", "4.13", testonly = True),
7-
maven.artifact("org.mockito", "mockito-core", "3.5.15", testonly = True),
6+
maven.artifact("junit", "junit", "4.13"),
7+
maven.artifact("org.mockito.kotlin", "mockito-kotlin", "4.0.0", testonly = True),
8+
maven.artifact("com.willowtreeapps.assertk", "assertk-jvm", "0.25", testonly = True),
9+
maven.artifact("io.insert-koin", "koin-test-junit4", "3.1.6", testonly = True),
810
"info.picocli:picocli:jar:4.3.2",
911
"com.google.code.gson:gson:jar:2.8.6",
1012
"com.google.guava:guava:29.0-jre",
1113
"org.apache.commons:commons-pool2:2.11.1",
14+
"io.insert-koin:koin-core-jvm:3.1.6",
15+
"org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2",
1216
]

bazel-diff-example.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ echo "Generating Hashes for Revision '$final_revision'"
3333
$bazel_diff generate-hashes -w $workspace_path -b $bazel_path $final_hashes_json
3434

3535
echo "Determining Impacted Targets"
36-
$bazel_diff -sh $starting_hashes_json -fh $final_hashes_json -w $workspace_path -b $bazel_path -o $impacted_targets_path
36+
$bazel_diff get-impacted-targets -sh $starting_hashes_json -fh $final_hashes_json -o $impacted_targets_path
3737

3838
IFS=$'\n' read -d '' -r -a impacted_targets < $impacted_targets_path
3939
formatted_impacted_targets=$(IFS=$'\n'; echo "${impacted_targets[*]}")

cli/BUILD

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
load("@rules_java//java:defs.bzl", "java_binary", "java_library", "java_proto_library")
2+
load("@rules_proto//proto:defs.bzl", "proto_library")
3+
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_binary", "kt_jvm_library", "kt_jvm_test")
4+
load("@rules_jvm_external//:defs.bzl", "artifact")
5+
6+
config_setting(
7+
name = "enable_debug",
8+
values = {
9+
"compilation_mode": "dbg",
10+
},
11+
)
12+
13+
java_binary(
14+
name = "bazel-diff",
15+
jvm_flags = select({
16+
":enable_debug": ["-DDEBUG=true"],
17+
"//conditions:default": [],
18+
}),
19+
main_class = "com.bazel_diff.Main",
20+
visibility = ["//visibility:public"],
21+
runtime_deps = [":cli-lib"],
22+
)
23+
24+
kt_jvm_library(
25+
name = "cli-lib",
26+
srcs = glob(["src/main/kotlin/**/*.kt"]),
27+
deps = [
28+
":build_java_proto",
29+
"@bazel_diff_maven//:com_google_code_gson_gson",
30+
"@bazel_diff_maven//:com_google_guava_guava",
31+
"@bazel_diff_maven//:info_picocli_picocli",
32+
"@bazel_diff_maven//:io_insert_koin_koin_core_jvm",
33+
"@bazel_diff_maven//:org_apache_commons_commons_pool2",
34+
"@bazel_diff_maven//:org_jetbrains_kotlinx_kotlinx_coroutines_core_jvm",
35+
"@com_google_protobuf//:protobuf_java",
36+
],
37+
)
38+
39+
java_proto_library(
40+
name = "build_java_proto",
41+
deps = [":build_proto"],
42+
)
43+
44+
proto_library(
45+
name = "build_proto",
46+
srcs = [":build_proto_gen"],
47+
)
48+
49+
genrule(
50+
name = "build_proto_gen",
51+
srcs = ["@bazel_tools//src/main/protobuf:build.proto"],
52+
outs = ["build.proto"],
53+
cmd = "cp $< $@",
54+
)
55+
56+
kt_jvm_test(
57+
name = "BuildGraphHasherTest",
58+
test_class = "com.bazel_diff.hash.BuildGraphHasherTest",
59+
runtime_deps = [":cli-test-lib"],
60+
)
61+
62+
kt_jvm_test(
63+
name = "CalculateImpactedTargetsInteractorTest",
64+
test_class = "com.bazel_diff.interactor.CalculateImpactedTargetsInteractorTest",
65+
runtime_deps = [":cli-test-lib"],
66+
)
67+
68+
kt_jvm_test(
69+
name = "NormalisingPathConverterTest",
70+
test_class = "com.bazel_diff.cli.converter.NormalisingPathConverterTest",
71+
runtime_deps = [":cli-test-lib"],
72+
)
73+
74+
kt_jvm_test(
75+
name = "OptionsConverterTest",
76+
test_class = "com.bazel_diff.cli.converter.OptionsConverterTest",
77+
runtime_deps = [":cli-test-lib"],
78+
)
79+
80+
kt_jvm_test(
81+
name = "DeserialiseHashesInteractorTest",
82+
test_class = "com.bazel_diff.interactor.DeserialiseHashesInteractorTest",
83+
runtime_deps = [":cli-test-lib"],
84+
)
85+
86+
kt_jvm_test(
87+
name = "E2ETest",
88+
test_class = "com.bazel_diff.e2e.E2ETest",
89+
runtime_deps = [":cli-test-lib"],
90+
)
91+
92+
kt_jvm_library(
93+
name = "cli-test-lib",
94+
testonly = True,
95+
srcs = glob(["src/test/kotlin/**/*.kt"]),
96+
resources = glob(["src/test/resources/**/*"]),
97+
deps = [
98+
":cli-lib",
99+
"@bazel_diff_maven//:com_willowtreeapps_assertk_assertk_jvm",
100+
"@bazel_diff_maven//:io_insert_koin_koin_test_junit4",
101+
"@bazel_diff_maven//:io_insert_koin_koin_test_jvm",
102+
"@bazel_diff_maven//:junit_junit",
103+
"@bazel_diff_maven//:org_mockito_kotlin_mockito_kotlin",
104+
],
105+
)

0 commit comments

Comments
 (0)