Skip to content

Commit cb6aae4

Browse files
authored
Propagate instrumentation runner arguments to FTL (firebase#2379)
1 parent 7055d2a commit cb6aae4

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

buildSrc/src/main/java/com/google/firebase/gradle/plugins/FirebaseLibraryPlugin.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ public void apply(Project project) {
8585
}
8686

8787
setupApiInformationAnalysis(project, android);
88-
89-
android.testServer(new FirebaseTestServer(project, firebaseLibrary.testLab));
88+
android.testServer(new FirebaseTestServer(project, firebaseLibrary.testLab, android));
9089

9190
setupStaticAnalysis(project, firebaseLibrary);
9291

buildSrc/src/main/java/com/google/firebase/gradle/plugins/ci/device/FirebaseTestLabPlugin.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
package com.google.firebase.gradle.plugins.ci.device;
1616

17-
import com.android.build.gradle.BaseExtension;
18-
17+
import com.android.build.gradle.TestedExtension;
1918
import org.gradle.api.Plugin;
2019
import org.gradle.api.Project;
2120

@@ -34,7 +33,7 @@ public void apply(Project project) {
3433
.getExtensions()
3534
.create("firebaseTestLab", FirebaseTestLabExtension.class, project.getObjects());
3635
extension.setEnabled(true);
37-
BaseExtension android = (BaseExtension) project.getExtensions().getByName("android");
38-
android.testServer(new FirebaseTestServer(project, extension));
36+
TestedExtension android = (TestedExtension) project.getExtensions().getByName("android");
37+
android.testServer(new FirebaseTestServer(project, extension, android));
3938
}
4039
}

buildSrc/src/main/java/com/google/firebase/gradle/plugins/ci/device/FirebaseTestServer.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@
1414

1515
package com.google.firebase.gradle.plugins.ci.device;
1616

17+
import com.android.build.gradle.TestedExtension;
1718
import com.android.builder.testing.api.TestServer;
1819
import com.google.common.collect.ImmutableList;
1920
import com.google.firebase.gradle.plugins.ci.Environment;
2021
import java.io.File;
2122
import java.nio.file.Paths;
23+
import java.util.HashMap;
24+
import java.util.Map;
2225
import java.util.Optional;
2326
import java.util.Random;
2427
import java.util.stream.Collectors;
@@ -29,11 +32,22 @@ public class FirebaseTestServer extends TestServer {
2932
private final Project project;
3033
private final FirebaseTestLabExtension extension;
3134
private final Random random;
35+
private final Map<String, Map<String, String>> instrumentationArgs;
3236

33-
public FirebaseTestServer(Project project, FirebaseTestLabExtension extension) {
37+
public FirebaseTestServer(
38+
Project project, FirebaseTestLabExtension extension, TestedExtension android) {
3439
this.project = project;
3540
this.extension = extension;
41+
this.instrumentationArgs = new HashMap<>();
3642
this.random = new Random(System.currentTimeMillis());
43+
44+
android
45+
.getTestVariants()
46+
.all(
47+
variant ->
48+
instrumentationArgs.put(
49+
variant.getName(),
50+
variant.getMergedFlavor().getTestInstrumentationRunnerArguments()));
3751
}
3852

3953
@Override
@@ -43,6 +57,8 @@ public String getName() {
4357

4458
@Override
4559
public void uploadApks(String variantName, File testApk, File testedApk) {
60+
61+
Map<String, String> currentInstrumentationArgs = instrumentationArgs.get(variantName);
4662
// test lab requires an "app" apk, so we give an empty apk to it.
4763
String testedApkPath =
4864
testedApk != null
@@ -85,6 +101,14 @@ public void uploadApks(String variantName, File testApk, File testedApk) {
85101
"--results-dir",
86102
Paths.get(dir, project.getPath() + "_" + random.nextLong()).toString()));
87103

104+
if (currentInstrumentationArgs != null) {
105+
String variablesArg =
106+
currentInstrumentationArgs.entrySet().stream()
107+
.map(entry -> entry.getKey() + "=" + entry.getValue())
108+
.collect(Collectors.joining(","));
109+
args.add("--environment-variables", variablesArg);
110+
}
111+
88112
project.exec(
89113
spec -> {
90114
spec.commandLine(args.build());

0 commit comments

Comments
 (0)