diff options
author | 2018-06-13 14:24:42 -0700 | |
---|---|---|
committer | 2018-06-13 14:25:50 -0700 | |
commit | 07b2ea405c1ee3b70d3dea153338f897ba522ee0 (patch) | |
tree | f655ed1a4af56269d6d65ee0b69517afb8354d9d /src | |
parent | e253f83306d155f9241493c1a8ca932760fd85a3 (diff) |
* Update apple_common.link_multi_arch_binary to return all of its providers and output groups.
* Make ctx a keyword argument so that we can more easily add more parameters in the future and eventually remove ctx.
PiperOrigin-RevId: 200453550
Diffstat (limited to 'src')
3 files changed, 51 insertions, 14 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleSkylarkCommon.java b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleSkylarkCommon.java index 9e4daaddb1..690bd6970a 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleSkylarkCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleSkylarkCommon.java @@ -17,6 +17,7 @@ package com.google.devtools.build.lib.rules.objc; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; +import com.google.common.collect.Maps; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException; import com.google.devtools.build.lib.analysis.RuleContext; @@ -24,12 +25,14 @@ import com.google.devtools.build.lib.analysis.skylark.SkylarkRuleContext; import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.collect.nestedset.Order; +import com.google.devtools.build.lib.events.Location; import com.google.devtools.build.lib.packages.Attribute.SplitTransitionProvider; import com.google.devtools.build.lib.packages.Info; -import com.google.devtools.build.lib.packages.NativeInfo; +import com.google.devtools.build.lib.packages.NativeProvider; import com.google.devtools.build.lib.packages.Provider; import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException; import com.google.devtools.build.lib.packages.SkylarkAspect; +import com.google.devtools.build.lib.packages.SkylarkInfo; import com.google.devtools.build.lib.rules.apple.AppleConfiguration; import com.google.devtools.build.lib.rules.apple.ApplePlatform; import com.google.devtools.build.lib.rules.apple.ApplePlatform.PlatformType; @@ -41,6 +44,7 @@ import com.google.devtools.build.lib.rules.objc.AppleBinary.AppleBinaryOutput; import com.google.devtools.build.lib.rules.objc.ObjcProvider.Key; import com.google.devtools.build.lib.skylarkbuildapi.SkylarkRuleContextApi; import com.google.devtools.build.lib.skylarkbuildapi.apple.AppleCommonApi; +import com.google.devtools.build.lib.skylarkinterface.SkylarkValue; import com.google.devtools.build.lib.syntax.Environment; import com.google.devtools.build.lib.syntax.EvalException; import com.google.devtools.build.lib.syntax.Runtime; @@ -230,13 +234,14 @@ public class AppleSkylarkCommon } @Override - public NativeInfo linkMultiArchBinary(SkylarkRuleContextApi skylarkRuleContextApi) + public Info linkMultiArchBinary( + SkylarkRuleContextApi skylarkRuleContextApi, Environment environment) throws EvalException, InterruptedException { SkylarkRuleContext skylarkRuleContext = (SkylarkRuleContext) skylarkRuleContextApi; try { RuleContext ruleContext = skylarkRuleContext.getRuleContext(); AppleBinaryOutput appleBinaryOutput = AppleBinary.linkMultiArchBinary(ruleContext); - return appleBinaryOutput.getBinaryInfoProvider(); + return createAppleBinaryOutputSkylarkStruct(appleBinaryOutput, environment); } catch (RuleErrorException | ActionConflictException exception) { throw new EvalException(null, exception); } @@ -252,6 +257,27 @@ public class AppleSkylarkCommon return objcProtoAspect; } + /** + * Creates a Skylark struct that contains the results of the {@code link_multi_arch_binary} + * function. + */ + private Info createAppleBinaryOutputSkylarkStruct( + AppleBinaryOutput output, Environment environment) { + Provider constructor = new NativeProvider<Info>(Info.class, "apple_binary_output") {}; + // We have to transform the output group dictionary into one that contains SkylarkValues instead + // of plain NestedSets because the Skylark caller may want to return this directly from their + // implementation function. + Map<String, SkylarkValue> outputGroups = + Maps.transformValues(output.getOutputGroups(), v -> SkylarkNestedSet.of(Artifact.class, v)); + + ImmutableMap<String, Object> fields = + ImmutableMap.of( + "binary_provider", output.getBinaryInfoProvider(), + "debug_outputs_provider", output.getDebugOutputsProvider(), + "output_groups", SkylarkDict.copyOf(environment, outputGroups)); + return SkylarkInfo.createSchemaless(constructor, fields, Location.BUILTIN); + } + static { SkylarkSignatureProcessor.configureSkylarkFunctions(AppleSkylarkCommon.class); } diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/AppleCommonApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/AppleCommonApi.java index 6f547e4bf4..2499ec4f3b 100644 --- a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/AppleCommonApi.java +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/apple/AppleCommonApi.java @@ -336,15 +336,25 @@ public interface AppleCommonApi<FileApiT extends FileApi, @SkylarkCallable( name = "link_multi_arch_binary", - doc = "Links a (potentially multi-architecture) binary targeting Apple platforms. This " - + "method comprises a bulk of the logic of the <code>apple_binary</code> rule, and is " - + "exposed as an API to iterate on migration of <code>apple_binary</code> to skylark.\n" - + "<p>This API is <b>highly experimental</b> and subject to change at any time. Do not " - + "depend on the stability of this function at this time.", - mandatoryPositionals = 1 // The SkylarkRuleContext. - ) + doc = + "Links a (potentially multi-architecture) binary targeting Apple platforms. This " + + "method comprises a bulk of the logic of the <code>apple_binary</code> rule, and " + + "is exposed as an API to iterate on migration of <code>apple_binary</code> to " + + "Skylark.\n" + + "<p>This API is <b>highly experimental</b> and subject to change at any time. Do " + + "not depend on the stability of this function at this time.", + parameters = { + @Param( + name = "ctx", + type = SkylarkRuleContextApi.class, + named = true, + positional = false, + doc = "The Skylark rule context."), + }, + useEnvironment = true) // TODO(b/70937317): Iterate on, improve, and solidify this API. - public StructApi linkMultiArchBinary(SkylarkRuleContextApi skylarkRuleContext) + public StructApi linkMultiArchBinary( + SkylarkRuleContextApi skylarkRuleContext, Environment environment) throws EvalException, InterruptedException; @SkylarkCallable( diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/AppleBinarySkylarkApiTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/AppleBinarySkylarkApiTest.java index 7cc75c1766..d6e1096740 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/AppleBinarySkylarkApiTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/objc/AppleBinarySkylarkApiTest.java @@ -57,10 +57,11 @@ public class AppleBinarySkylarkApiTest extends AppleBinaryTest { scratch.file( "test_skylark/apple_binary_skylark.bzl", "def apple_binary_skylark_impl(ctx):", - " link_provider = apple_common.link_multi_arch_binary(ctx)", + " binary_output = apple_common.link_multi_arch_binary(ctx=ctx)", " return struct(", - " files=depset([link_provider.binary]),", - " providers=[link_provider],", + " files=depset([binary_output.binary_provider.binary]),", + " output_groups=binary_output.output_groups,", + " providers=[binary_output.binary_provider, binary_output.debug_outputs_provider],", " )", "apple_binary_skylark = rule(", " apple_binary_skylark_impl,", |