Skip to content

Commit f2f5167

Browse files
authored
Clean up the tool code (#499)
1 parent fa24af4 commit f2f5167

File tree

12 files changed

+110
-136
lines changed

12 files changed

+110
-136
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Dry run on pull request
2121
if: ${{ github.event_name == 'pull_request' }}
2222
run: |
23-
./tools/tools_runner.sh publish-plugin \
23+
./tools/tools_runner.sh publish \
2424
--all-changed \
2525
--pub-publish-flags=--dry-run \
2626
--base-sha=HEAD~
@@ -34,12 +34,12 @@ jobs:
3434
wait-interval: 180 # seconds
3535
allowed-conclusions: success
3636
verbose: false
37-
- name: Publish plugins
37+
- name: Publish packages
3838
if: ${{ github.event_name == 'push' }}
3939
env:
4040
PUB_CREDENTIALS: ${{ secrets.PUB_CREDENTIALS }}
4141
run: |
42-
./tools/tools_runner.sh publish-plugin \
42+
./tools/tools_runner.sh publish \
4343
--all-changed \
4444
--base-sha=HEAD~ \
4545
--skip-confirmation

tools/LICENSE

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Copyright 2021 Samsung Electronics Co., Ltd. All rights reserved.
2-
Copyright 2013 The Flutter Authors. All rights reserved.
1+
Copyright (c) 2022 Samsung Electronics Co., Ltd. All rights reserved.
2+
Copyright (c) 2013 The Flutter Authors. All rights reserved.
33

44
Redistribution and use in source and binary forms, with or without modification,
55
are permitted provided that the following conditions are met:
@@ -10,7 +10,7 @@ are permitted provided that the following conditions are met:
1010
copyright notice, this list of conditions and the following
1111
disclaimer in the documentation and/or other materials provided
1212
with the distribution.
13-
* Neither the name of Google Inc. nor the names of its
13+
* Neither the names of the copyright holders nor the names of the
1414
contributors may be used to endorse or promote products derived
1515
from this software without specific prior written permission.
1616

tools/lib/src/device.dart

Lines changed: 29 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@ import 'dart:io' as io;
88

99
import 'package:file/file.dart';
1010
import 'package:flutter_plugin_tools/src/common/core.dart';
11-
import 'package:flutter_plugin_tools/src/common/package_looping_command.dart';
1211
import 'package:flutter_plugin_tools/src/common/process_runner.dart';
1312

1413
import 'process_runner_apis.dart';
1514
import 'tizen_sdk.dart';
1615

17-
export 'package:flutter_plugin_tools/src/common/package_looping_command.dart'
18-
show PackageResult, RunState;
19-
2016
/// A reference to a Tizen device (either physical or emulator) that can run
2117
/// Flutter applications.
2218
///
@@ -114,36 +110,24 @@ class Device {
114110

115111
/// Runs integration test in [workingDir].
116112
///
117-
/// [workingDir] must be a valid exisiting flutter directory where
118-
/// `flutter pub get` has already been ran succesfully. For an app project,
113+
/// [workingDir] must be a valid existing Flutter project directory where
114+
/// `flutter pub get` has already been run succesfully. For an app project,
119115
/// [workingDir] is the app's source root. For a plugin project, [workingDir]
120116
/// is one of the example directories.
121117
///
122-
/// If test doesn't finish after [timeout], it's considered a failure and the
123-
/// function will return [PackageResult.fail] with time expired log.
124-
///
125-
/// Returns [PackageResult.success] when every test passes succesfully,
126-
/// otherwise returns [PackageResult.fail]. Never returns [PackageResult.skip]
127-
/// nor [PackageResult.exclude].
128-
Future<PackageResult> runIntegrationTest(
118+
/// Returns null if all tests have passed successfully before [timeout],
119+
/// otherwise returns a string with the error details.
120+
Future<String?> runIntegrationTest(
129121
Directory workingDir,
130-
Duration timeout, {
131-
bool debug = false,
132-
}) async {
122+
Duration timeout,
123+
) async {
133124
if (!isConnected) {
134-
return PackageResult.fail(
135-
<String>['Device $name ($profile) is not connected.']);
125+
return 'Device $name ($profile) is not connected.';
136126
}
137127

138128
final io.Process process = await _processRunner.start(
139129
'flutter-tizen',
140-
<String>[
141-
if (debug) '-v',
142-
'-d',
143-
serial!,
144-
'test',
145-
'integration_test',
146-
],
130+
<String>['-d', serial!, 'test', 'integration_test'],
147131
workingDirectory: workingDir,
148132
);
149133

@@ -173,30 +157,27 @@ class Device {
173157
// guarantee that all buffered outputs of the process have returned.
174158
await completer.future;
175159

176-
final List<String> errors = <String>[];
160+
String? error;
177161
if (timedOut) {
178-
errors.add('Timeout expired. The test may need more time to finish. '
162+
error = 'Timeout expired. The test may need more time to finish. '
179163
'If you expect the test to finish before timeout, check if the tests '
180164
'require device screen to be awake or if they require manually '
181-
'clicking the UI button for permissions.');
165+
'clicking the UI button for permissions.';
182166
} else if (lastLine.startsWith('No tests ran')) {
183-
errors.add(
184-
'Missing integration tests (use --exclude if this is intentional).');
167+
error =
168+
'Missing integration tests (use --exclude if this is intentional).';
185169
} else if (lastLine.startsWith('No devices found')) {
186-
errors.add('Device was disconnected during test.');
170+
error = 'Device was disconnected during test.';
187171
} else {
188172
final RegExpMatch? match = _logPattern.firstMatch(lastLine);
189173
if (match == null || match.group(2) == null) {
190-
throw Exception('Log message is not parsed correctly.');
174+
error = 'Could not parse the log output.';
191175
} else if (!match.group(2)!.startsWith('All tests passed!')) {
192-
errors.add('flutter-tizen test integration_test failed, see the output '
193-
'above for details.');
176+
error = 'flutter-tizen test integration_test failed, see the output '
177+
'above for details.';
194178
}
195179
}
196-
197-
return errors.isEmpty
198-
? PackageResult.success()
199-
: PackageResult.fail(errors);
180+
return error;
200181
}
201182
}
202183

@@ -247,6 +228,7 @@ class EmulatorDevice extends Device {
247228
final io.ProcessResult result =
248229
_processRunner.runSync(_tizenSdk.emCli.path, <String>['list-vm']);
249230
if (result.exitCode != 0) {
231+
print('Error: Unable to list available emulators.');
250232
throw ToolExit(result.exitCode);
251233
}
252234

@@ -319,11 +301,10 @@ class EmulatorDevice extends Device {
319301
}
320302

321303
/// Deletes this emulator.
322-
Future<void> delete() async => await _processRunner.runAndStream(
323-
_tizenSdk.emCli.path,
324-
<String>['delete', '-n', name],
325-
exitOnError: true,
326-
);
304+
Future<void> delete() async {
305+
await _processRunner
306+
.runAndStream(_tizenSdk.emCli.path, <String>['delete', '-n', name]);
307+
}
327308

328309
/// Launches this emualtor.
329310
Future<void> launch() async {
@@ -385,7 +366,7 @@ class EmulatorDevice extends Device {
385366
Future<void> _poll(
386367
FutureOr<bool> Function() function, {
387368
Duration interval = const Duration(seconds: 1),
388-
Duration timeout = const Duration(minutes: 10),
369+
Duration timeout = const Duration(minutes: 5),
389370
}) async {
390371
final DateTime start = DateTime.now();
391372
while (DateTime.now().difference(start) <= timeout) {
@@ -398,11 +379,10 @@ class EmulatorDevice extends Device {
398379
}
399380

400381
@override
401-
Future<PackageResult> runIntegrationTest(
382+
Future<String?> runIntegrationTest(
402383
Directory workingDir,
403-
Duration timeout, {
404-
bool debug = false,
405-
}) async {
384+
Duration timeout,
385+
) async {
406386
bool autoLaunched = false;
407387
bool autoCreated = false;
408388
try {
@@ -415,7 +395,7 @@ class EmulatorDevice extends Device {
415395
await launch();
416396
}
417397
_disablePermissionPopups();
418-
return await super.runIntegrationTest(workingDir, timeout, debug: debug);
398+
return await super.runIntegrationTest(workingDir, timeout);
419399
} finally {
420400
if (autoLaunched) {
421401
await close();

tools/lib/src/integration_test_command.dart

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import 'package:args/args.dart';
88
import 'package:file/file.dart';
99
import 'package:file/local.dart';
1010
import 'package:flutter_plugin_tools/src/common/core.dart';
11+
import 'package:flutter_plugin_tools/src/common/package_command.dart';
1112
import 'package:flutter_plugin_tools/src/common/package_looping_command.dart';
12-
import 'package:flutter_plugin_tools/src/common/plugin_command.dart';
1313
import 'package:flutter_plugin_tools/src/common/repository_package.dart';
1414
import 'package:yaml/yaml.dart';
1515

@@ -58,16 +58,16 @@ class IntegrationTestCommand extends PackageLoopingCommand {
5858
);
5959
argParser.addOption(
6060
_timeoutArg,
61-
help: 'Timeout limit of each integration test in seconds.',
61+
help: 'Time in seconds to wait for each test to finish.',
6262
valueHelp: 'seconds',
6363
defaultsTo: _timeout.inSeconds.toString(),
6464
);
6565
}
6666

67-
/// Copied from [PluginCommand].
67+
/// Copied from [PackageCommand].
6868
static const String _excludeArg = 'exclude';
6969

70-
/// Copied from [PluginCommand].
70+
/// Copied from [PackageCommand].
7171
static const String _packagesArg = 'packages';
7272

7373
static const String _generateEmulatorsArg = 'generate-emulators';
@@ -142,7 +142,7 @@ class IntegrationTestCommand extends PackageLoopingCommand {
142142
}
143143
}
144144

145-
/// See: [PluginCommand.getTargetPackages].
145+
/// See: [PackageCommand.getTargetPackages].
146146
@override
147147
Stream<PackageEnumerationEntry> getTargetPackages({
148148
bool filterExcluded = true,
@@ -151,19 +151,19 @@ class IntegrationTestCommand extends PackageLoopingCommand {
151151
yield* super.getTargetPackages(filterExcluded: filterExcluded);
152152
} else {
153153
final Recipe recipe = _recipe!;
154-
final List<PackageEnumerationEntry> plugins = await super
154+
final List<PackageEnumerationEntry> packages = await super
155155
.getTargetPackages(filterExcluded: filterExcluded)
156156
.toList();
157157

158-
for (final PackageEnumerationEntry plugin in plugins) {
159-
final String pluginName = plugin.package.displayName;
160-
if (!recipe.contains(pluginName)) {
158+
for (final PackageEnumerationEntry package in packages) {
159+
final String packageName = package.package.displayName;
160+
if (!recipe.contains(packageName)) {
161161
continue;
162162
}
163-
if (!(filterExcluded && plugin.excluded)) {
164-
yield recipe.isExcluded(pluginName)
165-
? PackageEnumerationEntry(plugin.package, excluded: true)
166-
: plugin;
163+
if (!(filterExcluded && package.excluded)) {
164+
yield recipe.isExcluded(packageName)
165+
? PackageEnumerationEntry(package.package, excluded: true)
166+
: package;
167167
}
168168
}
169169
}
@@ -224,15 +224,14 @@ class IntegrationTestCommand extends PackageLoopingCommand {
224224
}
225225

226226
for (final Device device in devices) {
227-
PackageResult packageResult =
227+
String? error =
228228
await device.runIntegrationTest(example.directory, _timeout);
229-
if (packageResult.state == RunState.failed) {
229+
if (error != null) {
230230
// Tests may fail unexpectedly on a self-hosted runner. Try again.
231-
packageResult = await device
232-
.runIntegrationTest(example.directory, _timeout, debug: true);
231+
error = await device.runIntegrationTest(example.directory, _timeout);
233232
}
234-
if (packageResult.state == RunState.failed) {
235-
errors.addAll(packageResult.details);
233+
if (error != null) {
234+
errors.add(error);
236235
}
237236
}
238237
}

tools/lib/src/main.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import 'package:flutter_plugin_tools/src/list_command.dart';
1515

1616
import 'build_examples_command.dart';
1717
import 'integration_test_command.dart';
18-
import 'publish_plugin_command.dart';
18+
import 'publish_command.dart';
1919

2020
void main(List<String> args) {
2121
const FileSystem fileSystem = LocalFileSystem();
@@ -40,7 +40,7 @@ void main(List<String> args) {
4040
..addCommand(FormatCommand(packagesDir))
4141
..addCommand(IntegrationTestCommand(packagesDir))
4242
..addCommand(ListCommand(packagesDir))
43-
..addCommand(PublishPluginCommand(packagesDir));
43+
..addCommand(PublishCommand(packagesDir));
4444

4545
commandRunner.run(args).catchError((Object e) {
4646
final ToolExit toolExit = e as ToolExit;

tools/lib/src/process_runner_apis.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import 'dart:io' as io;
77

88
import 'package:file/file.dart';
99
import 'package:flutter_plugin_tools/src/common/core.dart';
10-
1110
import 'package:flutter_plugin_tools/src/common/process_runner.dart';
1211

1312
/// An extension method of [ProcessRunner] to supports synchronous operations.
Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,25 @@ import 'package:file/file.dart';
1111
import 'package:flutter_plugin_tools/src/common/core.dart';
1212
import 'package:flutter_plugin_tools/src/common/file_utils.dart';
1313
import 'package:flutter_plugin_tools/src/common/git_version_finder.dart';
14+
import 'package:flutter_plugin_tools/src/common/package_command.dart';
1415
import 'package:flutter_plugin_tools/src/common/package_looping_command.dart';
15-
import 'package:flutter_plugin_tools/src/common/plugin_command.dart';
1616
import 'package:flutter_plugin_tools/src/common/process_runner.dart';
1717
import 'package:flutter_plugin_tools/src/common/pub_version_finder.dart';
1818
import 'package:flutter_plugin_tools/src/common/repository_package.dart';
19+
import 'package:flutter_plugin_tools/src/publish_command.dart'
20+
as flutter_plugin_tools;
1921
import 'package:http/http.dart' as http;
2022
import 'package:path/path.dart' as p;
2123
import 'package:platform/platform.dart';
2224
import 'package:pub_semver/pub_semver.dart';
2325

2426
/// Wraps pub publish with a few niceties used by the flutter-tizen team.
25-
// The code is mostly copied from `PublishPluginCommand` in
26-
// `flutter_plugin_tools`, parts regarding git tagging are removed as we don't
27-
// tag our releases.
28-
class PublishPluginCommand extends PackageLoopingCommand {
27+
///
28+
/// The code is a copy of [flutter_plugin_tools.PublishCommand] with parts
29+
/// related to git tagging removed as we don't tag our releases.
30+
class PublishCommand extends PackageLoopingCommand {
2931
/// Creates an instance of the publish command.
30-
PublishPluginCommand(
32+
PublishCommand(
3133
super.packagesDir, {
3234
super.processRunner = const ProcessRunner(),
3335
super.platform = const LocalPlatform(),
@@ -48,23 +50,18 @@ class PublishPluginCommand extends PackageLoopingCommand {
4850
help:
4951
'Release all packages that contains pubspec changes at the current commit compares to the base-sha.\n'
5052
'The --packages option is ignored if this is on.',
51-
defaultsTo: false,
5253
);
5354
argParser.addFlag(
5455
_dryRunFlag,
5556
help:
5657
'Skips the real `pub publish` command and assumes the command is successful.\n'
5758
'This does not run `pub publish --dry-run`.\n'
5859
'If you want to run the command with `pub publish --dry-run`, use `--pub-publish-flags=--dry-run`',
59-
defaultsTo: false,
60-
negatable: true,
6160
);
6261
argParser.addFlag(
6362
_skipConfirmationFlag,
6463
help: 'Run the command without asking for Y/N inputs.\n'
6564
'This command will add a `--force` flag to the `pub publish` command if it is not added with $_pubFlagsOption\n',
66-
defaultsTo: false,
67-
negatable: true,
6865
);
6966
}
7067

@@ -76,7 +73,7 @@ class PublishPluginCommand extends PackageLoopingCommand {
7673
static const String _pubCredentialName = 'PUB_CREDENTIALS';
7774

7875
@override
79-
String get name => 'publish-plugin';
76+
String get name => 'publish';
8077

8178
@override
8279
String get description => 'Attempts to publish the given packages to pub.\n'

0 commit comments

Comments
 (0)