From 078000ab663a895b61d3e29b3b37073828f887d9 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Sat, 7 Apr 2018 19:03:49 -0700 Subject: [PATCH 1/2] Move support build runner version around --- webdev/lib/src/pubspec.dart | 8 +++++--- webdev/lib/src/util.dart | 4 ---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/webdev/lib/src/pubspec.dart b/webdev/lib/src/pubspec.dart index 508975249..efef9334e 100644 --- a/webdev/lib/src/pubspec.dart +++ b/webdev/lib/src/pubspec.dart @@ -10,6 +10,8 @@ import 'package:yaml/yaml.dart'; import 'util.dart'; +final _supportedBuildRunnerVersion = new VersionConstraint.parse('^0.8.0'); + class PackageException implements Exception { final List details; @@ -32,7 +34,7 @@ class PackageExceptionDetails { description: ''' # pubspec.yaml dev_dependencies: - build_runner: $supportedBuildRunnerVersionConstraint'''); + build_runner: $_supportedBuildRunnerVersion'''); @override String toString() => [error, description].join('\n'); @@ -82,9 +84,9 @@ Future checkPubspecLock() async { var version = buildRunner['version'] as String; var buildRunnerVersion = new Version.parse(version); - if (!supportedBuildRunnerVersionConstraint.allows(buildRunnerVersion)) { + if (!_supportedBuildRunnerVersion.allows(buildRunnerVersion)) { var error = 'The `build_runner` version – $buildRunnerVersion – is not ' - 'within the allowed constraint – $supportedBuildRunnerVersionConstraint.'; + 'within the allowed constraint – $_supportedBuildRunnerVersion.'; issues.add(new PackageExceptionDetails._(error)); } } else { diff --git a/webdev/lib/src/util.dart b/webdev/lib/src/util.dart index 81b2cbcae..2f3086c42 100644 --- a/webdev/lib/src/util.dart +++ b/webdev/lib/src/util.dart @@ -5,13 +5,9 @@ import 'dart:io'; import 'package:path/path.dart' as p; -import 'package:pub_semver/pub_semver.dart'; const appName = 'webdev'; -final supportedBuildRunnerVersionConstraint = - new VersionConstraint.parse('^0.8.0'); - /// The path to the root directory of the SDK. final String _sdkDir = (() { // The Dart executable is in "/path/to/sdk/bin/dart", so two levels up is From b3f435533255c5b3735aa2ac2b9458a6a9c9f1c9 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 9 Apr 2018 10:15:30 -0700 Subject: [PATCH 2/2] Require and use features from `build_runner` 0.8.2. --- webdev/CHANGELOG.md | 4 ++ webdev/lib/src/command/build_command.dart | 2 + .../command/build_runner_command_base.dart | 39 +++++++++++-- webdev/lib/src/command/serve_command.dart | 2 +- webdev/lib/src/pubspec.dart | 2 +- webdev/pubspec.yaml | 1 + webdev/test/integration_test.dart | 57 +++++++++++++------ 7 files changed, 83 insertions(+), 24 deletions(-) diff --git a/webdev/CHANGELOG.md b/webdev/CHANGELOG.md index c7dab95c9..1c7553836 100644 --- a/webdev/CHANGELOG.md +++ b/webdev/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.4 + +- Require and use features from `build_runner` 0.8.2. + ## 0.1.3+1 - Support running `pub` when it's not in the environment path. diff --git a/webdev/lib/src/command/build_command.dart b/webdev/lib/src/command/build_command.dart index 002c6327b..822211b95 100644 --- a/webdev/lib/src/command/build_command.dart +++ b/webdev/lib/src/command/build_command.dart @@ -7,6 +7,8 @@ import 'build_runner_command_base.dart'; /// Command to execute pub run build_runner build. class BuildCommand extends BuildRunnerCommandBase { + BuildCommand() : super(releaseDefault: true); + @override final name = 'build'; diff --git a/webdev/lib/src/command/build_runner_command_base.dart b/webdev/lib/src/command/build_runner_command_base.dart index 7d2e309ce..fe7adc399 100644 --- a/webdev/lib/src/command/build_runner_command_base.dart +++ b/webdev/lib/src/command/build_runner_command_base.dart @@ -7,22 +7,38 @@ import 'dart:io' hide exitCode, exit; import 'dart:isolate'; import 'package:args/command_runner.dart'; +import 'package:meta/meta.dart'; import 'package:stack_trace/stack_trace.dart'; import '../pubspec.dart'; const _packagesFileName = '.packages'; +const _release = 'release'; +const _output = 'output'; +const _verbose = 'verbose'; /// Extend to get a command with the arguments common to all build_runner /// commands. abstract class BuildRunnerCommandBase extends Command { - BuildRunnerCommandBase() { + final bool releaseDefault; + + BuildRunnerCommandBase({@required this.releaseDefault}) { // TODO(nshahan) Expose more common args passed to build_runner commands. // build_runner might expose args for use in wrapping scripts like this one. argParser - ..addOption('output', - abbr: 'o', help: 'A directory to write the result of a build to.') - ..addFlag('verbose', + ..addFlag(_release, + abbr: 'r', + defaultsTo: releaseDefault, + negatable: true, + help: 'Build with release mode defaults for builders.') + ..addOption( + _output, + abbr: 'o', + help: 'A directory to write the result of a build to. Or a mapping ' + 'from a top-level directory in the package to the directory to ' + 'write a filtered build output to. For example "web:deploy".', + ) + ..addFlag(_verbose, abbr: 'v', defaultsTo: false, negatable: false, @@ -34,7 +50,20 @@ abstract class BuildRunnerCommandBase extends Command { var buildRunnerScript = await _buildRunnerScript(); - final arguments = [command]..addAll(argResults.arguments); + final arguments = [command]; + + if ((argResults[_release] as bool) ?? releaseDefault) { + arguments.add('--$_release'); + } + + var output = argResults[_output] as String; + if (output != null) { + arguments.addAll(['--$_output', output]); + } + + if (argResults[_verbose] as bool) { + arguments.add('--$_verbose'); + } var exitCode = 0; diff --git a/webdev/lib/src/command/serve_command.dart b/webdev/lib/src/command/serve_command.dart index 23a5dc728..142d2da87 100644 --- a/webdev/lib/src/command/serve_command.dart +++ b/webdev/lib/src/command/serve_command.dart @@ -18,7 +18,7 @@ class ServeCommand extends BuildRunnerCommandBase { @override String get invocation => '${super.invocation} [[:]]...'; - ServeCommand() { + ServeCommand() : super(releaseDefault: false) { // TODO(nshahan) Expose more args passed to build_runner serve. // build_runner might expose args for use in wrapping scripts like this one. argParser diff --git a/webdev/lib/src/pubspec.dart b/webdev/lib/src/pubspec.dart index efef9334e..c866191f6 100644 --- a/webdev/lib/src/pubspec.dart +++ b/webdev/lib/src/pubspec.dart @@ -10,7 +10,7 @@ import 'package:yaml/yaml.dart'; import 'util.dart'; -final _supportedBuildRunnerVersion = new VersionConstraint.parse('^0.8.0'); +final _supportedBuildRunnerVersion = new VersionConstraint.parse('^0.8.2'); class PackageException implements Exception { final List details; diff --git a/webdev/pubspec.yaml b/webdev/pubspec.yaml index b0a47ac01..6a7220494 100644 --- a/webdev/pubspec.yaml +++ b/webdev/pubspec.yaml @@ -12,6 +12,7 @@ environment: dependencies: args: ^1.2.0 io: ^0.3.2+1 + meta: ^1.1.2 path: ^1.5.1 pub_semver: ^1.3.2 stack_trace: ^1.9.2 diff --git a/webdev/test/integration_test.dart b/webdev/test/integration_test.dart index d6717c920..eb0c2d2ef 100644 --- a/webdev/test/integration_test.dart +++ b/webdev/test/integration_test.dart @@ -70,7 +70,7 @@ name: sample await expectLater( process.stdout, emits('The `build_runner` version – $version – ' - 'is not within the allowed constraint – ^0.8.0.')); + 'is not within the allowed constraint – ^0.8.2.')); await process.shouldExit(78); }); } @@ -165,30 +165,53 @@ dependencies: await process.shouldExit(78); }); - test('should succeed with valid configuration', () async { - var exampleDirectory = p.absolute(p.join(p.current, '..', 'example')); - var process = await TestProcess.start(pubPath, ['get'], - workingDirectory: exampleDirectory, environment: _getPubEnvironment()); + group('should succeed with valid configuration', () { + for (var withDDC in [true, false]) { + test(withDDC ? 'DDC' : 'dart2js', () async { + var exampleDirectory = p.absolute(p.join(p.current, '..', 'example')); + var process = await TestProcess.start(pubPath, ['get'], + workingDirectory: exampleDirectory, + environment: _getPubEnvironment()); - await process.shouldExit(0); + await process.shouldExit(0); - await d.file('.packages', isNotEmpty).validate(exampleDirectory); - await d.file('pubspec.lock', isNotEmpty).validate(exampleDirectory); + await d.file('.packages', isNotEmpty).validate(exampleDirectory); + await d.file('pubspec.lock', isNotEmpty).validate(exampleDirectory); - process = await _runWebDev(['build', '-o', d.sandbox], - workingDirectory: exampleDirectory); + var args = ['build', '-o', 'web:${d.sandbox}']; + if (withDDC) { + args.add('--no-release'); + } - var output = await process.stdoutStream().join('\n'); + process = await _runWebDev(args, workingDirectory: exampleDirectory); - expect(output, contains(d.sandbox)); - expect(output, contains('[INFO] Succeeded')); - await process.shouldExit(0); + var output = await process.stdoutStream().join('\n'); + + expect(output, contains('[INFO] Succeeded')); + + if (!withDDC && !output.contains('with 0 outputs')) { + // If outputs were generated, then dart2js should have been run + expect(output, contains('Running dart2js with'), + reason: 'Should run dart2js during build.'); + } - await d.file('web/main.dart.js', isNotEmpty).validate(); - }, timeout: const Timeout(const Duration(minutes: 5))); + await process.shouldExit(0); + + await d.file('main.dart.js', isNotEmpty).validate(); + + for (var ddcFile in ['main.dart.bootstrap.js', 'main.ddc.js']) { + if (withDDC) { + await d.file(ddcFile, isNotEmpty).validate(); + } else { + await d.nothing(ddcFile).validate(); + } + } + }, timeout: const Timeout(const Duration(minutes: 5))); + } + }); } -String _pubspecLock({String version: '0.8.0'}) => ''' +String _pubspecLock({String version: '0.8.2'}) => ''' # Copy-pasted from a valid run packages: build_runner: