Skip to content

Commit f475c25

Browse files
Benjamin Denhartogmikelalcon
Benjamin Denhartog
authored andcommitted
feat: use macros for defining external repositories
This patch adds macros that wrap around this workspace's external dependencies: - `//:repositories.bzl%copybara_repositories` - `//:repositories.go.bzl%copybara_go_repositories` - `//:repositories.maven.bzl%copybara_maven_repositories` The primary motivation for this is to enable easier loading of copybara from within external repositories. Prior to this patch, those external repositories would need to re-define each and every dependency listed in this repository's WORKSPACE file. With this patch, those external repositories need only to load and call the macros (shown above). An empty BUILD file is also added in this patch as it is necessary in order to refer to the files in the workspace root. closes #73 Closes #146 GitOrigin-RevId: 00d767b Change-Id: I09f2b2d023c77cae7a18d10f1d6d5a5bb1ea9728
1 parent fe39aef commit f475c25

10 files changed

+299
-189
lines changed

BUILD

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2016 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.

README.md

+34-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ you need:
7575
* `git clone https://github.com/google/copybara.git`
7676
* Build:
7777
* `bazel build //java/com/google/copybara`.
78-
* `bazel build //java/com/google/copybara:copybara_deploy.jar` to create an executable uberjar.
78+
* `bazel build //java/com/google/copybara:copybara_deploy.jar` to create an executable uberjar.
7979
* Tests: `bazel test //...` if you want to ensure you are not using a broken version.
8080

8181
### System packages
@@ -110,6 +110,39 @@ targets:
110110
Note that configuration files can be stored in any place, even in a local folder. We recommend to
111111
use a VCS (like git) to store them; treat them as source code.
112112

113+
### Building Copybara in an external Bazel workspace
114+
115+
There are convenience macros defined for all of Copybara's dependencies. Add the
116+
following code to your `WORKSPACE` file, replacing `{{ sha256sum }}` and
117+
`{{ commit }}` as necessary.
118+
119+
```
120+
http_archive(
121+
name = "com_github_google_copybara",
122+
sha256 = "{{ sha256sum }}"
123+
strip_prefix = "copybara-{{ commit }}",
124+
url = "https://github.com/google/copybara/archive/{{ commit }}",
125+
)
126+
127+
load("@com_github_google_copybara//:repositories.bzl", "copybara_repositories")
128+
129+
copybara_repositories()
130+
131+
load("@com_github_google_copybara//:repositories.maven.bzl", "copybara_maven_repositories")
132+
133+
copybara_maven_repositories()
134+
135+
load("@com_github_google_copybara//:repositories.go.bzl", "copybara_go_repositories")
136+
137+
copybara_go_repositories()
138+
```
139+
140+
You can then build and run the Copybara tool from within your workspace:
141+
142+
```
143+
bazel run @com_github_google_copybara//java/com/google/copybara -- <args...>
144+
```
145+
113146
### Using Docker to build and run Copybara
114147

115148
*NOTE: Docker use is currently experimental, and we encourage feedback or contributions.*

WORKSPACE

+6-176
Original file line numberDiff line numberDiff line change
@@ -14,184 +14,14 @@
1414

1515
workspace(name = "com_github_google_copybara")
1616

17-
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
18-
load("//third_party:bazel.bzl", "bazel_sha256", "bazel_version")
19-
load("//third_party:bazel_buildtools.bzl", "buildtools_sha256", "buildtools_version")
20-
load("//third_party:bazel_skylib.bzl", "skylib_sha256", "skylib_version")
17+
load("//:repositories.bzl", "copybara_repositories")
2118

19+
copybara_repositories()
2220

23-
RULES_JVM_EXTERNAL_TAG = "3.0"
21+
load("//:repositories.maven.bzl", "copybara_maven_repositories")
2422

25-
RULES_JVM_EXTERNAL_SHA = "62133c125bf4109dfd9d2af64830208356ce4ef8b165a6ef15bbff7460b35c3a"
23+
copybara_maven_repositories()
2624

27-
http_archive(
28-
name = "rules_jvm_external",
29-
sha256 = RULES_JVM_EXTERNAL_SHA,
30-
strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG,
31-
url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG,
32-
)
25+
load("//:repositories.go.bzl", "copybara_go_repositories")
3326

