Skip to content

Commit

Permalink
[bazel] Restructure build files
Browse files Browse the repository at this point in the history
The following changes have been made:

* Following bazel idioms

Whereas Buck required the target to be fully qualified, the
idiom in Bazel is to omit the specific target within a build
file provided that target is the name of the directory. That
is `//third_party/java/guava:guava` is the same as
`//third_party/java/guava`. Bazel favours brevity.

* Minimal visibility

Unpicking dependency graphs is a PITA. To avoid accidentally
making life hard for ourselves, all targets default to bring
private. We only expose a target if it is absolutely required.
Public visibility should be vanishingly rare in our build
files.

* One visible rule per build file

Other than breaking cycles in dependency graphs, we should be
striving for a single visible target per build file. While
this is not a hard-and-fast rule, it makes wiring things up
simpler. Typically, this single rule will export anything
that should be visible from the file.

* Follow seams created by deployable artifacts

In the java world, the deployable artifacts are maven jars.
By definition, these are public, but for the sake of keeping
things under control, we may limit the visibility of them.
Despite this, if a library is part of a deployable artifact,
then rather than allowing people to depend on the library
itself, we should be depending on the deployable artifact.
This is why so many targets depend on the remote jar.
  • Loading branch information
Simon Stewart committed Nov 22, 2018
1 parent c770b54 commit 2ed1c5e
Show file tree
Hide file tree
Showing 28 changed files with 126 additions and 180 deletions.
4 changes: 2 additions & 2 deletions java/client/src/org/openqa/selenium/chrome/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ java_library(
],
srcs = glob(["*.java"]),
deps = [
"//java/client/src/org/openqa/selenium/remote:remote",
"//third_party/java/guava:guava",
"//java/client/src/org/openqa/selenium/remote",
"//third_party/java/guava",
"//third_party/java/service",
],
visibility = [
Expand Down
4 changes: 2 additions & 2 deletions java/client/src/org/openqa/selenium/edge/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ java_library(
],
srcs = glob(["*.java"]),
deps = [
"//java/client/src/org/openqa/selenium/remote:remote",
"//third_party/java/guava:guava",
"//java/client/src/org/openqa/selenium/remote",
"//third_party/java/guava",
"//third_party/java/service",
],
visibility = [
Expand Down
4 changes: 2 additions & 2 deletions java/client/src/org/openqa/selenium/firefox/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ java_library(
],
srcs = glob(["*.java"]),
deps = [
"//java/client/src/org/openqa/selenium/remote:remote",
"//third_party/java/guava:guava",
"//java/client/src/org/openqa/selenium/remote",
"//third_party/java/guava",
"//third_party/java/service",
],
visibility = [
Expand Down
4 changes: 2 additions & 2 deletions java/client/src/org/openqa/selenium/ie/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ java_library(
],
srcs = glob(["*.java"]),
deps = [
"//java/client/src/org/openqa/selenium/remote:remote",
"//third_party/java/guava:guava",
"//java/client/src/org/openqa/selenium/remote",
"//third_party/java/guava",
"//third_party/java/service",
],
visibility = [
Expand Down
4 changes: 2 additions & 2 deletions java/client/src/org/openqa/selenium/opera/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ java_library(
],
srcs = glob(["*.java"]),
deps = [
"//java/client/src/org/openqa/selenium/remote:remote",
"//third_party/java/guava:guava",
"//java/client/src/org/openqa/selenium/remote",
"//third_party/java/guava",
"//third_party/java/service",
],
visibility = [
Expand Down
1 change: 0 additions & 1 deletion java/client/src/org/openqa/selenium/os/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ java_library(
],
visibility = [
"//java/client/src/org/openqa/selenium/remote:__pkg__",
"//java/client/test:__subpackages__",
],
)
4 changes: 2 additions & 2 deletions java/client/src/org/openqa/selenium/safari/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ java_library(
],
srcs = glob(["*.java"]),
deps = [
"//java/client/src/org/openqa/selenium/remote:remote",
"//third_party/java/guava:guava",
"//java/client/src/org/openqa/selenium/remote",
"//third_party/java/guava",
"//third_party/java/service",
],
visibility = [
Expand Down
25 changes: 12 additions & 13 deletions java/client/src/org/openqa/selenium/support/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ java_library(
"Colors.java",
"ThreadGuard.java",
],
exports = [
":page-factory",
"//java/client/src/org/openqa/selenium/support/events",
"//java/client/src/org/openqa/selenium/support/ui",
],
deps = [
":page-factory",
"//java/client/src/org/openqa/selenium/support/events:events",
"//java/client/src/org/openqa/selenium/support/ui:clock",
"//java/client/src/org/openqa/selenium/support/ui:components",
"//java/client/src/org/openqa/selenium/support/ui:elements",
"//java/client/src/org/openqa/selenium/support/ui:wait",
"//java/client/src/org/openqa/selenium:selenium",
"//java/client/src/org/openqa/selenium",
"//java/client/src/org/openqa/selenium/support/events",
"//java/client/src/org/openqa/selenium/support/ui",
],
visibility = [
"//visibility:public",
Expand All @@ -41,12 +43,9 @@ java_library(
"pagefactory/internal/*.java",
]),
deps = [
"//java/client/src/org/openqa/selenium:selenium",
"//java/client/src/org/openqa/selenium/support/ui:clock",
"//java/client/src/org/openqa/selenium/support/ui:components",
"//third_party/java/guava:guava",
],
visibility = [
"//visibility:public",
"//java/client/src/org/openqa/selenium",
"//java/client/src/org/openqa/selenium/support/ui",
"//third_party/java/guava",
],
)

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ java_library(
name = "events",
srcs = glob(["**/*.java"]),
deps = [
"//java/client/src/org/openqa/selenium:selenium",
"//java/client/src/org/openqa/selenium",
],
visibility = [
"//visibility:public",
"//java/client/src/org/openqa/selenium/support:__pkg__",
],
)
37 changes: 19 additions & 18 deletions java/client/src/org/openqa/selenium/support/ui/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
java_library(
name = "ui",
exports = [
":clock",
":components",
":elements",
":wait",
],
visibility = [
"//java/client/src/org/openqa/selenium/support:__pkg__",
],
)

java_library(
name = "clock",
srcs = [
"Sleeper.java",
],
deps = [
"//third_party/java/guava:guava",
],
visibility = [
"//visibility:public",
"//third_party/java/guava",
],
)

Expand All @@ -19,10 +29,7 @@ java_library(
],
deps = [
":clock",
"//java/client/src/org/openqa/selenium:selenium",
],
visibility = [
"//visibility:public",
"//java/client/src/org/openqa/selenium",
],
)

Expand All @@ -35,10 +42,7 @@ java_library(
"UnexpectedTagNameException.java",
],
deps = [
"//java/client/src/org/openqa/selenium:selenium",
],
visibility = [
"//visibility:public",
"//java/client/src/org/openqa/selenium",
],
)

Expand All @@ -53,11 +57,8 @@ java_library(
],
deps = [
":clock",
"//java/client/src/org/openqa/selenium:selenium",
"//java/client/src/org/openqa/selenium/remote:remote",
"//third_party/java/guava:guava",
],
visibility = [
"//visibility:public",
"//java/client/src/org/openqa/selenium/remote",
"//third_party/java/guava",
],
)

23 changes: 11 additions & 12 deletions java/client/test/org/openqa/selenium/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ gen_java_tests(
srcs = SMALL_TESTS,
size = "small",
deps = [
"//java/client/src/org/openqa/selenium:selenium",
"//third_party/java/assertj:assertj",
"//third_party/java/guava:guava",
"//third_party/java/junit:junit",
"//java/client/src/org/openqa/selenium",
"//third_party/java/assertj",
"//third_party/java/guava",
"//third_party/java/junit",
"//third_party/java/mockito:mockito-core",
],
)

java_library(
name = "helpers",
name = "selenium",
srcs = [
"BuckBuild.java",
"Build.java",
Expand All @@ -37,13 +37,12 @@ java_library(
"WrappedWebElement.java",
],
deps = [
"//java/client/src/org/openqa/selenium:selenium",
"//java/client/src/org/openqa/selenium/os:os",
"//java/client/src/org/openqa/selenium/support/ui:wait",
"//java/client/test/org/openqa/selenium/environment:environment",
"//java/client/test/org/openqa/selenium/testing:helpers",
"//third_party/java/guava:guava",
"//third_party/java/junit:junit",
"//java/client/src/org/openqa/selenium/remote",
"//java/client/src/org/openqa/selenium/support",
"//java/client/test/org/openqa/selenium/environment",
"//java/client/test/org/openqa/selenium/testing",
"//third_party/java/guava",
"//third_party/java/junit",
],
visibility = [
"//java/client/test:__subpackages__",
Expand Down
9 changes: 4 additions & 5 deletions java/client/test/org/openqa/selenium/environment/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ java_library(
"webserver/*.java"
], exclude = ["**/*Test.java", "**/*TestBase.java"]),
deps = [
"//java/client/src/org/openqa/selenium:selenium",
"//java/client/src/org/openqa/selenium/remote:remote",
"//java/client/test/org/openqa/selenium/testing:helpers",
"//third_party/java/guava:guava",
"//third_party/java/jetty:jetty",
"//java/client/src/org/openqa/selenium/remote",
"//java/client/test/org/openqa/selenium/testing",
"//third_party/java/guava",
"//third_party/java/jetty",
"//third_party/java/servlet:javax.servlet-api",
],
visibility = [
Expand Down
48 changes: 24 additions & 24 deletions java/client/test/org/openqa/selenium/testing/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
java_library(
name = "testing",
exports = [
":annotations",
":helpers",
],
visibility = [
"//java/client/test/org/openqa:__subpackages__",
"//java/server/test/org/openqa:__subpackages__",
],
)

java_library(
name = "annotations",
srcs = [
Expand All @@ -13,10 +25,7 @@ java_library(
"SwitchToTopAfterTest.java",
],
deps = [
"//java/client/src/org/openqa/selenium:selenium",
],
visibility = [
"//java/client/test:__subpackages__",
"//java/client/src/org/openqa/selenium",
],
)

Expand All @@ -27,12 +36,8 @@ java_library(
"InProject.java",
],
deps = [
"//java/client/src/org/openqa/selenium:selenium",
"//third_party/java/guava:guava",
],
visibility = [
"//java/client/test:__subpackages__",
"//java/server/test:__subpackages__",
"//java/client/src/org/openqa/selenium",
"//third_party/java/guava",
],
)

Expand All @@ -47,20 +52,15 @@ java_library(
deps = [
":annotations",
":helpers",
"//java/client/test/org/openqa/selenium:helpers",
"//java/client/test/org/openqa/selenium/environment:environment",
"//java/client/test/org/openqa/selenium/testing/drivers:browser",
"//java/client/src/org/openqa/selenium:selenium",
"//java/client/src/org/openqa/selenium/remote:remote",
"//java/client/src/org/openqa/selenium/support/ui:wait",
"//java/client/test/org/openqa/selenium/testing/drivers:drivers",
"//third_party/java/guava:guava",
"//third_party/java/assertj:assertj",
"//third_party/java/junit:junit",
"//java/client/test/org/openqa/selenium",
"//java/client/test/org/openqa/selenium/environment",
"//java/client/test/org/openqa/selenium/testing/drivers",
"//java/client/src/org/openqa/selenium/remote",
"//java/client/src/org/openqa/selenium/support",
"//third_party/java/guava",
"//third_party/java/assertj",
"//third_party/java/junit",
"//third_party/java/selenium:htmlunit-driver",
],
visibility = [
"//java/client/test:__subpackages__",
"//java/server/test:__subpackages__",
],
)

Loading

0 comments on commit 2ed1c5e

Please sign in to comment.