Skip to content

Commit

Permalink
Update tests to avoid depset union.
Browse files Browse the repository at this point in the history
Progress towards #5817

RELNOTES: None.
PiperOrigin-RevId: 245242309
  • Loading branch information
laurentlb authored and copybara-github committed Apr 25, 2019
1 parent 861a7e1 commit 63c7ea6
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,8 @@ public void aspectPropagating() throws Exception {
scratch.file(
"test/aspect.bzl",
"def _impl(target, ctx):",
" s = depset([target.label])",
" c = depset([ctx.rule.kind])",
" for i in ctx.rule.attr.deps:",
" s += i.target_labels",
" c += i.rule_kinds",
" s = depset([target.label], transitive = [i.target_labels for i in ctx.rule.attr.deps])",
" c = depset([ctx.rule.kind], transitive = [i.rule_kinds for i in ctx.rule.attr.deps])",
" return struct(target_labels = s, rule_kinds = c)",
"",
"MyAspect = aspect(",
Expand Down Expand Up @@ -314,16 +311,18 @@ public void aspectsPropagatingForDefaultAndImplicit() throws Exception {
scratch.file(
"test/aspect.bzl",
"def _impl(target, ctx):",
" s = depset([target.label])",
" c = depset([ctx.rule.kind])",
" s = []",
" c = []",
" a = ctx.rule.attr",
" if hasattr(a, '_defaultattr') and a._defaultattr:",
" s += a._defaultattr.target_labels",
" c += a._defaultattr.rule_kinds",
" if hasattr(a, '_cc_toolchain') and a._cc_toolchain:",
" s += a._cc_toolchain.target_labels",
" c += a._cc_toolchain.rule_kinds",
" return struct(target_labels = s, rule_kinds = c)",
" if getattr(a, '_defaultattr', None):",
" s += [a._defaultattr.target_labels]",
" c += [a._defaultattr.rule_kinds]",
" if getattr(a, '_cc_toolchain', None):",
" s += [a._cc_toolchain.target_labels]",
" c += [a._cc_toolchain.rule_kinds]",
" return struct(",
" target_labels = depset([target.label], transitive = s),",
" rule_kinds = depset([ctx.rule.kind], transitive = c))",
"",
"def _rule_impl(ctx):",
" pass",
Expand Down Expand Up @@ -558,15 +557,11 @@ public void aspectsFromSkylarkRules() throws Exception {
scratch.file(
"test/aspect.bzl",
"def _aspect_impl(target, ctx):",
" s = depset([target.label])",
" for i in ctx.rule.attr.deps:",
" s += i.target_labels",
" s = depset([target.label], transitive = [i.target_labels for i in ctx.rule.attr.deps])",
" return struct(target_labels = s)",
"",
"def _rule_impl(ctx):",
" s = depset([])",
" for i in ctx.attr.attr:",
" s += i.target_labels",
" s = depset(transitive = [i.target_labels for i in ctx.attr.attr])",
" return struct(rule_deps = s)",
"",
"MyAspect = aspect(",
Expand Down Expand Up @@ -1652,10 +1647,8 @@ private void buildTargetAndCheckRuleInfo(String... expectedLabels) throws Except
private String[] aspectBzlFile(String attrAspects) {
return new String[] {
"def _repro_aspect_impl(target, ctx):",
" s = depset([str(target.label)])",
" for d in ctx.rule.attr.deps:",
" if hasattr(d, 'aspect_info'):",
" s = s | d.aspect_info",
" s = depset([str(target.label)], transitive =",
" [d.aspect_info for d in ctx.rule.attr.deps if hasattr(d, 'aspect_info')])",
" return struct(aspect_info = s)",
"",
"_repro_aspect = aspect(",
Expand All @@ -1664,10 +1657,8 @@ private String[] aspectBzlFile(String attrAspects) {
")",
"",
"def repro_impl(ctx):",
" s = depset()",
" for d in ctx.attr.deps:",
" if hasattr(d, 'aspect_info'):",
" s = s | d.aspect_info",
" s = depset(transitive = ",
" [d.aspect_info for d in ctx.attr.deps if hasattr(d, 'aspect_info')])",
" return struct(rule_info = s)",
"",
"def repro_no_aspect_impl(ctx):",
Expand Down Expand Up @@ -1706,9 +1697,7 @@ public void aspectOutputsToBinDirectory() throws Exception {
"rule_bin_out = rule(_rule_impl, output_to_genfiles=False)",
"rule_gen_out = rule(_rule_impl, output_to_genfiles=True)",
"def _main_rule_impl(ctx):",
" s = depset()",
" for d in ctx.attr.deps:",
" s = s | depset([d.aspect_file])",
" s = depset([d.aspect_file for d in ctx.attr.deps])",
" return struct(aspect_files = s)",
"main_rule = rule(_main_rule_impl,",
" attrs = { 'deps' : attr.label_list(aspects = [my_aspect]) },",
Expand Down Expand Up @@ -1839,10 +1828,9 @@ public void aspectsPropagatingToAllAttributes() throws Exception {
scratch.file(
"test/aspect.bzl",
"def _impl(target, ctx):",
" s = depset([target.label])",
" if hasattr(ctx.rule.attr, 'runtime_deps'):",
" for i in ctx.rule.attr.runtime_deps:",
" s += i.target_labels",
" s = depset([target.label], transitive =",
" [i.target_labels for i in ctx.rule.attr.runtime_deps]",
" if hasattr(ctx.rule.attr, 'runtime_deps') else [])",
" return struct(target_labels = s)",
"",
"MyAspect = aspect(",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,7 @@ public void testOutputGroupsAsDictionaryPipe() throws Exception {
"test/skylark/extension.bzl",
"load('//myinfo:myinfo.bzl', 'MyInfo')",
"def _impl(ctx):",
" f = ctx.attr.dep.output_groups['_hidden_top_level" + INTERNAL_SUFFIX + "']",
" g = ctx.attr.dep.output_groups['_hidden_top_level" + INTERNAL_SUFFIX + "'] | depset([])",
" g = depset(ctx.attr.dep.output_groups['_hidden_top_level" + INTERNAL_SUFFIX + "'])",
" return [MyInfo(result = g),",
" OutputGroupInfo(my_group = g)]",
"my_rule = rule(implementation = _impl,",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ public void testRunfilesArtifactsFromNestedSetArtifacts() throws Exception {
Object result =
evalRuleContextCode(
ruleContext,
"ftb = depset() + ruleContext.files.srcs",
"ftb = depset(ruleContext.files.srcs)",
"ruleContext.runfiles(transitive_files = ftb)");
assertThat(ImmutableList.of("a.txt", "b.img"))
.isEqualTo(ActionsTestUtil.baseArtifactNames(getRunfileArtifacts(result)));
Expand Down Expand Up @@ -996,7 +996,7 @@ public void testRunfilesBadKeywordArguments() throws Exception {
@Test
public void testNsetContainsList() throws Exception {
checkErrorContains(
"depsets cannot contain items of type 'list'", "depset() + [ruleContext.files.srcs]");
"depsets cannot contain items of type 'list'", "depset([[ruleContext.files.srcs]])");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1496,7 +1496,7 @@ public void testInSet() throws Exception {

@Test
public void testUnionSet() throws Exception {
new SkylarkTest()
new SkylarkTest("--incompatible_depset_union=false")
.testStatement("str(depset([1, 3]) | depset([1, 2]))", "depset([1, 2, 3])")
.testStatement("str(depset([1, 2]) | [1, 3])", "depset([1, 2, 3])")
.testIfExactError("unsupported operand type(s) for |: 'int' and 'int'", "2 | 4");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,20 +366,17 @@ public void testUnionOrder() throws Exception {

@Test
public void testUnionIncompatibleOrder() throws Exception {
env = newEnvironmentWithSkylarkOptions("--incompatible_depset_union=false");
checkEvalError(
"Order mismatch: topological != postorder",
"depset(['a', 'b'], order='postorder') + depset(['c', 'd'], order='topological')");
}

@Test
public void testUnionWithNonsequence() throws Exception {
new BothModesTest()
.testIfExactError(
"cannot union value of type 'int' to a depset",
"depset([]).union(5)")
.testIfExactError(
"cannot union value of type 'string' to a depset",
"depset(['a']).union('b')");
env = newEnvironmentWithSkylarkOptions("--incompatible_depset_union=false");
checkEvalError("cannot union value of type 'int' to a depset", "depset([]).union(5)");
checkEvalError("cannot union value of type 'string' to a depset", "depset(['a']).union('b')");
}

@Test
Expand All @@ -393,6 +390,7 @@ public void testUnionWrongNumArgs() throws Exception {

@Test
public void testUnionNoSideEffects() throws Exception {
env = newEnvironmentWithSkylarkOptions("--incompatible_depset_union=false");
eval(
"def func():",
" s1 = depset(['a'])",
Expand All @@ -404,6 +402,7 @@ public void testUnionNoSideEffects() throws Exception {

@Test
public void testFunctionReturnsDepset() throws Exception {
env = newEnvironmentWithSkylarkOptions("--incompatible_depset_union=false");
eval(
"def func():",
" t = depset()",
Expand All @@ -416,6 +415,7 @@ public void testFunctionReturnsDepset() throws Exception {

@Test
public void testPlusEqualsWithList() throws Exception {
env = newEnvironmentWithSkylarkOptions("--incompatible_depset_union=false");
eval(
"def func():",
" t = depset()",
Expand All @@ -427,6 +427,7 @@ public void testPlusEqualsWithList() throws Exception {

@Test
public void testPlusEqualsNoSideEffects() throws Exception {
env = newEnvironmentWithSkylarkOptions("--incompatible_depset_union=false");
eval(
"def func():",
" s1 = depset()",
Expand All @@ -440,6 +441,7 @@ public void testPlusEqualsNoSideEffects() throws Exception {

@Test
public void testFuncParamNoSideEffects() throws Exception {
env = newEnvironmentWithSkylarkOptions("--incompatible_depset_union=false");
eval(
"def func1(t):",
" t += ['b']",
Expand All @@ -454,6 +456,7 @@ public void testFuncParamNoSideEffects() throws Exception {

@Test
public void testTransitiveOrdering() throws Exception {
env = newEnvironmentWithSkylarkOptions("--incompatible_depset_union=false");
eval(
"def func():",
" sa = depset(['a'], order='postorder')",
Expand All @@ -467,6 +470,7 @@ public void testTransitiveOrdering() throws Exception {

@Test
public void testLeftRightDirectOrdering() throws Exception {
env = newEnvironmentWithSkylarkOptions("--incompatible_depset_union=false");
eval(
"def func():",
" t = depset()",
Expand Down

0 comments on commit 63c7ea6

Please sign in to comment.