Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for bzlmod #287

Closed
wants to merge 14 commits into from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ bazel-*
*.pyc
.ijwb
/.bazelrc.user
MODULE.bazel.lock
189 changes: 189 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
module(
name = "copybara",
version = "0",
compatibility_level = 0,
)

bazel_dep(name = "bazel_skylib", version = "1.5.0")
bazel_dep(name = "buildifier_prebuilt", version = "6.4.0")
bazel_dep(name = "platforms", version = "0.0.8")
bazel_dep(name = "rules_java", version = "7.5.0")
bazel_dep(name = "rules_jvm_external", version = "6.0")
bazel_dep(name = "rules_license", version = "0.0.8")
bazel_dep(name = "rules_pkg", version = "0.10.1")
bazel_dep(name = "rules_python", version = "0.31.0")

non_module_deps = use_extension("//:repositories.bzl", "non_module_deps")
use_repo(non_module_deps, "JCommander", "io_bazel")

maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
maven.install(
name = "copybara_maven",
artifacts = [
"com.github.stephenc.jcip:jcip-annotations:1.0-1",
"com.google.auto.service:auto-service-annotations:1.1.1",
"com.google.auto.service:auto-service:1.1.1",
"com.google.auto.value:auto-value-annotations:1.10.2",
"com.google.auto.value:auto-value:1.10.2",
"com.google.auto:auto-common:1.2.2",
"com.google.code.findbugs:jsr305:3.0.2",
"com.google.code.gson:gson:2.10.1",
"com.google.errorprone:error_prone_type_annotations:2.20.0",
"com.google.flogger:flogger-system-backend:0.7.4",
"com.google.flogger:flogger:0.7.4",
"com.google.flogger:google-extensions:0.7.4",
"com.google.guava:failureaccess:1.0.1",
"com.google.guava:guava-testlib:33.0.0-jre",
"com.google.guava:guava:33.0.0-jre",
"com.google.http-client:google-http-client-gson:1.43.3",
"com.google.http-client:google-http-client-test:1.43.3",
"com.google.http-client:google-http-client:1.43.3",
"com.google.jimfs:jimfs:1.2",
"com.google.re2j:re2j:1.7",
"com.google.testparameterinjector:test-parameter-injector:1.8",
"com.google.truth.extensions:truth-java8-extension:1.3.0",
"com.google.truth:truth:1.3.0",
"com.googlecode.java-diff-utils:diffutils:1.3.0",
"com.ryanharter.auto.value:auto-value-gson-extension:1.3.1",
"com.ryanharter.auto.value:auto-value-gson-factory:1.3.1",
"com.ryanharter.auto.value:auto-value-gson-runtime:1.3.1",
"com.sun.mail:javax.mail:1.5.6",
"commons-codec:commons-codec:1.16.0",
"junit:junit:4.13.2",
"net.bytebuddy:byte-buddy-agent:1.14.5",
"net.bytebuddy:byte-buddy:1.14.5",
"org.apache.commons:commons-compress:1.25.0",
"org.apache.tomcat:tomcat-annotations-api:8.0.5",
"org.apache.velocity:velocity:1.7",
"org.jsoup:jsoup:1.16.1",
"org.mockito:mockito-core:4.5.1",
"org.objenesis:objenesis:1.0",
"org.tomlj:tomlj:1.1.1",
],
fail_if_repin_required = True,
repositories = [
"https://repo1.maven.org/maven2",
"https://maven.google.com",
],
)
use_repo(maven, "copybara_maven")

