-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: external_data: Hoist lint checking to Drake; simplify dependencies.
- Loading branch information
1 parent
0c94752
commit d4c5d86
Showing
15 changed files
with
111 additions
and
133 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,28 @@ | ||
load("//tools/lint:lint.bzl", "add_lint_tests") | ||
load(":external_data.bzl", "external_data_stub_test") | ||
|
||
# Use a symlink forest, so `bazel run` of `workspace_test` will not pollute the | ||
# source directory with `bazel-*` symlinks. | ||
filegroup( | ||
name = "workspace_symlink_forest", | ||
srcs = glob( | ||
["workspace/*"], | ||
exclude_directories = 0, | ||
), | ||
load( | ||
"@bazel_external_data_pkg//test:workspace_test.bzl", | ||
"workspace_test", | ||
) | ||
|
||
# Run all tests in `workspace` as a separate package. | ||
sh_test( | ||
workspace_test( | ||
name = "workspace_test", | ||
srcs = ["test/workspace_test.sh"], | ||
# We must use a file, and not just `workspace`, because Bazel will not give | ||
# us the location unless it's in `data`. We do NOT want this, because | ||
# we want a symlink forest. (See above.) | ||
args = ["$(location workspace/WORKSPACE)"], | ||
data = [ | ||
# Must explicitly list this file so that we can get its location. | ||
"workspace/WORKSPACE", | ||
"workspace_symlink_forest", | ||
# Get necessary upstream files from Drake. | ||
"//tools:external_data_meta_testing_files", | ||
"//:external_data_meta_testing_files", | ||
], | ||
workspace = "workspace", | ||
) | ||
|
||
# Ensure that we can consume `external_data.bzl`. | ||
external_data_stub_test() | ||
|
||
add_lint_tests() | ||
# Ensure that we add all relevant files under `workspace`. | ||
# We should be able to glob them, as they are not a package. | ||
add_lint_tests( | ||
bazel_lint_extra_srcs = glob([ | ||
"workspace/**/BUILD.bazel", | ||
"workspace/**/WORKSPACE", | ||
"workspace/**/*.bzl", | ||
]), | ||
python_lint_extra_srcs = glob([ | ||
"workspace/**/*.py", | ||
]), | ||
) |
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 |
---|---|---|
@@ -1,23 +1,19 @@ | ||
# -*- python -*- | ||
load("//tools:lint.bzl", "add_lint_tests") | ||
load(":workspace_writeable_test.bzl", "workspace_writeable_test") | ||
load(":workspace_test.bzl", "workspace_test") | ||
|
||
root_data = ["//:meta_testing_files"] | ||
|
||
workspace_writeable_test( | ||
workspace_test( | ||
name = "bazel_pkg_test", | ||
data = root_data, | ||
workspace = "workspaces/bazel_pkg_test", | ||
writeable = 1, | ||
) | ||
|
||
# Ensure that we add all relevant files under `workspaces`. | ||
# We should be able to glob them, as they are not a package. | ||
add_lint_tests( | ||
bazel_lint_extra_srcs = glob([ | ||
"workspaces/**/BUILD.bazel", | ||
"workspaces/**/WORKSPACE", | ||
]), | ||
python_lint_extra_srcs = glob([ | ||
"workspaces/**/*.py", | ||
]), | ||
exports_files( | ||
srcs = [ | ||
"workspace_test.sh", | ||
"workspace_writeable_test.sh", | ||
], | ||
visibility = ["//visibility:public"], | ||
) |
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,66 @@ | ||
# -*- python -*- | ||
|
||
# Default command. Do not run linting tests, so that the downstream test | ||
# packages do not need to consume `drake`. | ||
# Needs quotes, because `sh_test(args = [...])` just concatenates them??? | ||
_CMD_DEFAULT = "'bazel test //...'" | ||
|
||
def _get_target(name): | ||
return "@bazel_external_data_pkg//test:" + name | ||
|
||
def workspace_test( | ||
name, | ||
workspace, | ||
cmd = _CMD_DEFAULT, | ||
data = [], | ||
writeable = 0): | ||
"""Provides a unittest access to a given workspace | ||
contained in the current project. | ||
@param workspace | ||
Workspace directory relative to this package. | ||
@param cmd | ||
Command to run. By default is `bazel test //...`. | ||
@param data | ||
Additional data (e.g. other workspaces). | ||
@param writeable | ||
If the data should be copied such that modifications can be made. """ | ||
|
||
if writeable: | ||
args = [cmd, "$(location {})".format(workspace)] | ||
for datum in data: | ||
args.append("$(locations {})".format(datum)) | ||
native.sh_test( | ||
name = name, | ||
srcs = [_get_target("workspace_writeable_test.sh")], | ||
args = args, | ||
data = [workspace] + data, | ||
) | ||
else: | ||
# Use a symlink forest, so `bazel run` of `workspace_test` will not | ||
# pollute the source directory with `bazel-*` symlinks. | ||
workspace_filegroup = name + "_filegroup" | ||
# We must use a file, and not just `workspace`, because Bazel will not | ||
# give us the location unless it's in `data`. We do NOT want this, | ||
# because we want a symlink forest. (See above.) | ||
workspace_file = workspace + "/WORKSPACE" | ||
native.filegroup( | ||
name = workspace_filegroup, | ||
srcs = native.glob( | ||
[workspace + "/*"], | ||
exclude_directories = 0, | ||
), | ||
) | ||
native.sh_test( | ||
name = name, | ||
srcs = [_get_target("workspace_test.sh")], | ||
args = [ | ||
cmd, | ||
"$(location {})".format(workspace_file)], | ||
data = [ | ||
# Must explicitly list this file so that we can get its | ||
# location. | ||
workspace_file, | ||
workspace_filegroup, | ||
] + data, | ||
) |
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
27 changes: 0 additions & 27 deletions
27
tools/external_data/workspace/test/workspace_writeable_test.bzl
This file was deleted.
Oops, something went wrong.
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
2 changes: 1 addition & 1 deletion
2
tools/external_data/workspace/test/workspaces/bazel_pkg_test/tools/path.bzl
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# -*- python -*- | ||
|
||
def dirname(p, remove=1): | ||
def dirname(p, remove = 1): | ||
pieces = p.split('/') | ||
return '/'.join(pieces[0:-remove]) |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# -*- python -*- | ||
|
||
def dirname(p, remove=1): | ||
def dirname(p, remove = 1): | ||
pieces = p.split('/') | ||
return '/'.join(pieces[0:-remove]) |