From c30a3299f5246d68fe15c9c232d219e442665f07 Mon Sep 17 00:00:00 2001 From: Jeremy Nimmer Date: Mon, 16 Apr 2018 09:14:06 -0400 Subject: [PATCH] Only run library_lint tests when snopt is enabled --- tools/lint/library_lint.bzl | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/tools/lint/library_lint.bzl b/tools/lint/library_lint.bzl index 4c338958bbea..39b292cc6714 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"], )