Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion script/build_all_plugins_app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ echo "Excluding the following plugins: $ALL_EXCLUDED"

(cd "$REPO_DIR" && plugin_tools all-plugins-app --exclude $ALL_EXCLUDED)

# Master now creates null-safe app code by default; migrate stable so both
# branches are building in the same mode.
if [[ "${CHANNEL}" == "stable" ]]; then
(cd $REPO_DIR/all_plugins && dart migrate --apply-changes)
fi

function error() {
echo "$@" 1>&2
}
Expand All @@ -53,7 +59,7 @@ fi

for version in "${BUILD_MODES[@]}"; do
echo "Building $version..."
(cd $REPO_DIR/all_plugins && flutter build $@ --$version)
(cd $REPO_DIR/all_plugins && flutter build $@ --$version --no-sound-null-safety)
Copy link
Contributor Author

@stuartmorgan-g stuartmorgan-g Mar 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ditman I had to add this because of web Maps, so once this lands if you can update your NNBD PR to remove it, it should work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I'll update mine once this lands. (For cross-linking purposes, this is what's supposed to be updated: #3726)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Done: 479a543 )


if [ $? -eq 0 ]; then
echo "Successfully built $version all_plugins app."
Expand Down
53 changes: 29 additions & 24 deletions script/tool/lib/src/create_all_plugins_app_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,21 @@ import 'package:pubspec_parse/pubspec_parse.dart';

import 'common.dart';

