diff --git a/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/packages/StarlarkSemanticsOptions.java b/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/packages/StarlarkSemanticsOptions.java index 448c210e934..97f5ace13fb 100644 --- a/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/packages/StarlarkSemanticsOptions.java +++ b/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/packages/StarlarkSemanticsOptions.java @@ -439,6 +439,21 @@ public class StarlarkSemanticsOptions extends OptionsBase implements Serializabl help = "If set, disallow downloads via plain http if no checksum is given") public boolean incompatibleDisallowUnverifiedHttpDownloads; + @Option( + name = "incompatible_expand_directories", + defaultValue = "true", + category = "incompatible changes", + documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, + effectTags = {OptionEffectTag.UNKNOWN}, + metadataTags = { + OptionMetadataTag.INCOMPATIBLE_CHANGE, + OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES + }, + help = + "Controls whether directories are expanded to the list of files under that directory " + + "when added to Args, instead of replaced by the path of the directory.") + public boolean incompatibleExpandDirectories; + @Option( name = "incompatible_new_actions_api", defaultValue = "true", @@ -692,6 +707,7 @@ public StarlarkSemantics toSkylarkSemantics() { incompatibleDisallowRuleExecutionPlatformConstraintsAllowed) .incompatibleDisallowUnverifiedHttpDownloads( incompatibleDisallowUnverifiedHttpDownloads) + .incompatibleExpandDirectories(incompatibleExpandDirectories) .incompatibleNewActionsApi(incompatibleNewActionsApi) .incompatibleNoAttrLicense(incompatibleNoAttrLicense) .incompatibleNoImplicitFileExport(incompatibleNoImplicitFileExport) diff --git a/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java b/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java index a533cec3bbc..676d0bee556 100644 --- a/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java +++ b/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java @@ -17,6 +17,7 @@ import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.common.collect.Ordering; import com.google.devtools.build.lib.collect.nestedset.NestedSet; @@ -304,6 +305,34 @@ public static Object checkNotNull(Expression expr, Object obj) throws EvalExcept return obj; } + /** + * Returns the truth value of an object, according to Python rules. + * http://docs.python.org/2/library/stdtypes.html#truth-value-testing + */ + // TODO(adonovan): rename 'Skylark.truth', make it a default-true method of SkylarkValue, + // and delete most of the cases. + public static boolean toBoolean(Object o) { + if (o == null || o == Runtime.NONE) { + return false; + } else if (o instanceof Boolean) { + return (Boolean) o; + } else if (o instanceof String) { + return !((String) o).isEmpty(); + } else if (o instanceof Integer) { + return (Integer) o != 0; + } else if (o instanceof Collection) { + return !((Collection) o).isEmpty(); + } else if (o instanceof Map) { + return !((Map) o).isEmpty(); + } else if (o instanceof SkylarkNestedSet) { + return !((SkylarkNestedSet) o).isEmpty(); + } else if (o instanceof Iterable) { + return !Iterables.isEmpty((Iterable) o); + } else { + return true; + } + } + public static Collection toCollection(Object o, Location loc, @Nullable StarlarkThread thread) throws EvalException { if (o instanceof Collection) { @@ -1027,7 +1056,7 @@ static Object unaryOp(TokenKind op, Object x, Location loc) throws EvalException, InterruptedException { switch (op) { case NOT: - return !Starlark.truth(x); + return !toBoolean(x); case MINUS: if (x instanceof Integer) { diff --git a/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/syntax/StarlarkSemantics.java b/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/syntax/StarlarkSemantics.java index 4a96e17cd7f..e6acacafaa7 100644 --- a/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/syntax/StarlarkSemantics.java +++ b/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/syntax/StarlarkSemantics.java @@ -178,6 +178,8 @@ public boolean flagValue(FlagIdentifier flagIdentifier) { public abstract boolean incompatibleDisallowUnverifiedHttpDownloads(); + public abstract boolean incompatibleExpandDirectories(); + public abstract boolean incompatibleNewActionsApi(); public abstract boolean incompatibleNoAttrLicense(); @@ -276,6 +278,7 @@ public static Builder builderWithDefaults() { .incompatibleDisallowRuleExecutionPlatformConstraintsAllowed(true) .incompatibleDisallowStructProviderSyntax(false) .incompatibleDisallowUnverifiedHttpDownloads(true) + .incompatibleExpandDirectories(true) .incompatibleNewActionsApi(true) .incompatibleNoAttrLicense(true) .incompatibleNoImplicitFileExport(false) @@ -353,6 +356,8 @@ public abstract Builder incompatibleDisallowRuleExecutionPlatformConstraintsAllo public abstract Builder incompatibleDisallowUnverifiedHttpDownloads(boolean value); + public abstract Builder incompatibleExpandDirectories(boolean value); + public abstract Builder incompatibleNewActionsApi(boolean value); public abstract Builder incompatibleNoAttrLicense(boolean value); diff --git a/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/packages/SkylarkSemanticsConsistencyTest.java b/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/packages/SkylarkSemanticsConsistencyTest.java index 60b2120d2cb..8edf8905ba4 100644 --- a/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/packages/SkylarkSemanticsConsistencyTest.java +++ b/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/packages/SkylarkSemanticsConsistencyTest.java @@ -148,6 +148,7 @@ private static StarlarkSemanticsOptions buildRandomOptions(Random rand) throws E "--incompatible_disallow_struct_provider_syntax=" + rand.nextBoolean(), "--incompatible_disallow_unverified_http_downloads=" + rand.nextBoolean(), "--incompatible_do_not_split_linking_cmdline=" + rand.nextBoolean(), + "--incompatible_expand_directories=" + rand.nextBoolean(), "--incompatible_new_actions_api=" + rand.nextBoolean(), "--incompatible_no_attr_license=" + rand.nextBoolean(), "--incompatible_no_implicit_file_export=" + rand.nextBoolean(), @@ -202,6 +203,7 @@ private static StarlarkSemantics buildRandomSemantics(Random rand) { .incompatibleDisallowStructProviderSyntax(rand.nextBoolean()) .incompatibleDisallowUnverifiedHttpDownloads(rand.nextBoolean()) .incompatibleDoNotSplitLinkingCmdline(rand.nextBoolean()) + .incompatibleExpandDirectories(rand.nextBoolean()) .incompatibleNewActionsApi(rand.nextBoolean()) .incompatibleNoAttrLicense(rand.nextBoolean()) .incompatibleNoImplicitFileExport(rand.nextBoolean()) diff --git a/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java b/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java index f9839aeb7be..a09fc86c6b4 100644 --- a/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java +++ b/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java @@ -55,10 +55,10 @@ import com.google.devtools.build.lib.skyframe.PackageFunction; import com.google.devtools.build.lib.skyframe.SkyFunctions; import com.google.devtools.build.lib.skyframe.SkylarkImportLookupFunction; -import com.google.devtools.build.lib.syntax.Depset; -import com.google.devtools.build.lib.syntax.Sequence; -import com.google.devtools.build.lib.syntax.Starlark; -import com.google.devtools.build.lib.syntax.StarlarkList; +import com.google.devtools.build.lib.syntax.Runtime; +import com.google.devtools.build.lib.syntax.SkylarkList; +import com.google.devtools.build.lib.syntax.SkylarkList.MutableList; +import com.google.devtools.build.lib.syntax.SkylarkNestedSet; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.skyframe.InMemoryMemoizingEvaluator; import com.google.devtools.build.skyframe.SkyFunction; @@ -228,7 +228,7 @@ public void testOutputGroups() throws Exception { OutputGroupInfo.get(getConfiguredTarget("//test/skylark:lib")) .getOutputGroup(OutputGroupInfo.HIDDEN_TOP_LEVEL); ConfiguredTarget myTarget = getConfiguredTarget("//test/skylark:my"); - Depset result = (Depset) getMyInfoFromTarget(myTarget).getValue("result"); + SkylarkNestedSet result = (SkylarkNestedSet) getMyInfoFromTarget(myTarget).getValue("result"); assertThat(result.getSet(Artifact.class)).containsExactlyElementsIn(hiddenTopLevelArtifacts); assertThat(OutputGroupInfo.get(myTarget).getOutputGroup("my_group")) .containsExactlyElementsIn(hiddenTopLevelArtifacts); @@ -254,7 +254,7 @@ public void testOutputGroupsDeclaredProvider() throws Exception { OutputGroupInfo.get(getConfiguredTarget("//test/skylark:lib")) .getOutputGroup(OutputGroupInfo.HIDDEN_TOP_LEVEL); ConfiguredTarget myTarget = getConfiguredTarget("//test/skylark:my"); - Depset result = (Depset) getMyInfoFromTarget(myTarget).getValue("result"); + SkylarkNestedSet result = (SkylarkNestedSet) getMyInfoFromTarget(myTarget).getValue("result"); assertThat(result.getSet(Artifact.class)).containsExactlyElementsIn(hiddenTopLevelArtifacts); assertThat(OutputGroupInfo.get(myTarget).getOutputGroup("my_group")) .containsExactlyElementsIn(hiddenTopLevelArtifacts); @@ -288,13 +288,13 @@ public void testOutputGroupsAsDictionary() throws Exception { .getOutputGroup(OutputGroupInfo.HIDDEN_TOP_LEVEL); ConfiguredTarget myTarget = getConfiguredTarget("//test/skylark:my"); StructImpl myInfo = getMyInfoFromTarget(myTarget); - Depset result = (Depset) myInfo.getValue("result"); + SkylarkNestedSet result = (SkylarkNestedSet) myInfo.getValue("result"); assertThat(result.getSet(Artifact.class)).containsExactlyElementsIn(hiddenTopLevelArtifacts); assertThat(OutputGroupInfo.get(myTarget).getOutputGroup("my_group")) .containsExactlyElementsIn(hiddenTopLevelArtifacts); assertThat(myInfo.getValue("has_key1")).isEqualTo(Boolean.TRUE); assertThat(myInfo.getValue("has_key2")).isEqualTo(Boolean.FALSE); - assertThat((Sequence) myInfo.getValue("all_keys")) + assertThat((SkylarkList) myInfo.getValue("all_keys")) .containsExactly( OutputGroupInfo.HIDDEN_TOP_LEVEL, OutputGroupInfo.COMPILATION_PREREQUISITES, @@ -322,7 +322,7 @@ public void testOutputGroupsAsDictionaryPipe() throws Exception { OutputGroupInfo.get(getConfiguredTarget("//test/skylark:lib")) .getOutputGroup(OutputGroupInfo.HIDDEN_TOP_LEVEL); ConfiguredTarget myTarget = getConfiguredTarget("//test/skylark:my"); - Depset result = (Depset) getMyInfoFromTarget(myTarget).getValue("result"); + SkylarkNestedSet result = (SkylarkNestedSet) getMyInfoFromTarget(myTarget).getValue("result"); assertThat(result.getSet(Artifact.class)).containsExactlyElementsIn(hiddenTopLevelArtifacts); assertThat(OutputGroupInfo.get(myTarget).getOutputGroup("my_group")) .containsExactlyElementsIn(hiddenTopLevelArtifacts); @@ -351,7 +351,7 @@ public void testOutputGroupsWithList() throws Exception { OutputGroupInfo.get(getConfiguredTarget("//test/skylark:lib")) .getOutputGroup(OutputGroupInfo.HIDDEN_TOP_LEVEL); ConfiguredTarget myTarget = getConfiguredTarget("//test/skylark:my"); - Depset result = (Depset) getMyInfoFromTarget(myTarget).getValue("result"); + SkylarkNestedSet result = (SkylarkNestedSet) getMyInfoFromTarget(myTarget).getValue("result"); assertThat(result.getSet(Artifact.class)).containsExactlyElementsIn(hiddenTopLevelArtifacts); assertThat(OutputGroupInfo.get(myTarget).getOutputGroup("my_group")) .containsExactlyElementsIn(hiddenTopLevelArtifacts); @@ -380,7 +380,7 @@ public void testOutputGroupsDeclaredProviderWithList() throws Exception { OutputGroupInfo.get(getConfiguredTarget("//test/skylark:lib")) .getOutputGroup(OutputGroupInfo.HIDDEN_TOP_LEVEL); ConfiguredTarget myTarget = getConfiguredTarget("//test/skylark:my"); - Depset result = (Depset) getMyInfoFromTarget(myTarget).getValue("result"); + SkylarkNestedSet result = (SkylarkNestedSet) getMyInfoFromTarget(myTarget).getValue("result"); assertThat(result.getSet(Artifact.class)).containsExactlyElementsIn(hiddenTopLevelArtifacts); assertThat(OutputGroupInfo.get(myTarget).getOutputGroup("my_group")) .containsExactlyElementsIn(hiddenTopLevelArtifacts); @@ -402,9 +402,7 @@ public void testStackTraceErrorInFunction() throws Exception { public void testStackTraceMissingMethod() throws Exception { runStackTraceTest( "None", - "\t\tNone.index" - + System.lineSeparator() - + "'NoneType' value has no field or method 'index'"); + "\t\tNone.index(1)" + System.lineSeparator() + "type 'NoneType' has no method index()"); } protected void runStackTraceTest(String object, String errorMessage) throws Exception { @@ -836,7 +834,7 @@ public void testTransitiveInfoProviders() throws Exception { assertThat( ActionsTestUtil.baseArtifactNames( - ((Depset) getMyInfoFromTarget(target).getValue("provider_key")) + ((SkylarkNestedSet) getMyInfoFromTarget(target).getValue("provider_key")) .getSet(Artifact.class))) .containsExactly("a.txt"); } @@ -1247,7 +1245,7 @@ public void testLegacyOutputAttrDefault() throws Exception { StructImpl myInfo = getMyInfoFromTarget(target); assertThat(myInfo.getValue("o1")) .isEqualTo(Label.parseAbsoluteUnchecked("//test/skylark:foo.txt")); - assertThat(myInfo.getValue("o2")).isEqualTo(StarlarkList.empty()); + assertThat(myInfo.getValue("o2")).isEqualTo(MutableList.empty()); } @Test @@ -1271,8 +1269,8 @@ public void testRuleClassNonMandatoryEmptyOutputs() throws Exception { ConfiguredTarget target = getConfiguredTarget("//test/skylark:cr"); StructImpl myInfo = getMyInfoFromTarget(target); - assertThat(myInfo.getValue("o1")).isEqualTo(Starlark.NONE); - assertThat(myInfo.getValue("o2")).isEqualTo(StarlarkList.empty()); + assertThat(myInfo.getValue("o1")).isEqualTo(Runtime.NONE); + assertThat(myInfo.getValue("o2")).isEqualTo(MutableList.empty()); } @Test @@ -1461,7 +1459,7 @@ public void testRecursionDetection() throws Exception { "empty(name = 'test_target')"); getConfiguredTarget("//test/skylark:test_target"); - assertContainsEvent("function '_impl' called recursively"); + assertContainsEvent("Recursion was detected when calling '_impl' from '_impl'"); } @Test @@ -1665,6 +1663,54 @@ public void testRecursiveImport2() throws Exception { + "`-- //test/skylark:ext2.bzl"); } + @Test + public void testSymbolPropagateThroughImports() throws Exception { + setSkylarkSemanticsOptions("--incompatible_no_transitive_loads=false"); + scratch.file("test/skylark/implementation.bzl", "def custom_rule_impl(ctx):", " return None"); + + scratch.file( + "test/skylark/extension2.bzl", + "load('//test/skylark:implementation.bzl', 'custom_rule_impl')"); + + scratch.file( + "test/skylark/extension1.bzl", + "load('//test/skylark:extension2.bzl', 'custom_rule_impl')", + "", + "custom_rule = rule(implementation = custom_rule_impl)"); + + scratch.file( + "test/skylark/BUILD", + "load('//test/skylark:extension1.bzl', 'custom_rule')", + "custom_rule(name = 'cr')"); + + getConfiguredTarget("//test/skylark:cr"); + } + + @Test + public void testSymbolDoNotPropagateThroughImports() throws Exception { + setSkylarkSemanticsOptions("--incompatible_no_transitive_loads=true"); + scratch.file("test/skylark/implementation.bzl", "def custom_rule_impl(ctx):", " return None"); + + scratch.file( + "test/skylark/extension2.bzl", + "load('//test/skylark:implementation.bzl', 'custom_rule_impl')"); + + scratch.file( + "test/skylark/extension1.bzl", + "load('//test/skylark:extension2.bzl', 'custom_rule_impl')", + "", + "custom_rule = rule(implementation = custom_rule_impl)"); + + scratch.file( + "test/skylark/BUILD", + "load('//test/skylark:extension1.bzl', 'custom_rule')", + "custom_rule(name = 'cr')"); + + reporter.removeHandler(failFastHandler); + getConfiguredTarget("//test/skylark:cr"); + assertContainsEvent("does not contain symbol 'custom_rule_impl'"); + } + @Test public void testLoadSymbolTypo() throws Exception { scratch.file("test/skylark/ext1.bzl", "myvariable = 2"); @@ -1990,7 +2036,7 @@ public void testNoTargetOutputGroup() throws Exception { checkError( "test/skylark", "r", - " (rule 'cc_binary') doesn't have provider 'output_group'", + "type 'Target' has no method output_group()", "load('//test/skylark:extension.bzl', 'my_rule')", "cc_binary(name = 'lib', data = ['a.txt'])", "my_rule(name='r', dep = ':lib')"); @@ -2227,8 +2273,8 @@ public void testAnalysisTestTransitionOnAnalysisTest() throws Exception { StructImpl outerDepInfo = (StructImpl) outerTarget.get(myDepKey); StructImpl innerInfo = (StructImpl) outerDepInfo.getValue("info"); - assertThat((Sequence) outerInfo.getValue("copts")).containsExactly("yeehaw"); - assertThat((Sequence) innerInfo.getValue("copts")).containsExactly("cowabunga"); + assertThat((SkylarkList) outerInfo.getValue("copts")).containsExactly("yeehaw"); + assertThat((SkylarkList) innerInfo.getValue("copts")).containsExactly("cowabunga"); } @Test