Skip to content

Commit

Permalink
Expose freeze-deps as a buildable target (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c authored Jun 7, 2022
1 parent efa25bf commit a7b24d6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ file you need to do the following:

pinned_maven_install()
```
2. Run `./tools/freeze-deps.py --repo <repo name> --zip
2. Run `bazel run //tools:freeze-deps -- --repo <repo name> --zip
<path/to/dependency.zip>`. The `<repo name>` matches the name used
for the `maven_install()` rule above. This will pin the
dependencies then collect them into the zip file.
Expand Down
8 changes: 8 additions & 0 deletions tools/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@ java_binary(
main_class = "com.google.googlejavaformat.java.Main",
runtime_deps = ["@maven//:com_google_googlejavaformat_google_java_format"],
)

py_binary(
name = "freeze-deps",
srcs = [
"freeze-deps.py",
],
visibility = ["//visibility:public"],
)
12 changes: 9 additions & 3 deletions tools/freeze-deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,28 @@
help="Name of the zip repository used to import the zip file. Used only if compat_repositories are enabled"
)

# When run under `bazel run` this directory will be set. If not,
# then we should assume our current directory is the right one
# to use.
cwd = os.environ.get("BUILD_WORKSPACE_DIRECTORY", None)

args = parser.parse_args()

pin_env = {"REPIN": "1"}
pin_env.update(os.environ)

# Repin our dependencies
cmd = ["bazel", "run", "@unpinned_%s//:pin" % args.repo]
subprocess.check_call(cmd, env=pin_env)
subprocess.check_call(cmd, env=pin_env, cwd = cwd)

# Now grab the files we need from their output locations
cmd = ["bazel", "info", "output_base"]
output_base = subprocess.check_output(cmd).rstrip()
output_base = subprocess.check_output(cmd, cwd = cwd).rstrip()
base = output_base.decode(encoding=sys.stdin.encoding)

# Generate a stable-ish zip file
output = zipfile.ZipFile(args.zip, "w", zipfile.ZIP_DEFLATED)
zip_path = path.join(cwd, args.zip) if cwd else args.zip
output = zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED)

for f in UNCHANGED_FILES:
p = path.join(base, "external", args.repo, f)
Expand Down

0 comments on commit a7b24d6

Please sign in to comment.