Skip to content

Commit

Permalink
Update drake and allow using local copy (RobotLocomotion#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpetersen94 authored Oct 20, 2021
1 parent 61961b9 commit 1faf413
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 6 deletions.
1 change: 1 addition & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- python -*
33 changes: 27 additions & 6 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,44 @@ new_local_repository(
)

(DRAKE_COMMIT, DRAKE_CHECKSUM) = (
"e899feec209a6d4a6f7ecc1266cbc933f46ce30e",
"d15eda0625b8fed108b33facd3dde048d0ab6f31588e45e881382f1b79eed723",
"b79928f03f94780ef8096a08c109d85cefe428f8",
"ac001ccac82d560b32038585129192e2931857d142db8989116450ec36f3f58f",
)
# Before changing the COMMIT, temporarily uncomment the next line so that Bazel
# displays the suggested new value for the CHECKSUM.
# DRAKE_CHECKSUM = "0" * 64

# Download a specific commit of Drake, from github.
# Or to build against a local checkout of Drake, at the bash prompt set an
# environment variable before building:
# export IIWA_LOCAL_DRAKE_PATH=/home/user/stuff/drake

# Load an environment variable.
load("//:environ.bzl", "environ_repository")
environ_repository(name = "environ", vars = ["IIWA_LOCAL_DRAKE_PATH"])
load("@environ//:environ.bzl", IIWA_LOCAL_DRAKE_PATH = "IIWA_LOCAL_DRAKE_PATH")

# This declares the `@drake` repository as an http_archive from github,
# iff IIWA_LOCAL_DRAKE_PATH is unset. When it is set, this declares a
# `@drake_ignored` package which is never referenced, and thus is ignored.
http_archive(
name = "drake",
name = "drake" if not IIWA_LOCAL_DRAKE_PATH else "drake_ignored",
sha256 = DRAKE_CHECKSUM,
strip_prefix = "drake-{}".format(DRAKE_COMMIT),
urls = [x.format(DRAKE_COMMIT) for x in [
"https://github.com/RobotLocomotion/drake/archive/{}.tar.gz",
]],
)

# This declares the `@drake` repository as a local directory,
# iff IIWA_LOCAL_DRAKE_PATH is set. When it is unset, this declares a
# `@drake_ignored` package which is never referenced, and thus is ignored.
local_repository(
name = "drake" if IIWA_LOCAL_DRAKE_PATH else "drake_ignored",
path = IIWA_LOCAL_DRAKE_PATH,
)
print("Using IIWA_LOCAL_DRAKE_PATH={}".format(IIWA_LOCAL_DRAKE_PATH)) if IIWA_LOCAL_DRAKE_PATH else None # noqa


load("@drake//tools/workspace/cc:repository.bzl", "cc_repository")
cc_repository(name = "cc")

Expand All @@ -44,5 +65,5 @@ lcm_repository(name = "lcm", mirrors = DEFAULT_MIRRORS)
load("@drake//tools/workspace/python:repository.bzl", "python_repository")
python_repository(name = "python")

load("@drake//tools/workspace/python3:repository.bzl", "python3_repository")
python3_repository(name = "python3")
load("@drake//tools/workspace/rules_python:repository.bzl", "rules_python_repository") # noqa
rules_python_repository(name = "rules_python", mirrors = DEFAULT_MIRRORS)
41 changes: 41 additions & 0 deletions environ.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- mode: python -*-
# vi: set ft=python :

# Write out a repository that contains:
# - An empty BUILD file, to define a package.
# - An environ.bzl file with variable assignments for each ENV_NAMES item.
def _impl(repository_ctx):
vars = repository_ctx.attr._vars
bzl_content = []
for key in vars:
value = repository_ctx.os.environ.get(key, "")
bzl_content.append("{}='{}'\n".format(key, value))
repository_ctx.file(
"BUILD.bazel",
content = "\n",
executable = False,
)
repository_ctx.file(
"environ.bzl",
content = "".join(bzl_content),
executable = False,
)

def environ_repository(name = None, vars = []):
"""Provide specific environment variables for use in a WORKSPACE file.
The `vars` are the environment variables to provide.
Example:
environ_repository(name = "foo", vars = ["BAR", "BAZ"])
load("@foo//:environ.bzl", "BAR", "BAZ")
print(BAR)
"""
rule = repository_rule(
implementation = _impl,
attrs = {
"_vars": attr.string_list(default = vars),
},
local = True,
environ = vars,
)
rule(name = name)

0 comments on commit 1faf413

Please sign in to comment.