Skip to content

get basic windows support working #80

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

Merged
merged 1 commit into from
Mar 8, 2016
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
2 changes: 1 addition & 1 deletion lib/src/generate/watch_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class WatchImpl {

/// Checks if we should skip a watch event for this [id].
bool _shouldSkipInput(AssetId id, ChangeType type) {
if (id.path.startsWith('.build')) return true;
if (id.path.contains('.build/')) return true;
var node = _assetGraph.get(id);
return node is GeneratedAssetNode && type != ChangeType.REMOVE;
}
Expand Down
6 changes: 5 additions & 1 deletion lib/src/package_graph/package_graph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ class PackageGraph {
packagesFile.readAsLinesSync().skip(1).forEach((line) {
var firstColon = line.indexOf(':');
var name = line.substring(0, firstColon);
assert(line.endsWith('lib${Platform.pathSeparator}'));
assert(line.endsWith('lib/'));
// Start after package_name:, and strip out trailing `lib` dir.
var uriString = line.substring(firstColon + 1, line.length - 4);
// Strip the trailing slash, if present.
if (uriString.endsWith('/')) {
uriString = uriString.substring(0, uriString.length - 1);
}
var uri;
try {
uri = Uri.parse(uriString);
Expand Down
15 changes: 9 additions & 6 deletions test/asset/file_based_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,32 @@
@TestOn('vm')
import 'dart:io';

import 'package:path/path.dart' as path;
import 'package:test/test.dart';

import 'package:build/build.dart';

import '../common/common.dart';

final packageGraph = new PackageGraph.forPath('test/fixtures/basic_pkg');
final packageGraph =
new PackageGraph.forPath('test/fixtures/basic_pkg');
final newLine = Platform.isWindows ? '\r\n' : '\n';

main() {
group('FileBasedAssetReader', () {
final reader = new FileBasedAssetReader(packageGraph, ignoredDirs: ['pkg']);

test('can read any application package files', () async {
expect(await reader.readAsString(makeAssetId('basic_pkg|hello.txt')),
'world\n');
'world$newLine');
expect(await reader.readAsString(makeAssetId('basic_pkg|lib/hello.txt')),
'world\n');
'world$newLine');
expect(await reader.readAsString(makeAssetId('basic_pkg|web/hello.txt')),
'world\n');
'world$newLine');
});

test('can read package dependency files in the lib dir', () async {
expect(await reader.readAsString(makeAssetId('a|lib/a.txt')), 'A\n');
expect(await reader.readAsString(makeAssetId('a|lib/a.txt')), 'A$newLine');
});

test('can check for existence of any application package files', () async {
Expand Down Expand Up @@ -101,7 +104,7 @@ main() {
var asset = makeAsset('basic_pkg|test_file.txt', 'test');
await writer.writeAsString(asset);
var id = asset.id;
var file = new File('test/fixtures/${id.package}/${id.path}');
var file = new File(path.join('test', 'fixtures', id.package, id.path));
expect(await file.exists(), isTrue);
expect(await file.readAsString(), 'test');

Expand Down
9 changes: 5 additions & 4 deletions test/generate/serve_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import 'dart:async';

import 'package:logging/logging.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';

import 'package:build/build.dart';
Expand Down Expand Up @@ -44,8 +45,8 @@ main() {
checkOutputs({'a|web/a.txt.copy': 'a'}, result, writer.assets);

await writer.writeAsString(makeAsset('a|web/a.txt', 'b'));
FakeWatcher
.notifyWatchers(new WatchEvent(ChangeType.MODIFY, 'a/web/a.txt'));
FakeWatcher.notifyWatchers(
new WatchEvent(ChangeType.MODIFY, path.join('a', 'web', 'a.txt')));

result = await nextResult(results);
checkOutputs({'a|web/a.txt.copy': 'b',}, result, writer.assets);
Expand Down Expand Up @@ -82,8 +83,8 @@ main() {
/// Make an edit to force another build, and we should block again.
copyBuilder.blockUntil = buildBlocker2.future;
await writer.writeAsString(makeAsset('a|web/a.txt', 'b'));
FakeWatcher
.notifyWatchers(new WatchEvent(ChangeType.MODIFY, 'a/web/a.txt'));
FakeWatcher.notifyWatchers(
new WatchEvent(ChangeType.MODIFY, path.join('a', 'web', 'a.txt')));
// Give the build enough time to get started.
await wait(500);
var done = new Completer();
Expand Down
49 changes: 25 additions & 24 deletions test/generate/watch_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'dart:async';
import 'dart:convert';

import 'package:logging/logging.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
import 'package:watcher/watcher.dart';

Expand Down Expand Up @@ -40,8 +41,8 @@ main() {
checkOutputs({'a|web/a.txt.copy': 'a',}, result, writer.assets);

await writer.writeAsString(makeAsset('a|web/a.txt', 'b'));
FakeWatcher
.notifyWatchers(new WatchEvent(ChangeType.MODIFY, 'a/web/a.txt'));
FakeWatcher.notifyWatchers(
new WatchEvent(ChangeType.MODIFY, path.join('a', 'web', 'a.txt')));

result = await nextResult(results);
checkOutputs({'a|web/a.txt.copy': 'b',}, result, writer.assets);
Expand All @@ -57,8 +58,8 @@ main() {
checkOutputs({'a|web/a.txt.copy': 'a',}, result, writer.assets);

await writer.writeAsString(makeAsset('a|web/b.txt', 'b'));
FakeWatcher
.notifyWatchers(new WatchEvent(ChangeType.ADD, 'a/web/b.txt'));
FakeWatcher.notifyWatchers(
new WatchEvent(ChangeType.ADD, path.join('a', 'web', 'b.txt')));

result = await nextResult(results);
checkOutputs({'a|web/b.txt.copy': 'b',}, result, writer.assets);
Expand All @@ -78,8 +79,8 @@ main() {
result, writer.assets);

await writer.delete(makeAssetId('a|web/a.txt'));
FakeWatcher
.notifyWatchers(new WatchEvent(ChangeType.REMOVE, 'a/web/a.txt'));
FakeWatcher.notifyWatchers(
new WatchEvent(ChangeType.REMOVE, path.join('a', 'web', 'a.txt')));

result = await nextResult(results);

Expand All @@ -104,11 +105,11 @@ main() {
result, writer.assets);

await writer.writeAsString(makeAsset('a|web/c.txt', 'c'));
FakeWatcher
.notifyWatchers(new WatchEvent(ChangeType.ADD, 'a/web/c.txt'));
FakeWatcher.notifyWatchers(
new WatchEvent(ChangeType.ADD, path.join('a', 'web', 'c.txt')));
await writer.delete(makeAssetId('a|web/a.txt'));
FakeWatcher
.notifyWatchers(new WatchEvent(ChangeType.REMOVE, 'a/web/a.txt'));
FakeWatcher.notifyWatchers(
new WatchEvent(ChangeType.REMOVE, path.join('a', 'web', 'a.txt')));

result = await nextResult(results);
checkOutputs({'a|web/c.txt.copy': 'c'}, result, writer.assets);
Expand Down Expand Up @@ -141,8 +142,8 @@ main() {
await writer.writeAsString(makeAsset('test|lib/test.dart', ''),
lastModified: new DateTime.now().add(new Duration(days: 1)));
await writer.writeAsString(makeAsset('a|web/a.txt', 'b'));
FakeWatcher
.notifyWatchers(new WatchEvent(ChangeType.MODIFY, 'a/web/a.txt'));
FakeWatcher.notifyWatchers(
new WatchEvent(ChangeType.MODIFY, path.join('a', 'web', 'a.txt')));

result = await nextResult(results);
expect(result.status, BuildStatus.Failure);
Expand All @@ -165,8 +166,8 @@ main() {
result, writer.assets);

await writer.writeAsString(makeAsset('a|web/a.txt', 'b'));
FakeWatcher
.notifyWatchers(new WatchEvent(ChangeType.MODIFY, 'a/web/a.txt'));
FakeWatcher.notifyWatchers(
new WatchEvent(ChangeType.MODIFY, path.join('a', 'web', 'a.txt')));

result = await nextResult(results);
checkOutputs({'a|web/a.txt.copy': 'b', 'a|web/a.txt.copy.copy': 'b'},
Expand All @@ -188,8 +189,8 @@ main() {
result, writer.assets);

await writer.writeAsString(makeAsset('a|web/b.txt', 'b'));
FakeWatcher
.notifyWatchers(new WatchEvent(ChangeType.ADD, 'a/web/b.txt'));
FakeWatcher.notifyWatchers(
new WatchEvent(ChangeType.ADD, path.join('a', 'web', 'b.txt')));

result = await nextResult(results);
checkOutputs({'a|web/b.txt.copy': 'b', 'a|web/b.txt.copy.copy': 'b'},
Expand Down Expand Up @@ -219,8 +220,8 @@ main() {
}, result, writer.assets);

await writer.delete(makeAssetId('a|web/a.txt'));
FakeWatcher
.notifyWatchers(new WatchEvent(ChangeType.REMOVE, 'a/web/a.txt'));
FakeWatcher.notifyWatchers(
new WatchEvent(ChangeType.REMOVE, path.join('a', 'web', 'a.txt')));

result = await nextResult(results);
// Shouldn't rebuild anything, no outputs.
Expand Down Expand Up @@ -249,8 +250,8 @@ main() {
result, writer.assets);

await writer.delete(makeAssetId('a|web/a.txt.copy'));
FakeWatcher.notifyWatchers(
new WatchEvent(ChangeType.REMOVE, 'a/web/a.txt.copy'));
FakeWatcher.notifyWatchers(new WatchEvent(
ChangeType.REMOVE, path.join('a', 'web', 'a.txt.copy')));

result = await nextResult(results);
// Should rebuild the generated asset and its outputs.
Expand All @@ -275,8 +276,8 @@ main() {
checkOutputs({'a|web/a.txt.copy': 'b'}, result, writer.assets);

await writer.writeAsString(makeAsset('a|web/b.txt', 'c'));
FakeWatcher
.notifyWatchers(new WatchEvent(ChangeType.MODIFY, 'a/web/b.txt'));
FakeWatcher.notifyWatchers(
new WatchEvent(ChangeType.MODIFY, path.join('a', 'web', 'b.txt')));

result = await nextResult(results);
checkOutputs({'a|web/a.txt.copy': 'c'}, result, writer.assets);
Expand All @@ -303,8 +304,8 @@ main() {
result, writer.assets);

await writer.writeAsString(makeAsset('a|web/b.txt', 'c'));
FakeWatcher
.notifyWatchers(new WatchEvent(ChangeType.MODIFY, 'a/web/b.txt'));
FakeWatcher.notifyWatchers(
new WatchEvent(ChangeType.MODIFY, path.join('a', 'web', 'b.txt')));

result = await nextResult(results);
checkOutputs({'a|web/a.txt.copy.copy': 'c'}, result, writer.assets);
Expand Down
19 changes: 12 additions & 7 deletions test/package_graph/package_graph_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@TestOn('vm')
import 'package:path/path.dart' as path;
import 'package:test/test.dart';

import 'package:build/build.dart';
Expand Down Expand Up @@ -44,17 +45,17 @@ main() {

test('pub dependency', () {
expectPkg(graph['a'], 'a', '2.0.0', PackageDependencyType.Pub,
'$basicPkgPath/pkg/a/', [graph['b'], graph['c']]);
'$basicPkgPath/pkg/a', [graph['b'], graph['c']]);
});

test('git dependency', () {
expectPkg(graph['b'], 'b', '3.0.0', PackageDependencyType.Github,
'$basicPkgPath/pkg/b/', [graph['c']]);
'$basicPkgPath/pkg/b', [graph['c']]);
});

test('path dependency', () {
expectPkg(graph['c'], 'c', '4.0.0', PackageDependencyType.Path,
'$basicPkgPath/pkg/c/', [graph['basic_pkg']]);
'$basicPkgPath/pkg/c', [graph['basic_pkg']]);
});
});

Expand Down Expand Up @@ -87,10 +88,10 @@ main() {

// Package `c` does not appear because this is not the root package.
expectPkg(graph['a'], 'a', '2.0.0', PackageDependencyType.Pub,
'$withDevDepsPkgPath/pkg/a/', []);
'$withDevDepsPkgPath/pkg/a', []);

expectPkg(graph['b'], 'b', '3.0.0', PackageDependencyType.Pub,
'$withDevDepsPkgPath/pkg/b/', []);
'$withDevDepsPkgPath/pkg/b', []);

expect(graph['c'], isNull);
});
Expand All @@ -110,11 +111,15 @@ main() {

test('missing pubspec throws on create', () {
expect(
() => new PackageGraph.forPath('test/fixtures/no_pubspec'), throws);
() => new PackageGraph.forPath(
path.join('test', 'fixtures', 'no_pubspec')),
throws);
});

test('missing .packages file throws on create', () {
expect(() => new PackageGraph.forPath('test/fixtures/no_packages_file'),
expect(
() => new PackageGraph.forPath(
path.join('test', 'fixtures', 'no_packages_file')),
throws);
});
});
Expand Down