From e506858c14d9ffceedbb22988f7c65fe70df5536 Mon Sep 17 00:00:00 2001 From: cparsons Date: Mon, 16 Jul 2018 13:33:33 -0700 Subject: Add --incompatible_disable_deprecated_attr_params to disable some deprecated parameters of the skylark attr module. RELNOTES: None. PiperOrigin-RevId: 204797954 --- .../build/lib/analysis/skylark/SkylarkAttr.java | 20 ++++++++++++++--- .../build/lib/packages/SkylarkSemanticsCodec.java | 2 ++ .../lib/packages/SkylarkSemanticsOptions.java | 16 +++++++++++++ .../build/lib/syntax/SkylarkSemantics.java | 5 +++++ .../packages/SkylarkSemanticsConsistencyTest.java | 2 ++ .../lib/skylark/SkylarkRuleClassFunctionsTest.java | 26 ++++++++++++++++++++++ tools/build_defs/pkg/pkg.bzl | 18 +++++++-------- 7 files changed, 77 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkAttr.java b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkAttr.java index 0d1a1aa6c8..a0cf36dab9 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkAttr.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkAttr.java @@ -147,8 +147,15 @@ public final class SkylarkAttr implements SkylarkAttrApi { builder.setPropertyFlag("MANDATORY"); } - // TODO(laurentlb): Deprecated, remove in August 2016 (use allow_empty instead). - if (containsNonNoneKey(arguments, NON_EMPTY_ARG) && (Boolean) arguments.get(NON_EMPTY_ARG)) { + if (containsNonNoneKey(arguments, NON_EMPTY_ARG) + && (Boolean) arguments.get(NON_EMPTY_ARG)) { + if (env.getSemantics().incompatibleDisableDeprecatedAttrParams()) { + throw new EvalException(ast.getLocation(), + "'non_empty' is no longer supported. use allow_empty instead. You can use " + + "--incompatible_disable_deprecated_attr_params to temporarily disable this " + + "check."); + } + builder.setPropertyFlag("NON_EMPTY"); } @@ -168,14 +175,21 @@ public final class SkylarkAttr implements SkylarkAttrApi { } } - // TODO(laurentlb): Deprecated, remove in August 2016 (use allow_single_file). if (containsNonNoneKey(arguments, SINGLE_FILE_ARG) && (Boolean) arguments.get(SINGLE_FILE_ARG)) { + if (env.getSemantics().incompatibleDisableDeprecatedAttrParams()) { + throw new EvalException( + ast.getLocation(), + "'single_file' is no longer supported. use allow_single_file instead. You can use " + + "--incompatible_disable_deprecated_attr_params to temporarily disable this " + + "check."); + } if (containsNonNoneKey(arguments, ALLOW_SINGLE_FILE_ARG)) { throw new EvalException( ast.getLocation(), "Cannot specify both single_file (deprecated) and allow_single_file"); } + builder.setPropertyFlag("SINGLE_ARTIFACT"); } diff --git a/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsCodec.java b/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsCodec.java index 7f147cb422..a8647a8d6e 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsCodec.java +++ b/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsCodec.java @@ -47,6 +47,7 @@ public final class SkylarkSemanticsCodec implements ObjectCodec eval("attr.label(single_file = True)")); + assertThat(expected).hasMessageThat().contains( + "'single_file' is no longer supported. use allow_single_file instead."); + Attribute attr = buildAttribute("a1", "attr.label(allow_single_file = ['.xml'])"); + assertThat(attr.isSingleArtifact()).isTrue(); + + // Verify 'non_empty' deprecation. + expected = + assertThrows(EvalException.class, () -> eval("attr.string_list(non_empty=True)")); + assertThat(expected).hasMessageThat().contains( + "'non_empty' is no longer supported. use allow_empty instead."); + attr = buildAttribute("a2", "attr.string_list(allow_empty=False)"); + assertThat(attr.isNonEmpty()).isTrue(); + } + @Test public void testAttrAllowedSingleFileTypesWrongType() throws Exception { checkErrorContains( diff --git a/tools/build_defs/pkg/pkg.bzl b/tools/build_defs/pkg/pkg.bzl index 459161785b..0e250b261e 100644 --- a/tools/build_defs/pkg/pkg.bzl +++ b/tools/build_defs/pkg/pkg.bzl @@ -231,23 +231,23 @@ def pkg_tar(**kwargs): pkg_deb = rule( implementation = _pkg_deb_impl, attrs = { - "data": attr.label(mandatory = True, allow_files = tar_filetype, single_file = True), + "data": attr.label(mandatory = True, allow_single_file = tar_filetype), "package": attr.string(mandatory = True), "architecture": attr.string(default = "all"), "distribution": attr.string(default = "unstable"), "urgency": attr.string(default = "medium"), "maintainer": attr.string(mandatory = True), - "preinst": attr.label(allow_files = True, single_file = True), - "postinst": attr.label(allow_files = True, single_file = True), - "prerm": attr.label(allow_files = True, single_file = True), - "postrm": attr.label(allow_files = True, single_file = True), - "conffiles_file": attr.label(allow_files = True, single_file = True), + "preinst": attr.label(allow_single_file = True), + "postinst": attr.label(allow_single_file = True), + "prerm": attr.label(allow_single_file = True), + "postrm": attr.label(allow_single_file = True), + "conffiles_file": attr.label(allow_single_file = True), "conffiles": attr.string_list(default = []), - "version_file": attr.label(allow_files = True, single_file = True), + "version_file": attr.label(allow_single_file = True), "version": attr.string(), - "description_file": attr.label(allow_files = True, single_file = True), + "description_file": attr.label(allow_single_file = True), "description": attr.string(), - "built_using_file": attr.label(allow_files = True, single_file = True), + "built_using_file": attr.label(allow_single_file = True), "built_using": attr.string(), "priority": attr.string(), "section": attr.string(), -- cgit v1.2.3