# Copied from bazelbuild/bazel/MODULE.bazel, has to be kept in sync
maven.install(
artifacts = [
"com.beust:jcommander:1.82",
"com.github.ben-manes.caffeine:caffeine:3.0.5",
"com.github.kevinstern:software-and-algorithms:1.0",
"com.github.stephenc.jcip:jcip-annotations:1.0-1",
"com.google.api-client:google-api-client-gson:1.35.2",
"com.google.api-client:google-api-client:1.35.2",
"com.google.auth:google-auth-library-credentials:1.6.0",
"com.google.auth:google-auth-library-oauth2-http:1.6.0",
"com.google.auto.service:auto-service-annotations:1.0.1",
"com.google.auto.service:auto-service:1.0",
"com.google.auto.value:auto-value-annotations:1.9",
"com.google.auto.value:auto-value:1.8.2",
"com.google.auto:auto-common:1.2.1",
"com.google.code.findbugs:jsr305:3.0.2",
"com.google.code.gson:gson:2.9.0",
"com.google.code.java-allocation-instrumenter:java-allocation-instrumenter:3.3.0",
"com.google.errorprone:error_prone_annotation:2.23.0",
"com.google.errorprone:error_prone_annotations:2.23.0",
"com.google.errorprone:error_prone_check_api:2.23.0",
"com.google.errorprone:error_prone_core:2.23.0",
"com.google.errorprone:error_prone_type_annotations:2.23.0",
"com.google.flogger:flogger-system-backend:0.5.1",
"com.google.flogger:flogger:0.5.1",
"com.google.flogger:google-extensions:0.5.1",
"com.google.guava:failureaccess:1.0.1",
"com.google.guava:guava:33.0.0-jre",
"com.google.http-client:google-http-client-gson:1.42.0",
"com.google.http-client:google-http-client:1.42.0",
"com.google.j2objc:j2objc-annotations:1.3",
"com.google.turbine:turbine:0.5.0",
"com.ryanharter.auto.value:auto-value-gson-extension:1.3.1",
"com.ryanharter.auto.value:auto-value-gson-runtime:1.3.1",
"com.ryanharter.auto.value:auto-value-gson-factory:1.3.1",
"com.squareup:javapoet:1.12.0",
"commons-collections:commons-collections:3.2.2",
"commons-lang:commons-lang:2.6",
"io.github.java-diff-utils:java-diff-utils:4.12",
"io.grpc:grpc-api:1.48.1",
"io.grpc:grpc-auth:1.48.1",
"io.grpc:grpc-context:1.48.1",
"io.grpc:grpc-core:1.48.1",
"io.grpc:grpc-netty:1.48.1",
"io.grpc:grpc-protobuf-lite:1.48.1",
"io.grpc:grpc-protobuf:1.48.1",
"io.grpc:grpc-stub:1.48.1",
"io.netty:netty-buffer:4.1.93.Final",
"io.netty:netty-codec-http2:4.1.93.Final",
"io.netty:netty-codec-http:4.1.93.Final",
"io.netty:netty-codec:4.1.93.Final",
"io.netty:netty-common:4.1.93.Final",
"io.netty:netty-handler-proxy:4.1.93.Final",
"io.netty:netty-handler:4.1.93.Final",
"io.netty:netty-resolver-dns:4.1.93.Final",
"io.netty:netty-resolver:4.1.93.Final",
"io.netty:netty-tcnative-boringssl-static:jar:linux-aarch_64:2.0.56.Final",
"io.netty:netty-tcnative-boringssl-static:jar:linux-x86_64:2.0.56.Final",
"io.netty:netty-tcnative-boringssl-static:jar:osx-aarch_64:2.0.56.Final",
"io.netty:netty-tcnative-boringssl-static:jar:osx-x86_64:2.0.56.Final",
"io.netty:netty-tcnative-boringssl-static:jar:windows-x86_64:2.0.56.Final",
"io.netty:netty-tcnative-classes:2.0.56.Final",
"io.netty:netty-transport-classes-epoll:4.1.93.Final",
"io.netty:netty-transport-classes-kqueue:4.1.93.Final",
"io.netty:netty-transport-native-epoll:jar:linux-aarch_64:4.1.93.Final",
"io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.93.Final",
"io.netty:netty-transport-native-kqueue:jar:osx-aarch_64:4.1.93.Final",
"io.netty:netty-transport-native-kqueue:jar:osx-x86_64:4.1.93.Final",
"io.netty:netty-transport-native-unix-common:4.1.93.Final",
"io.netty:netty-transport-native-unix-common:jar:linux-aarch_64:4.1.93.Final",
"io.netty:netty-transport-native-unix-common:jar:linux-x86_64:4.1.93.Final",
"io.netty:netty-transport-native-unix-common:jar:osx-aarch_64:4.1.93.Final",
"io.netty:netty-transport-native-unix-common:jar:osx-x86_64:4.1.93.Final",
"io.netty:netty-transport:4.1.93.Final",
"io.reactivex.rxjava3:rxjava:3.1.2",
"it.unimi.dsi:fastutil:7.2.1",
"javax.activation:javax.activation-api:1.2.0",
"javax.annotation:javax.annotation-api:1.3.2",
"javax.inject:javax.inject:1",
"net.bytebuddy:byte-buddy-agent:1.14.5",
"net.bytebuddy:byte-buddy:1.14.5",
"org.apache.commons:commons-compress:1.20",
"org.apache.commons:commons-pool2:2.8.0",
"org.apache.tomcat:tomcat-annotations-api:8.0.5",
"org.apache.velocity:velocity:1.7",
"org.checkerframework:checker-qual:3.19.0",
"org.ow2.asm:asm-analysis:9.2",
"org.ow2.asm:asm-commons:9.2",
"org.ow2.asm:asm-tree:9.2",
"org.ow2.asm:asm-util:9.2",
"org.ow2.asm:asm:9.2",
"org.pcollections:pcollections:3.1.4",
"org.threeten:threeten-extra:1.5.0",
"org.tukaani:xz:1.9",
"org.yaml:snakeyaml:1.28",
"tools.profiler:async-profiler:3.0",
# The following jars are for testing.
# junit is not test only due to //src/java_tools/junitrunner/java/com/google/testing/junit/junit4:runner,
# and hamcrest is a dependency of junit.
"junit:junit:4.13.2",
"org.hamcrest:hamcrest-core:1.3",
],
excluded_artifacts = [
# org.apache.httpcomponents and org.eclipse.jgit:org.eclipse.jgit
# require java.security.jgss module to be embedded in the Bazel binary.
"org.apache.httpcomponents:httpclient",
"org.apache.httpcomponents:httpcore",
"org.eclipse.jgit:org.eclipse.jgit",
# We build protobuf Java library from source, exclude protobuf jars to be safe.
"com.google.protobuf:protobuf-java",
"com.google.protobuf:protobuf-javalite",
],
repositories = [
"https://repo1.maven.org/maven2",
],
strict_visibility = True,
)
use_repo(maven, "maven")
8 changes: 8 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,11 @@ copybara_maven_repositories()
load("//:repositories.go.bzl", "copybara_go_repositories")

