Skip to content

Commit

Permalink
Merge pull request RobotLocomotion#6401 from mwoehlke-kitware/refacto…
Browse files Browse the repository at this point in the history
…r-license-checks

Refactor licence enforcement
  • Loading branch information
mwoehlke-kitware authored Jun 29, 2017
2 parents 4319b38 + 898a3f5 commit dfdbb8e
Show file tree
Hide file tree
Showing 27 changed files with 152 additions and 142 deletions.
59 changes: 33 additions & 26 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# This file is named BUILD.bazel instead of the more typical BUILD, so that on
# OSX it won't conflict with a build artifacts directory named "build".

load("//tools:check_licenses.bzl", "check_licenses")
load("//tools:install.bzl", "install", "install_files")

package(
Expand Down Expand Up @@ -31,36 +32,42 @@ alias(
actual = "@protobuf//:protobuf_python",
)

DRAKE_EXTERNAL_PACKAGE_INSTALLS = ["@%s//:install" % p for p in [
"bullet",
"ccd",
"eigen",
"fcl",
"fmt",
"ignition_math",
"ignition_rndf",
"ipopt",
"lcm",
"lcmtypes_bot2_core",
"lcmtypes_robotlocomotion",
"libbot",
"nlopt",
"octomap",
"pybind11",
"sdformat",
"spdlog",
"tinyobjloader",
"vtk",
"yaml_cpp",
]] + ["//tools/install/%s:install" % p for p in [
"gflags",
"jchart2d",
"optitrack_driver",
"protobuf",
]]

install(
name = "install",
license_docs = ["LICENSE.TXT"],
docs = ["LICENSE.TXT"],
deps = [
"//drake:install",
"//drake/common:install",
"//tools:install",
"//tools/install/gflags:install",
"//tools/install/jchart2d:install",
"//tools/install/optitrack_driver:install",
"//tools/install/protobuf:install",
"@bullet//:install",
"@ccd//:install",
"@eigen//:install",
"@fcl//:install",
"@fmt//:install",
"@ignition_math//:install",
"@ignition_rndf//:install",
"@ipopt//:install",
"@lcm//:install",
"@lcmtypes_bot2_core//:install",
"@lcmtypes_robotlocomotion//:install",
"@libbot//:install",
"@nlopt//:install",
"@octomap//:install",
"@pybind11//:install",
"@sdformat//:install",
"@spdlog//:install",
"@tinyobjloader//:install",
"@vtk//:install",
"@yaml_cpp//:install",
],
] + DRAKE_EXTERNAL_PACKAGE_INSTALLS,
)

check_licenses(DRAKE_EXTERNAL_PACKAGE_INSTALLS + [":install"])
1 change: 0 additions & 1 deletion drake/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package(default_visibility = ["//visibility:public"])

load("//tools:install.bzl", "install")
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")

# Should include everything any consumer of Drake would ever need.
# When adding new components to the package, please also add the licenses for
Expand Down
7 changes: 4 additions & 3 deletions tools/bullet.BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- python -*-

