mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Move gradle_non_android_plugin_test from its own test builders into tools integration.shard (#80161)
This commit is contained in:
parent
92dc007eeb
commit
ed5b8febf2
@ -2,112 +2,13 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_devicelab/framework/framework.dart';
|
||||
import 'package:flutter_devicelab/framework/task_result.dart';
|
||||
import 'package:flutter_devicelab/framework/utils.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
/// Tests that a flutter app that depends on a non-Android plugin
|
||||
/// (an iOS only plugin in this case) can still build for Android.
|
||||
Future<void> main() async {
|
||||
await task(() async {
|
||||
|
||||
section('Find Java');
|
||||
|
||||
final String javaHome = await findJavaHome();
|
||||
if (javaHome == null)
|
||||
return TaskResult.failure('Could not find Java');
|
||||
print('\nUsing JAVA_HOME=$javaHome');
|
||||
|
||||
section('Create Flutter plugin project');
|
||||
|
||||
final Directory tempDir = Directory.systemTemp.createTempSync('flutter_plugin_test.');
|
||||
final Directory projectDir = Directory(path.join(tempDir.path, 'ios_only'));
|
||||
try {
|
||||
await inDirectory(tempDir, () async {
|
||||
await flutter(
|
||||
'create',
|
||||
options: <String>[
|
||||
'--org', 'io.flutter.devicelab',
|
||||
'-t', 'plugin',
|
||||
'--platforms=ios,android',
|
||||
'ios_only',
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
section("Delete plugin's Android folder");
|
||||
|
||||
final File androidFolder = File(path.join(
|
||||
projectDir.path,
|
||||
'android',
|
||||
));
|
||||
androidFolder.deleteSync(recursive: true);
|
||||
|
||||
section('Update pubspec.yaml to iOS only plugin');
|
||||
final File pubspecFile = File(path.join(projectDir.path, 'pubspec.yaml'));
|
||||
final String pubspecString = pubspecFile.readAsStringSync();
|
||||
|
||||
final StringBuffer iosOnlyPubspec = StringBuffer();
|
||||
bool inAndroidSection = false;
|
||||
const String pluginPlatformIndentation = ' ';
|
||||
for (final String line in pubspecString.split('\n')) {
|
||||
// Skip everything in the Android section of the plugin platforms list.
|
||||
if (line.startsWith('${pluginPlatformIndentation}android:')) {
|
||||
inAndroidSection = true;
|
||||
continue;
|
||||
}
|
||||
if (inAndroidSection) {
|
||||
if (line.startsWith('$pluginPlatformIndentation ')) {
|
||||
continue;
|
||||
} else {
|
||||
inAndroidSection = false;
|
||||
}
|
||||
}
|
||||
iosOnlyPubspec.write('$line\n');
|
||||
}
|
||||
|
||||
pubspecFile.writeAsStringSync(iosOnlyPubspec.toString());
|
||||
|
||||
section('Build example APK');
|
||||
|
||||
final StringBuffer stderr = StringBuffer();
|
||||
|
||||
final Directory exampleDir = Directory(path.join(projectDir.path, 'example'));
|
||||
await inDirectory(exampleDir, () async {
|
||||
await evalFlutter(
|
||||
'build',
|
||||
options: <String>[
|
||||
'apk',
|
||||
'--target-platform', 'android-arm',
|
||||
'--verbose',
|
||||
],
|
||||
canFail: true,
|
||||
stderr: stderr,
|
||||
);
|
||||
});
|
||||
|
||||
section('Check that the example APK was built');
|
||||
|
||||
final String exampleAppApk = path.join(
|
||||
exampleDir.path,
|
||||
'build',
|
||||
'app',
|
||||
'outputs',
|
||||
'apk',
|
||||
'release',
|
||||
'app-release.apk',
|
||||
);
|
||||
if (!exists(File(exampleAppApk))) {
|
||||
return TaskResult.failure('Failed to build example app');
|
||||
}
|
||||
return TaskResult.success(null);
|
||||
} catch (e) {
|
||||
return TaskResult.failure(e.toString());
|
||||
} finally {
|
||||
rmTree(tempDir);
|
||||
}
|
||||
// TODO(jmagman): Remove once gradle_non_android_plugin_test builder can be deleted
|
||||
// when https://github.com/flutter/flutter/pull/80161 rolls to stable.
|
||||
return TaskResult.success(null);
|
||||
});
|
||||
}
|
||||
|
||||
@ -294,12 +294,6 @@
|
||||
"task_name": "linux_gradle_desugar_classes_test",
|
||||
"flaky": false
|
||||
},
|
||||
{
|
||||
"name": "Linux gradle_non_android_plugin_test",
|
||||
"repo": "flutter",
|
||||
"task_name": "linux_gradle_non_android_plugin_test",
|
||||
"flaky": false
|
||||
},
|
||||
{
|
||||
"name": "Linux gradle_plugin_bundle_test",
|
||||
"repo": "flutter",
|
||||
@ -858,12 +852,6 @@
|
||||
"task_name": "mac_framework_tests_widgets",
|
||||
"flaky": false
|
||||
},
|
||||
{
|
||||
"name": "Mac gradle_non_android_plugin_test",
|
||||
"repo": "flutter",
|
||||
"task_name": "mac_gradle_non_android_plugin_test",
|
||||
"flaky": false
|
||||
},
|
||||
{
|
||||
"name": "Mac gradle_plugin_bundle_test",
|
||||
"repo": "flutter",
|
||||
@ -1242,12 +1230,6 @@
|
||||
"task_name": "win_gradle_plugin_light_apk_test",
|
||||
"flaky": true
|
||||
},
|
||||
{
|
||||
"name": "Windows gradle_non_android_plugin_test",
|
||||
"repo": "flutter",
|
||||
"task_name": "win_gradle_non_android_plugin_test",
|
||||
"flaky": false
|
||||
},
|
||||
{
|
||||
"name": "Windows gradle_plugin_bundle_test",
|
||||
"repo": "flutter",
|
||||
|
||||
@ -130,13 +130,6 @@
|
||||
"enabled": true,
|
||||
"run_if": ["dev/**", "bin/**"]
|
||||
},
|
||||
{
|
||||
"name": "Linux gradle_non_android_plugin_test",
|
||||
"repo": "flutter",
|
||||
"task_name": "linux_gradle_non_android_plugin_test",
|
||||
"enabled": true,
|
||||
"run_if": ["dev/**", "packages/flutter_tools/**", "bin/**"]
|
||||
},
|
||||
{
|
||||
"name": "Linux gradle_plugin_bundle_test",
|
||||
"repo": "flutter",
|
||||
@ -468,13 +461,6 @@
|
||||
"bin/**"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Mac gradle_non_android_plugin_test",
|
||||
"repo": "flutter",
|
||||
"task_name": "mac_gradle_non_android_plugin_test",
|
||||
"enabled": true,
|
||||
"run_if": ["dev/**", "packages/flutter_tools/**", "bin/**"]
|
||||
},
|
||||
{
|
||||
"name": "Mac gradle_plugin_bundle_test",
|
||||
"repo": "flutter",
|
||||
@ -672,13 +658,6 @@
|
||||
"bin/"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Windows gradle_non_android_plugin_test",
|
||||
"repo": "flutter",
|
||||
"task_name": "win_gradle_non_android_plugin_test",
|
||||
"enabled": true,
|
||||
"run_if": ["dev/**", "packages/flutter_tools/**", "bin/**"]
|
||||
},
|
||||
{
|
||||
"name": "Windows gradle_plugin_bundle_test",
|
||||
"repo": "flutter",
|
||||
|
||||
@ -0,0 +1,95 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
import 'package:file/file.dart';
|
||||
import 'package:file_testing/file_testing.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
import 'test_utils.dart';
|
||||
|
||||
void main() {
|
||||
Directory tempDir;
|
||||
|
||||
setUp(() {
|
||||
tempDir = createResolvedTempDirectorySync('flutter_plugin_test.');
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
tryToDelete(tempDir);
|
||||
});
|
||||
|
||||
testUsingContext('flutter app that depends on a non-Android plugin can still build for Android', () {
|
||||
final String flutterRoot = getFlutterRoot();
|
||||
final String flutterBin = fileSystem.path.join(
|
||||
flutterRoot,
|
||||
'bin',
|
||||
'flutter',
|
||||
);
|
||||
processManager.runSync(<String>[
|
||||
flutterBin,
|
||||
...getLocalEngineArguments(),
|
||||
'create',
|
||||
'-t',
|
||||
'plugin',
|
||||
'--platforms=ios,android',
|
||||
'ios_only',
|
||||
], workingDirectory: tempDir.path);
|
||||
|
||||
// Delete plugin's Android folder
|
||||
final Directory projectRoot = tempDir.childDirectory('ios_only');
|
||||
projectRoot.childDirectory('android').deleteSync(recursive: true);
|
||||
|
||||
// Update pubspec.yaml to iOS only plugin
|
||||
final File pubspecFile = projectRoot.childFile('pubspec.yaml');
|
||||
final String pubspecString = pubspecFile.readAsStringSync();
|
||||
|
||||
final StringBuffer iosOnlyPubspec = StringBuffer();
|
||||
bool inAndroidSection = false;
|
||||
const String pluginPlatformIndentation = ' ';
|
||||
for (final String line in pubspecString.split('\n')) {
|
||||
// Skip everything in the Android section of the plugin platforms list.
|
||||
if (line.startsWith('${pluginPlatformIndentation}android:')) {
|
||||
inAndroidSection = true;
|
||||
continue;
|
||||
}
|
||||
if (inAndroidSection) {
|
||||
if (line.startsWith('$pluginPlatformIndentation ')) {
|
||||
continue;
|
||||
} else {
|
||||
inAndroidSection = false;
|
||||
}
|
||||
}
|
||||
iosOnlyPubspec.write('$line\n');
|
||||
}
|
||||
|
||||
pubspecFile.writeAsStringSync(iosOnlyPubspec.toString());
|
||||
|
||||
// Build example APK
|
||||
final Directory exampleDir = projectRoot.childDirectory('example');
|
||||
|
||||
processManager.runSync(<String>[
|
||||
flutterBin,
|
||||
...getLocalEngineArguments(),
|
||||
'build',
|
||||
'apk',
|
||||
'--target-platform',
|
||||
'android-arm',
|
||||
'--verbose',
|
||||
], workingDirectory: exampleDir.path);
|
||||
|
||||
final String exampleAppApk = fileSystem.path.join(
|
||||
exampleDir.path,
|
||||
'build',
|
||||
'app',
|
||||
'outputs',
|
||||
'apk',
|
||||
'release',
|
||||
'app-release.apk',
|
||||
);
|
||||
expect(fileSystem.file(exampleAppApk), exists);
|
||||
}, timeout: const Timeout(Duration(minutes: 5)));
|
||||
}
|
||||
@ -7,6 +7,7 @@
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
import 'test_utils.dart';
|
||||
|
||||
final String toolBackend = fileSystem.path.join(getFlutterRoot(), 'packages', 'flutter_tools', 'bin', 'tool_backend.dart');
|
||||
@ -14,7 +15,7 @@ final String examplePath = fileSystem.path.join(getFlutterRoot(), 'examples', 'h
|
||||
final String dart = fileSystem.path.join(getFlutterRoot(), 'bin', platform.isWindows ? 'dart.bat' : 'dart');
|
||||
|
||||
void main() {
|
||||
testWithoutContext('tool_backend.dart exits if PROJECT_DIR is not set', () async {
|
||||
testUsingContext('tool_backend.dart exits if PROJECT_DIR is not set', () async {
|
||||
final ProcessResult result = await processManager.run(<String>[
|
||||
dart,
|
||||
toolBackend,
|
||||
@ -23,10 +24,10 @@ void main() {
|
||||
]);
|
||||
|
||||
expect(result.exitCode, 1);
|
||||
expect(result.stderr, 'PROJECT_DIR environment variable must be set to the location of Flutter project to be built.');
|
||||
expect(result.stderr, contains('PROJECT_DIR environment variable must be set to the location of Flutter project to be built.'));
|
||||
});
|
||||
|
||||
testWithoutContext('tool_backend.dart exits if FLUTTER_ROOT is not set', () async {
|
||||
testUsingContext('tool_backend.dart exits if FLUTTER_ROOT is not set', () async {
|
||||
// Removing parent environment means that batch script cannot be run.
|
||||
final String dart = fileSystem.path.join(getFlutterRoot(), 'bin', 'cache', 'dart-sdk', 'bin', platform.isWindows ? 'dart.exe' : 'dart');
|
||||
|
||||
@ -40,10 +41,10 @@ void main() {
|
||||
}, includeParentEnvironment: false); // Prevent FLUTTER_ROOT set by test environment from leaking
|
||||
|
||||
expect(result.exitCode, 1);
|
||||
expect(result.stderr, 'FLUTTER_ROOT environment variable must be set to the location of the Flutter SDK.');
|
||||
expect(result.stderr, contains('FLUTTER_ROOT environment variable must be set to the location of the Flutter SDK.'));
|
||||
});
|
||||
|
||||
testWithoutContext('tool_backend.dart exits if local engine does not match build mode', () async {
|
||||
testUsingContext('tool_backend.dart exits if local engine does not match build mode', () async {
|
||||
final ProcessResult result = await processManager.run(<String>[
|
||||
dart,
|
||||
toolBackend,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user