34-
load("@rules_jvm_external//:defs.bzl", "maven_install")
35-
36-
maven_install(
37-
artifacts = [
38-
"com.beust:jcommander:1.48",
39-
"com.google.auto.value:auto-value-annotations:1.6.3",
40-
"com.google.auto.value:auto-value:1.6.3",
41-
"com.google.auto:auto-common:0.10",
42-
"com.google.code.findbugs:jsr305:3.0.2",
43-
"com.google.code.gson:gson:jar:2.8.5",
44-
"com.google.flogger:flogger-system-backend:0.3.1",
45-
"com.google.flogger:flogger:0.3.1",
46-
"com.google.guava:failureaccess:1.0.1",
47-
"com.google.guava:guava-testlib:27.1-jre",
48-
"com.google.guava:guava:27.1-jre",
49-
"com.google.http-client:google-http-client-gson:jar:1.27.0",
50-
"com.google.http-client:google-http-client-test:jar:1.27.0",
51-
"com.google.http-client:google-http-client:jar:1.27.0",
52-
"com.google.jimfs:jimfs:1.1",
53-
"com.google.re2j:re2j:1.2",
54-
"com.google.truth:truth:0.45",
55-
"com.googlecode.java-diff-utils:diffutils:1.3.0",
56-
"commons-codec:commons-codec:jar:1.11",
57-
"junit:junit:4.13",
58-
"net.bytebuddy:byte-buddy-agent:1.9.10",
59-
"net.bytebuddy:byte-buddy:1.9.10",
60-
"org.mockito:mockito-core:2.28.2",
61-
"org.objenesis:objenesis:1.0",
62-
],
63-
repositories = [
64-
"https://maven.google.com",
65-
"https://repo1.maven.org/maven2",
66-
],
67-
)
68-
69-
# LICENSE: The Apache Software License, Version 2.0
70-
http_archive(
71-
name = "io_bazel",
72-
sha256 = bazel_sha256,
73-
strip_prefix = "bazel-" + bazel_version,
74-
url = "https://github.com/bazelbuild/bazel/archive/" + bazel_version + ".zip",
75-
)
76-
77-
# LICENSE: The Apache Software License, Version 2.0
78-
# Buildifier and friends:
79-
http_archive(
80-
name = "buildtools",
81-
sha256 = buildtools_sha256,
82-
strip_prefix = "buildtools-" + buildtools_version,
83-
url = "https://github.com/bazelbuild/buildtools/archive/" + buildtools_version + ".zip",
84-
)
85-
86-
87-
# LICENSE: The Apache Software License, Version 2.0
88-
# Additional bazel rules:
89-
http_archive(
90-
name = "bazel_skylib",
91-
sha256 = skylib_sha256,
92-
strip_prefix = "bazel-skylib-" + skylib_version,
93-
url = "https://github.com/bazelbuild/bazel-skylib/archive/" + skylib_version + ".zip",
94-
)
95-
96-
EXPORT_WORKSPACE_IN_BUILD_FILE = [
97-
"test -f BUILD && chmod u+w BUILD || true",
98-
"echo >> BUILD",
99-
"echo 'exports_files([\"WORKSPACE\"], visibility = [\"//visibility:public\"])' >> BUILD",
100-
]
101-
102-
EXPORT_WORKSPACE_IN_BUILD_FILE_WIN = [
103-
"Add-Content -Path BUILD -Value \"`nexports_files([`\"WORKSPACE`\"], visibility = [`\"//visibility:public`\"])`n\" -Force",
104-
]
105-
106-
# Stuff used by Bazel Starlark syntax package transitively:
107-
# LICENSE: The Apache Software License, Version 2.0
108-
http_archive(
109-
name = "com_google_protobuf",
110-
patch_args = ["-p1"],
111-
patches = ["@io_bazel//third_party/protobuf:3.13.0.patch"],
112-
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_FILE,
113-
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_FILE_WIN,
114-
sha256 = "9b4ee22c250fe31b16f1a24d61467e40780a3fbb9b91c3b65be2a376ed913a1a",
115-
strip_prefix = "protobuf-3.13.0",
116-
urls = [
117-
"https://mirror.bazel.build/github.com/protocolbuffers/protobuf/archive/v3.13.0.tar.gz",
118-
"https://github.com/protocolbuffers/protobuf/archive/v3.13.0.tar.gz",
119-
],
120-
)
121-
122-
# Stuff used by Buildifier transitively:
123-
# LICENSE: The Apache Software License, Version 2.0
124-
http_archive(
125-
name = "io_bazel_rules_go",
126-
sha256 = "b27e55d2dcc9e6020e17614ae6e0374818a3e3ce6f2024036e688ada24110444",
127-
urls = [
128-
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.21.0/rules_go-v0.21.0.tar.gz",
129-
"https://github.com/bazelbuild/rules_go/releases/download/v0.21.0/rules_go-v0.21.0.tar.gz",
130-
],
131-
)
132-
133-
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
134-
135-
go_rules_dependencies()
136-
137-
go_register_toolchains()
138-
139-
# LICENSE: The Apache Software License, Version 2.0
140-
http_archive(
141-
name = "bazel_gazelle",
142-
sha256 = "86c6d481b3f7aedc1d60c1c211c6f76da282ae197c3b3160f54bd3a8f847896f",
143-
urls = [
144-
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.19.1/bazel-gazelle-v0.19.1.tar.gz",
145-
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.19.1/bazel-gazelle-v0.19.1.tar.gz",
146-
],
147-
)
148-
149-
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")
150-
151-
gazelle_dependencies()
152-
153-
# LICENSE: The Apache Software License, Version 2.0
154-
go_repository(
155-
name = "skylark_syntax",
156-
importpath = "go.starlark.net",
157-
sum = "h1:Qoe+9POtDT51UBQ8XEnS9QKeHDQzEl2QRh3eok9R4aw=",
158-
version = "v0.0.0-20200203144150-6677ee5c7211",
159-
)
160-
161-
# LICENSE: The Apache Software License, Version 2.0
162-
http_archive(
163-
name = "rules_pkg",
164-
sha256 = "5bdc04987af79bd27bc5b00fe30f59a858f77ffa0bd2d8143d5b31ad8b1bd71c",
165-
url = "https://github.com/bazelbuild/rules_pkg/releases/download/0.2.0/rules_pkg-0.2.0.tar.gz",
166-
)
167-
168-
# LICENSE: The Apache Software License, Version 2.0
169-
http_archive(
170-
name = "rules_java",
171-
sha256 = "52423cb07384572ab60ef1132b0c7ded3a25c421036176c0273873ec82f5d2b2",
172-
url = "https://github.com/bazelbuild/rules_java/releases/download/0.1.0/rules_java-0.1.0.tar.gz",
173-
)
174-
175-
# LICENSE: The Apache Software License, Version 2.0
176-
http_archive(
177-
name = "rules_python",
178-
sha256 = "f7402f11691d657161f871e11968a984e5b48b023321935f5a55d7e56cf4758a",
179-
strip_prefix = "rules_python-9d68f24659e8ce8b736590ba1e4418af06ec2552",
180-
url = "https://github.com/bazelbuild/rules_python/archive/9d68f24659e8ce8b736590ba1e4418af06ec2552.zip",
181-
)
182-
183-
# LICENSE: The Apache Software License, Version 2.0
184-
http_archive(
185-
name = "rules_cc",
186-
sha256 = "faa25a149f46077e7eca2637744f494e53a29fe3814bfe240a2ce37115f6e04d",
187-
strip_prefix = "rules_cc-ea5c5422a6b9e79e6432de3b2b29bbd84eb41081",
188-
url = "https://github.com/bazelbuild/rules_cc/archive/ea5c5422a6b9e79e6432de3b2b29bbd84eb41081.zip",
189-
)
190-
191-
# LICENSE: The Apache Software License, Version 2.0
192-
http_archive(
193-
name = "rules_proto",
194-
sha256 = "7d05492099a4359a6006d1b89284d34b76390c3b67d08e30840299b045838e2d",
195-
strip_prefix = "rules_proto-9cd4f8f1ede19d81c6d48910429fe96776e567b1",
196-
url = "https://github.com/bazelbuild/rules_proto/archive/9cd4f8f1ede19d81c6d48910429fe96776e567b1.zip",
197-
)
27+
copybara_go_repositories()

0 commit comments

Comments
 (0)