forked from firka/flutter
Add initial implementation of flutter assemble (#32816)
This commit is contained in:
554
packages/flutter_tools/test/build_system/build_system_test.dart
Normal file
554
packages/flutter_tools/test/build_system/build_system_test.dart
Normal file
@@ -0,0 +1,554 @@
|
||||
// Copyright 2019 The Chromium 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:flutter_tools/src/artifacts.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/build_info.dart';
|
||||
import 'package:flutter_tools/src/build_system/build_system.dart';
|
||||
import 'package:flutter_tools/src/build_system/exceptions.dart';
|
||||
import 'package:flutter_tools/src/build_system/file_hash_store.dart';
|
||||
import 'package:flutter_tools/src/build_system/filecache.pb.dart' as pb;
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/convert.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
import '../src/testbed.dart';
|
||||
|
||||
void main() {
|
||||
setUpAll(() {
|
||||
Cache.disableLocking();
|
||||
});
|
||||
|
||||
group(Target, () {
|
||||
Testbed testbed;
|
||||
MockPlatform mockPlatform;
|
||||
Environment environment;
|
||||
Target fooTarget;
|
||||
Target barTarget;
|
||||
Target fizzTarget;
|
||||
BuildSystem buildSystem;
|
||||
int fooInvocations;
|
||||
int barInvocations;
|
||||
|
||||
setUp(() {
|
||||
fooInvocations = 0;
|
||||
barInvocations = 0;
|
||||
mockPlatform = MockPlatform();
|
||||
// Keep file paths the same.
|
||||
when(mockPlatform.isWindows).thenReturn(false);
|
||||
testbed = Testbed(
|
||||
setup: () {
|
||||
environment = Environment(
|
||||
projectDir: fs.currentDirectory,
|
||||
);
|
||||
fs.file('foo.dart').createSync(recursive: true);
|
||||
fs.file('pubspec.yaml').createSync();
|
||||
fooTarget = Target(
|
||||
name: 'foo',
|
||||
inputs: const <Source>[
|
||||
Source.pattern('{PROJECT_DIR}/foo.dart'),
|
||||
],
|
||||
outputs: const <Source>[
|
||||
Source.pattern('{BUILD_DIR}/out'),
|
||||
],
|
||||
dependencies: <Target>[],
|
||||
buildAction: (Map<String, ChangeType> updates, Environment environment) {
|
||||
environment
|
||||
.buildDir
|
||||
.childFile('out')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('hey');
|
||||
fooInvocations++;
|
||||
}
|
||||
);
|
||||
barTarget = Target(
|
||||
name: 'bar',
|
||||
inputs: const <Source>[
|
||||
Source.pattern('{BUILD_DIR}/out'),
|
||||
],
|
||||
outputs: const <Source>[
|
||||
Source.pattern('{BUILD_DIR}/bar'),
|
||||
],
|
||||
dependencies: <Target>[fooTarget],
|
||||
buildAction: (Map<String, ChangeType> updates, Environment environment) {
|
||||
environment.buildDir
|
||||
.childFile('bar')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('there');
|
||||
barInvocations++;
|
||||
}
|
||||
);
|
||||
fizzTarget = Target(
|
||||
name: 'fizz',
|
||||
inputs: const <Source>[
|
||||
Source.pattern('{BUILD_DIR}/out'),
|
||||
],
|
||||
outputs: const <Source>[
|
||||
Source.pattern('{BUILD_DIR}/fizz'),
|
||||
],
|
||||
dependencies: <Target>[fooTarget],
|
||||
buildAction: (Map<String, ChangeType> updates, Environment environment) {
|
||||
throw Exception('something bad happens');
|
||||
}
|
||||
);
|
||||
buildSystem = BuildSystem(<String, Target>{
|
||||
fooTarget.name: fooTarget,
|
||||
barTarget.name: barTarget,
|
||||
fizzTarget.name: fizzTarget,
|
||||
});
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
Platform: () => mockPlatform,
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
test('can describe build rules', () => testbed.run(() {
|
||||
expect(buildSystem.describe('foo', environment), <Object>[
|
||||
<String, Object>{
|
||||
'name': 'foo',
|
||||
'dependencies': <String>[],
|
||||
'inputs': <String>['/foo.dart'],
|
||||
'outputs': <String>[fs.path.join(environment.buildDir.path, 'out')],
|
||||
'stamp': fs.path.join(environment.buildDir.path, 'foo.stamp'),
|
||||
}
|
||||
]);
|
||||
}));
|
||||
|
||||
test('Throws exception if asked to build non-existent target', () => testbed.run(() {
|
||||
expect(buildSystem.build('not_real', environment, const BuildSystemConfig()), throwsA(isInstanceOf<Exception>()));
|
||||
}));
|
||||
|
||||
test('Throws exception if asked to build with missing inputs', () => testbed.run(() async {
|
||||
// Delete required input file.
|
||||
fs.file('foo.dart').deleteSync();
|
||||
final BuildResult buildResult = await buildSystem.build('foo', environment, const BuildSystemConfig());
|
||||
|
||||
expect(buildResult.hasException, true);
|
||||
expect(buildResult.exceptions.values.single.exception, isInstanceOf<MissingInputException>());
|
||||
}));
|
||||
|
||||
test('Throws exception if it does not produce a specified output', () => testbed.run(() async {
|
||||
final Target badTarget = Target
|
||||
(buildAction: (Map<String, ChangeType> inputs, Environment environment) {},
|
||||
inputs: const <Source>[
|
||||
Source.pattern('{PROJECT_DIR}/foo.dart'),
|
||||
],
|
||||
outputs: const <Source>[
|
||||
Source.pattern('{BUILD_DIR}/out')
|
||||
],
|
||||
name: 'bad'
|
||||
);
|
||||
buildSystem = BuildSystem(<String, Target>{
|
||||
badTarget.name: badTarget,
|
||||
});
|
||||
final BuildResult result = await buildSystem.build('bad', environment, const BuildSystemConfig());
|
||||
|
||||
expect(result.hasException, true);
|
||||
expect(result.exceptions.values.single.exception, isInstanceOf<MissingOutputException>());
|
||||
}));
|
||||
|
||||
test('Saves a stamp file with inputs and outputs', () => testbed.run(() async {
|
||||
await buildSystem.build('foo', environment, const BuildSystemConfig());
|
||||
|
||||
final File stampFile = fs.file(fs.path.join(environment.buildDir.path, 'foo.stamp'));
|
||||
expect(stampFile.existsSync(), true);
|
||||
|
||||
final Map<String, Object> stampContents = json.decode(stampFile.readAsStringSync());
|
||||
expect(stampContents['inputs'], <Object>['/foo.dart']);
|
||||
}));
|
||||
|
||||
test('Does not re-invoke build if stamp is valid', () => testbed.run(() async {
|
||||
await buildSystem.build('foo', environment, const BuildSystemConfig());
|
||||
await buildSystem.build('foo', environment, const BuildSystemConfig());
|
||||
|
||||
expect(fooInvocations, 1);
|
||||
}));
|
||||
|
||||
test('Re-invoke build if input is modified', () => testbed.run(() async {
|
||||
await buildSystem.build('foo', environment, const BuildSystemConfig());
|
||||
|
||||
fs.file('foo.dart').writeAsStringSync('new contents');
|
||||
|
||||
await buildSystem.build('foo', environment, const BuildSystemConfig());
|
||||
expect(fooInvocations, 2);
|
||||
}));
|
||||
|
||||
test('does not re-invoke build if input timestamp changes', () => testbed.run(() async {
|
||||
await buildSystem.build('foo', environment, const BuildSystemConfig());
|
||||
|
||||
fs.file('foo.dart').writeAsStringSync('');
|
||||
|
||||
await buildSystem.build('foo', environment, const BuildSystemConfig());
|
||||
expect(fooInvocations, 1);
|
||||
}));
|
||||
|
||||
test('does not re-invoke build if output timestamp changes', () => testbed.run(() async {
|
||||
await buildSystem.build('foo', environment, const BuildSystemConfig());
|
||||
|
||||
environment.buildDir.childFile('out').writeAsStringSync('hey');
|
||||
|
||||
await buildSystem.build('foo', environment, const BuildSystemConfig());
|
||||
expect(fooInvocations, 1);
|
||||
}));
|
||||
|
||||
|
||||
test('Re-invoke build if output is modified', () => testbed.run(() async {
|
||||
await buildSystem.build('foo', environment, const BuildSystemConfig());
|
||||
|
||||
environment.buildDir.childFile('out').writeAsStringSync('Something different');
|
||||
|
||||
await buildSystem.build('foo', environment, const BuildSystemConfig());
|
||||
expect(fooInvocations, 2);
|
||||
}));
|
||||
|
||||
test('Runs dependencies of targets', () => testbed.run(() async {
|
||||
await buildSystem.build('bar', environment, const BuildSystemConfig());
|
||||
|
||||
expect(fs.file(fs.path.join(environment.buildDir.path, 'bar')).existsSync(), true);
|
||||
expect(fooInvocations, 1);
|
||||
expect(barInvocations, 1);
|
||||
}));
|
||||
|
||||
test('handles a throwing build action', () => testbed.run(() async {
|
||||
final BuildResult result = await buildSystem.build('fizz', environment, const BuildSystemConfig());
|
||||
|
||||
expect(result.hasException, true);
|
||||
}));
|
||||
|
||||
test('Can describe itself with JSON output', () => testbed.run(() {
|
||||
environment.buildDir.createSync(recursive: true);
|
||||
expect(fooTarget.toJson(environment), <String, dynamic>{
|
||||
'inputs': <Object>[
|
||||
'/foo.dart'
|
||||
],
|
||||
'outputs': <Object>[
|
||||
fs.path.join(environment.buildDir.path, 'out'),
|
||||
],
|
||||
'dependencies': <Object>[],
|
||||
'name': 'foo',
|
||||
'stamp': fs.path.join(environment.buildDir.path, 'foo.stamp'),
|
||||
});
|
||||
}));
|
||||
|
||||
test('Compute update recognizes added files', () => testbed.run(() async {
|
||||
fs.directory('build').createSync();
|
||||
final FileHashStore fileCache = FileHashStore(environment);
|
||||
fileCache.initialize();
|
||||
final List<File> inputs = fooTarget.resolveInputs(environment);
|
||||
final Map<String, ChangeType> changes = await fooTarget.computeChanges(inputs, environment, fileCache);
|
||||
fileCache.persist();
|
||||
|
||||
expect(changes, <String, ChangeType>{
|
||||
'/foo.dart': ChangeType.Added
|
||||
});
|
||||
|
||||
await buildSystem.build('foo', environment, const BuildSystemConfig());
|
||||
final Map<String, ChangeType> secondChanges = await fooTarget.computeChanges(inputs, environment, fileCache);
|
||||
|
||||
expect(secondChanges, <String, ChangeType>{});
|
||||
}));
|
||||
});
|
||||
|
||||
group('FileCache', () {
|
||||
Testbed testbed;
|
||||
Environment environment;
|
||||
|
||||
setUp(() {
|
||||
testbed = Testbed(setup: () {
|
||||
fs.directory('build').createSync();
|
||||
environment = Environment(
|
||||
projectDir: fs.currentDirectory,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test('Initializes file cache', () => testbed.run(() {
|
||||
final FileHashStore fileCache = FileHashStore(environment);
|
||||
fileCache.initialize();
|
||||
fileCache.persist();
|
||||
|
||||
expect(fs.file(fs.path.join('build', '.filecache')).existsSync(), true);
|
||||
|
||||
final List<int> buffer = fs.file(fs.path.join('build', '.filecache')).readAsBytesSync();
|
||||
final pb.FileStorage fileStorage = pb.FileStorage.fromBuffer(buffer);
|
||||
|
||||
expect(fileStorage.files, isEmpty);
|
||||
expect(fileStorage.version, 1);
|
||||
}));
|
||||
|
||||
test('saves and restores to file cache', () => testbed.run(() {
|
||||
final File file = fs.file('foo.dart')
|
||||
..createSync()
|
||||
..writeAsStringSync('hello');
|
||||
final FileHashStore fileCache = FileHashStore(environment);
|
||||
fileCache.initialize();
|
||||
fileCache.hashFiles(<File>[file]);
|
||||
fileCache.persist();
|
||||
final String currentHash = fileCache.currentHashes[file.resolveSymbolicLinksSync()];
|
||||
final List<int> buffer = fs.file(fs.path.join('build', '.filecache')).readAsBytesSync();
|
||||
pb.FileStorage fileStorage = pb.FileStorage.fromBuffer(buffer);
|
||||
|
||||
expect(fileStorage.files.single.hash, currentHash);
|
||||
expect(fileStorage.files.single.path, file.resolveSymbolicLinksSync());
|
||||
|
||||
|
||||
final FileHashStore newFileCache = FileHashStore(environment);
|
||||
newFileCache.initialize();
|
||||
expect(newFileCache.currentHashes, isEmpty);
|
||||
expect(newFileCache.previousHashes[fs.path.absolute('foo.dart')], currentHash);
|
||||
newFileCache.persist();
|
||||
|
||||
// Still persisted correctly.
|
||||
fileStorage = pb.FileStorage.fromBuffer(buffer);
|
||||
|
||||
expect(fileStorage.files.single.hash, currentHash);
|
||||
expect(fileStorage.files.single.path, file.resolveSymbolicLinksSync());
|
||||
}));
|
||||
});
|
||||
|
||||
group('Target', () {
|
||||
Testbed testbed;
|
||||
MockPlatform mockPlatform;
|
||||
Environment environment;
|
||||
Target sharedTarget;
|
||||
BuildSystem buildSystem;
|
||||
int shared;
|
||||
|
||||
setUp(() {
|
||||
shared = 0;
|
||||
Cache.flutterRoot = '';
|
||||
mockPlatform = MockPlatform();
|
||||
// Keep file paths the same.
|
||||
when(mockPlatform.isWindows).thenReturn(false);
|
||||
when(mockPlatform.isLinux).thenReturn(true);
|
||||
when(mockPlatform.isMacOS).thenReturn(false);
|
||||
testbed = Testbed(
|
||||
setup: () {
|
||||
environment = Environment(
|
||||
projectDir: fs.currentDirectory,
|
||||
);
|
||||
fs.file('foo.dart').createSync(recursive: true);
|
||||
fs.file('pubspec.yaml').createSync();
|
||||
sharedTarget = Target(
|
||||
name: 'shared',
|
||||
inputs: const <Source>[
|
||||
Source.pattern('{PROJECT_DIR}/foo.dart'),
|
||||
],
|
||||
outputs: const <Source>[],
|
||||
dependencies: <Target>[],
|
||||
buildAction: (Map<String, ChangeType> updates, Environment environment) {
|
||||
shared += 1;
|
||||
}
|
||||
);
|
||||
final Target fooTarget = Target(
|
||||
name: 'foo',
|
||||
inputs: const <Source>[
|
||||
Source.pattern('{PROJECT_DIR}/foo.dart'),
|
||||
],
|
||||
outputs: const <Source>[
|
||||
Source.pattern('{BUILD_DIR}/out'),
|
||||
],
|
||||
dependencies: <Target>[sharedTarget],
|
||||
buildAction: (Map<String, ChangeType> updates, Environment environment) {
|
||||
environment
|
||||
.buildDir
|
||||
.childFile('out')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('hey');
|
||||
}
|
||||
);
|
||||
final Target barTarget = Target(
|
||||
name: 'bar',
|
||||
inputs: const <Source>[
|
||||
Source.pattern('{BUILD_DIR}/out'),
|
||||
],
|
||||
outputs: const <Source>[
|
||||
Source.pattern('{BUILD_DIR}/bar'),
|
||||
],
|
||||
dependencies: <Target>[fooTarget, sharedTarget],
|
||||
buildAction: (Map<String, ChangeType> updates, Environment environment) {
|
||||
environment
|
||||
.buildDir
|
||||
.childFile('bar')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('there');
|
||||
}
|
||||
);
|
||||
buildSystem = BuildSystem(<String, Target>{
|
||||
fooTarget.name: fooTarget,
|
||||
barTarget.name: barTarget,
|
||||
sharedTarget.name: sharedTarget,
|
||||
});
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
Platform: () => mockPlatform,
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
test('Only invokes shared target once', () => testbed.run(() async {
|
||||
await buildSystem.build('bar', environment, const BuildSystemConfig());
|
||||
|
||||
expect(shared, 1);
|
||||
}));
|
||||
});
|
||||
|
||||
group('Source', () {
|
||||
Testbed testbed;
|
||||
SourceVisitor visitor;
|
||||
Environment environment;
|
||||
|
||||
setUp(() {
|
||||
testbed = Testbed(setup: () {
|
||||
fs.directory('cache').createSync();
|
||||
environment = Environment(
|
||||
projectDir: fs.currentDirectory,
|
||||
buildDir: fs.directory('build'),
|
||||
);
|
||||
visitor = SourceVisitor(environment);
|
||||
environment.buildDir.createSync(recursive: true);
|
||||
});
|
||||
});
|
||||
|
||||
test('configures implicit vs explict correctly', () => testbed.run(() {
|
||||
expect(const Source.pattern('{PROJECT_DIR}/foo').implicit, false);
|
||||
expect(const Source.pattern('{PROJECT_DIR}/*foo').implicit, true);
|
||||
expect(Source.function((Environment environment) => <File>[]).implicit, true);
|
||||
expect(Source.behavior(TestBehavior()).implicit, true);
|
||||
}));
|
||||
|
||||
test('can substitute {PROJECT_DIR}/foo', () => testbed.run(() {
|
||||
fs.file('foo').createSync();
|
||||
const Source fooSource = Source.pattern('{PROJECT_DIR}/foo');
|
||||
fooSource.accept(visitor);
|
||||
|
||||
expect(visitor.sources.single.path, fs.path.absolute('foo'));
|
||||
}));
|
||||
|
||||
test('can substitute {BUILD_DIR}/bar', () => testbed.run(() {
|
||||
final String path = fs.path.join(environment.buildDir.path, 'bar');
|
||||
fs.file(path).createSync();
|
||||
const Source barSource = Source.pattern('{BUILD_DIR}/bar');
|
||||
barSource.accept(visitor);
|
||||
|
||||
expect(visitor.sources.single.path, fs.path.absolute(path));
|
||||
}));
|
||||
|
||||
test('can substitute Artifact', () => testbed.run(() {
|
||||
final String path = fs.path.join(
|
||||
Cache.instance.getArtifactDirectory('engine').path,
|
||||
'windows-x64',
|
||||
'foo',
|
||||
);
|
||||
fs.file(path).createSync(recursive: true);
|
||||
const Source fizzSource = Source.artifact(Artifact.windowsDesktopPath, platform: TargetPlatform.windows_x64);
|
||||
fizzSource.accept(visitor);
|
||||
|
||||
expect(visitor.sources.single.resolveSymbolicLinksSync(), fs.path.absolute(path));
|
||||
}));
|
||||
|
||||
test('can substitute {PROJECT_DIR}/*.fizz', () => testbed.run(() {
|
||||
const Source fizzSource = Source.pattern('{PROJECT_DIR}/*.fizz');
|
||||
fizzSource.accept(visitor);
|
||||
|
||||
expect(visitor.sources, isEmpty);
|
||||
|
||||
fs.file('foo.fizz').createSync();
|
||||
fs.file('foofizz').createSync();
|
||||
|
||||
|
||||
fizzSource.accept(visitor);
|
||||
|
||||
expect(visitor.sources.single.path, fs.path.absolute('foo.fizz'));
|
||||
}));
|
||||
|
||||
test('can substitute {PROJECT_DIR}/fizz.*', () => testbed.run(() {
|
||||
const Source fizzSource = Source.pattern('{PROJECT_DIR}/fizz.*');
|
||||
fizzSource.accept(visitor);
|
||||
|
||||
expect(visitor.sources, isEmpty);
|
||||
|
||||
fs.file('fizz.foo').createSync();
|
||||
fs.file('fizz').createSync();
|
||||
|
||||
fizzSource.accept(visitor);
|
||||
|
||||
expect(visitor.sources.single.path, fs.path.absolute('fizz.foo'));
|
||||
}));
|
||||
|
||||
|
||||
test('can substitute {PROJECT_DIR}/a*bc', () => testbed.run(() {
|
||||
const Source fizzSource = Source.pattern('{PROJECT_DIR}/bc*bc');
|
||||
fizzSource.accept(visitor);
|
||||
|
||||
expect(visitor.sources, isEmpty);
|
||||
|
||||
fs.file('bcbc').createSync();
|
||||
fs.file('bc').createSync();
|
||||
|
||||
fizzSource.accept(visitor);
|
||||
|
||||
expect(visitor.sources.single.path, fs.path.absolute('bcbc'));
|
||||
}));
|
||||
|
||||
|
||||
test('crashes on bad substitute of two **', () => testbed.run(() {
|
||||
const Source fizzSource = Source.pattern('{PROJECT_DIR}/*.*bar');
|
||||
|
||||
fs.file('abcd.bar').createSync();
|
||||
|
||||
expect(() => fizzSource.accept(visitor), throwsA(isInstanceOf<InvalidPatternException>()));
|
||||
}));
|
||||
|
||||
|
||||
test('can\'t substitute foo', () => testbed.run(() {
|
||||
const Source invalidBase = Source.pattern('foo');
|
||||
|
||||
expect(() => invalidBase.accept(visitor), throwsA(isInstanceOf<InvalidPatternException>()));
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
|
||||
test('Can find dependency cycles', () {
|
||||
final Target barTarget = Target(
|
||||
name: 'bar',
|
||||
inputs: <Source>[],
|
||||
outputs: <Source>[],
|
||||
buildAction: null,
|
||||
dependencies: nonconst(<Target>[])
|
||||
);
|
||||
final Target fooTarget = Target(
|
||||
name: 'foo',
|
||||
inputs: <Source>[],
|
||||
outputs: <Source>[],
|
||||
buildAction: null,
|
||||
dependencies: nonconst(<Target>[])
|
||||
);
|
||||
barTarget.dependencies.add(fooTarget);
|
||||
fooTarget.dependencies.add(barTarget);
|
||||
expect(() => checkCycles(barTarget), throwsA(isInstanceOf<CycleException>()));
|
||||
});
|
||||
}
|
||||
|
||||
class MockPlatform extends Mock implements Platform {}
|
||||
|
||||
// Work-around for silly lint check.
|
||||
T nonconst<T>(T input) => input;
|
||||
|
||||
class TestBehavior extends SourceBehavior {
|
||||
@override
|
||||
List<File> inputs(Environment environment) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
List<File> outputs(Environment environment) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
// Copyright 2019 The Chromium 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:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/build_system/build_system.dart';
|
||||
import 'package:flutter_tools/src/build_system/exceptions.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
|
||||
void main() {
|
||||
test('Exceptions', () {
|
||||
final MissingInputException missingInputException = MissingInputException(
|
||||
<File>[fs.file('foo'), fs.file('bar')], 'example');
|
||||
final CycleException cycleException = CycleException(const <Target>{
|
||||
Target(
|
||||
name: 'foo',
|
||||
buildAction: null,
|
||||
inputs: <Source>[],
|
||||
outputs: <Source>[],
|
||||
),
|
||||
Target(
|
||||
name: 'bar',
|
||||
buildAction: null,
|
||||
inputs: <Source>[],
|
||||
outputs: <Source>[],
|
||||
)
|
||||
});
|
||||
final InvalidPatternException invalidPatternException = InvalidPatternException(
|
||||
'ABC'
|
||||
);
|
||||
final MissingOutputException missingOutputException = MissingOutputException(
|
||||
<File>[ fs.file('foo'), fs.file('bar') ],
|
||||
'example'
|
||||
);
|
||||
final MisplacedOutputException misplacedOutputException = MisplacedOutputException(
|
||||
'foo',
|
||||
'example',
|
||||
);
|
||||
final MissingDefineException missingDefineException = MissingDefineException(
|
||||
'foobar',
|
||||
'example',
|
||||
);
|
||||
|
||||
expect(
|
||||
missingInputException.toString(),
|
||||
'foo, bar were declared as an inputs, '
|
||||
'but did not exist. Check the definition of target:example for errors');
|
||||
expect(
|
||||
cycleException.toString(),
|
||||
'Dependency cycle detected in build: foo -> bar'
|
||||
);
|
||||
expect(
|
||||
invalidPatternException.toString(),
|
||||
'The pattern "ABC" is not valid'
|
||||
);
|
||||
expect(
|
||||
missingOutputException.toString(),
|
||||
'foo, bar were declared as outputs, but were not generated by the '
|
||||
'action. Check the definition of target:example for errors'
|
||||
);
|
||||
expect(
|
||||
misplacedOutputException.toString(),
|
||||
'Target example produced an output at foo which is outside of the '
|
||||
'current build or project directory',
|
||||
);
|
||||
expect(
|
||||
missingDefineException.toString(),
|
||||
'Target example required define foobar but it was not provided'
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
// Copyright 2019 The Chromium 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:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/build_system/build_system.dart';
|
||||
import 'package:flutter_tools/src/build_system/targets/assets.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/testbed.dart';
|
||||
|
||||
void main() {
|
||||
group('copy_assets', () {
|
||||
Testbed testbed;
|
||||
BuildSystem buildSystem;
|
||||
Environment environment;
|
||||
|
||||
setUp(() {
|
||||
testbed = Testbed(setup: () {
|
||||
environment = Environment(
|
||||
projectDir: fs.currentDirectory,
|
||||
);
|
||||
buildSystem = BuildSystem(<String, Target>{
|
||||
copyAssets.name: copyAssets,
|
||||
});
|
||||
fs.file(fs.path.join('assets', 'foo', 'bar.png'))
|
||||
..createSync(recursive: true);
|
||||
fs.file('.packages')
|
||||
..createSync();
|
||||
fs.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync('''
|
||||
name: example
|
||||
|
||||
flutter:
|
||||
assets:
|
||||
- assets/foo/bar.png
|
||||
''');
|
||||
});
|
||||
});
|
||||
|
||||
test('Copies files to correct asset directory', () => testbed.run(() async {
|
||||
await buildSystem.build('copy_assets', environment, const BuildSystemConfig());
|
||||
|
||||
expect(fs.file(fs.path.join(environment.buildDir.path, 'flutter_assets', 'AssetManifest.json')).existsSync(), true);
|
||||
expect(fs.file(fs.path.join(environment.buildDir.path, 'flutter_assets', 'FontManifest.json')).existsSync(), true);
|
||||
expect(fs.file(fs.path.join(environment.buildDir.path, 'flutter_assets', 'LICENSE')).existsSync(), true);
|
||||
// See https://github.com/flutter/flutter/issues/35293
|
||||
expect(fs.file(fs.path.join(environment.buildDir.path, 'flutter_assets', 'assets/foo/bar.png')).existsSync(), true);
|
||||
}));
|
||||
|
||||
test('Does not leave stale files in build directory', () => testbed.run(() async {
|
||||
await buildSystem.build('copy_assets', environment, const BuildSystemConfig());
|
||||
|
||||
expect(fs.file(fs.path.join(environment.buildDir.path, 'flutter_assets', 'assets/foo/bar.png')).existsSync(), true);
|
||||
// Modify manifest to remove asset.
|
||||
fs.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync('''
|
||||
name: example
|
||||
|
||||
flutter:
|
||||
''');
|
||||
await buildSystem.build('copy_assets', environment, const BuildSystemConfig());
|
||||
|
||||
// See https://github.com/flutter/flutter/issues/35293
|
||||
expect(fs.file(fs.path.join(environment.buildDir.path, 'flutter_assets', 'assets/foo/bar.png')).existsSync(), false);
|
||||
}));
|
||||
});
|
||||
}
|
||||
224
packages/flutter_tools/test/build_system/targets/dart_test.dart
Normal file
224
packages/flutter_tools/test/build_system/targets/dart_test.dart
Normal file
@@ -0,0 +1,224 @@
|
||||
// Copyright 2019 The Chromium 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:flutter_tools/src/base/build.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/build_info.dart';
|
||||
import 'package:flutter_tools/src/build_system/build_system.dart';
|
||||
import 'package:flutter_tools/src/build_system/exceptions.dart';
|
||||
import 'package:flutter_tools/src/build_system/targets/dart.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/compile.dart';
|
||||
import 'package:flutter_tools/src/project.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:process/process.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/mocks.dart';
|
||||
import '../../src/testbed.dart';
|
||||
|
||||
void main() {
|
||||
group('dart rules', () {
|
||||
Testbed testbed;
|
||||
BuildSystem buildSystem;
|
||||
Environment androidEnvironment;
|
||||
Environment iosEnvironment;
|
||||
MockProcessManager mockProcessManager;
|
||||
|
||||
setUpAll(() {
|
||||
Cache.disableLocking();
|
||||
});
|
||||
|
||||
setUp(() {
|
||||
mockProcessManager = MockProcessManager();
|
||||
testbed = Testbed(setup: () {
|
||||
androidEnvironment = Environment(
|
||||
projectDir: fs.currentDirectory,
|
||||
defines: <String, String>{
|
||||
kBuildMode: getNameForBuildMode(BuildMode.profile),
|
||||
kTargetPlatform: getNameForTargetPlatform(TargetPlatform.android_arm),
|
||||
}
|
||||
);
|
||||
iosEnvironment = Environment(
|
||||
projectDir: fs.currentDirectory,
|
||||
defines: <String, String>{
|
||||
kBuildMode: getNameForBuildMode(BuildMode.profile),
|
||||
kTargetPlatform: getNameForTargetPlatform(TargetPlatform.ios),
|
||||
}
|
||||
);
|
||||
buildSystem = BuildSystem();
|
||||
HostPlatform hostPlatform;
|
||||
if (platform.isWindows) {
|
||||
hostPlatform = HostPlatform.windows_x64;
|
||||
} else if (platform.isLinux) {
|
||||
hostPlatform = HostPlatform.linux_x64;
|
||||
} else if (platform.isMacOS) {
|
||||
hostPlatform = HostPlatform.darwin_x64;
|
||||
} else {
|
||||
assert(false);
|
||||
}
|
||||
final String skyEngineLine = platform.isWindows
|
||||
? r'sky_engine:file:///C:/bin/cache/pkg/sky_engine/lib/'
|
||||
: 'sky_engine:file:///bin/cache/pkg/sky_engine/lib/';
|
||||
fs.file('.packages')
|
||||
..createSync()
|
||||
..writeAsStringSync('''
|
||||
# Generated
|
||||
$skyEngineLine
|
||||
flutter_tools:lib/''');
|
||||
final String engineArtifacts = fs.path.join('bin', 'cache',
|
||||
'artifacts', 'engine');
|
||||
final List<String> paths = <String>[
|
||||
fs.path.join('bin', 'cache', 'pkg', 'sky_engine', 'lib', 'ui',
|
||||
'ui.dart'),
|
||||
fs.path.join('bin', 'cache', 'pkg', 'sky_engine', 'sdk_ext',
|
||||
'vmservice_io.dart'),
|
||||
fs.path.join('bin', 'cache', 'dart-sdk', 'bin', 'dart'),
|
||||
fs.path.join(engineArtifacts, getNameForHostPlatform(hostPlatform),
|
||||
'frontend_server.dart.snapshot'),
|
||||
fs.path.join(engineArtifacts, 'android-arm-profile',
|
||||
getNameForHostPlatform(hostPlatform), 'gen_snapshot'),
|
||||
fs.path.join(engineArtifacts, 'ios-profile', 'gen_snapshot'),
|
||||
fs.path.join(engineArtifacts, 'common', 'flutter_patched_sdk',
|
||||
'platform_strong.dill'),
|
||||
fs.path.join('lib', 'foo.dart'),
|
||||
fs.path.join('lib', 'bar.dart'),
|
||||
fs.path.join('lib', 'fizz'),
|
||||
];
|
||||
for (String path in paths) {
|
||||
fs.file(path).createSync(recursive: true);
|
||||
}
|
||||
}, overrides: <Type, Generator>{
|
||||
KernelCompilerFactory: () => FakeKernelCompilerFactory(),
|
||||
GenSnapshot: () => FakeGenSnapshot(),
|
||||
});
|
||||
});
|
||||
|
||||
test('kernel_snapshot Produces correct output directory', () => testbed.run(() async {
|
||||
await buildSystem.build('kernel_snapshot', androidEnvironment, const BuildSystemConfig());
|
||||
|
||||
expect(fs.file(fs.path.join(androidEnvironment.buildDir.path,'main.app.dill')).existsSync(), true);
|
||||
}));
|
||||
|
||||
test('kernel_snapshot throws error if missing build mode', () => testbed.run(() async {
|
||||
final BuildResult result = await buildSystem.build('kernel_snapshot',
|
||||
androidEnvironment..defines.remove(kBuildMode), const BuildSystemConfig());
|
||||
|
||||
expect(result.exceptions.values.single.exception, isInstanceOf<MissingDefineException>());
|
||||
}));
|
||||
|
||||
test('aot_elf_profile Produces correct output directory', () => testbed.run(() async {
|
||||
await buildSystem.build('aot_elf_profile', androidEnvironment, const BuildSystemConfig());
|
||||
|
||||
expect(fs.file(fs.path.join(androidEnvironment.buildDir.path, 'main.app.dill')).existsSync(), true);
|
||||
expect(fs.file(fs.path.join(androidEnvironment.buildDir.path, 'app.so')).existsSync(), true);
|
||||
}));
|
||||
|
||||
test('aot_elf_profile throws error if missing build mode', () => testbed.run(() async {
|
||||
final BuildResult result = await buildSystem.build('aot_elf_profile',
|
||||
androidEnvironment..defines.remove(kBuildMode), const BuildSystemConfig());
|
||||
|
||||
expect(result.exceptions.values.single.exception, isInstanceOf<MissingDefineException>());
|
||||
}));
|
||||
|
||||
|
||||
test('aot_elf_profile throws error if missing target platform', () => testbed.run(() async {
|
||||
final BuildResult result = await buildSystem.build('aot_elf_profile',
|
||||
androidEnvironment..defines.remove(kTargetPlatform), const BuildSystemConfig());
|
||||
|
||||
expect(result.exceptions.values.single.exception, isInstanceOf<MissingDefineException>());
|
||||
}));
|
||||
|
||||
|
||||
test('aot_assembly_profile throws error if missing build mode', () => testbed.run(() async {
|
||||
final BuildResult result = await buildSystem.build('aot_assembly_profile',
|
||||
iosEnvironment..defines.remove(kBuildMode), const BuildSystemConfig());
|
||||
|
||||
expect(result.exceptions.values.single.exception, isInstanceOf<MissingDefineException>());
|
||||
}));
|
||||
|
||||
test('aot_assembly_profile throws error if missing target platform', () => testbed.run(() async {
|
||||
final BuildResult result = await buildSystem.build('aot_assembly_profile',
|
||||
iosEnvironment..defines.remove(kTargetPlatform), const BuildSystemConfig());
|
||||
|
||||
expect(result.exceptions.values.single.exception, isInstanceOf<MissingDefineException>());
|
||||
}));
|
||||
|
||||
test('aot_assembly_profile throws error if built for non-iOS platform', () => testbed.run(() async {
|
||||
final BuildResult result = await buildSystem.build('aot_assembly_profile',
|
||||
androidEnvironment, const BuildSystemConfig());
|
||||
|
||||
expect(result.exceptions.values.single.exception, isInstanceOf<Exception>());
|
||||
}));
|
||||
|
||||
test('aot_assembly_profile will lipo binaries together when multiple archs are requested', () => testbed.run(() async {
|
||||
iosEnvironment.defines[kIosArchs] ='armv7,arm64';
|
||||
when(mockProcessManager.run(any)).thenAnswer((Invocation invocation) async {
|
||||
fs.file(fs.path.join(iosEnvironment.buildDir.path, 'App.framework', 'App'))
|
||||
.createSync(recursive: true);
|
||||
return FakeProcessResult(
|
||||
stdout: '',
|
||||
stderr: '',
|
||||
);
|
||||
});
|
||||
final BuildResult result = await buildSystem.build('aot_assembly_profile',
|
||||
iosEnvironment, const BuildSystemConfig());
|
||||
|
||||
expect(result.success, true);
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
class MockProcessManager extends Mock implements ProcessManager {}
|
||||
|
||||
class FakeGenSnapshot implements GenSnapshot {
|
||||
@override
|
||||
Future<int> run({SnapshotType snapshotType, IOSArch iosArch, Iterable<String> additionalArgs = const <String>[]}) async {
|
||||
final Directory out = fs.file(additionalArgs.last).parent;
|
||||
if (iosArch == null) {
|
||||
out.childFile('app.so').createSync();
|
||||
out.childFile('gen_snapshot.d').createSync();
|
||||
return 0;
|
||||
}
|
||||
out.childDirectory('App.framework').childFile('App').createSync(recursive: true);
|
||||
out.childFile('snapshot_assembly.S').createSync();
|
||||
out.childFile('snapshot_assembly.o').createSync();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
class FakeKernelCompilerFactory implements KernelCompilerFactory {
|
||||
FakeKernelCompiler kernelCompiler = FakeKernelCompiler();
|
||||
|
||||
@override
|
||||
Future<KernelCompiler> create(FlutterProject flutterProject) async {
|
||||
return kernelCompiler;
|
||||
}
|
||||
}
|
||||
|
||||
class FakeKernelCompiler implements KernelCompiler {
|
||||
@override
|
||||
Future<CompilerOutput> compile({
|
||||
String sdkRoot,
|
||||
String mainPath,
|
||||
String outputFilePath,
|
||||
String depFilePath,
|
||||
TargetModel targetModel = TargetModel.flutter,
|
||||
bool linkPlatformKernelIn = false,
|
||||
bool aot = false,
|
||||
bool trackWidgetCreation,
|
||||
List<String> extraFrontEndOptions,
|
||||
String incrementalCompilerByteStorePath,
|
||||
String packagesPath,
|
||||
List<String> fileSystemRoots,
|
||||
String fileSystemScheme,
|
||||
bool targetProductVm = false,
|
||||
String initializeFromDill}) async {
|
||||
fs.file(outputFilePath).createSync(recursive: true);
|
||||
return CompilerOutput(outputFilePath, 0, null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
// Copyright 2019 The Chromium 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:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/build_system/build_system.dart';
|
||||
import 'package:flutter_tools/src/build_system/targets/linux.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/testbed.dart';
|
||||
|
||||
void main() {
|
||||
group('unpack_linux', () {
|
||||
Testbed testbed;
|
||||
BuildSystem buildSystem;
|
||||
Environment environment;
|
||||
MockPlatform mockPlatform;
|
||||
|
||||
setUpAll(() {
|
||||
Cache.disableLocking();
|
||||
});
|
||||
|
||||
setUp(() {
|
||||
mockPlatform = MockPlatform();
|
||||
when(mockPlatform.isWindows).thenReturn(false);
|
||||
when(mockPlatform.isMacOS).thenReturn(false);
|
||||
when(mockPlatform.isLinux).thenReturn(true);
|
||||
testbed = Testbed(setup: () {
|
||||
Cache.flutterRoot = '';
|
||||
environment = Environment(
|
||||
projectDir: fs.currentDirectory,
|
||||
);
|
||||
buildSystem = BuildSystem(<String, Target>{
|
||||
unpackLinux.name: unpackLinux,
|
||||
});
|
||||
fs.file('bin/cache/artifacts/engine/linux-x64/libflutter_linux.so').createSync(recursive: true);
|
||||
fs.file('bin/cache/artifacts/engine/linux-x64/flutter_export.h').createSync();
|
||||
fs.file('bin/cache/artifacts/engine/linux-x64/flutter_messenger.h').createSync();
|
||||
fs.file('bin/cache/artifacts/engine/linux-x64/flutter_plugin_registrar.h').createSync();
|
||||
fs.file('bin/cache/artifacts/engine/linux-x64/flutter_glfw.h').createSync();
|
||||
fs.file('bin/cache/artifacts/engine/linux-x64/icudtl.dat').createSync();
|
||||
fs.file('bin/cache/artifacts/engine/linux-x64/cpp_client_wrapper/foo').createSync(recursive: true);
|
||||
fs.directory('linux').createSync();
|
||||
}, overrides: <Type, Generator>{
|
||||
Platform: () => mockPlatform,
|
||||
});
|
||||
});
|
||||
|
||||
test('Copies files to correct cache directory', () => testbed.run(() async {
|
||||
final BuildResult result = await buildSystem.build('unpack_linux', environment, const BuildSystemConfig());
|
||||
|
||||
expect(result.hasException, false);
|
||||
expect(fs.file('linux/flutter/libflutter_linux.so').existsSync(), true);
|
||||
expect(fs.file('linux/flutter/flutter_export.h').existsSync(), true);
|
||||
expect(fs.file('linux/flutter/flutter_messenger.h').existsSync(), true);
|
||||
expect(fs.file('linux/flutter/flutter_plugin_registrar.h').existsSync(), true);
|
||||
expect(fs.file('linux/flutter/flutter_glfw.h').existsSync(), true);
|
||||
expect(fs.file('linux/flutter/icudtl.dat').existsSync(), true);
|
||||
expect(fs.file('linux/flutter/cpp_client_wrapper/foo').existsSync(), true);
|
||||
}));
|
||||
|
||||
test('Does not re-copy files unecessarily', () => testbed.run(() async {
|
||||
await buildSystem.build('unpack_linux', environment, const BuildSystemConfig());
|
||||
final DateTime modified = fs.file('linux/flutter/libflutter_linux.so').statSync().modified;
|
||||
await buildSystem.build('unpack_linux', environment, const BuildSystemConfig());
|
||||
|
||||
expect(fs.file('linux/flutter/libflutter_linux.so').statSync().modified, equals(modified));
|
||||
}));
|
||||
|
||||
test('Detects changes in input cache files', () => testbed.run(() async {
|
||||
await buildSystem.build('unpack_linux', environment, const BuildSystemConfig());
|
||||
fs.file('bin/cache/artifacts/engine/linux-x64/libflutter_linux.so').writeAsStringSync('asd'); // modify cache.
|
||||
|
||||
await buildSystem.build('unpack_linux', environment, const BuildSystemConfig());
|
||||
|
||||
expect(fs.file('linux/flutter/libflutter_linux.so').readAsStringSync(), 'asd');
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
class MockPlatform extends Mock implements Platform {}
|
||||
115
packages/flutter_tools/test/build_system/targets/macos_test.dart
Normal file
115
packages/flutter_tools/test/build_system/targets/macos_test.dart
Normal file
@@ -0,0 +1,115 @@
|
||||
// Copyright 2019 The Chromium 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:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/base/process_manager.dart';
|
||||
import 'package:flutter_tools/src/build_system/build_system.dart';
|
||||
import 'package:flutter_tools/src/build_system/targets/macos.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:process/process.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/testbed.dart';
|
||||
|
||||
void main() {
|
||||
group('unpack_macos', () {
|
||||
Testbed testbed;
|
||||
BuildSystem buildSystem;
|
||||
Environment environment;
|
||||
MockPlatform mockPlatform;
|
||||
|
||||
setUp(() {
|
||||
mockPlatform = MockPlatform();
|
||||
when(mockPlatform.isWindows).thenReturn(false);
|
||||
when(mockPlatform.isMacOS).thenReturn(true);
|
||||
when(mockPlatform.isLinux).thenReturn(false);
|
||||
testbed = Testbed(setup: () {
|
||||
environment = Environment(
|
||||
projectDir: fs.currentDirectory,
|
||||
);
|
||||
buildSystem = BuildSystem(<String, Target>{
|
||||
unpackMacos.name: unpackMacos,
|
||||
});
|
||||
final List<File> inputs = <File>[
|
||||
fs.file('bin/cache/artifacts/engine/darwin-x64/FlutterMacOS.framework/FlutterMacOS'),
|
||||
fs.file('bin/cache/artifacts/engine/darwin-x64/FlutterMacOS.framework/Headers/FLEOpenGLContextHandling.h'),
|
||||
fs.file('bin/cache/artifacts/engine/darwin-x64/FlutterMacOS.framework/Headers/FLEReshapeListener.h'),
|
||||
fs.file('bin/cache/artifacts/engine/darwin-x64/FlutterMacOS.framework/Headers/FLEView.h'),
|
||||
fs.file('bin/cache/artifacts/engine/darwin-x64/FlutterMacOS.framework/Headers/FLEViewController.h'),
|
||||
fs.file('bin/cache/artifacts/engine/darwin-x64/FlutterMacOS.framework/Headers/FlutterBinaryMessenger.h'),
|
||||
fs.file('bin/cache/artifacts/engine/darwin-x64/FlutterMacOS.framework/Headers/FlutterChannels.h'),
|
||||
fs.file('bin/cache/artifacts/engine/darwin-x64/FlutterMacOS.framework/Headers/FlutterCodecs.h'),
|
||||
fs.file('bin/cache/artifacts/engine/darwin-x64/FlutterMacOS.framework/Headers/FlutterMacOS.h'),
|
||||
fs.file('bin/cache/artifacts/engine/darwin-x64/FlutterMacOS.framework/Headers/FlutterPluginMacOS.h'),
|
||||
fs.file('bin/cache/artifacts/engine/darwin-x64/FlutterMacOS.framework/Headers/FlutterPluginRegisrarMacOS.h'),
|
||||
fs.file('bin/cache/artifacts/engine/darwin-x64/FlutterMacOS.framework/Modules/module.modulemap'),
|
||||
fs.file('bin/cache/artifacts/engine/darwin-x64/FlutterMacOS.framework/Resources/icudtl.dat'),
|
||||
fs.file('bin/cache/artifacts/engine/darwin-x64/FlutterMacOS.framework/Resources/info.plist'),
|
||||
];
|
||||
for (File input in inputs) {
|
||||
input.createSync(recursive: true);
|
||||
}
|
||||
when(processManager.runSync(any)).thenAnswer((Invocation invocation) {
|
||||
final List<String> arguments = invocation.positionalArguments.first;
|
||||
final Directory source = fs.directory(arguments[arguments.length - 2]);
|
||||
final Directory target = fs.directory(arguments.last)
|
||||
..createSync(recursive: true);
|
||||
for (FileSystemEntity entity in source.listSync(recursive: true)) {
|
||||
if (entity is File) {
|
||||
final String relative = fs.path.relative(entity.path, from: source.path);
|
||||
final String destination = fs.path.join(target.path, relative);
|
||||
if (!fs.file(destination).parent.existsSync()) {
|
||||
fs.file(destination).parent.createSync();
|
||||
}
|
||||
entity.copySync(destination);
|
||||
}
|
||||
}
|
||||
return FakeProcessResult()..exitCode = 0;
|
||||
});
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => MockProcessManager(),
|
||||
Platform: () => mockPlatform,
|
||||
});
|
||||
});
|
||||
|
||||
test('Copies files to correct cache directory', () => testbed.run(() async {
|
||||
await buildSystem.build('unpack_macos', environment, const BuildSystemConfig());
|
||||
|
||||
expect(fs.directory('macos/Flutter/FlutterMacOS.framework').existsSync(), true);
|
||||
expect(fs.file('macos/Flutter/FlutterMacOS.framework/FlutterMacOS').existsSync(), true);
|
||||
expect(fs.file('macos/Flutter/FlutterMacOS.framework/Headers/FLEOpenGLContextHandling.h').existsSync(), true);
|
||||
expect(fs.file('macos/Flutter/FlutterMacOS.framework/Headers/FLEReshapeListener.h').existsSync(), true);
|
||||
expect(fs.file('macos/Flutter/FlutterMacOS.framework/Headers/FLEView.h').existsSync(), true);
|
||||
expect(fs.file('macos/Flutter/FlutterMacOS.framework/Headers/FLEViewController.h').existsSync(), true);
|
||||
expect(fs.file('macos/Flutter/FlutterMacOS.framework/Headers/FlutterBinaryMessenger.h').existsSync(), true);
|
||||
expect(fs.file('macos/Flutter/FlutterMacOS.framework/Headers/FlutterChannels.h').existsSync(), true);
|
||||
expect(fs.file('macos/Flutter/FlutterMacOS.framework/Headers/FlutterCodecs.h').existsSync(), true);
|
||||
expect(fs.file('macos/Flutter/FlutterMacOS.framework/Headers/FlutterMacOS.h').existsSync(), true);
|
||||
expect(fs.file('macos/Flutter/FlutterMacOS.framework/Headers/FlutterPluginMacOS.h').existsSync(), true);
|
||||
expect(fs.file('macos/Flutter/FlutterMacOS.framework/Headers/FlutterPluginRegisrarMacOS.h').existsSync(), true);
|
||||
expect(fs.file('macos/Flutter/FlutterMacOS.framework/Modules/module.modulemap').existsSync(), true);
|
||||
expect(fs.file('macos/Flutter/FlutterMacOS.framework/Resources/icudtl.dat').existsSync(), true);
|
||||
expect(fs.file('macos/Flutter/FlutterMacOS.framework/Resources/info.plist').existsSync(), true);
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
class MockPlatform extends Mock implements Platform {}
|
||||
|
||||
class MockProcessManager extends Mock implements ProcessManager {}
|
||||
class FakeProcessResult implements ProcessResult {
|
||||
@override
|
||||
int exitCode;
|
||||
|
||||
@override
|
||||
int pid = 0;
|
||||
|
||||
@override
|
||||
String stderr = '';
|
||||
|
||||
@override
|
||||
String stdout = '';
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
// Copyright 2019 The Chromium 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:file/memory.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/build_system/build_system.dart';
|
||||
import 'package:flutter_tools/src/build_system/targets/windows.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/testbed.dart';
|
||||
|
||||
void main() {
|
||||
group('unpack_windows', () {
|
||||
Testbed testbed;
|
||||
BuildSystem buildSystem;
|
||||
Environment environment;
|
||||
Platform platform;
|
||||
|
||||
setUpAll(() {
|
||||
Cache.disableLocking();
|
||||
});
|
||||
|
||||
setUp(() {
|
||||
Cache.flutterRoot = '';
|
||||
platform = MockPlatform();
|
||||
when(platform.isWindows).thenReturn(true);
|
||||
when(platform.isMacOS).thenReturn(false);
|
||||
when(platform.isLinux).thenReturn(false);
|
||||
when(platform.pathSeparator).thenReturn(r'\');
|
||||
testbed = Testbed(setup: () {
|
||||
environment = Environment(
|
||||
projectDir: fs.currentDirectory,
|
||||
);
|
||||
buildSystem = BuildSystem(<String, Target>{
|
||||
unpackWindows.name: unpackWindows,
|
||||
});
|
||||
fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_export.h').createSync(recursive: true);
|
||||
fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_messenger.h').createSync();
|
||||
fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_windows.dll').createSync();
|
||||
fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_windows.dll.exp').createSync();
|
||||
fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_windows.dll.lib').createSync();
|
||||
fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_windows.dll.pdb').createSync();
|
||||
fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\lutter_export.h').createSync();
|
||||
fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_messenger.h').createSync();
|
||||
fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_plugin_registrar.h').createSync();
|
||||
fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_glfw.h').createSync();
|
||||
fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\icudtl.dat').createSync();
|
||||
fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\cpp_client_wrapper\foo').createSync(recursive: true);
|
||||
fs.directory('windows').createSync();
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => MemoryFileSystem(style: FileSystemStyle.windows),
|
||||
Platform: () => platform,
|
||||
});
|
||||
});
|
||||
|
||||
test('Copies files to correct cache directory', () => testbed.run(() async {
|
||||
await buildSystem.build('unpack_windows', environment, const BuildSystemConfig());
|
||||
|
||||
expect(fs.file(r'C:\windows\flutter\flutter_export.h').existsSync(), true);
|
||||
expect(fs.file(r'C:\windows\flutter\flutter_messenger.h').existsSync(), true);
|
||||
expect(fs.file(r'C:\windows\flutter\flutter_windows.dll').existsSync(), true);
|
||||
expect(fs.file(r'C:\windows\flutter\flutter_windows.dll.exp').existsSync(), true);
|
||||
expect(fs.file(r'C:\windows\flutter\flutter_windows.dll.lib').existsSync(), true);
|
||||
expect(fs.file(r'C:\windows\flutter\flutter_windows.dll.pdb').existsSync(), true);
|
||||
expect(fs.file(r'C:\windows\flutter\flutter_export.h').existsSync(), true);
|
||||
expect(fs.file(r'C:\windows\flutter\flutter_messenger.h').existsSync(), true);
|
||||
expect(fs.file(r'C:\windows\flutter\flutter_plugin_registrar.h').existsSync(), true);
|
||||
expect(fs.file(r'C:\windows\flutter\flutter_glfw.h').existsSync(), true);
|
||||
expect(fs.file(r'C:\windows\flutter\icudtl.dat').existsSync(), true);
|
||||
expect(fs.file(r'C:\windows\flutter\cpp_client_wrapper\foo').existsSync(), true);
|
||||
}));
|
||||
|
||||
test('Does not re-copy files unecessarily', () => testbed.run(() async {
|
||||
await buildSystem.build('unpack_windows', environment, const BuildSystemConfig());
|
||||
final DateTime modified = fs.file(r'C:\windows\flutter\flutter_export.h').statSync().modified;
|
||||
await buildSystem.build('unpack_windows', environment, const BuildSystemConfig());
|
||||
|
||||
expect(fs.file(r'C:\windows\flutter\flutter_export.h').statSync().modified, equals(modified));
|
||||
}));
|
||||
|
||||
test('Detects changes in input cache files', () => testbed.run(() async {
|
||||
await buildSystem.build('unpack_windows', environment, const BuildSystemConfig());
|
||||
final DateTime modified = fs.file(r'C:\windows\flutter\flutter_export.h').statSync().modified;
|
||||
fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_export.h').writeAsStringSync('asd'); // modify cache.
|
||||
|
||||
await buildSystem.build('unpack_windows', environment, const BuildSystemConfig());
|
||||
|
||||
expect(fs.file(r'C:\windows\flutter\flutter_export.h').statSync().modified, isNot(modified));
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
class MockPlatform extends Mock implements Platform {}
|
||||
84
packages/flutter_tools/test/commands/assemble_test.dart
Normal file
84
packages/flutter_tools/test/commands/assemble_test.dart
Normal file
@@ -0,0 +1,84 @@
|
||||
// Copyright 2019 The Chromium 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:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/build_info.dart';
|
||||
import 'package:flutter_tools/src/build_system/build_system.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/commands/assemble.dart';
|
||||
import 'package:flutter_tools/src/globals.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/testbed.dart';
|
||||
|
||||
void main() {
|
||||
group('Assemble', () {
|
||||
Testbed testbed;
|
||||
MockBuildSystem mockBuildSystem;
|
||||
|
||||
setUpAll(() {
|
||||
Cache.disableLocking();
|
||||
});
|
||||
|
||||
setUp(() {
|
||||
mockBuildSystem = MockBuildSystem();
|
||||
testbed = Testbed(overrides: <Type, Generator>{
|
||||
BuildSystem: () => mockBuildSystem,
|
||||
});
|
||||
});
|
||||
|
||||
test('Can list the output directory relative to project root', () => testbed.run(() async {
|
||||
final CommandRunner<void> commandRunner = createTestCommandRunner(AssembleCommand());
|
||||
await commandRunner.run(<String>['assemble', '--flutter-root=.', 'build-dir', '-dBuildMode=debug']);
|
||||
final BufferLogger bufferLogger = logger;
|
||||
final Environment environment = Environment(
|
||||
defines: <String, String>{
|
||||
'BuildMode': 'debug'
|
||||
}, projectDir: fs.currentDirectory,
|
||||
buildDir: fs.directory(getBuildDirectory()),
|
||||
);
|
||||
|
||||
expect(bufferLogger.statusText.trim(),
|
||||
fs.path.relative(environment.buildDir.path, from: fs.currentDirectory.path));
|
||||
}));
|
||||
|
||||
test('Can describe a target', () => testbed.run(() async {
|
||||
when(mockBuildSystem.describe('foobar', any)).thenReturn(<Map<String, Object>>[
|
||||
<String, Object>{'fizz': 'bar'},
|
||||
]);
|
||||
final CommandRunner<void> commandRunner = createTestCommandRunner(AssembleCommand());
|
||||
await commandRunner.run(<String>['assemble', '--flutter-root=.', 'describe', 'foobar']);
|
||||
final BufferLogger bufferLogger = logger;
|
||||
|
||||
expect(bufferLogger.statusText.trim(), '[{"fizz":"bar"}]');
|
||||
}));
|
||||
|
||||
test('Can describe a target\'s inputs', () => testbed.run(() async {
|
||||
when(mockBuildSystem.describe('foobar', any)).thenReturn(<Map<String, Object>>[
|
||||
<String, Object>{'name': 'foobar', 'inputs': <String>['bar', 'baz']},
|
||||
]);
|
||||
final CommandRunner<void> commandRunner = createTestCommandRunner(AssembleCommand());
|
||||
await commandRunner.run(<String>['assemble', '--flutter-root=.', 'inputs', 'foobar']);
|
||||
final BufferLogger bufferLogger = logger;
|
||||
|
||||
expect(bufferLogger.statusText.trim(), 'bar\nbaz');
|
||||
}));
|
||||
|
||||
test('Can run a build', () => testbed.run(() async {
|
||||
when(mockBuildSystem.build('foobar', any, any)).thenAnswer((Invocation invocation) async {
|
||||
return BuildResult(true, const <String, ExceptionMeasurement>{}, const <String, PerformanceMeasurement>{});
|
||||
});
|
||||
final CommandRunner<void> commandRunner = createTestCommandRunner(AssembleCommand());
|
||||
await commandRunner.run(<String>['assemble', 'run', 'foobar']);
|
||||
final BufferLogger bufferLogger = logger;
|
||||
|
||||
expect(bufferLogger.statusText.trim(), 'build succeeded');
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
class MockBuildSystem extends Mock implements BuildSystem {}
|
||||
@@ -76,7 +76,7 @@ class Testbed {
|
||||
: _setup = setup,
|
||||
_overrides = overrides;
|
||||
|
||||
final Future<void> Function() _setup;
|
||||
final FutureOr<void> Function() _setup;
|
||||
final Map<Type, Generator> _overrides;
|
||||
|
||||
/// Runs `test` within a tool zone.
|
||||
|
||||
Reference in New Issue
Block a user