load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
load(
"@drake//tools:install.bzl",
"cmake_config",
Expand Down Expand Up @@ -76,11 +75,13 @@ install_cmake_config(package = "Bullet")

install(
name = "install",
docs = ["AUTHORS.txt"],
docs = [
"AUTHORS.txt",
"LICENSE.txt",
],
guess_hdrs = "PACKAGE",
hdr_dest = "include/bullet",
hdr_strip_prefix = BULLET_INCLUDES,
license_docs = ["LICENSE.txt"],
targets = [
":BulletCollision",
":BulletDynamics",
Expand Down
2 changes: 1 addition & 1 deletion tools/ccd.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ install_cmake_config(package = "ccd") # Creates rule :install_cmake_config.
install(
name = "install",
hdrs = CCD_PUBLIC_HEADERS,
docs = ["BSD-LICENSE"],
hdr_dest = "include/ccd",
hdr_strip_prefix = ["**/"],
license_docs = ["BSD-LICENSE"],
targets = [":ccd"],
deps = [":install_cmake_config"],
)
80 changes: 80 additions & 0 deletions tools/check_licenses.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# -*- python -*-

# List of exact file names of license files
LICENSE_LITERALS = [
"BSD-LICENSE", # ccd
"COPYING",
"Copyright.txt", # vtk
"LICENSE",
]

# List of file name prefixes of license files
LICENSE_PREFIXES = [
"COPYING.",
"LICENSE.",
]

#------------------------------------------------------------------------------
def _is_license_file(filename):
# Check literal file names
if filename in LICENSE_LITERALS:
return True

# Check file prefixes
for p in LICENSE_PREFIXES:
if filename.startswith(p):
return True

# No match
return False

#------------------------------------------------------------------------------
def _check_licenses_for_label(label):
has_license = False
for a in label.install_actions:
if _is_license_file(a.src.basename):
has_license = True

if not has_license:
return [label.label]

return []

#------------------------------------------------------------------------------
def _check_licenses_impl(ctx):
labels_missing_licenses = []
for l in ctx.attr.install_labels:
labels_missing_licenses += _check_licenses_for_label(l)

if labels_missing_licenses:
fail("Missing license files for install label(s) %s" %
labels_missing_licenses)

_check_licenses = rule(
attrs = {
"install_labels": attr.label_list(providers = ["install_actions"]),
},
implementation = _check_licenses_impl,
)

def check_licenses(install_labels, name = "check_licenses"):
"""Check that install labels include license files.
Given a list of install labels (e.g. ``//package:install``), check that the
set of files installed by the label includes one or more files that appear
to provide a license, by checking the file names against a list of known
names of license files (e.g. ``LICENSE``).
This is used to verify that a set of packages is installing the license
files for those packages.
Args:
name (:obj:`str`): Rule name (default = ``"check_licenses"``).
install_labels (:obj:`list` of :obj:`Label`): List of install labels
(must be created by :func:`install` or :func:`install_files`) to
be checked.
"""
_check_licenses(
name = name,
install_labels = install_labels,
)
11 changes: 1 addition & 10 deletions tools/eigen.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ load(
"install_cmake_config",
)
load("@drake//tools:python_lint.bzl", "python_lint")
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")

package(
default_visibility = ["//visibility:public"],
Expand Down Expand Up @@ -39,19 +38,11 @@ install_cmake_config(package = "Eigen3") # Creates rule :install_cmake_config.
install(
name = "install",
doc_dest = "share/doc/eigen3",
docs = glob(["COPYING.*"]),
guess_hdrs = "PACKAGE",
hdr_dest = "include/eigen3",
license_docs = glob(["COPYING.*"]),
targets = [":eigen"],
deps = [":install_cmake_config"],
)

pkg_tar(
name = "license",
extension = "tar.gz",
files = glob(["COPYING.*"]),
mode = "0644",
package_dir = "eigen",
)

python_lint()
2 changes: 1 addition & 1 deletion tools/fcl.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ install_cmake_config(package = "fcl") # Creates rule :install_cmake_config.

install(
name = "install",
docs = ["LICENSE"],
guess_hdrs = "PACKAGE",
hdr_dest = "include/fcl",
hdr_strip_prefix = ["include/fcl"],
license_docs = glob(["LICENSE"]),
targets = [":fcl"],
deps = [":install_cmake_config"],
)
11 changes: 1 addition & 10 deletions tools/fmt.BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- python -*-

load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
load(
"@drake//tools:install.bzl",
"cmake_config",
Expand Down Expand Up @@ -29,18 +28,10 @@ install_cmake_config(package = "fmt") # Creates rule :install_cmake_config.

install(
name = "install",
docs = ["LICENSE.rst"],
guess_hdrs = "PACKAGE",
hdr_dest = "include/fmt",
hdr_strip_prefix = ["fmt"],
license_docs = ["LICENSE.rst"],
targets = [":fmt"],
deps = [":install_cmake_config"],
)

pkg_tar(
name = "license",
extension = "tar.gz",
files = ["LICENSE.rst"],
mode = "0644",
package_dir = "fmt",
)
5 changes: 2 additions & 3 deletions tools/ignition_math.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,11 @@ install(
":config",
":mathhh_genrule",
],
hdr_dest = "include",
hdr_strip_prefix = ["include"],
license_docs = [
docs = [
"LICENSE",
"COPYING",
],
hdr_strip_prefix = ["include"],
targets = [":ignition_math"],
workspace = CMAKE_PACKAGE,
deps = [":install_cmake_config"],
Expand Down
5 changes: 2 additions & 3 deletions tools/ignition_rndf.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,11 @@ install(
":config",
":rndfhh_genrule",
],
hdr_dest = "include",
hdr_strip_prefix = ["include"],
license_docs = [
docs = [
"LICENSE",
"COPYING",
],
hdr_strip_prefix = ["include"],
targets = [":ignition_rndf"],
workspace = CMAKE_PACKAGE,
deps = [":install_cmake_config"],
Expand Down
23 changes: 0 additions & 23 deletions tools/install.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@ InstallInfo = provider()
#==============================================================================
#BEGIN internal helpers

#------------------------------------------------------------------------------
def _is_drake_label(x):
root = x.workspace_root
if root == "":
x.package.startswith("drake") or fail("Unknown '%s'" % x.package)
return True
else:
root.startswith("external") or fail("Unknown '%s'" % root)
return False

#------------------------------------------------------------------------------
def _workspace(ctx):
"""Compute name of current workspace."""
Expand Down Expand Up @@ -236,22 +226,11 @@ def _install_code(action):
def _install_impl(ctx):
actions = []

# Check for missing license files.
non_drake_labels = [
x.label for x in ctx.attr.targets + ctx.attr.hdrs
if not _is_drake_label(x.label)]
if non_drake_labels and not ctx.attr.license_docs:
fail("%s is missing required license_docs= attribute for %s" % (
ctx.label, non_drake_labels))

# Collect install actions from dependencies.
for d in ctx.attr.deps:
actions += d.install_actions

# Generate actions for data, docs and includes.
actions += _install_actions(ctx, ctx.attr.license_docs, ctx.attr.doc_dest,
strip_prefixes = ctx.attr.doc_strip_prefix,
rename = ctx.attr.rename)
actions += _install_actions(ctx, ctx.attr.docs, ctx.attr.doc_dest,
strip_prefixes = ctx.attr.doc_strip_prefix,
rename = ctx.attr.rename)
Expand Down Expand Up @@ -304,7 +283,6 @@ install = rule(
"docs": attr.label_list(allow_files = True),
"doc_dest": attr.string(default = "share/doc/@WORKSPACE@"),
"doc_strip_prefix": attr.string_list(),
"license_docs": attr.label_list(allow_files = True),
"data": attr.label_list(allow_files = True),
"data_dest": attr.string(default = "share/@WORKSPACE@"),
"data_strip_prefix": attr.string_list(),
Expand Down Expand Up @@ -390,7 +368,6 @@ Args:
doc_dest: Destination for documentation files
(default = "share/doc/@WORKSPACE@").
doc_strip_prefix: List of prefixes to remove from documentation paths.
license_docs: List of license files to install (uses doc_dest).
guess_data: See note.
guess_data_exclude: List of resources found by ``guess_data`` to exclude
from installation.
Expand Down
4 changes: 2 additions & 2 deletions tools/install/gflags/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ install(
name = "install",
allowed_externals = ["@com_github_gflags_gflags//:gflags"],
doc_dest = "share/doc/gflags",
docs = ["@com_github_gflags_gflags//:COPYING.txt"],
guess_hdrs = "PACKAGE",
guess_hdrs_exclude = [
"config.h",
Expand All @@ -23,8 +24,7 @@ install(
],
hdr_dest = "include",
hdr_strip_prefix = ["include"],
license_docs = ["@com_github_gflags_gflags//:COPYING.txt"],
targets = ["@com_github_gflags_gflags//:gflags"],
deps = [":install_cmake_config"],
visibility = ["//:__pkg__"],
deps = [":install_cmake_config"],
)
6 changes: 3 additions & 3 deletions tools/install/jchart2d/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ JCHART_TARGETS = [
install(
name = "install",
allowed_externals = JCHART_LICENSE_DOCS + JCHART_TARGETS,
doc_dest = "share/doc/" + CMAKE_PACKAGE,
doc_strip_prefix = ["**/"],
license_docs = JCHART_LICENSE_DOCS,
docs = JCHART_LICENSE_DOCS,
java_strip_prefix = ["**/"],
targets = JCHART_TARGETS,
deps = [":install_cmake_config"],
visibility = ["//:__pkg__"],
workspace = CMAKE_PACKAGE,
deps = [":install_cmake_config"],
)
Loading

0 comments on commit dfdbb8e

Please sign in to comment.