diff --git a/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommandLineOptions.java b/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommandLineOptions.java index 838e7e2ce7c..db7c4b5cb51 100644 --- a/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommandLineOptions.java +++ b/dataset/GitHub_Java/bazelbuild.bazel/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommandLineOptions.java @@ -14,7 +14,7 @@ package com.google.devtools.build.lib.rules.objc; -import com.google.devtools.build.lib.analysis.config.CoreOptionConverters.LabelConverter; +import com.google.devtools.build.lib.analysis.config.BuildConfiguration.LabelConverter; import com.google.devtools.build.lib.analysis.config.FragmentOptions; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.rules.apple.DottedVersion; @@ -319,7 +319,7 @@ public class ObjcCommandLineOptions extends FragmentOptions { OptionMetadataTag.INCOMPATIBLE_CHANGE, OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES }, - help = "Unused. Will be removed in future versions of Bazel.") + help = "If enabled, objc_library resource attributes are disallowed.") public boolean disableObjcLibraryResources; @Override diff --git a/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/rules/objc/AppleStaticLibraryTest.java b/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/rules/objc/AppleStaticLibraryTest.java index 75623ff3f75..ebaf09eb1d0 100644 --- a/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/rules/objc/AppleStaticLibraryTest.java +++ b/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/rules/objc/AppleStaticLibraryTest.java @@ -98,6 +98,38 @@ public void testSymlinkInsteadOfLipoSingleArch() throws Exception { .containsExactly(Iterables.getOnlyElement(linkAction.getOutputs())); } + @Test + public void testAvoidDepsProviders() throws Exception { + useConfiguration("--incompatible_disable_objc_library_resources=false"); + scratch.file( + "package/BUILD", + "apple_static_library(", + " name = 'test',", + " deps = [':objcLib'],", + " platform_type = 'ios',", + " avoid_deps = [':avoidLib'],", + ")", + "objc_library(name = 'objcLib', srcs = [ 'b.m' ], deps = [':avoidLib', ':baseLib'])", + "objc_library(", + " name = 'baseLib',", + " srcs = [ 'base.m' ],", + " sdk_frameworks = ['BaseSDK'],", + " resources = [':base.png']", + ")", + "objc_library(", + " name = 'avoidLib',", + " srcs = [ 'c.m' ],", + " sdk_frameworks = ['AvoidSDK'],", + " resources = [':avoid.png']", + ")"); + + ObjcProvider provider = getConfiguredTarget("//package:test") + .get(AppleStaticLibraryInfo.SKYLARK_CONSTRUCTOR).getDepsObjcProvider(); + // Do not remove SDK_FRAMEWORK values in avoid_deps. + assertThat(provider.get(ObjcProvider.SDK_FRAMEWORK)) + .containsAllOf(new SdkFramework("AvoidSDK"), new SdkFramework("BaseSDK")); + } + @Test public void testNoSrcs() throws Exception { scratch.file("package/BUILD", @@ -167,7 +199,7 @@ public void testWatchSimulatorDepCompile() throws Exception { getGeneratingAction(getFirstArtifactEndingWith(linkAction.getInputs(), "libobjcLib.a")); assertAppleSdkPlatformEnv(objcLibCompileAction, "WatchSimulator"); - assertThat(objcLibCompileAction.getArguments()).containsAtLeast("-arch_only", "i386").inOrder(); + assertThat(objcLibCompileAction.getArguments()).containsAllOf("-arch_only", "i386").inOrder(); } @Test @@ -222,7 +254,7 @@ public void testWatchSimulatorLipoAction() throws Exception { assertContainsSublist(action.getArguments(), ImmutableList.of( MOCK_XCRUNWRAPPER_EXECUTABLE_PATH, LIPO, "-create")); - assertThat(action.getArguments()).containsAtLeast(armv7kBin, i386Bin); + assertThat(action.getArguments()).containsAllOf(armv7kBin, i386Bin); assertContainsSublist(action.getArguments(), ImmutableList.of( "-o", execPathEndingWith(action.getOutputs(), "x_lipo.a"))); @@ -447,7 +479,7 @@ public void testWatchSimulatorLinkAction() throws Exception { assertAppleSdkPlatformEnv(linkAction, "WatchSimulator"); assertThat(normalizeBashArgs(linkAction.getArguments())) - .containsAtLeast("-arch_only", "i386") + .containsAllOf("-arch_only", "i386") .inOrder(); } @@ -484,8 +516,8 @@ public void testAvoidDepsObjects() throws Exception { "objc_library(name = 'avoidLib', srcs = [ 'c.m' ])"); CommandAction action = linkLibAction("//package:test"); - assertThat(Artifact.toRootRelativePaths(action.getInputs())) - .containsAtLeast("package/libobjcLib.a", "package/libbaseLib.a"); + assertThat(Artifact.toRootRelativePaths(action.getInputs())).containsAllOf( + "package/libobjcLib.a", "package/libbaseLib.a"); assertThat(Artifact.toRootRelativePaths(action.getInputs())).doesNotContain( "package/libavoidLib.a"); } @@ -641,7 +673,9 @@ public void testAppleStaticLibraryProvider() throws Exception { " dep_provider = ctx.attr.proxy[apple_common.AppleStaticLibrary]", " my_provider = apple_common.AppleStaticLibrary(archive = dep_provider.archive,", " objc = dep_provider.objc)", - " return [my_provider]", + " return struct(", + " providers = [my_provider]", + " )", "", "skylark_static_lib = rule(", " implementation = skylark_static_lib_impl,", @@ -679,7 +713,9 @@ public void testAppleStaticLibraryProvider_invalidArgs() throws Exception { " dep_provider = ctx.attr.proxy[apple_common.AppleStaticLibrary]", " my_provider = apple_common.AppleStaticLibrary(archive = dep_provider.archive,", " objc = dep_provider.objc, foo = 'bar')", - " return [my_provider]", + " return struct(", + " providers = [my_provider]", + " )", "", "skylark_static_lib = rule(", " implementation = skylark_static_lib_impl,", diff --git a/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryTest.java b/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryTest.java index 6810fd4ca9d..3675f2da7c4 100644 --- a/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryTest.java +++ b/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryTest.java @@ -518,11 +518,9 @@ public void testArchivesPrecompiledObjectFiles() throws Exception { } @Test - public void testCompileWithFrameworkImportsIncludesFlagsAndInputArtifactsPreCleanup() - throws Exception { + public void testCompileWithFrameworkImportsIncludesFlagsAndInputArtifacts() throws Exception { useConfiguration("--crosstool_top=" + MockObjcSupport.DEFAULT_OSX_CROSSTOOL); - setSkylarkSemanticsOptions("--incompatible_objc_framework_cleanup=false"); - addBinWithTransitiveDepOnFrameworkImport(false); + addBinWithTransitiveDepOnFrameworkImport(); CommandAction compileAction = compileAction("//lib:lib", "a.o"); assertThat(compileAction.getArguments()).doesNotContain("-framework"); @@ -535,17 +533,6 @@ public void testCompileWithFrameworkImportsIncludesFlagsAndInputArtifactsPreClea getSourceArtifact("fx/fx2.framework/d")); } - @Test - public void testCompileWithFrameworkImportsIncludesFlagsPostCleanup() throws Exception { - useConfiguration("--crosstool_top=" + MockObjcSupport.DEFAULT_OSX_CROSSTOOL); - setSkylarkSemanticsOptions("--incompatible_objc_framework_cleanup=true"); - addBinWithTransitiveDepOnFrameworkImport(true); - CommandAction compileAction = compileAction("//lib:lib", "a.o"); - - assertThat(compileAction.getArguments()).doesNotContain("-framework"); - assertThat(Joiner.on("").join(compileAction.getArguments())).contains("-Ffx"); - } - @Test public void testPrecompiledHeaders() throws Exception { useConfiguration("--crosstool_top=" + MockObjcSupport.DEFAULT_OSX_CROSSTOOL); diff --git a/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcRuleTestCase.java b/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcRuleTestCase.java index f9b6ae20918..8b0535608be 100644 --- a/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcRuleTestCase.java +++ b/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcRuleTestCase.java @@ -470,21 +470,15 @@ protected void assertRequiresDarwin(ExecutionInfoSpecifier action) { assertThat(action.getExecutionInfo()).containsKey(ExecutionRequirements.REQUIRES_DARWIN); } - protected ConfiguredTarget addBinWithTransitiveDepOnFrameworkImport(boolean cleanup) - throws Exception { - ConfiguredTarget lib; - if (!cleanup) { - lib = addLibWithDepOnFrameworkImportPreCleanup(); - } else { - lib = addLibWithDepOnFrameworkImportPostCleanup(); - } + protected ConfiguredTarget addBinWithTransitiveDepOnFrameworkImport() throws Exception { + ConfiguredTarget lib = addLibWithDepOnFrameworkImport(); return createBinaryTargetWriter("//bin:bin") .setList("deps", lib.getLabel().toString()) .write(); } - private ConfiguredTarget addLibWithDepOnFrameworkImportPreCleanup() throws Exception { + protected ConfiguredTarget addLibWithDepOnFrameworkImport() throws Exception { scratch.file( "fx/defs.bzl", "def _custom_static_framework_import_impl(ctx):", @@ -511,29 +505,6 @@ private ConfiguredTarget addLibWithDepOnFrameworkImportPreCleanup() throws Excep .write(); } - private ConfiguredTarget addLibWithDepOnFrameworkImportPostCleanup() throws Exception { - scratch.file( - "fx/defs.bzl", - "def _custom_static_framework_import_impl(ctx):", - " return [apple_common.new_objc_provider(", - " framework_search_paths=depset(ctx.attr.framework_search_paths))]", - "custom_static_framework_import = rule(", - " _custom_static_framework_import_impl,", - " attrs={'framework_search_paths': attr.string_list()},", - ")"); - scratch.file( - "fx/BUILD", - "load(':defs.bzl', 'custom_static_framework_import')", - "custom_static_framework_import(", - " name = 'fx',", - " framework_search_paths = ['fx/fx1.framework', 'fx/fx2.framework'],", - ")"); - return createLibraryTargetWriter("//lib:lib") - .setAndCreateFiles("srcs", "a.m", "b.m", "private.h") - .setList("deps", "//fx:fx") - .write(); - } - protected CommandAction compileAction(String ownerLabel, String objFileName) throws Exception { Action archiveAction = archiveAction(ownerLabel); return (CommandAction) @@ -865,8 +836,8 @@ protected void checkProtoBundlingWithTargetsWithNoDeps(RuleType ruleType) throws assertThat(protoProvider).isNotNull(); } - protected void checkFrameworkDepLinkFlags( - RuleType ruleType, ExtraLinkArgs extraLinkArgs, boolean cleanup) throws Exception { + protected void checkFrameworkDepLinkFlags(RuleType ruleType, + ExtraLinkArgs extraLinkArgs) throws Exception { scratch.file( "libs/defs.bzl", "def _custom_static_framework_import_impl(ctx):", @@ -890,12 +861,6 @@ protected void checkFrameworkDepLinkFlags( " link_inputs = glob(['buzzbuzz.framework/*']),", ")"); - if (!cleanup) { - setSkylarkSemanticsOptions("--incompatible_objc_framework_cleanup=true"); - } else { - setSkylarkSemanticsOptions("--incompatible_objc_framework_cleanup=false"); - } - ruleType.scratchTarget(scratch, "deps", "['//libs:objc_lib']"); CommandAction linkAction = linkAction("//x:x"); @@ -1593,7 +1558,11 @@ protected void checkMinimumOs_invalid_tooManyComponents(RuleType ruleType) throw ruleType.target(scratch, "x", "x", "minimum_os_version", "'4.3.1'")); } - private void checkDylibDependenciesSetupFrameworkPreCleanup() throws Exception { + protected void checkDylibDependencies(RuleType ruleType, + ExtraLinkArgs extraLinkArgs) throws Exception { + ruleType.scratchTarget(scratch, + "dylibs", "['//fx:framework_import']"); + scratch.file( "fx/defs.bzl", "def _custom_dynamic_framework_import_impl(ctx):", @@ -1615,43 +1584,6 @@ private void checkDylibDependenciesSetupFrameworkPreCleanup() throws Exception { " name = 'framework_import',", " link_inputs = glob(['MyFramework.framework/*']),", ")"); - } - - private void checkDylibDependenciesSetupFrameworkPostCleanup() throws Exception { - scratch.file( - "fx/defs.bzl", - "def _custom_dynamic_framework_import_impl(ctx):", - " return [", - " apple_common.new_objc_provider(", - " dynamic_framework_file=depset(ctx.files.link_inputs)),", - " apple_common.new_dynamic_framework_provider(objc=apple_common.new_objc_provider()),", - " ]", - "custom_dynamic_framework_import = rule(", - " _custom_dynamic_framework_import_impl,", - " attrs={'link_inputs': attr.label_list(allow_files=True)},", - ")"); - scratch.file("fx/MyFramework.framework/MyFramework"); - scratch.file( - "fx/BUILD", - "load(':defs.bzl', 'custom_dynamic_framework_import')", - "custom_dynamic_framework_import(", - " name = 'framework_import',", - " link_inputs = ['MyFramework.framework/MyFramework'],", - ")"); - } - - protected void checkDylibDependencies( - RuleType ruleType, ExtraLinkArgs extraLinkArgs, boolean cleanup) throws Exception { - ruleType.scratchTarget(scratch, "dylibs", "['//fx:framework_import']"); - - if (!cleanup) { - checkDylibDependenciesSetupFrameworkPreCleanup(); - setSkylarkSemanticsOptions("--incompatible_objc_framework_cleanup=false"); - } else { - checkDylibDependenciesSetupFrameworkPostCleanup(); - setSkylarkSemanticsOptions("--incompatible_objc_framework_cleanup=true"); - } - useConfiguration("--ios_multi_cpus=i386,x86_64"); Action lipobinAction = lipoBinAction("//x:x"); diff --git a/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcSkylarkTest.java b/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcSkylarkTest.java index 67c168ee124..5b6cc48503b 100644 --- a/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcSkylarkTest.java +++ b/dataset/GitHub_Java/bazelbuild.bazel/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcSkylarkTest.java @@ -1590,168 +1590,4 @@ private void checkSkylarkRunMemleaksWithExpectedValue(boolean expectedValue) thr boolean runMemleaks = (boolean) skylarkTarget.get("run_memleaks"); assertThat(runMemleaks).isEqualTo(expectedValue); } - - private void addDummyObjcProviderRule(String name) throws Exception { - scratch.file( - "fx/defs.bzl", - "def _my_rule_impl(ctx):", - " objc = apple_common.new_objc_provider()", - String.format(" return struct(names=objc.%s)", name), - "my_rule = rule(implementation = _my_rule_impl,", - " attrs = {})"); - scratch.file("fx/BUILD", "load(':defs.bzl', 'my_rule')", "my_rule(name = 'lib')"); - } - - private void testObjcProviderHas(String name) throws Exception { - addDummyObjcProviderRule(name); - assertThat(view.hasErrors(getConfiguredTarget("//fx:lib"))).isFalse(); - } - - private void testObjcProviderDoesNotHave(String name) throws Exception { - addDummyObjcProviderRule(name); - try { - getConfiguredTarget("//fx:lib"); - fail("Should throw AssertionError"); - } catch (AssertionError e) { - if (name.endsWith("()")) { - assertThat(e).hasMessageThat().contains("'ObjcProvider' has no method " + name); - } else { - assertThat(e).hasMessageThat().contains("'ObjcProvider' has no field '" + name + "'"); - } - } - } - - @Test - public void testObjcProviderDynamicFrameworkDirPreCleanup() throws Exception { - setSkylarkSemanticsOptions("--incompatible_objc_framework_cleanup=false"); - testObjcProviderHas("dynamic_framework_dir"); - } - - @Test - public void testObjcProviderFrameworkDirPreCleanup() throws Exception { - setSkylarkSemanticsOptions("--incompatible_objc_framework_cleanup=false"); - testObjcProviderHas("framework_dir"); - } - - @Test - public void testObjcProviderDynamicFrameworkNamesPreCleanup() throws Exception { - setSkylarkSemanticsOptions("--incompatible_objc_framework_cleanup=false"); - testObjcProviderDoesNotHave("dynamic_framework_names"); - } - - @Test - public void testObjcProviderDynamicFrameworkPathsPreCleanup() throws Exception { - setSkylarkSemanticsOptions("--incompatible_objc_framework_cleanup=false"); - testObjcProviderDoesNotHave("dynamic_framework_paths"); - } - - @Test - public void testObjcProviderStaticFrameworkNamesPreCleanup() throws Exception { - setSkylarkSemanticsOptions("--incompatible_objc_framework_cleanup=false"); - testObjcProviderDoesNotHave("static_framework_names"); - } - - @Test - public void testObjcProviderStaticFrameworkPathsPreCleanup() throws Exception { - setSkylarkSemanticsOptions("--incompatible_objc_framework_cleanup=false"); - testObjcProviderDoesNotHave("static_framework_paths"); - } - - @Test - public void testObjcProviderDynamicFrameworkDirPostCleanup() throws Exception { - setSkylarkSemanticsOptions("--incompatible_objc_framework_cleanup=true"); - testObjcProviderDoesNotHave("dynamic_framework_dir"); - } - - @Test - public void testObjcProviderFrameworkDirPostCleanup() throws Exception { - setSkylarkSemanticsOptions("--incompatible_objc_framework_cleanup=true"); - testObjcProviderDoesNotHave("framework_dir"); - } - - @Test - public void testObjcProviderDynamicFrameworkNamesPostCleanup() throws Exception { - setSkylarkSemanticsOptions("--incompatible_objc_framework_cleanup=true"); - testObjcProviderHas("dynamic_framework_names"); - } - - @Test - public void testObjcProviderDynamicFrameworkPathsPostCleanup() throws Exception { - setSkylarkSemanticsOptions("--incompatible_objc_framework_cleanup=true"); - testObjcProviderHas("dynamic_framework_paths"); - } - - @Test - public void testObjcProviderStaticFrameworkNamesPostCleanup() throws Exception { - setSkylarkSemanticsOptions("--incompatible_objc_framework_cleanup=true"); - testObjcProviderHas("static_framework_names"); - } - - @Test - public void testObjcProviderStaticFrameworkPathsPostCleanup() throws Exception { - setSkylarkSemanticsOptions("--incompatible_objc_framework_cleanup=true"); - testObjcProviderHas("static_framework_paths"); - } - - @Test - public void testStaticFrameworkApiPostCleanup() throws Exception { - setSkylarkSemanticsOptions("--incompatible_objc_framework_cleanup=true"); - - scratch.file( - "fx/defs.bzl", - "def _custom_static_framework_import_impl(ctx):", - " return [apple_common.new_objc_provider(", - " static_framework_file=depset(ctx.files.link_inputs))]", - "custom_static_framework_import = rule(", - " _custom_static_framework_import_impl,", - " attrs={'link_inputs': attr.label_list(allow_files=True)},", - ")"); - scratch.file("fx/fx1.framework/fx1"); - scratch.file("fx/fx2.framework/fx2"); - scratch.file( - "fx/BUILD", - "load(':defs.bzl', 'custom_static_framework_import')", - "custom_static_framework_import(", - " name = 'framework',", - " link_inputs = ['fx1.framework/fx1', 'fx2.framework/fx2'],", - ")"); - - ConfiguredTarget framework = getConfiguredTarget("//fx:framework"); - ObjcProvider objc = framework.get(ObjcProvider.SKYLARK_CONSTRUCTOR); - assertThat(Artifact.toRootRelativePaths(objc.staticFrameworkFile())) - .containsExactly("fx/fx1.framework/fx1", "fx/fx2.framework/fx2"); - assertThat(objc.staticFrameworkNames()).containsExactly("fx1", "fx2"); - assertThat(objc.staticFrameworkPaths()).containsExactly("fx"); - } - - @Test - public void testDynamicFrameworkApiPostCleanup() throws Exception { - setSkylarkSemanticsOptions("--incompatible_objc_framework_cleanup=true"); - - scratch.file( - "fx/defs.bzl", - "def _custom_dynamic_framework_import_impl(ctx):", - " return [apple_common.new_objc_provider(", - " dynamic_framework_file=depset(ctx.files.link_inputs))]", - "custom_dynamic_framework_import = rule(", - " _custom_dynamic_framework_import_impl,", - " attrs={'link_inputs': attr.label_list(allow_files=True)},", - ")"); - scratch.file("fx/fx1.framework/fx1"); - scratch.file("fx/fx2.framework/fx2"); - scratch.file( - "fx/BUILD", - "load(':defs.bzl', 'custom_dynamic_framework_import')", - "custom_dynamic_framework_import(", - " name = 'framework',", - " link_inputs = ['fx1.framework/fx1', 'fx2.framework/fx2'],", - ")"); - - ConfiguredTarget framework = getConfiguredTarget("//fx:framework"); - ObjcProvider objc = framework.get(ObjcProvider.SKYLARK_CONSTRUCTOR); - assertThat(Artifact.toRootRelativePaths(objc.dynamicFrameworkFile())) - .containsExactly("fx/fx1.framework/fx1", "fx/fx2.framework/fx2"); - assertThat(objc.dynamicFrameworkNames()).containsExactly("fx1", "fx2"); - assertThat(objc.dynamicFrameworkPaths()).containsExactly("fx"); - } }