Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require and use features from build_runner 0.8.2. #29

Merged
merged 2 commits into from
Apr 9, 2018
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
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
8 changes: 5 additions & 3 deletions webdev/lib/src/pubspec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import 'package:yaml/yaml.dart';

import 'util.dart';

final _supportedBuildRunnerVersion = new VersionConstraint.parse('^0.8.2');

class PackageException implements Exception {
final List<PackageExceptionDetails> details;

Expand All @@ -32,7 +34,7 @@ class PackageExceptionDetails {
description: '''
# pubspec.yaml
dev_dependencies:
build_runner: $supportedBuildRunnerVersionConstraint''');
build_runner: $_supportedBuildRunnerVersion''');

@override
String toString() => [error, description].join('\n');
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions webdev/lib/src/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
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