// TODO(cyanglaz): Add tests for this command.
// https://github.com/flutter/flutter/issues/61049
class CreateAllPluginsAppCommand extends PluginCommand {
CreateAllPluginsAppCommand(Directory packagesDir, FileSystem fileSystem)
: super(packagesDir, fileSystem);
CreateAllPluginsAppCommand(
Directory packagesDir,
FileSystem fileSystem, {
this.pluginsRoot,
}) : super(packagesDir, fileSystem) {
pluginsRoot ??= fileSystem.currentDirectory;
appDirectory = pluginsRoot.childDirectory('all_plugins');
}

/// The root directory of the plugin repository.
Directory pluginsRoot;

/// The location of the synthesized app project.
Directory appDirectory;

@override
String get description =>
Expand All @@ -27,7 +37,7 @@ class CreateAllPluginsAppCommand extends PluginCommand {

@override
Future<Null> run() async {
final int exitCode = await _createPlugin();
final int exitCode = await _createApp();
if (exitCode != 0) {
throw ToolExit(exitCode);
}
Expand All @@ -39,15 +49,15 @@ class CreateAllPluginsAppCommand extends PluginCommand {
]);
}

Future<int> _createPlugin() async {
Future<int> _createApp() async {
final io.ProcessResult result = io.Process.runSync(
'flutter',
<String>[
'create',
'--template=app',
'--project-name=all_plugins',
'--android-language=java',
'./all_plugins',
appDirectory.path,
],
);

Expand All @@ -57,12 +67,10 @@ class CreateAllPluginsAppCommand extends PluginCommand {
}

Future<void> _updateAppGradle() async {
final File gradleFile = fileSystem.file(p.join(
'all_plugins',
'android',
'app',
'build.gradle',
));
final File gradleFile = appDirectory
.childDirectory('android')
.childDirectory('app')
.childFile('build.gradle');
if (!gradleFile.existsSync()) {
throw ToolExit(64);
}
Expand All @@ -86,14 +94,12 @@ class CreateAllPluginsAppCommand extends PluginCommand {
}

Future<void> _updateManifest() async {
final File manifestFile = fileSystem.file(p.join(
'all_plugins',
'android',
'app',
'src',
'main',
'AndroidManifest.xml',
));
final File manifestFile = appDirectory
.childDirectory('android')
.childDirectory('app')
.childDirectory('src')
.childDirectory('main')
.childFile('AndroidManifest.xml');
if (!manifestFile.existsSync()) {
throw ToolExit(64);
}
Expand Down Expand Up @@ -124,7 +130,7 @@ class CreateAllPluginsAppCommand extends PluginCommand {
version: Version.parse('1.0.0+1'),
environment: <String, VersionConstraint>{
'sdk': VersionConstraint.compatibleWith(
Version.parse('2.0.0'),
Version.parse('2.12.0'),
),
},
dependencies: <String, Dependency>{
Expand All @@ -135,8 +141,7 @@ class CreateAllPluginsAppCommand extends PluginCommand {
},
dependencyOverrides: pluginDeps,
);
final File pubspecFile =
fileSystem.file(p.join('all_plugins', 'pubspec.yaml'));
final File pubspecFile = appDirectory.childFile('pubspec.yaml');
pubspecFile.writeAsStringSync(_pubspecToString(pubspec));
}

Expand Down
91 changes: 91 additions & 0 deletions script/tool/test/create_all_plugins_app_command_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright 2013 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.

import 'package:args/command_runner.dart';
import 'package:file/file.dart';
import 'package:file/local.dart';
import 'package:flutter_plugin_tools/src/create_all_plugins_app_command.dart';
import 'package:test/test.dart';

import 'util.dart';

void main() {
group('$CreateAllPluginsAppCommand', () {
CommandRunner<Null> runner;
FileSystem fileSystem;
Directory testRoot;
Directory packagesDir;
Directory appDir;

setUp(() {
// Since the core of this command is a call to 'flutter create', the test
// has to use the real filesystem. Put everything possible in a unique
// temporary to minimize affect on the host system.
fileSystem = LocalFileSystem();
testRoot = fileSystem.systemTempDirectory.createTempSync();
packagesDir = testRoot.childDirectory('packages');

final CreateAllPluginsAppCommand command = CreateAllPluginsAppCommand(
packagesDir,
fileSystem,
pluginsRoot: testRoot,
);
appDir = command.appDirectory;
runner = CommandRunner<Null>(
'create_all_test', 'Test for $CreateAllPluginsAppCommand');
runner.addCommand(command);
});

tearDown(() {
testRoot.deleteSync(recursive: true);
});

test('pubspec includes all plugins', () async {
createFakePlugin('plugina', packagesDirectory: packagesDir);
createFakePlugin('pluginb', packagesDirectory: packagesDir);
createFakePlugin('pluginc', packagesDirectory: packagesDir);

await runner.run(<String>['all-plugins-app']);
final List<String> pubspec =
appDir.childFile('pubspec.yaml').readAsLinesSync();

expect(
pubspec,
containsAll(<Matcher>[
contains(RegExp('path: .*/packages/plugina')),
contains(RegExp('path: .*/packages/pluginb')),
contains(RegExp('path: .*/packages/pluginc')),
]));
});

test('pubspec has overrides for all plugins', () async {
createFakePlugin('plugina', packagesDirectory: packagesDir);
createFakePlugin('pluginb', packagesDirectory: packagesDir);
createFakePlugin('pluginc', packagesDirectory: packagesDir);

await runner.run(<String>['all-plugins-app']);
final List<String> pubspec =
appDir.childFile('pubspec.yaml').readAsLinesSync();

expect(
pubspec,
containsAllInOrder(<Matcher>[
contains('dependency_overrides:'),
contains(RegExp('path: .*/packages/plugina')),
contains(RegExp('path: .*/packages/pluginb')),
contains(RegExp('path: .*/packages/pluginc')),
]));
});

test('pubspec is compatible with null-safe app code', () async {
createFakePlugin('plugina', packagesDirectory: packagesDir);

await runner.run(<String>['all-plugins-app']);
final String pubspec =
appDir.childFile('pubspec.yaml').readAsStringSync();

expect(pubspec, contains(RegExp('sdk:\\s*(?:["\']>=|[^])2\\.12\\.')));
});
});
}
15 changes: 11 additions & 4 deletions script/tool/test/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import 'package:platform/platform.dart';
import 'package:flutter_plugin_tools/src/common.dart';
import 'package:quiver/collection.dart';

// TODO(stuartmorgan): Eliminate this in favor of setting up a clean filesystem
// for each test, to eliminate the chance of files from one test interfering
// with another test.
FileSystem mockFileSystem = MemoryFileSystem(
style: LocalPlatform().isWindows
? FileSystemStyle.windows
Expand All @@ -28,7 +31,8 @@ void initializeFakePackages({Directory parentDir}) {
mockPackagesDir.createSync();
}

/// Creates a plugin package with the given [name] in [mockPackagesDir].
/// Creates a plugin package with the given [name] in [packagesDirectory],
/// defaulting to [mockPackagesDir].
Directory createFakePlugin(
String name, {
bool withSingleExample = false,
Expand All @@ -44,13 +48,16 @@ Directory createFakePlugin(
bool includeChangeLog = false,
bool includeVersion = false,
String parentDirectoryName = '',
Directory packagesDirectory,
}) {
assert(!(withSingleExample && withExamples.isNotEmpty),
'cannot pass withSingleExample and withExamples simultaneously');

final Directory pluginDirectory = (parentDirectoryName != '')
? mockPackagesDir.childDirectory(parentDirectoryName).childDirectory(name)
: mockPackagesDir.childDirectory(name);
Directory parentDirectory = packagesDirectory ?? mockPackagesDir;
if (parentDirectoryName != '') {
parentDirectory = parentDirectory.childDirectory(parentDirectoryName);
}
final Directory pluginDirectory = parentDirectory.childDirectory(name);
pluginDirectory.createSync(recursive: true);

createFakePubspec(
Expand Down