Revert "[flutter_tools] integrate l10n tool into build/run (#56167)" (#56800)

This reverts commit f865ac7e25.
This commit is contained in:
Jonah Williams
2020-05-09 17:50:46 -07:00
committed by GitHub
parent f5d2c8c770
commit d70d0913b2
14 changed files with 54 additions and 632 deletions

View File

@@ -57,7 +57,6 @@ void _testMessageLength({
expect(commandHelp.U.toString().length, lessThanOrEqualTo(expectedWidth));
expect(commandHelp.a.toString().length, lessThanOrEqualTo(expectedWidth));
expect(commandHelp.d.toString().length, lessThanOrEqualTo(expectedWidth));
expect(commandHelp.g.toString().length, lessThanOrEqualTo(expectedWidth));
expect(commandHelp.h.toString().length, lessThanOrEqualTo(expectedWidth));
expect(commandHelp.i.toString().length, lessThanOrEqualTo(expectedWidth));
expect(commandHelp.k.toString().length, lessThanOrEqualTo(expectedWidth));
@@ -89,7 +88,6 @@ void main() {
expect(commandHelp.U.toString(), startsWith('\x1B[1mU\x1B[22m'));
expect(commandHelp.a.toString(), startsWith('\x1B[1ma\x1B[22m'));
expect(commandHelp.d.toString(), startsWith('\x1B[1md\x1B[22m'));
expect(commandHelp.g.toString(), startsWith('\x1B[1mg\x1B[22m'));
expect(commandHelp.h.toString(), startsWith('\x1B[1mh\x1B[22m'));
expect(commandHelp.i.toString(), startsWith('\x1B[1mi\x1B[22m'));
expect(commandHelp.o.toString(), startsWith('\x1B[1mo\x1B[22m'));
@@ -166,7 +164,6 @@ void main() {
expect(commandHelp.U.toString(), equals('\x1B[1mU\x1B[22m Dump accessibility tree in inverse hit test order. \x1B[1;30m(debugDumpSemantics)\x1B[39m'));
expect(commandHelp.a.toString(), equals('\x1B[1ma\x1B[22m Toggle timeline events for all widget build methods. \x1B[1;30m(debugProfileWidgetBuilds)\x1B[39m'));
expect(commandHelp.d.toString(), equals('\x1B[1md\x1B[22m Detach (terminate "flutter run" but leave application running).'));
expect(commandHelp.g.toString(), equals('\x1B[1mg\x1B[22m Run source code generators.'));
expect(commandHelp.h.toString(), equals('\x1B[1mh\x1B[22m Repeat this help message.'));
expect(commandHelp.i.toString(), equals('\x1B[1mi\x1B[22m Toggle widget inspector. \x1B[1;30m(WidgetsApp.showWidgetInspectorOverride)\x1B[39m'));
expect(commandHelp.o.toString(), equals('\x1B[1mo\x1B[22m Simulate different operating systems. \x1B[1;30m(defaultTargetPlatform)\x1B[39m'));
@@ -193,7 +190,6 @@ void main() {
expect(commandHelp.U.toString(), equals('U Dump accessibility tree in inverse hit test order. (debugDumpSemantics)'));
expect(commandHelp.a.toString(), equals('a Toggle timeline events for all widget build methods. (debugProfileWidgetBuilds)'));
expect(commandHelp.d.toString(), equals('d Detach (terminate "flutter run" but leave application running).'));
expect(commandHelp.g.toString(), equals('g Run source code generators.'));
expect(commandHelp.h.toString(), equals('h Repeat this help message.'));
expect(commandHelp.i.toString(), equals('i Toggle widget inspector. (WidgetsApp.showWidgetInspectorOverride)'));
expect(commandHelp.o.toString(), equals('o Simulate different operating systems. (defaultTargetPlatform)'));

View File

@@ -565,50 +565,6 @@ void main() {
expect(fileSystem.file('output/debug'), isNot(exists));
expect(fileSystem.file('output/release'), exists);
});
testWithoutContext('A target using canSkip can create a conditional output', () async {
final BuildSystem buildSystem = setUpBuildSystem(fileSystem);
final File bar = environment.buildDir.childFile('bar');
final File foo = environment.buildDir.childFile('foo');
// The target will write a file `foo`, but only if `bar` already exists.
final TestTarget target = TestTarget(
(Environment environment) async {
foo.writeAsStringSync(bar.readAsStringSync());
environment.buildDir
.childFile('example.d')
.writeAsStringSync('${foo.path}: ${bar.path}');
},
(Environment environment) {
return !environment.buildDir.childFile('bar').existsSync();
}
)
..depfiles = const <String>['example.d'];
// bar does not exist, there should be no inputs/outputs.
final BuildResult firstResult = await buildSystem.build(target, environment);
expect(foo, isNot(exists));
expect(firstResult.inputFiles, isEmpty);
expect(firstResult.outputFiles, isEmpty);
// bar is created, the target should be able to run.
bar.writeAsStringSync('content-1');
final BuildResult secondResult = await buildSystem.build(target, environment);
expect(foo, exists);
expect(secondResult.inputFiles.map((File file) => file.path), <String>[bar.path]);
expect(secondResult.outputFiles.map((File file) => file.path), <String>[foo.path]);
// bar is destroyed, foo is also deleted.
bar.deleteSync();
final BuildResult thirdResult = await buildSystem.build(target, environment);
expect(foo, isNot(exists));
expect(thirdResult.inputFiles, isEmpty);
expect(thirdResult.outputFiles, isEmpty);
});
}
BuildSystem setUpBuildSystem(FileSystem fileSystem) {
@@ -620,20 +576,10 @@ BuildSystem setUpBuildSystem(FileSystem fileSystem) {
}
class TestTarget extends Target {
TestTarget([this._build, this._canSkip]);
TestTarget([this._build]);
final Future<void> Function(Environment environment) _build;
final bool Function(Environment environment) _canSkip;
@override
bool canSkip(Environment environment) {
if (_canSkip != null) {
return _canSkip(environment);
}
return super.canSkip(environment);
}
@override
Future<void> build(Environment environment) => _build(environment);

View File

@@ -1,131 +0,0 @@
// Copyright 2014 The Flutter 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/logger.dart';
import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/build_system/targets/localizations.dart';
import '../../../src/common.dart';
import '../../../src/context.dart';
void main() {
// Verifies that values are correctly passed through the localizations
// target, but does not validate them beyond the serialized data type.
testWithoutContext('generateLocalizations forwards arguments correctly', () async {
final FileSystem fileSystem = MemoryFileSystem.test();
final Logger logger = BufferLogger.test();
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>[
'dart',
'dev/tools/localization/bin/gen_l10n.dart',
'--gen-inputs-and-outputs-list=/',
'--arb-dir=arb',
'--template-arb-file=example.arb',
'--output-localization-file=bar',
'--untranslated-messages-file=untranslated',
'--output-class=Foo',
'--header-file=header',
'--header=HEADER',
'--use-deferred-loading',
'--preferred-supported-locales=en_US'
],
),
]);
final Directory arbDirectory = fileSystem.directory('arb')
..createSync();
arbDirectory.childFile('foo.arb').createSync();
arbDirectory.childFile('bar.arb').createSync();
final LocalizationOptions options = LocalizationOptions(
header: 'HEADER',
headerFile: Uri.file('header'),
arbDirectory: Uri.file('arb'),
deferredLoading: true,
outputClass: 'Foo',
outputLocalizationsFile: Uri.file('bar'),
preferredSupportedLocales: 'en_US',
templateArbFile: Uri.file('example.arb'),
untranslatedMessagesFile: Uri.file('untranslated'),
);
await generateLocalizations(
options: options,
logger: logger,
fileSystem: fileSystem,
processManager: processManager,
projectDir: fileSystem.currentDirectory,
dartBinaryPath: 'dart',
flutterRoot: '',
dependenciesDir: fileSystem.currentDirectory,
);
expect(processManager.hasRemainingExpectations, false);
});
testWithoutContext('generateLocalizations is skipped if l10n.yaml does not exist.', () async {
final FileSystem fileSystem = MemoryFileSystem.test();
final Environment environment = Environment.test(
fileSystem.currentDirectory,
artifacts: null,
fileSystem: fileSystem,
logger: BufferLogger.test(),
processManager: FakeProcessManager.any(),
);
expect(const GenerateLocalizationsTarget().canSkip(environment), true);
environment.projectDir.childFile('l10n.yaml').createSync();
expect(const GenerateLocalizationsTarget().canSkip(environment), false);
});
testWithoutContext('parseLocalizationsOptions handles valid yaml configuration', () async {
final FileSystem fileSystem = MemoryFileSystem.test();
final File configFile = fileSystem.file('l10n.yaml')
..writeAsStringSync('''
arb-dir: arb
template-arb-file: example.arb
output-localization-file: bar
untranslated-messages-file: untranslated
output-class: Foo
header-file: header
header: HEADER
use-deferred-loading: true
preferred-supported-locales: en_US
''');
final LocalizationOptions options = parseLocalizationsOptions(
file: configFile,
logger: BufferLogger.test(),
);
expect(options.arbDirectory, Uri.parse('arb'));
expect(options.templateArbFile, Uri.parse('example.arb'));
expect(options.outputLocalizationsFile, Uri.parse('bar'));
expect(options.untranslatedMessagesFile, Uri.parse('untranslated'));
expect(options.outputClass, 'Foo');
expect(options.headerFile, Uri.parse('header'));
expect(options.header, 'HEADER');
expect(options.deferredLoading, true);
expect(options.preferredSupportedLocales, 'en_US');
});
testWithoutContext('parseLocalizationsOptions throws exception on invalid yaml configuration', () async {
final FileSystem fileSystem = MemoryFileSystem.test();
final File configFile = fileSystem.file('l10n.yaml')
..writeAsStringSync('''
use-deferred-loading: string
''');
expect(
() => parseLocalizationsOptions(
file: configFile,
logger: BufferLogger.test(),
),
throwsA(isA<Exception>()),
);
});
}

View File

@@ -4,7 +4,6 @@
import 'dart:async';
import 'package:flutter_tools/src/cache.dart';
import 'package:vm_service/vm_service.dart' as vm_service;
import 'package:file/memory.dart';
import 'package:file_testing/file_testing.dart';
@@ -538,61 +537,6 @@ void main() {
expect(cacheDill, isNot(exists));
}));
test('ResidentRunner can run source generation', () => testbed.run(() async {
final FakeProcessManager processManager = globals.processManager as FakeProcessManager;
final Directory dependencies = globals.fs.directory(
globals.fs.path.join('build', '6ec2559087977927717927ede0a147f1'));
processManager.addCommand(FakeCommand(
command: <String>[
globals.artifacts.getArtifactPath(Artifact.engineDartBinary),
globals.fs.path.join(Cache.flutterRoot, 'dev', 'tools', 'localization', 'bin', 'gen_l10n.dart'),
'--gen-inputs-and-outputs-list=${dependencies.absolute.path}',
],
onRun: () {
dependencies
.childFile('gen_l10n_inputs_and_outputs.json')
..createSync()
..writeAsStringSync('{"inputs":[],"outputs":[]}');
}
));
globals.fs.file(globals.fs.path.join('lib', 'l10n', 'foo.arb'))
.createSync(recursive: true);
globals.fs.file('l10n.yaml').createSync();
await residentRunner.runSourceGenerators();
expect(testLogger.errorText, isEmpty);
}, overrides: <Type, Generator>{
ProcessManager: () => FakeProcessManager.list(<FakeCommand>[]),
}));
test('ResidentRunner can run source generation - generation fails', () => testbed.run(() async {
final FakeProcessManager processManager = globals.processManager as FakeProcessManager;
final Directory dependencies = globals.fs.directory(
globals.fs.path.join('build', '6ec2559087977927717927ede0a147f1'));
processManager.addCommand(FakeCommand(
command: <String>[
globals.artifacts.getArtifactPath(Artifact.engineDartBinary),
globals.fs.path.join(Cache.flutterRoot, 'dev', 'tools', 'localization', 'bin', 'gen_l10n.dart'),
'--gen-inputs-and-outputs-list=${dependencies.absolute.path}',
],
exitCode: 1,
stderr: 'stderr'
));
globals.fs.file(globals.fs.path.join('lib', 'l10n', 'foo.arb'))
.createSync(recursive: true);
globals.fs.file('l10n.yaml').createSync();
await residentRunner.runSourceGenerators();
expect(testLogger.errorText, allOf(
contains('stderr'), // Message from gen_l10n.dart
contains('Exception') // Message from build_system
));
}, overrides: <Type, Generator>{
ProcessManager: () => FakeProcessManager.list(<FakeCommand>[]),
}));
test('ResidentRunner printHelpDetails', () => testbed.run(() {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
when(mockDevice.supportsHotRestart).thenReturn(true);
@@ -629,7 +573,6 @@ void main() {
commandHelp.p,
commandHelp.o,
commandHelp.z,
commandHelp.g,
commandHelp.M,
commandHelp.v,
commandHelp.P,

View File

@@ -6,14 +6,15 @@ import 'dart:async';
import 'package:file/file.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:process/process.dart';
import '../src/common.dart';
import 'test_data/gen_l10n_project.dart';
import 'test_driver.dart';
import 'test_utils.dart';
final GenL10nProject project = GenL10nProject();
// Verify that the code generated by gen_l10n executes correctly.
// It can fail if gen_l10n produces a lib/l10n/app_localizations.dart that:
// - Does not analyze cleanly.
@@ -22,23 +23,50 @@ final GenL10nProject project = GenL10nProject();
// loaded workstation, so the test could time out on a heavily loaded bot.
void main() {
Directory tempDir;
FlutterRunTestDriver flutter;
final GenL10nProject _project = GenL10nProject();
FlutterRunTestDriver _flutter;
setUp(() async {
tempDir = createResolvedTempDirectorySync('gen_l10n_test.');
await _project.setUpIn(tempDir);
_flutter = FlutterRunTestDriver(tempDir);
});
tearDown(() async {
await flutter.stop();
await _flutter.stop();
tryToDelete(tempDir);
});
void runCommand(List<String> command) {
final ProcessResult result = const LocalProcessManager().runSync(
command,
workingDirectory: tempDir.path,
environment: <String, String>{ 'FLUTTER_ROOT': getFlutterRoot() },
);
if (result.exitCode != 0) {
throw Exception('FAILED [${result.exitCode}]: ${command.join(' ')}\n${result.stderr}\n${result.stdout}');
}
}
void setUpAndRunGenL10n({List<String> args}) {
// Get the intl packages before running gen_l10n.
final String flutterBin = globals.platform.isWindows ? 'flutter.bat' : 'flutter';
final String flutterPath = globals.fs.path.join(getFlutterRoot(), 'bin', flutterBin);
runCommand(<String>[flutterPath, 'pub', 'get']);
// Generate lib/l10n/app_localizations.dart
final String genL10nPath = globals.fs.path.join(getFlutterRoot(), 'dev', 'tools', 'localization', 'bin', 'gen_l10n.dart');
final String dartBin = globals.platform.isWindows ? 'dart.exe' : 'dart';
final String dartPath = globals.fs.path.join(getFlutterRoot(), 'bin', 'cache', 'dart-sdk', 'bin', dartBin);
runCommand(<String>[dartPath, genL10nPath, args?.join(' ')]);
}
Future<StringBuffer> runApp() async {
// Run the app defined in GenL10nProject.main and wait for it to
// send '#l10n END' to its stdout.
final Completer<void> l10nEnd = Completer<void>();
final StringBuffer stdout = StringBuffer();
final StreamSubscription<String> subscription = flutter.stdout.listen((String line) {
final StreamSubscription<String> subscription = _flutter.stdout.listen((String line) {
if (line.contains('#l10n')) {
stdout.writeln(line.substring(line.indexOf('#l10n')));
}
@@ -46,7 +74,7 @@ void main() {
l10nEnd.complete();
}
});
await flutter.run();
await _flutter.run();
await l10nEnd.future;
await subscription.cancel();
return stdout;
@@ -152,15 +180,13 @@ void main() {
}
test('generated l10n classes produce expected localized strings', () async {
await project.setUpIn(tempDir);
flutter = FlutterRunTestDriver(tempDir);
setUpAndRunGenL10n();
final StringBuffer stdout = await runApp();
expectOutput(stdout);
});
test('generated l10n classes produce expected localized strings with deferred loading', () async {
await project.setUpIn(tempDir, useDeferredLoading: true);
flutter = FlutterRunTestDriver(tempDir);
setUpAndRunGenL10n(args: <String>['--use-deferred-loading']);
final StringBuffer stdout = await runApp();
expectOutput(stdout);
});

View File

@@ -7,16 +7,13 @@ import 'dart:async';
import 'package:file/file.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:meta/meta.dart';
import '../test_utils.dart';
import 'project.dart';
class GenL10nProject extends Project {
@override
Future<void> setUpIn(Directory dir, {
bool useDeferredLoading = false,
}) {
Future<void> setUpIn(Directory dir) {
this.dir = dir;
writeFile(globals.fs.path.join(dir.path, 'lib', 'l10n', 'app_en.arb'), appEn);
writeFile(globals.fs.path.join(dir.path, 'lib', 'l10n', 'app_en_CA.arb'), appEnCa);
@@ -27,7 +24,6 @@ class GenL10nProject extends Project {
writeFile(globals.fs.path.join(dir.path, 'lib', 'l10n', 'app_zh_Hant.arb'), appZhHant);
writeFile(globals.fs.path.join(dir.path, 'lib', 'l10n', 'app_zh_Hans.arb'), appZhHans);
writeFile(globals.fs.path.join(dir.path, 'lib', 'l10n', 'app_zh_Hant_TW.arb'), appZhHantTw);
writeFile(globals.fs.path.join(dir.path, 'l10n.yaml'), l10nYaml(useDeferredLoading: useDeferredLoading));
return super.setUpIn(dir);
}
@@ -565,15 +561,4 @@ void main() {
"helloWorld": "台灣繁體你好世界"
}
''';
String l10nYaml({
@required bool useDeferredLoading,
}) {
if (useDeferredLoading) {
return r'''
use-deferred-loading: false
''';
}
return '';
}
}