copybara_go_repositories()

load("@buildifier_prebuilt//:deps.bzl", "buildifier_prebuilt_deps")

buildifier_prebuilt_deps()

load("@buildifier_prebuilt//:defs.bzl", "buildifier_prebuilt_register_toolchains")

buildifier_prebuilt_register_toolchains()
1 change: 1 addition & 0 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# When bzlmod is enabled this makes sure nothing from the legacy WORKSPACE is loaded
4 changes: 2 additions & 2 deletions java/com/google/copybara/buildozer/testing/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ licenses(["notice"])
genrule(
name = "normalised_buildozer",
testonly = 1,
srcs = ["@buildtools//buildozer"],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buildtools isn't in the bcr yet, this repo vendors the downloads directly from that repo's releases

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We currently automatically vendor buildtools from HEAD because we had needs to be pretty close to the edge. I wonder if this can be treated like io_bazel?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the problem is that pulling in buildtools that way would require pulling rules_go and resolving the go.mod transitive dependencies of that repo as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I will look into merging this provided we don't end up with too much version skew for build_tools vs the internal monorepo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good, i don't feel like there are a ton of changes there enough to cause major drift

srcs = ["@buildifier_prebuilt//:buildozer"],
outs = ["buildozer"],
cmd = "cp $(SRCS) $@",
)

