Skip to content

Commit 7b3aa18

Browse files
authored
Switching to a pegged revision of drake (as default) (#36)
* Following jwnimmer's advice, utilizing pegged revisions as the default, with an option to use a local copy. * Added scripts to auto-install pre-reqs.
1 parent 9a7932d commit 7b3aa18

File tree

6 files changed

+194
-7
lines changed

6 files changed

+194
-7
lines changed

BUILD.bazel

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# -*- mode: python -*-
2+
# vi: set ft=python :
3+
4+
# Copyright (c) 2019, Toyota Research Institute.
5+
# All rights reserved.
6+
#
7+
# Redistribution and use in source and binary forms, with or without
8+
# modification, are permitted provided that the following conditions are met:
9+
#
10+
# * Redistributions of source code must retain the above copyright notice, this
11+
# list of conditions and the following disclaimer.
12+
#
13+
# * Redistributions in binary form must reproduce the above copyright notice,
14+
# this list of conditions and the following disclaimer in the documentation
15+
# and/or other materials provided with the distribution.
16+
#
17+
# * Neither the name of the copyright holder nor the names of its contributors
18+
# may be used to endorse or promote products derived from this software
19+
# without specific prior written permission.
20+
#
21+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31+
# POSSIBILITY OF SUCH DAMAGE.
32+
33+
# This is an empty BUILD file, to ensure that the project's root directory is a
34+
# bazel package.

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,23 @@
22

33
## Complete Build Instructions
44
### Build Drake
5-
The library is meant to be built with Drake (see http://drake.mit.edu/ for more details)
5+
The library is meant to be built with Drake (see http://drake.mit.edu/ for more details). There are two ways to use Drake within dairlib:
6+
#### Option 1: use pegged revision
7+
The only specific action needed here is to install all of Drake's prerequisites. There are two choices
8+
1. (Experimental) In `dairlib` (after cloning below), run the appropriate `install_prereqs_xxx.sh` file in `install`. This is untested on mac, and has not been tested to get every dependency for a fresh install.
9+
2. Download a source copy of drake, and install pre-requisites as described here: http://drake.mit.edu/from_source.html
610

11+
bazel will automatically download the pegged revision, specified in the WORKSPACE file. dairlib developers hope to keep this pegged revision current, and ensure that the pegged version will always work with a specific version of dairlib.
12+
13+
This option is recommended for users who are not currently editing any source code in Drake itself.
14+
#### Option 2: source install of Drake
715
Install Drake from source into `"my-workspace"/drake` http://drake.mit.edu/from_source.html. You do not need to build it, but prerequisites should also be installed. You will need `git` to start.
816

17+
To tell dairlib to use your local install, set the environment variable `DAIRLIB_LOCAL_DRAKE_PATH`, e.g.
18+
```
19+
export DAIRLIB_LOCAL_DRAKE_PATH=/home/user/my-workspace/drake
20+
```
21+
922
### Other dependencies
1023
These dependencies are necessary for some advanced visualization and process management. Many examples will work without a full installation of Director or libbot, but (for lab members), these are ultimately recommended.
1124
1. Install a local copy of `lcm` and `libbot2` using `sudo apt install lcm libbot2'. The prerequisites installation from Drake should add the proper repo for these.

WORKSPACE

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,56 @@
44

55
workspace(name = "dairlib")
66

7-
local_repository(
8-
name = "drake",
9-
path = "../drake",
10-
)
7+
# dairlib can use either a local version of drake or a pegged revision
8+
# If the environment variable DAIRLIB_LOCAL_DRAKE_PATH is set, it will use
9+
# a local version, ad the specified path. Otherwise, it will get a pegged
10+
# revision from github.
11+
# As an example,
12+
# export DAIRLIB_LOCAL_DRAKE_PATH=/home/user/workspace/drake
1113

12-
load("@dairlib//tools/workspace/signal_scope:repository.bzl", "signal_scope_repository")
13-
signal_scope_repository(name = "signal_scope")
14+
# Choose a revision of Drake to use.
15+
DRAKE_COMMIT = "f7741cf6d6fe3cc3e7a7554179028d078b0efeed"
16+
DRAKE_CHECKSUM = "a736b4ed8387ad7d5dbc53c0bb542853d68e449d36444402476daa1bcf2a90ce"
17+
# Before changing the COMMIT, temporarily uncomment the next line so that Bazel
18+
# displays the suggested new value for the CHECKSUM.
19+
# DRAKE_CHECKSUM = "0" * 64
1420

21+
# Load an environment variable.
22+
load("//:environ.bzl", "environ_repository")
23+
environ_repository(name = "environ", vars = ["DAIRLIB_LOCAL_DRAKE_PATH"])
24+
load("@environ//:environ.bzl", "DAIRLIB_LOCAL_DRAKE_PATH")
1525

26+
# The WORKSPACE file does not permit `if` statements, so we handle the local
27+
# option by toying with the repository names. The selected repository is named
28+
# "@drake", the other is named "@drake_ignored".
29+
(_http_drake_repo_name, _local_drake_repo_name) = (
30+
"drake_ignored" if DAIRLIB_LOCAL_DRAKE_PATH else "drake",
31+
"drake" if DAIRLIB_LOCAL_DRAKE_PATH else "drake_ignored",
32+
)
33+
34+
# Maybe download Drake.
35+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
36+
http_archive(
37+
name = _http_drake_repo_name,
38+
urls = [x.format(DRAKE_COMMIT) for x in [
39+
"https://github.com/RobotLocomotion/drake/archive/{}.tar.gz",
40+
]],
41+
sha256 = DRAKE_CHECKSUM,
42+
strip_prefix = "drake-{}".format(DRAKE_COMMIT),
43+
)
44+
45+
# Maybe use a local checkout of Drake.
46+
print("Using DAIRLIB_LOCAL_DRAKE_PATH={}".format(DAIRLIB_LOCAL_DRAKE_PATH)) if DAIRLIB_LOCAL_DRAKE_PATH else None # noqa
47+
local_repository(
48+
name = _local_drake_repo_name,
49+
path = DAIRLIB_LOCAL_DRAKE_PATH,
50+
)
1651

1752
# Reference external software libraries and tools per Drake's defaults. Some
1853
# software will come from the host system (Ubuntu or macOS); other software
1954
# will be downloaded in source or binary form from github or other sites.
2055
load("@drake//tools/workspace:default.bzl", "add_default_repositories")
2156
add_default_repositories()
57+
58+
load("@dairlib//tools/workspace/signal_scope:repository.bzl", "signal_scope_repository")
59+
signal_scope_repository(name = "signal_scope")

environ.bzl

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# -*- mode: python -*-
2+
# vi: set ft=python :
3+
4+
# Copyright (c) 2018-2019, Toyota Research Institute.
5+
# All rights reserved.
6+
#
7+
# Redistribution and use in source and binary forms, with or without
8+
# modification, are permitted provided that the following conditions are met:
9+
#
10+
# * Redistributions of source code must retain the above copyright notice, this
11+
# list of conditions and the following disclaimer.
12+
#
13+
# * Redistributions in binary form must reproduce the above copyright notice,
14+
# this list of conditions and the following disclaimer in the documentation
15+
# and/or other materials provided with the distribution.
16+
#
17+
# * Neither the name of the copyright holder nor the names of its contributors
18+
# may be used to endorse or promote products derived from this software
19+
# without specific prior written permission.
20+
#
21+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31+
# POSSIBILITY OF SUCH DAMAGE.
32+
33+
# Write out a repository that contains:
34+
# - An empty BUILD file, to define a package.
35+
# - An environ.bzl file with variable assignments for each ENV_NAMES item.
36+
def _impl(repository_ctx):
37+
vars = repository_ctx.attr._vars
38+
bzl_content = []
39+
for key in vars:
40+
value = repository_ctx.os.environ.get(key, "")
41+
bzl_content.append("{}='{}'\n".format(key, value))
42+
repository_ctx.file(
43+
"BUILD.bazel",
44+
content = "\n",
45+
executable = False,
46+
)
47+
repository_ctx.file(
48+
"environ.bzl",
49+
content = "".join(bzl_content),
50+
executable = False,
51+
)
52+
53+
def environ_repository(name = None, vars = []):
54+
"""Provide specific environment variables for use in a WORKSPACE file.
55+
The `vars` are the environment variables to provide.
56+
57+
Example:
58+
environ_repository(name = "foo", vars = ["BAR", "BAZ"])
59+
load("@foo//:environ.bzl", "BAR", "BAZ")
60+
print(BAR)
61+
"""
62+
rule = repository_rule(
63+
implementation = _impl,
64+
attrs = {
65+
"_vars": attr.string_list(default = vars),
66+
},
67+
local = True,
68+
environ = vars,
69+
)
70+
rule(name = name)

install/install_prereqs_mac.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
DRAKE_COMMIT=$(grep -oP '(?<=DRAKE_COMMIT = ")(.*)(?=")' $(dirname "$0")/../WORKSPACE)
4+
5+
echo "Using Drake commit '${DRAKE_COMMIT}'"
6+
wget --quiet -O drake_binary_brewfile \
7+
"https://raw.githubusercontent.com/RobotLocomotion/drake/${DRAKE_COMMIT}/setup/mac/binary_distribution/Brewfile"
8+
wget --quiet -O drake_source_brewfile \
9+
"https://raw.githubusercontent.com/RobotLocomotion/drake/${DRAKE_COMMIT}/setup/mac/source_distribution/Brewfile"
10+
# We blacklist kcov-35 because it is only available from the Drake PPA, and we don't want to add that PPA to sources.list.
11+
sed -i 's#^kcov-35$##g' drake_source_brewfile
12+
/usr/local/bin/brew bundle --file="drake_binary_brewfile"
13+
/usr/local/bin/brew bundle --file="drake_source_brewfile"
14+
rm drake_binary_brewfile
15+
rm drake_source_brewfile

install/install_prereqs_ubuntu.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
DRAKE_COMMIT=$(grep -oP '(?<=DRAKE_COMMIT = ")(.*)(?=")' $(dirname "$0")/../WORKSPACE)
4+
5+
ubuntu_codename=$(lsb_release -sc)
6+
7+
echo "Using Drake commit '${DRAKE_COMMIT}'"
8+
wget --quiet -O drake_binary_packages.txt \
9+
"https://raw.githubusercontent.com/RobotLocomotion/drake/${DRAKE_COMMIT}/setup/ubuntu/binary_distribution/packages-${ubuntu_codename}.txt"
10+
wget --quiet -O drake_source_packages.txt \
11+
"https://raw.githubusercontent.com/RobotLocomotion/drake/${DRAKE_COMMIT}/setup/ubuntu/source_distribution/packages-${ubuntu_codename}.txt"
12+
# We blacklist kcov-35 because it is only available from the Drake PPA, and we don't want to add that PPA to sources.list.
13+
sed -i 's#^kcov-35$##g' drake_source_packages.txt
14+
sudo apt-get -q install --no-install-recommends $(cat drake_binary_packages.txt)
15+
sudo apt-get -q install --no-install-recommends $(cat drake_source_packages.txt)
16+
rm drake_binary_packages.txt
17+
rm drake_source_packages.txt

0 commit comments

Comments
 (0)