From ab9732b9af5f8dad4ee9c0be47d7f51b1a90e37d Mon Sep 17 00:00:00 2001 From: Jeremy Nimmer Date: Mon, 16 Apr 2018 23:46:11 -0400 Subject: [PATCH] Only run library_lint tests when snopt is enabled --- .../multibody_plant/BUILD.bazel | 5 +-- tools/lint/library_lint.bzl | 36 ++++++++++++++++--- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/multibody/multibody_tree/multibody_plant/BUILD.bazel b/multibody/multibody_tree/multibody_plant/BUILD.bazel index b27cf5677d22..af68dbd2e042 100644 --- a/multibody/multibody_tree/multibody_plant/BUILD.bazel +++ b/multibody/multibody_tree/multibody_plant/BUILD.bazel @@ -16,12 +16,13 @@ package( drake_cc_package_library( name = "multibody_plant", deps = [ - ":everything", + ":coulomb_friction", + ":multibody_plant_core", ], ) drake_cc_library( - name = "everything", + name = "multibody_plant_core", srcs = [ "multibody_plant.cc", ], diff --git a/tools/lint/library_lint.bzl b/tools/lint/library_lint.bzl index 5b3d276ceca4..7056c78613af 100644 --- a/tools/lint/library_lint.bzl +++ b/tools/lint/library_lint.bzl @@ -95,17 +95,45 @@ def library_lint( # If there was a package_library rule, ensure its deps are comprehensive. if package_library_rule: + # If snopt is disabled, we have to use a dummy scope and expression. + # + # Details: When snopt is enabled, we obtain the @snopt source code via + # git. When snopt is disabled, there is no guarantee that git is still + # going to work (e.g., the repository is authenticated). Normally this + # is not a problem. However, during a `bazel query` or `genquery()` + # computation, Bazel still builds a graph where the conditional + # dependency on snopt is reified, and so its repository_rule gets run + # (and fails). Thus, we shouldn't do any genquery() operations unless + # snopt is enabled. Instead, we'll scope the genquery to a dummy + # label, and nerf the expression to be definitionally empty. + # + # TODO(jwnimmer-tri) Figure out how make linting work even when snopt + # is disabled. + dummy = "@bazel_tools//tools/cpp:empty" + dummy_expression = "{} except {}".format(dummy, dummy) native.genquery( name = "library_lint_missing_deps", - expression = missing_deps_expression, - scope = scope, + expression = select({ + "//tools:with_snopt": missing_deps_expression, + "//conditions:default": dummy_expression, + }), + scope = select({ + "//tools:with_snopt": scope, + "//conditions:default": [dummy], + }), testonly = 1, visibility = ["//visibility:private"], ) native.genquery( name = "library_lint_extra_deps", - expression = extra_deps_expression, - scope = scope, + expression = select({ + "//tools:with_snopt": extra_deps_expression, + "//conditions:default": dummy_expression, + }), + scope = select({ + "//tools:with_snopt": scope, + "//conditions:default": [dummy], + }), testonly = 1, visibility = ["//visibility:private"], )