forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request RobotLocomotion#6401 from mwoehlke-kitware/refacto…
…r-license-checks Refactor licence enforcement
- Loading branch information
Showing
27 changed files
with
152 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.