Skip to content

Commit

Permalink
lcmtypes: Ensure Python2 versions are always installed for drake_visu…
Browse files Browse the repository at this point in the history
…alizer
  • Loading branch information
EricCousineau-TRI committed Dec 10, 2018
1 parent 5861852 commit c827ae0
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 4 deletions.
14 changes: 13 additions & 1 deletion lcmtypes/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

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

load("@drake//tools/install:install.bzl", "install")
load(
"@drake//tools/install:install.bzl",
"install",
"install_py2_duplicates_if_py3",
)
load(
"@drake//tools/skylark:drake_cc.bzl",
"drake_cc_library",
Expand Down Expand Up @@ -390,6 +394,13 @@ install(
visibility = ["//visibility:private"],
)

# For Python2-only `drake_visualizer`.
install_py2_duplicates_if_py3(
name = "install_py2_duplicates_if_py3",
targets = [":lcmtypes_py"],
visibility = ["//visibility:private"],
)

install(
name = "install",
install_tests = [":test/drake-lcm-spy_install_test.py"],
Expand All @@ -405,6 +416,7 @@ install(
},
deps = [
":install_cc_headers",
":install_py2_duplicates_if_py3",
"//tools/workspace/optitrack_driver:install",
"@lcm//:install",
"@lcmtypes_bot2_core//:install",
Expand Down
36 changes: 35 additions & 1 deletion tools/install/install.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ load(
"join_paths",
"output_path",
)
load("@python//:version.bzl", "PYTHON_SITE_PACKAGES_RELPATH")
load("@python//:version.bzl", "PYTHON_SITE_PACKAGES_RELPATH", "PYTHON_VERSION")

InstallInfo = provider()

Expand Down Expand Up @@ -689,6 +689,40 @@ Args:
allowed_externals: List of external packages whose files may be installed.
"""

def install_py2_duplicates_if_py3(
name,
targets = None,
py_dest = "@PYTHON_SITE_PACKAGES@",
**kwargs):
"""
Creates a duplicate install, only if Python3 is Bazel's version of Python.
Otherwise, creates an empty install target.
For `py_dest`, `@PYTHON_SITE_PACKAGES@` will be replaced with
`lib/python2.7/site-packages`.
This is presently only used to support Python2-only `drake_visualizer`.
"""
cur_major, _ = PYTHON_VERSION.split(".")
if cur_major == "3":
py2_targets = targets
else:
py2_targets = []

# Assuming that we will only have one supported major-minor version of
# Python2.
py2_major_minor = "2.7"
py2_dest = py_dest.replace(
"@PYTHON_SITE_PACKAGES@",
"lib/python{}/site-packages".format(py2_major_minor),
)
install(
name = name,
targets = py2_targets,
py_dest = py2_dest,
**kwargs
)

#------------------------------------------------------------------------------
# Generate information to install files to specified destination.
def _install_files_impl(ctx):
Expand Down
14 changes: 13 additions & 1 deletion tools/workspace/lcmtypes_bot2_core/package.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ load(
"cmake_config",
"install",
"install_cmake_config",
"install_py2_duplicates_if_py3",
)
load(
"@drake//tools/workspace/lcm:lcm.bzl",
Expand Down Expand Up @@ -64,6 +65,14 @@ install_cmake_config(
versioned = 0,
)

# For Python2-only `drake_visualizer`.
install_py2_duplicates_if_py3(
name = "install_py2_duplicates_if_py3",
targets = [":lcmtypes_bot2_core_py"],
py_strip_prefix = ["lcmtypes"],
visibility = ["//visibility:private"],
)

# For docs, see https://github.com/RobotLocomotion/lcmtypes/issues/2
# and https://github.com/openhumanoids/bot_core_lcmtypes/issues/33.
install(
Expand All @@ -81,5 +90,8 @@ install(
"share/java/liblcmtypes_bot2_core_java.jar": "lcmtypes_bot2_core.jar",
},
allowed_externals = ["@lcmtypes_robotlocomotion//:LICENSE.txt"],
deps = [":install_cmake_config"],
deps = [
":install_cmake_config",
":install_py2_duplicates_if_py3",
],
)
14 changes: 13 additions & 1 deletion tools/workspace/lcmtypes_robotlocomotion/package.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ load(
"cmake_config",
"install",
"install_cmake_config",
"install_py2_duplicates_if_py3",
)
load(
"@drake//tools/workspace/lcm:lcm.bzl",
Expand Down Expand Up @@ -54,6 +55,14 @@ install_cmake_config(
versioned = 0,
)

# For Python2-only `drake_visualizer`.
install_py2_duplicates_if_py3(
name = "install_py2_duplicates_if_py3",
targets = [":lcmtypes_robotlocomotion_py"],
py_strip_prefix = ["lcmtypes"],
visibility = ["//visibility:private"],
)

install(
name = "install",
workspace = CMAKE_PACKAGE,
Expand All @@ -68,7 +77,10 @@ install(
rename = {
"share/java/liblcmtypes_robotlocomotion_java.jar": "lcmtypes_robotlocomotion.jar", # noqa
},
deps = [":install_cmake_config"],
deps = [
":install_cmake_config",
":install_py2_duplicates_if_py3",
],
)

# See https://github.com/RobotLocomotion/lcmtypes/issues/2 and
Expand Down
12 changes: 12 additions & 0 deletions tools/workspace/optitrack_driver/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ load(
"install",
"install_cmake_config",
"install_files",
"install_py2_duplicates_if_py3",
)
load("//tools/lint:lint.bzl", "add_lint_tests")

Expand Down Expand Up @@ -38,6 +39,16 @@ OPTITRACK_TARGETS = [
"@optitrack_driver//src:optitrack_client_py",
]

# For Python2-only `drake_visualizer`.
install_py2_duplicates_if_py3(
name = "install_py2_duplicates_if_py3",
allowed_externals = OPTITRACK_TARGETS,
py_dest = "@PYTHON_SITE_PACKAGES@/optitrack",
py_strip_prefix = ["**/"],
targets = ["@optitrack_driver//lcmtypes:py_optitrack_lcmtypes"],
visibility = ["//visibility:private"],
)

install(
name = "install",
workspace = CMAKE_PACKAGE,
Expand All @@ -57,6 +68,7 @@ install(
deps = [
":install_cmake_config",
":install_optitrack_client",
":install_py2_duplicates_if_py3",
],
)

Expand Down

0 comments on commit c827ae0

Please sign in to comment.