Skip to content

Commit

Permalink
Merge pull request #6014 from mwoehlke-kitware/generate-drake-config-…
Browse files Browse the repository at this point in the history
…from-cps

Generate Drake exports from CPS
  • Loading branch information
mwoehlke-kitware authored May 5, 2017
2 parents 6bb9e2b + 34ac102 commit dc9af67
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 63 deletions.
16 changes: 16 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,22 @@ github_archive(
sha256 = "0a0ae63cbffc274efb573bdde9a253e3f32e458c41261df51c5dbc5ad541e8f7",
)

pypi_archive(
name = "semantic_version",
version = "2.6.0",
sha256 = "2a4328680073e9b243667b201119772aefc5fc63ae32398d6afafff07c4f54c0",
build_file = "tools/semantic_version.BUILD",
strip_prefix = "semantic_version",
)

github_archive(
name = "pycps",
repository = "mwoehlke/pycps",
commit = "1b985467d1fe737ed3a43a25f4da3316bd45106f",
sha256 = "4491debd18ee40bf9d7eab9b35776eff98a71bc904a339f709273cbad9ac6efb",
build_file = "tools/pycps.BUILD",
)

# The "@python_headers//:python_headers" target is required by protobuf
# during "bazel query" but not "bazel build", so a stub is fine.
new_local_repository(
Expand Down
9 changes: 9 additions & 0 deletions tools/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ alias(
actual = "@com_github_bazelbuild_buildtools//buildifier",
)

genrule(
name = "cmake_exports",
srcs = ["drake.cps"],
outs = ["drake-config.cmake"],
cmd = "$(location @pycps//:cps2cmake_executable) $(location drake.cps) > \"$@\"",
tools = ["@pycps//:cps2cmake_executable"],
visibility = ["//visibility:private"],
)

# This pulls the otherwise-unused libbot targets into the "//..." label tree.
genrule(
name = "force_libbot",
Expand Down
58 changes: 0 additions & 58 deletions tools/drake-config.cmake

This file was deleted.

12 changes: 12 additions & 0 deletions tools/drake.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,15 @@ def drake_header_tar(name, deps=[], **kwargs):
mode="0644",
files=[":" + name + "_gather"],
strip_prefix="/")

# Generate a file with specified content
def _generate_file_impl(ctx):
ctx.file_action(output=ctx.outputs.out, content=ctx.attr.content)

drake_generate_file = rule(
implementation = _generate_file_impl,
attrs = {
"content": attr.string(),
"out": attr.output(mandatory = True),
},
)
1 change: 1 addition & 0 deletions tools/drake.cps
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"Meta-Schema": "https://mwoehlke.github.io/cps/",
"X-Purpose": "Used to generate drake-config.cmake via cps2cmake",
"X-See-Also": "https://github.com/mwoehlke/pycps",
"Cps-Version": "0.8.0",
"Name": "drake",
"Website": "http://drake.mit.edu/",
"Components": {
Expand Down
9 changes: 5 additions & 4 deletions tools/lcm.BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- python -*-

load("@//tools:drake.bzl", "drake_generate_file")

package(default_visibility = ["//visibility:public"])

# In LCM's upstream build system lcm_export.h is generated by CMake and
Expand Down Expand Up @@ -145,11 +147,10 @@ cc_binary(
# To repair this, we provide our own init file at the root of the sandbox that
# overrides the Bazel empty default. Its implementation just delegates to the
# lcm-python init file.
genrule(
drake_generate_file(
name = "init_genrule",
srcs = [],
outs = ["__init__.py"],
cmd = "echo 'execfile(__path__[0] + \"/lcm-python/lcm/__init__.py\")' > $@",
out = "__init__.py",
content = "execfile(__path__[0] + \"/lcm-python/lcm/__init__.py\")",
)

py_library(
Expand Down
2 changes: 1 addition & 1 deletion tools/package_drake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ function canonicalize
# Copy source artifacts to specified install prefix.
function copy_source_artifacts
{
cp tools/drake-config.cmake "$1/lib/cmake/drake/"
cp LICENSE.TXT "$1/"
}

Expand All @@ -32,6 +31,7 @@ function copy_source_artifacts
function copy_build_artifacts
{
cp bazel-bin/drake/libdrake.so "$1/lib/"
cp bazel-genfiles/tools/drake-config.cmake "$1/lib/cmake/drake/"
}

#------------------------------------------------------------------------------
Expand Down
21 changes: 21 additions & 0 deletions tools/pycps.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
genrule(
name = "copy_cps2cmake",
srcs = ["cps2cmake"],
outs = ["cps2cmake.py"],
cmd = "cp \"$<\" \"$(@)\"",
)

py_library(
name = "cps",
srcs = ["cps.py"],
deps = ["@semantic_version//:semantic_version"],
visibility = ["//visibility:private"], # LGPL; don't use externally
)

py_binary(
name = "cps2cmake_executable",
srcs = ["cps2cmake.py"],
main = "cps2cmake.py",
deps = [":cps"],
visibility = ["//visibility:public"],
)
7 changes: 7 additions & 0 deletions tools/semantic_version.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
load("@//tools:drake.bzl", "drake_generate_file")

py_library(
name = "semantic_version",
srcs = glob(["*.py"]),
visibility = ["//visibility:public"],
)

0 comments on commit dc9af67

Please sign in to comment.