Skip to content

Commit

Permalink
Require and use features from build_runner 0.8.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmoo committed Apr 9, 2018
1 parent 078000a commit b3f4355
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 24 deletions.
4 changes: 4 additions & 0 deletions webdev/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 2 additions & 0 deletions webdev/lib/src/command/build_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
39 changes: 34 additions & 5 deletions webdev/lib/src/command/build_runner_command_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> {
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,
Expand All @@ -34,7 +50,20 @@ abstract class BuildRunnerCommandBase extends Command<int> {

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;

Expand Down
2 changes: 1 addition & 1 deletion webdev/lib/src/command/serve_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ServeCommand extends BuildRunnerCommandBase {
@override
String get invocation => '${super.invocation} [<directory>[:<port>]]...';

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
Expand Down
2 changes: 1 addition & 1 deletion webdev/lib/src/pubspec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<PackageExceptionDetails> details;
Expand Down
1 change: 1 addition & 0 deletions webdev/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 40 additions & 17 deletions webdev/test/integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit b3f4355

Please sign in to comment.