genrule(
name = "normalised_buildifier",
testonly = 1,
srcs = ["@buildtools//buildifier"],
srcs = ["@buildifier_prebuilt//:buildifier"],
outs = ["buildifier"],
cmd = "cp $(SRCS) $@",
)
Expand Down
2 changes: 1 addition & 1 deletion javatests/com/google/copybara/format/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ licenses(["notice"])
genrule(
name = "normalised_buildifier",
testonly = 1,
srcs = ["@buildtools//buildifier"],
srcs = ["@buildifier_prebuilt//:buildifier"],
outs = ["buildifier"],
cmd = "cp $(SRCS) $@",
)
Expand Down
2 changes: 1 addition & 1 deletion javatests/com/google/copybara/onboard/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ licenses(["notice"])
genrule(
name = "normalised_buildifier",
testonly = 1,
srcs = ["@buildtools//buildifier"],
srcs = ["@buildifier_prebuilt//:buildifier"],
outs = ["buildifier"],
cmd = "cp $(SRCS) $@",
)
Expand Down
48 changes: 26 additions & 22 deletions repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("//third_party:bazel.bzl", "bazel_sha256", "bazel_version")
load("//third_party:bazel_buildtools.bzl", "buildtools_sha256", "buildtools_version")
load("//third_party:bazel_skylib.bzl", "skylib_sha256", "skylib_version")

def copybara_repositories():
Expand All @@ -39,27 +38,6 @@ def copybara_repositories():
sha256 = RULES_JVM_EXTERNAL_SHA,
strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG,
url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG,
patches = ["@io_bazel//third_party:rules_jvm_external_6.0.patch"],
patch_args = ["-p1"],
)

# LICENSE: The Apache Software License, Version 2.0
maybe(
http_archive,
name = "io_bazel",
sha256 = bazel_sha256,
strip_prefix = "bazel-" + bazel_version,
url = "https://github.com/bazelbuild/bazel/archive/" + bazel_version + ".zip",
)

# LICENSE: The Apache Software License, Version 2.0
# Buildifier and friends:
maybe(
http_archive,
name = "buildtools",
sha256 = buildtools_sha256,
strip_prefix = "buildtools-" + buildtools_version,
url = "https://github.com/bazelbuild/buildtools/archive/" + buildtools_version + ".zip",
)

# LICENSE: The Apache Software License, Version 2.0
Expand Down Expand Up @@ -173,3 +151,29 @@ def copybara_repositories():
],
)

# LICENSE: MIT
maybe(
http_archive,
name = "buildifier_prebuilt",
sha256 = "8ada9d88e51ebf5a1fdff37d75ed41d51f5e677cdbeafb0a22dda54747d6e07e",
strip_prefix = "buildifier-prebuilt-6.4.0",
urls = [
"http://github.com/keith/buildifier-prebuilt/archive/6.4.0.tar.gz",
],
)

_non_module_deps(None)

def _non_module_deps(_):
# LICENSE: The Apache Software License, Version 2.0
maybe(
http_archive,
name = "io_bazel",
sha256 = bazel_sha256,
strip_prefix = "bazel-" + bazel_version,
url = "https://github.com/bazelbuild/bazel/archive/" + bazel_version + ".zip",
)


non_module_deps = module_extension(implementation = _non_module_deps)

12 changes: 9 additions & 3 deletions repositories.maven.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@rules_jvm_external//:defs.bzl", "DEFAULT_REPOSITORY_NAME", "maven_install")
load("@rules_jvm_external//:specs.bzl", "maven")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("@rules_jvm_external//:defs.bzl", "maven_install")
load("@rules_jvm_external//:specs.bzl", "maven")

COPYBARA_MAVEN_ARTIFACTS = [
maven.artifact("com.github.stephenc.jcip", "jcip-annotations", "1.0-1"),
Expand Down Expand Up @@ -66,7 +66,13 @@ COPYBARA_MAVEN_ARTIFACT_ADDITIONAL_REPOSITORIES = [
def copybara_maven_repositories():
maybe(
maven_install,
name = DEFAULT_REPOSITORY_NAME,
name = "copybara_maven",
artifacts = COPYBARA_MAVEN_ARTIFACTS,
repositories = COPYBARA_MAVEN_ARTIFACT_ADDITIONAL_REPOSITORIES + ["https://repo1.maven.org/maven2"],
)
maybe(
maven_install,
name = "maven",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for bzlmod it's better to have a unique name for a repository that might be a dependency of something else, but for building bazel we have to use this name as well, right now these are dup'd but in bzlmod they have a separate set of deps

artifacts = COPYBARA_MAVEN_ARTIFACTS,
repositories = COPYBARA_MAVEN_ARTIFACT_ADDITIONAL_REPOSITORIES + ["https://repo1.maven.org/maven2"],
)
Loading