From 12f82746fd0fc77a35524e002689ab90b7d026dd Mon Sep 17 00:00:00 2001 From: ajmichael Date: Fri, 26 Jan 2018 13:02:28 -0800 Subject: Support Android testing with Skylark-defined device rules. Do this by exposing DeviceBrokerInfo and a constructor for it in android_common. See AndroidInstrumentationTestTest for an example. RELNOTES: None PiperOrigin-RevId: 183432674 --- .../build/lib/rules/android/AndroidDevice.java | 3 +- .../rules/android/AndroidInstrumentationTest.java | 2 +- .../android/AndroidInstrumentationTestRule.java | 2 +- .../lib/rules/android/AndroidSkylarkCommon.java | 15 +++++++ .../build/lib/rules/android/DeviceBrokerInfo.java | 49 ++++++++++++++++++++++ .../rules/android/DeviceBrokerTypeProvider.java | 36 ---------------- 6 files changed, 67 insertions(+), 40 deletions(-) create mode 100644 src/main/java/com/google/devtools/build/lib/rules/android/DeviceBrokerInfo.java delete mode 100644 src/main/java/com/google/devtools/build/lib/rules/android/DeviceBrokerTypeProvider.java (limited to 'src/main/java/com/google/devtools/build/lib') diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidDevice.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidDevice.java index 057739510b..8f44097450 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidDevice.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidDevice.java @@ -132,8 +132,7 @@ public class AndroidDevice implements RuleConfiguredTargetFactory { .setRunfilesSupport(runfilesSupport, executable) .addFilesToRun(extraFilesToRun) .addNativeDeclaredProvider(new ExecutionInfo(executionInfo)) - .addProvider( - DeviceBrokerTypeProvider.class, new DeviceBrokerTypeProvider(DEVICE_BROKER_TYPE)) + .addNativeDeclaredProvider(new DeviceBrokerInfo(DEVICE_BROKER_TYPE)) .addProvider( Dex2OatProvider.class, new Dex2OatProvider(cloudDex2oatEnabled)) .build(); diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentationTest.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentationTest.java index 7c68827089..64a7cf04b2 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentationTest.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentationTest.java @@ -300,7 +300,7 @@ public class AndroidInstrumentationTest implements RuleConfiguredTargetFactory { private static String getDeviceBrokerType(RuleContext ruleContext) { return ruleContext - .getPrerequisite("target_device", Mode.HOST, DeviceBrokerTypeProvider.class) + .getPrerequisite("target_device", Mode.HOST, DeviceBrokerInfo.PROVIDER) .getDeviceBrokerType(); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentationTestRule.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentationTestRule.java index 07908ad1b1..9dfae4b389 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentationTestRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentationTestRule.java @@ -45,7 +45,7 @@ public class AndroidInstrumentationTestRule implements RuleDefinition { .exec() .cfg(HostTransition.INSTANCE) .allowedFileTypes(FileTypeSet.NO_FILE) - .allowedRuleClasses("android_device")) + .mandatoryProviders(DeviceBrokerInfo.PROVIDER.id())) .add( attr("support_apks", LABEL_LIST) .allowedFileTypes(AndroidRuleClasses.APK) diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSkylarkCommon.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSkylarkCommon.java index be66ad689c..6cd0a855d9 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSkylarkCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSkylarkCommon.java @@ -15,6 +15,7 @@ package com.google.devtools.build.lib.rules.android; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.config.transitions.SplitTransition; +import com.google.devtools.build.lib.skylarkinterface.Param; import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; import com.google.devtools.build.lib.vfs.PathFragment; @@ -26,6 +27,20 @@ import com.google.devtools.build.lib.vfs.PathFragment; ) public class AndroidSkylarkCommon { + @SkylarkCallable( + name = "create_device_broker_info", + doc = "Create a device broker info", + parameters = { + @Param( + name = "type", + type = String.class + ) + } + ) + public DeviceBrokerInfo createDeviceBrokerInfo(String deviceBrokerType) { + return new DeviceBrokerInfo(deviceBrokerType); + } + @SkylarkCallable( name = "resource_source_directory", allowReturnNones = true, diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/DeviceBrokerInfo.java b/src/main/java/com/google/devtools/build/lib/rules/android/DeviceBrokerInfo.java new file mode 100644 index 0000000000..9d05cd274b --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/rules/android/DeviceBrokerInfo.java @@ -0,0 +1,49 @@ +// Copyright 2018 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.lib.rules.android; + +import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; +import com.google.devtools.build.lib.packages.NativeInfo; +import com.google.devtools.build.lib.packages.NativeProvider; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory; + +/** Supplies the device broker type string, passed to the Android test runtime. */ +@SkylarkModule( + name = "DeviceBrokerInfo", + doc = "Information about the device broker", + category = SkylarkModuleCategory.PROVIDER +) +@Immutable +public final class DeviceBrokerInfo extends NativeInfo { + + private static final String SKYLARK_NAME = "DeviceBrokerInfo"; + public static final NativeProvider PROVIDER = + new NativeProvider(DeviceBrokerInfo.class, SKYLARK_NAME) {}; + + private final String deviceBrokerType; + + public DeviceBrokerInfo(String deviceBrokerType) { + super(PROVIDER); + this.deviceBrokerType = deviceBrokerType; + } + + /** + * Returns the type of device broker that is appropriate to use to interact with devices obtained + * by this artifact. + */ + public String getDeviceBrokerType() { + return deviceBrokerType; + } +} diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/DeviceBrokerTypeProvider.java b/src/main/java/com/google/devtools/build/lib/rules/android/DeviceBrokerTypeProvider.java deleted file mode 100644 index 7a0b926741..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/android/DeviceBrokerTypeProvider.java +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2017 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package com.google.devtools.build.lib.rules.android; - -import com.google.devtools.build.lib.analysis.TransitiveInfoProvider; -import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; - -/** Supplies the device broker type string, passed to the android_test runtime. */ -@Immutable -public final class DeviceBrokerTypeProvider implements TransitiveInfoProvider { - - private final String deviceBrokerType; - - public DeviceBrokerTypeProvider(String deviceBrokerType) { - this.deviceBrokerType = deviceBrokerType; - } - - /** - * Returns the type of device broker that is appropriate to use to interact with devices obtained - * by this artifact. - */ - public String getDeviceBrokerType() { - return deviceBrokerType; - } -} -- cgit v1.2.3