Skip to content

Commit

Permalink
Remove Windows build workaround
Browse files Browse the repository at this point in the history
Now that the Windows app template is stable, examples should have it
checked in as usual, so the workaround is no longer needed.

Requires flutter/plugins#3149 to land first.
  • Loading branch information
stuartmorgan committed Oct 13, 2020
1 parent 1c6c801 commit ed27f09
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 217 deletions.
17 changes: 0 additions & 17 deletions lib/src/build_examples_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,6 @@ class BuildExamplesCommand extends PluginCommand {
if (argResults[kWindows]) {
print('\nBUILDING Windows for $packageName');
if (isWindowsPlugin(plugin, fileSystem)) {
// The Windows tooling is not yet stable, so we need to
// delete any existing windows directory and create a new one
// with 'flutter create .'
final Directory windowsFolder =
fileSystem.directory(p.join(example.path, 'windows'));
bool exampleCreated = false;
if (!windowsFolder.existsSync()) {
int exampleCreateCode = await processRunner.runAndStream(
flutterCommand, <String>['create', '.'],
workingDir: example);
if (exampleCreateCode == 0) {
exampleCreated = true;
}
}
int buildExitCode = await processRunner.runAndStream(
flutterCommand,
<String>[
Expand All @@ -140,9 +126,6 @@ class BuildExamplesCommand extends PluginCommand {
if (buildExitCode != 0) {
failingPackages.add('$packageName (windows)');
}
if (exampleCreated && windowsFolder.existsSync()) {
windowsFolder.deleteSync(recursive: true);
}
} else {
print('Windows is not supported by this plugin');
}
Expand Down
136 changes: 136 additions & 0 deletions lib/src/check_license.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';
import 'dart:convert';
import 'dart:io' as io;

import 'package:file/file.dart';
import 'package:http/http.dart' as http;
import 'package:path/path.dart' as p;
import 'package:quiver/iterables.dart';

import 'common.dart';

const String _googleFormatterUrl =
'https://github.com/google/google-java-format/releases/download/google-java-format-1.3/google-java-format-1.3-all-deps.jar';

class CheckLicenseCommand extends PluginCommand {
CheckLicenseCommand(
Directory packagesDir,
FileSystem fileSystem, {
ProcessRunner processRunner = const ProcessRunner(),
}) : super(packagesDir, fileSystem, processRunner: processRunner);

@override
final String name = 'check-license';

@override
final String description =
'Formats the code of all packages (Java, Objective-C, and Dart).\n\n'
'This command requires "git", "flutter" and "clang-format" v5 to be in '
'your path.';

@override
Future<Null> run() async {
checkSharding();
final String googleFormatterPath = await _getGoogleFormatterPath();

await _formatDart();
await _formatJava(googleFormatterPath);
await _formatObjectiveC();

if (argResults['travis']) {
final bool modified = await _didModifyAnything();
if (modified) {
throw ToolExit(1);
}
}
}

Future<bool> _didModifyAnything() async {
final io.ProcessResult modifiedFiles = await processRunner
.runAndExitOnError('git', <String>['ls-files', '--modified'],
workingDir: packagesDir);

print('\n\n');

if (modifiedFiles.stdout.isEmpty) {
print('All files formatted correctly.');
return false;
}

print('These files are not formatted correctly (see diff below):');
LineSplitter.split(modifiedFiles.stdout)
.map((String line) => ' $line')
.forEach(print);

print('\nTo fix run "pub global activate flutter_plugin_tools && '
'pub global run flutter_plugin_tools format" or copy-paste '
'this command into your terminal:');

print('patch -p1 <<DONE');
final io.ProcessResult diff = await processRunner
.runAndExitOnError('git', <String>['diff'], workingDir: packagesDir);
print(diff.stdout);
print('DONE');
return true;
}

Future<Null> _formatObjectiveC() async {
print('Formatting all .m and .h files...');
final Iterable<String> hFiles = await _getFilesWithExtension('.h');
final Iterable<String> mFiles = await _getFilesWithExtension('.m');
// Split this into multiple invocations to avoid a
// 'ProcessException: Argument list too long'
final Iterable<String> allFiles = <String>[]
..addAll(hFiles)
..addAll(mFiles);
final Iterable<List<String>> batches = partition(allFiles, 100);
for (List<String> batch in batches) {
await processRunner.runAndStream(argResults['clang-format'],
<String>['-i', '--style=Google']..addAll(batch),
workingDir: packagesDir, exitOnError: true);
}
}

Future<Null> _formatJava(String googleFormatterPath) async {
print('Formatting all .java files...');
final Iterable<String> javaFiles = await _getFilesWithExtension('.java');
await processRunner.runAndStream('java',
<String>['-jar', googleFormatterPath, '--replace']..addAll(javaFiles),
workingDir: packagesDir, exitOnError: true);
}

Future<Null> _formatDart() async {
// This actually should be fine for non-Flutter Dart projects, no need to
// specifically shell out to dartfmt -w in that case.
print('Formatting all .dart files...');
final Iterable<String> dartFiles = await _getFilesWithExtension('.dart');
await processRunner.runAndStream(
'flutter', <String>['format']..addAll(dartFiles),
workingDir: packagesDir, exitOnError: true);
}

Future<List<String>> _getFilesWithExtension(String extension) async =>
getFiles()
.where((File file) => p.extension(file.path) == extension)
.map((File file) => file.path)
.toList();

Future<String> _getGoogleFormatterPath() async {
final String javaFormatterPath = p.join(
p.dirname(p.fromUri(io.Platform.script)),
'google-java-format-1.3-all-deps.jar');
final File javaFormatterFile = fileSystem.file(javaFormatterPath);

if (!javaFormatterFile.existsSync()) {
print('Downloading Google Java Format...');
final http.Response response = await http.get(_googleFormatterUrl);
javaFormatterFile.writeAsBytesSync(response.bodyBytes);
}

return javaFormatterPath;
}
}
15 changes: 0 additions & 15 deletions lib/src/drive_examples_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,6 @@ class DriveExamplesCommand extends PluginCommand {
if (!(await pluginSupportedOnCurrentPlatform(plugin, fileSystem))) {
continue;
}
if (isWindows) {
// The Windows tooling is not yet stable, so the platform directory for the application
// might not exist, to prevent it from becoming stale. If it doesn't, create one.
final Directory windowsFolder =
fileSystem.directory(p.join(example.path, 'windows'));
if (!windowsFolder.existsSync()) {
int exitCode = await processRunner.runAndStream(
flutterCommand, <String>['create', '.'],
workingDir: example);
if (exitCode != 0) {
print('Failed to create a windows directory for $packageName');
continue;
}
}
}
final Directory driverTests =
fileSystem.directory(p.join(example.path, 'test_driver'));
if (!driverTests.existsSync()) {
Expand Down
82 changes: 0 additions & 82 deletions test/build_examples_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,46 +181,6 @@ void main() {
cleanupPackages();
});

test(
'building for Linux does not call flutter create if a directory exists',
() async {
createFakePlugin('plugin',
withExtraFiles: <List<String>>[
<String>['example', 'test'],
<String>['example', 'linux', 'test.h']
],
isLinuxPlugin: true);

final Directory pluginExampleDirectory =
mockPackagesDir.childDirectory('plugin').childDirectory('example');

createFakePubspec(pluginExampleDirectory, isFlutter: true);

final List<String> output = await runCapturingPrint(
runner, <String>['build-examples', '--no-ipa', '--linux']);
final String packageName =
p.relative(pluginExampleDirectory.path, from: mockPackagesDir.path);

expect(
output,
orderedEquals(<String>[
'\nBUILDING Linux for $packageName',
'\n\n',
'All builds successful!',
]),
);

print(processRunner.recordedCalls);
// flutter create . should NOT be called.
expect(
processRunner.recordedCalls,
orderedEquals(<ProcessCall>[
ProcessCall(flutterCommand, <String>['build', 'linux'],
pluginExampleDirectory.path),
]));
cleanupPackages();
});

test('building for macos with no implementation results in no-op',
() async {
createFakePlugin('plugin', withExtraFiles: <List<String>>[
Expand Down Expand Up @@ -355,48 +315,6 @@ void main() {
);

print(processRunner.recordedCalls);
expect(
processRunner.recordedCalls,
orderedEquals(<ProcessCall>[
ProcessCall(flutterCommand, <String>['create', '.'],
pluginExampleDirectory.path),
ProcessCall(flutterCommand, <String>['build', 'windows'],
pluginExampleDirectory.path),
]));
cleanupPackages();
});

test(
'building for windows does not call flutter create if a directory exists',
() async {
createFakePlugin('plugin',
withExtraFiles: <List<String>>[
<String>['example', 'test'],
<String>['example', 'windows', 'test.h']
],
isWindowsPlugin: true);

final Directory pluginExampleDirectory =
mockPackagesDir.childDirectory('plugin').childDirectory('example');

createFakePubspec(pluginExampleDirectory, isFlutter: true);

final List<String> output = await runCapturingPrint(
runner, <String>['build-examples', '--no-ipa', '--windows']);
final String packageName =
p.relative(pluginExampleDirectory.path, from: mockPackagesDir.path);

expect(
output,
orderedEquals(<String>[
'\nBUILDING Windows for $packageName',
'\n\n',
'All builds successful!',
]),
);

print(processRunner.recordedCalls);
// flutter create . should NOT be called.
expect(
processRunner.recordedCalls,
orderedEquals(<ProcessCall>[
Expand Down

0 comments on commit ed27f09

Please sign in to comment.