mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Remove generateSyntheticPackages and code that invoked it. (#169893)
Towards https://github.com/flutter/flutter/issues/102983.
This commit is contained in:
parent
34656ff29a
commit
d4f60bddd2
@ -12,11 +12,8 @@ import '../android/gradle_utils.dart' as gradle;
|
||||
import '../base/common.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../base/utils.dart';
|
||||
import '../build_info.dart';
|
||||
import '../build_system/build_system.dart';
|
||||
import '../cache.dart';
|
||||
import '../convert.dart';
|
||||
import '../dart/generate_synthetic_packages.dart';
|
||||
import '../flutter_project_metadata.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../project.dart';
|
||||
@ -494,31 +491,6 @@ mixin CreateBase on FlutterCommand {
|
||||
final bool windowsPlatform = templateContext['windows'] as bool? ?? false;
|
||||
final bool webPlatform = templateContext['web'] as bool? ?? false;
|
||||
|
||||
if (shouldCallPubGet) {
|
||||
final Environment environment = Environment(
|
||||
artifacts: globals.artifacts!,
|
||||
logger: globals.logger,
|
||||
cacheDir: globals.cache.getRoot(),
|
||||
engineVersion: globals.flutterVersion.engineRevision,
|
||||
fileSystem: globals.fs,
|
||||
flutterRootDir: globals.fs.directory(Cache.flutterRoot),
|
||||
outputDir: globals.fs.directory(getBuildDirectory()),
|
||||
processManager: globals.processManager,
|
||||
platform: globals.platform,
|
||||
analytics: globals.analytics,
|
||||
projectDir: project.directory,
|
||||
packageConfigPath: packageConfigPath(),
|
||||
generateDartPluginRegistry: true,
|
||||
);
|
||||
|
||||
// Generate the l10n synthetic package that will be injected into the
|
||||
// package_config in the call to pub.get() below.
|
||||
await generateLocalizationsSyntheticPackage(
|
||||
environment: environment,
|
||||
buildSystem: globals.buildSystem,
|
||||
buildTargets: globals.buildTargets,
|
||||
);
|
||||
}
|
||||
final List<SupportedPlatform> platformsForMigrateConfig = <SupportedPlatform>[
|
||||
SupportedPlatform.root,
|
||||
];
|
||||
|
||||
@ -12,7 +12,6 @@ import '../build_info.dart';
|
||||
import '../build_system/build_system.dart';
|
||||
import '../build_system/targets/localizations.dart';
|
||||
import '../cache.dart';
|
||||
import '../dart/generate_synthetic_packages.dart';
|
||||
import '../dart/package_map.dart';
|
||||
import '../dart/pub.dart';
|
||||
import '../flutter_plugins.dart';
|
||||
@ -304,12 +303,7 @@ class PackagesGetCommand extends FlutterCommand {
|
||||
packageConfigPath: packageConfigPath(),
|
||||
generateDartPluginRegistry: true,
|
||||
);
|
||||
if (rootProject.manifest.generateLocalizations &&
|
||||
!await generateLocalizationsSyntheticPackage(
|
||||
environment: environment,
|
||||
buildSystem: globals.buildSystem,
|
||||
buildTargets: globals.buildTargets,
|
||||
)) {
|
||||
if (rootProject.manifest.generateLocalizations) {
|
||||
// If localizations were enabled, but we are not using synthetic packages.
|
||||
final BuildResult result = await globals.buildSystem.build(
|
||||
const GenerateLocalizationsTarget(),
|
||||
|
||||
@ -1,96 +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:yaml/yaml.dart';
|
||||
|
||||
import '../base/common.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../base/utils.dart';
|
||||
import '../build_system/build_system.dart';
|
||||
import '../build_system/build_targets.dart';
|
||||
import '../features.dart';
|
||||
|
||||
/// Generates the `package:flutter_gen` synthetic package.
|
||||
///
|
||||
/// If the package has been configured *not* to use synthetic packages, this
|
||||
/// method is a NO-OP and returns `false`.
|
||||
///
|
||||
/// Returns `true` if the package was generated, or `false` it was not.
|
||||
Future<bool> generateLocalizationsSyntheticPackage({
|
||||
required Environment environment,
|
||||
required BuildSystem buildSystem,
|
||||
required BuildTargets buildTargets,
|
||||
}) async {
|
||||
final FileSystem fileSystem = environment.fileSystem;
|
||||
final File l10nYamlFile = fileSystem.file(
|
||||
fileSystem.path.join(environment.projectDir.path, 'l10n.yaml'),
|
||||
);
|
||||
|
||||
// If pubspec.yaml has generate:true and if l10n.yaml exists in the
|
||||
// root project directory, check to see if a synthetic package should
|
||||
// be generated for gen_l10n.
|
||||
if (!l10nYamlFile.existsSync()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final YamlNode yamlNode = loadYamlNode(l10nYamlFile.readAsStringSync());
|
||||
if (yamlNode.value != null && yamlNode is! YamlMap) {
|
||||
throwToolExit('Expected ${l10nYamlFile.path} to contain a map, instead was $yamlNode');
|
||||
}
|
||||
|
||||
// If an l10n.yaml file exists and is not empty, attempt to parse settings in
|
||||
// it.
|
||||
if (yamlNode.value != null) {
|
||||
final YamlMap yamlMap = yamlNode as YamlMap;
|
||||
final Object? value = yamlMap['synthetic-package'];
|
||||
if (value is! bool && value != null) {
|
||||
throwToolExit('Expected "synthetic-package" to have a bool value, instead was "$value"');
|
||||
}
|
||||
|
||||
// Generate gen_l10n synthetic package only if synthetic-package: true or
|
||||
// synthetic-package is null.
|
||||
final bool? isSyntheticL10nPackage = value as bool?;
|
||||
if (isSyntheticL10nPackage == false ||
|
||||
isSyntheticL10nPackage == null && featureFlags.isExplicitPackageDependenciesEnabled) {
|
||||
return false;
|
||||
}
|
||||
} else if (featureFlags.isExplicitPackageDependenciesEnabled) {
|
||||
// synthetic-packages: true was not set and it is no longer the default.
|
||||
return false;
|
||||
}
|
||||
|
||||
if (featureFlags.isExplicitPackageDependenciesEnabled) {
|
||||
throwToolExit(
|
||||
'Cannot generate a synthetic package when explicit-package-dependencies is enabled.\n'
|
||||
'\n'
|
||||
'Synthetic package output (package:flutter_gen) is deprecated: '
|
||||
'https://flutter.dev/to/flutter-gen-deprecation. If you are seeing this '
|
||||
'message either you have provided explicit-package-dependencies, or it '
|
||||
'is the default value (see flutter config --help).',
|
||||
);
|
||||
}
|
||||
|
||||
// Log a warning: synthetic-package: true (or implicit true) is deprecated.
|
||||
environment.logger.printWarning(
|
||||
'Synthetic package output (package:flutter_gen) is deprecated: '
|
||||
'https://flutter.dev/to/flutter-gen-deprecation. In a future release, '
|
||||
'synthetic-package will default to `false` and will later be removed '
|
||||
'entirely.',
|
||||
);
|
||||
|
||||
final BuildResult result = await buildSystem.build(
|
||||
buildTargets.generateLocalizationsTarget,
|
||||
environment,
|
||||
);
|
||||
|
||||
if (result.hasException) {
|
||||
throwToolExit(
|
||||
'Generating synthetic localizations package failed with ${result.exceptions.length} ${pluralize('error', result.exceptions.length)}:'
|
||||
'\n\n'
|
||||
'${result.exceptions.values.map<Object?>((ExceptionMeasurement e) => e.exception).join('\n\n')}',
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -17,11 +17,9 @@ import '../base/io.dart';
|
||||
import '../base/os.dart';
|
||||
import '../base/utils.dart';
|
||||
import '../build_info.dart';
|
||||
import '../build_system/build_system.dart';
|
||||
import '../bundle.dart' as bundle;
|
||||
import '../cache.dart';
|
||||
import '../convert.dart';
|
||||
import '../dart/generate_synthetic_packages.dart';
|
||||
import '../dart/package_map.dart';
|
||||
import '../dart/pub.dart';
|
||||
import '../device.dart';
|
||||
@ -1837,33 +1835,11 @@ abstract class FlutterCommand extends Command<void> {
|
||||
project.checkForDeprecation(deprecationBehavior: deprecationBehavior);
|
||||
|
||||
if (shouldRunPub) {
|
||||
final Environment environment = Environment(
|
||||
artifacts: globals.artifacts!,
|
||||
logger: globals.logger,
|
||||
cacheDir: globals.cache.getRoot(),
|
||||
engineVersion: globals.flutterVersion.engineRevision,
|
||||
fileSystem: globals.fs,
|
||||
flutterRootDir: globals.fs.directory(Cache.flutterRoot),
|
||||
outputDir: globals.fs.directory(getBuildDirectory()),
|
||||
processManager: globals.processManager,
|
||||
platform: globals.platform,
|
||||
analytics: analytics,
|
||||
projectDir: project.directory,
|
||||
packageConfigPath: packageConfigPath(),
|
||||
generateDartPluginRegistry: true,
|
||||
);
|
||||
|
||||
await pub.get(
|
||||
context: PubContext.getVerifyContext(name),
|
||||
project: project,
|
||||
checkUpToDate: cachePubGet,
|
||||
);
|
||||
|
||||
await generateLocalizationsSyntheticPackage(
|
||||
environment: environment,
|
||||
buildSystem: globals.buildSystem,
|
||||
buildTargets: globals.buildTargets,
|
||||
);
|
||||
}
|
||||
|
||||
if (regeneratePlatformSpecificToolingDuringVerify) {
|
||||
|
||||
@ -15,7 +15,6 @@ import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/commands/packages.dart';
|
||||
import 'package:flutter_tools/src/dart/pub.dart';
|
||||
import 'package:flutter_tools/src/features.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:unified_analytics/unified_analytics.dart';
|
||||
import 'package:yaml/yaml.dart';
|
||||
@ -30,15 +29,6 @@ import '../../src/test_flutter_command_runner.dart';
|
||||
void main() {
|
||||
late FakeStdio mockStdio;
|
||||
|
||||
// TODO(matanlurey): Remove after `flutter_gen` is removed.
|
||||
// See https://github.com/flutter/flutter/issues/102983 for details.
|
||||
FeatureFlags disableExplicitPackageDependencies() {
|
||||
return TestFeatureFlags(
|
||||
// ignore: avoid_redundant_argument_values
|
||||
isExplicitPackageDependenciesEnabled: false,
|
||||
);
|
||||
}
|
||||
|
||||
setUp(() {
|
||||
mockStdio = FakeStdio()..stdout.terminalColumns = 80;
|
||||
|
||||
@ -320,48 +310,6 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
testUsingContext(
|
||||
'get generates synthetic package when l10n.yaml has synthetic-package: true',
|
||||
() async {
|
||||
final String projectPath = await createProject(
|
||||
tempDir,
|
||||
arguments: <String>['--no-pub', '--template=module'],
|
||||
);
|
||||
final Directory projectDir = globals.fs.directory(projectPath);
|
||||
projectDir.childDirectory('lib').childDirectory('l10n').childFile('app_en.arb')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('{ "hello": "Hello world!" }');
|
||||
String pubspecFileContent = projectDir.childFile('pubspec.yaml').readAsStringSync();
|
||||
pubspecFileContent = pubspecFileContent.replaceFirst(RegExp(r'\nflutter\:'), '''
|
||||
flutter:
|
||||
generate: true
|
||||
''');
|
||||
projectDir.childFile('pubspec.yaml').writeAsStringSync(pubspecFileContent);
|
||||
projectDir.childFile('l10n.yaml').writeAsStringSync('synthetic-package: true');
|
||||
await runCommandIn(projectPath, 'get');
|
||||
expect(
|
||||
projectDir
|
||||
.childDirectory('.dart_tool')
|
||||
.childDirectory('flutter_gen')
|
||||
.childDirectory('gen_l10n')
|
||||
.childFile('app_localizations.dart')
|
||||
.existsSync(),
|
||||
true,
|
||||
);
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
Pub:
|
||||
() => Pub(
|
||||
fileSystem: globals.fs,
|
||||
logger: globals.logger,
|
||||
processManager: globals.processManager,
|
||||
botDetector: globals.botDetector,
|
||||
platform: globals.platform,
|
||||
),
|
||||
FeatureFlags: disableExplicitPackageDependencies,
|
||||
},
|
||||
);
|
||||
|
||||
testUsingContext(
|
||||
'get fetches packages for a workspace',
|
||||
() async {
|
||||
|
||||
@ -1,560 +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 'dart:async';
|
||||
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/artifacts.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/build_targets.dart';
|
||||
import 'package:flutter_tools/src/build_system/targets/localizations.dart';
|
||||
import 'package:flutter_tools/src/dart/generate_synthetic_packages.dart';
|
||||
import 'package:flutter_tools/src/features.dart';
|
||||
import 'package:flutter_tools/src/isolated/build_targets.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
import '../../src/fakes.dart';
|
||||
import '../../src/test_build_system.dart';
|
||||
|
||||
void main() {
|
||||
// TODO(matanlurey): Remove after support for flutter_gen is removed.
|
||||
// See https://github.com/flutter/flutter/issues/102983 for details.
|
||||
FeatureFlags disableExplicitPackageDependencies() {
|
||||
// ignore: avoid_redundant_argument_values
|
||||
return TestFeatureFlags(isExplicitPackageDependenciesEnabled: false);
|
||||
}
|
||||
|
||||
testUsingContext(
|
||||
'calls buildSystem.build with blank l10n.yaml file',
|
||||
() async {
|
||||
// Project directory setup for gen_l10n logic
|
||||
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
||||
|
||||
// Add generate:true to pubspec.yaml.
|
||||
final File pubspecFile = fileSystem.file('pubspec.yaml')..createSync();
|
||||
final String content = pubspecFile.readAsStringSync().replaceFirst(
|
||||
'\nflutter:\n',
|
||||
'\nflutter:\n generate: true\n',
|
||||
);
|
||||
pubspecFile.writeAsStringSync(content);
|
||||
|
||||
// Create an l10n.yaml file
|
||||
fileSystem.file('l10n.yaml').createSync();
|
||||
|
||||
final BufferLogger mockBufferLogger = BufferLogger.test();
|
||||
final Artifacts artifacts = Artifacts.test();
|
||||
final Environment environment = Environment.test(
|
||||
fileSystem.currentDirectory,
|
||||
fileSystem: fileSystem,
|
||||
logger: mockBufferLogger,
|
||||
artifacts: artifacts,
|
||||
processManager: FakeProcessManager.any(),
|
||||
);
|
||||
final Completer<void> completer = Completer<void>();
|
||||
final BuildResult exception = BuildResult(
|
||||
success: false,
|
||||
exceptions: <String, ExceptionMeasurement>{
|
||||
'hello': ExceptionMeasurement(
|
||||
'hello',
|
||||
const FormatException('illegal character in input string'),
|
||||
StackTrace.current,
|
||||
),
|
||||
},
|
||||
);
|
||||
final TestBuildSystem buildSystem = TestBuildSystem.all(exception, (
|
||||
Target target,
|
||||
Environment environment,
|
||||
) {
|
||||
expect(target, const GenerateLocalizationsTarget());
|
||||
expect(environment, environment);
|
||||
completer.complete();
|
||||
});
|
||||
|
||||
await expectLater(
|
||||
() => generateLocalizationsSyntheticPackage(
|
||||
environment: environment,
|
||||
buildSystem: buildSystem,
|
||||
buildTargets: const BuildTargetsImpl(),
|
||||
),
|
||||
throwsToolExit(
|
||||
message:
|
||||
'Generating synthetic localizations package failed with 1 error:'
|
||||
'\n\n'
|
||||
'FormatException: illegal character in input string',
|
||||
),
|
||||
);
|
||||
await completer.future;
|
||||
},
|
||||
overrides: <Type, Generator>{FeatureFlags: disableExplicitPackageDependencies},
|
||||
);
|
||||
|
||||
testUsingContext(
|
||||
'calls buildSystem.build with l10n.yaml synthetic-package: true',
|
||||
() async {
|
||||
// Project directory setup for gen_l10n logic
|
||||
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
||||
|
||||
// Add generate:true to pubspec.yaml.
|
||||
final File pubspecFile = fileSystem.file('pubspec.yaml')..createSync();
|
||||
final String content = pubspecFile.readAsStringSync().replaceFirst(
|
||||
'\nflutter:\n',
|
||||
'\nflutter:\n generate: true\n',
|
||||
);
|
||||
pubspecFile.writeAsStringSync(content);
|
||||
|
||||
// Create an l10n.yaml file
|
||||
fileSystem.file('l10n.yaml').writeAsStringSync('synthetic-package: true');
|
||||
|
||||
final FakeProcessManager fakeProcessManager = FakeProcessManager.any();
|
||||
final BufferLogger mockBufferLogger = BufferLogger.test();
|
||||
final Artifacts artifacts = Artifacts.test();
|
||||
final Environment environment = Environment.test(
|
||||
fileSystem.currentDirectory,
|
||||
fileSystem: fileSystem,
|
||||
logger: mockBufferLogger,
|
||||
artifacts: artifacts,
|
||||
processManager: fakeProcessManager,
|
||||
);
|
||||
final Completer<void> completer = Completer<void>();
|
||||
final BuildResult exception = BuildResult(
|
||||
success: false,
|
||||
exceptions: <String, ExceptionMeasurement>{
|
||||
'hello': ExceptionMeasurement(
|
||||
'hello',
|
||||
const FormatException('illegal character in input string'),
|
||||
StackTrace.current,
|
||||
),
|
||||
},
|
||||
);
|
||||
final TestBuildSystem buildSystem = TestBuildSystem.all(exception, (
|
||||
Target target,
|
||||
Environment environment,
|
||||
) {
|
||||
expect(target, const GenerateLocalizationsTarget());
|
||||
expect(environment, environment);
|
||||
completer.complete();
|
||||
});
|
||||
|
||||
await expectLater(
|
||||
() => generateLocalizationsSyntheticPackage(
|
||||
environment: environment,
|
||||
buildSystem: buildSystem,
|
||||
buildTargets: const BuildTargetsImpl(),
|
||||
),
|
||||
throwsToolExit(
|
||||
message:
|
||||
'Generating synthetic localizations package failed with 1 error:'
|
||||
'\n\n'
|
||||
'FormatException: illegal character in input string',
|
||||
),
|
||||
);
|
||||
await completer.future;
|
||||
},
|
||||
overrides: <Type, Generator>{FeatureFlags: disableExplicitPackageDependencies},
|
||||
);
|
||||
|
||||
testUsingContext(
|
||||
'calls buildSystem.build with l10n.yaml synthetic-package: null',
|
||||
() async {
|
||||
// Project directory setup for gen_l10n logic
|
||||
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
||||
|
||||
// Add generate:true to pubspec.yaml.
|
||||
final File pubspecFile = fileSystem.file('pubspec.yaml')..createSync();
|
||||
final String content = pubspecFile.readAsStringSync().replaceFirst(
|
||||
'\nflutter:\n',
|
||||
'\nflutter:\n generate: true\n',
|
||||
);
|
||||
pubspecFile.writeAsStringSync(content);
|
||||
|
||||
// Create an l10n.yaml file
|
||||
fileSystem.file('l10n.yaml').writeAsStringSync('synthetic-package: null');
|
||||
|
||||
final BufferLogger mockBufferLogger = BufferLogger.test();
|
||||
final Environment environment = Environment.test(
|
||||
fileSystem.currentDirectory,
|
||||
fileSystem: fileSystem,
|
||||
logger: mockBufferLogger,
|
||||
artifacts: Artifacts.test(),
|
||||
processManager: FakeProcessManager.any(),
|
||||
);
|
||||
final Completer<void> completer = Completer<void>();
|
||||
final BuildResult exception = BuildResult(
|
||||
success: false,
|
||||
exceptions: <String, ExceptionMeasurement>{
|
||||
'hello': ExceptionMeasurement(
|
||||
'hello',
|
||||
const FormatException('illegal character in input string'),
|
||||
StackTrace.current,
|
||||
),
|
||||
},
|
||||
);
|
||||
final TestBuildSystem buildSystem = TestBuildSystem.all(exception, (
|
||||
Target target,
|
||||
Environment environment,
|
||||
) {
|
||||
expect(target, const GenerateLocalizationsTarget());
|
||||
expect(environment, environment);
|
||||
completer.complete();
|
||||
});
|
||||
|
||||
await expectLater(
|
||||
() => generateLocalizationsSyntheticPackage(
|
||||
environment: environment,
|
||||
buildSystem: buildSystem,
|
||||
buildTargets: const BuildTargetsImpl(),
|
||||
),
|
||||
throwsToolExit(
|
||||
message:
|
||||
'Generating synthetic localizations package failed with 1 error:'
|
||||
'\n\n'
|
||||
'FormatException: illegal character in input string',
|
||||
),
|
||||
);
|
||||
await completer.future;
|
||||
},
|
||||
overrides: <Type, Generator>{FeatureFlags: disableExplicitPackageDependencies},
|
||||
);
|
||||
|
||||
testUsingContext('does not call buildSystem.build when l10n.yaml is not present', () async {
|
||||
// Project directory setup for gen_l10n logic
|
||||
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
||||
|
||||
// Add generate:true to pubspec.yaml.
|
||||
final File pubspecFile = fileSystem.file('pubspec.yaml')..createSync();
|
||||
final String content = pubspecFile.readAsStringSync().replaceFirst(
|
||||
'\nflutter:\n',
|
||||
'\nflutter:\n generate: true\n',
|
||||
);
|
||||
pubspecFile.writeAsStringSync(content);
|
||||
|
||||
final BufferLogger mockBufferLogger = BufferLogger.test();
|
||||
final Environment environment = Environment.test(
|
||||
fileSystem.currentDirectory,
|
||||
fileSystem: fileSystem,
|
||||
logger: mockBufferLogger,
|
||||
artifacts: Artifacts.test(),
|
||||
processManager: FakeProcessManager.any(),
|
||||
);
|
||||
// Will throw if build is called.
|
||||
final TestBuildSystem buildSystem = TestBuildSystem.all(null);
|
||||
|
||||
await generateLocalizationsSyntheticPackage(
|
||||
environment: environment,
|
||||
buildSystem: buildSystem,
|
||||
buildTargets: const NoOpBuildTargets(),
|
||||
);
|
||||
});
|
||||
|
||||
testUsingContext('does not call buildSystem.build with incorrect l10n.yaml format', () async {
|
||||
// Project directory setup for gen_l10n logic
|
||||
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
||||
|
||||
// Add generate:true to pubspec.yaml.
|
||||
final File pubspecFile = fileSystem.file('pubspec.yaml')..createSync();
|
||||
final String content = pubspecFile.readAsStringSync().replaceFirst(
|
||||
'\nflutter:\n',
|
||||
'\nflutter:\n generate: true\n',
|
||||
);
|
||||
pubspecFile.writeAsStringSync(content);
|
||||
|
||||
// Create an l10n.yaml file
|
||||
fileSystem.file('l10n.yaml').writeAsStringSync('helloWorld');
|
||||
|
||||
final BufferLogger mockBufferLogger = BufferLogger.test();
|
||||
final Environment environment = Environment.test(
|
||||
fileSystem.currentDirectory,
|
||||
fileSystem: fileSystem,
|
||||
logger: mockBufferLogger,
|
||||
artifacts: Artifacts.test(),
|
||||
processManager: FakeProcessManager.any(),
|
||||
);
|
||||
// Will throw if build is called.
|
||||
final TestBuildSystem buildSystem = TestBuildSystem.all(null);
|
||||
|
||||
await expectLater(
|
||||
() => generateLocalizationsSyntheticPackage(
|
||||
environment: environment,
|
||||
buildSystem: buildSystem,
|
||||
buildTargets: const NoOpBuildTargets(),
|
||||
),
|
||||
throwsToolExit(message: 'to contain a map, instead was helloWorld'),
|
||||
);
|
||||
});
|
||||
|
||||
testUsingContext(
|
||||
'does not call buildSystem.build with non-bool "synthetic-package" value',
|
||||
() async {
|
||||
// Project directory setup for gen_l10n logic
|
||||
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
||||
|
||||
// Add generate:true to pubspec.yaml.
|
||||
final File pubspecFile = fileSystem.file('pubspec.yaml')..createSync();
|
||||
final String content = pubspecFile.readAsStringSync().replaceFirst(
|
||||
'\nflutter:\n',
|
||||
'\nflutter:\n generate: true\n',
|
||||
);
|
||||
pubspecFile.writeAsStringSync(content);
|
||||
|
||||
// Create an l10n.yaml file
|
||||
fileSystem.file('l10n.yaml').writeAsStringSync('synthetic-package: nonBoolValue');
|
||||
|
||||
final BufferLogger mockBufferLogger = BufferLogger.test();
|
||||
final Environment environment = Environment.test(
|
||||
fileSystem.currentDirectory,
|
||||
fileSystem: fileSystem,
|
||||
logger: mockBufferLogger,
|
||||
artifacts: Artifacts.test(),
|
||||
processManager: FakeProcessManager.any(),
|
||||
);
|
||||
// Will throw if build is called.
|
||||
final TestBuildSystem buildSystem = TestBuildSystem.all(null);
|
||||
|
||||
await expectLater(
|
||||
() => generateLocalizationsSyntheticPackage(
|
||||
environment: environment,
|
||||
buildSystem: buildSystem,
|
||||
buildTargets: const NoOpBuildTargets(),
|
||||
),
|
||||
throwsToolExit(message: 'to have a bool value, instead was "nonBoolValue"'),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
testUsingContext(
|
||||
'synthetic-package: true (implicit) logs a deprecation warning',
|
||||
() async {
|
||||
// Project directory setup for gen_l10n logic.
|
||||
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
||||
|
||||
// Add generate:true to pubspec.yaml.
|
||||
final File pubspecFile = fileSystem.file('pubspec.yaml')..createSync();
|
||||
final String content = pubspecFile.readAsStringSync().replaceFirst(
|
||||
'\nflutter:\n',
|
||||
'\nflutter:\n generate: true\n',
|
||||
);
|
||||
pubspecFile.writeAsStringSync(content);
|
||||
|
||||
// Create a blank l10n.yaml file.
|
||||
fileSystem.file('l10n.yaml').writeAsStringSync('');
|
||||
|
||||
final BufferLogger mockBufferLogger = BufferLogger.test();
|
||||
final Environment environment = Environment.test(
|
||||
fileSystem.currentDirectory,
|
||||
fileSystem: fileSystem,
|
||||
logger: mockBufferLogger,
|
||||
artifacts: Artifacts.test(),
|
||||
processManager: FakeProcessManager.any(),
|
||||
);
|
||||
final TestBuildSystem buildSystem = TestBuildSystem.all(BuildResult(success: true));
|
||||
|
||||
await generateLocalizationsSyntheticPackage(
|
||||
environment: environment,
|
||||
buildSystem: buildSystem,
|
||||
buildTargets: const BuildTargetsImpl(),
|
||||
);
|
||||
|
||||
expect(
|
||||
mockBufferLogger.warningText,
|
||||
contains('https://flutter.dev/to/flutter-gen-deprecation'),
|
||||
);
|
||||
},
|
||||
overrides: <Type, Generator>{FeatureFlags: disableExplicitPackageDependencies},
|
||||
);
|
||||
|
||||
testUsingContext(
|
||||
'synthetic-package: true (explicit) logs a deprecation warning',
|
||||
() async {
|
||||
// Project directory setup for gen_l10n logic.
|
||||
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
||||
|
||||
// Add generate:true to pubspec.yaml.
|
||||
final File pubspecFile = fileSystem.file('pubspec.yaml')..createSync();
|
||||
final String content = pubspecFile.readAsStringSync().replaceFirst(
|
||||
'\nflutter:\n',
|
||||
'\nflutter:\n generate: true\n',
|
||||
);
|
||||
pubspecFile.writeAsStringSync(content);
|
||||
fileSystem.file('l10n.yaml').writeAsStringSync('synthetic-package: true');
|
||||
|
||||
final BufferLogger mockBufferLogger = BufferLogger.test();
|
||||
final Environment environment = Environment.test(
|
||||
fileSystem.currentDirectory,
|
||||
fileSystem: fileSystem,
|
||||
logger: mockBufferLogger,
|
||||
artifacts: Artifacts.test(),
|
||||
processManager: FakeProcessManager.any(),
|
||||
);
|
||||
final TestBuildSystem buildSystem = TestBuildSystem.all(BuildResult(success: true));
|
||||
|
||||
await generateLocalizationsSyntheticPackage(
|
||||
environment: environment,
|
||||
buildSystem: buildSystem,
|
||||
buildTargets: const BuildTargetsImpl(),
|
||||
);
|
||||
|
||||
expect(
|
||||
mockBufferLogger.warningText,
|
||||
contains('https://flutter.dev/to/flutter-gen-deprecation'),
|
||||
);
|
||||
},
|
||||
overrides: <Type, Generator>{FeatureFlags: disableExplicitPackageDependencies},
|
||||
);
|
||||
|
||||
testUsingContext('synthetic-package: false has no deprecation warning', () async {
|
||||
// Project directory setup for gen_l10n logic
|
||||
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
||||
|
||||
// Add generate:true to pubspec.yaml.
|
||||
final File pubspecFile = fileSystem.file('pubspec.yaml')..createSync();
|
||||
final String content = pubspecFile.readAsStringSync().replaceFirst(
|
||||
'\nflutter:\n',
|
||||
'\nflutter:\n generate: true\n',
|
||||
);
|
||||
pubspecFile.writeAsStringSync(content);
|
||||
fileSystem.file('l10n.yaml').writeAsStringSync('synthetic-package: false');
|
||||
|
||||
final BufferLogger mockBufferLogger = BufferLogger.test();
|
||||
final Environment environment = Environment.test(
|
||||
fileSystem.currentDirectory,
|
||||
fileSystem: fileSystem,
|
||||
logger: mockBufferLogger,
|
||||
artifacts: Artifacts.test(),
|
||||
processManager: FakeProcessManager.any(),
|
||||
);
|
||||
final TestBuildSystem buildSystem = TestBuildSystem.all(BuildResult(success: true));
|
||||
|
||||
await generateLocalizationsSyntheticPackage(
|
||||
environment: environment,
|
||||
buildSystem: buildSystem,
|
||||
buildTargets: const BuildTargetsImpl(),
|
||||
);
|
||||
|
||||
expect(
|
||||
mockBufferLogger.warningText,
|
||||
isNot(contains('https://flutter.dev/to/flutter-gen-deprecation')),
|
||||
);
|
||||
});
|
||||
|
||||
testUsingContext(
|
||||
'synthetic-package omitted with explicit-package-dependencies is a NOP',
|
||||
() async {
|
||||
// Project directory setup for gen_l10n logic
|
||||
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
||||
|
||||
// Add generate:true to pubspec.yaml.
|
||||
final File pubspecFile = fileSystem.file('pubspec.yaml')..createSync();
|
||||
final String content = pubspecFile.readAsStringSync().replaceFirst(
|
||||
'\nflutter:\n',
|
||||
'\nflutter:\n generate: true\n',
|
||||
);
|
||||
pubspecFile.writeAsStringSync(content);
|
||||
|
||||
final BufferLogger mockBufferLogger = BufferLogger.test();
|
||||
final Environment environment = Environment.test(
|
||||
fileSystem.currentDirectory,
|
||||
fileSystem: fileSystem,
|
||||
logger: mockBufferLogger,
|
||||
artifacts: Artifacts.test(),
|
||||
processManager: FakeProcessManager.empty(),
|
||||
);
|
||||
final TestBuildSystem buildSystem = TestBuildSystem.all(BuildResult(success: true));
|
||||
|
||||
await generateLocalizationsSyntheticPackage(
|
||||
environment: environment,
|
||||
buildSystem: buildSystem,
|
||||
buildTargets: const NoOpBuildTargets(),
|
||||
);
|
||||
|
||||
expect(
|
||||
mockBufferLogger.warningText,
|
||||
isNot(contains('https://flutter.dev/to/flutter-gen-deprecation')),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
testUsingContext(
|
||||
'synthetic-package: true with explicit-packages-resolution is an error',
|
||||
() async {
|
||||
// Project directory setup for gen_l10n logic
|
||||
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
||||
|
||||
// Add generate:true to pubspec.yaml.
|
||||
final File pubspecFile = fileSystem.file('pubspec.yaml')..createSync();
|
||||
final String content = pubspecFile.readAsStringSync().replaceFirst(
|
||||
'\nflutter:\n',
|
||||
'\nflutter:\n generate: true\n',
|
||||
);
|
||||
pubspecFile.writeAsStringSync(content);
|
||||
|
||||
// Create an l10n.yaml file
|
||||
fileSystem.file('l10n.yaml').writeAsStringSync('synthetic-package: true');
|
||||
|
||||
final BufferLogger mockBufferLogger = BufferLogger.test();
|
||||
final Environment environment = Environment.test(
|
||||
fileSystem.currentDirectory,
|
||||
fileSystem: fileSystem,
|
||||
logger: mockBufferLogger,
|
||||
artifacts: Artifacts.test(),
|
||||
processManager: FakeProcessManager.any(),
|
||||
);
|
||||
// Will throw if build is called.
|
||||
final TestBuildSystem buildSystem = TestBuildSystem.all(null);
|
||||
|
||||
await expectLater(
|
||||
() => generateLocalizationsSyntheticPackage(
|
||||
environment: environment,
|
||||
buildSystem: buildSystem,
|
||||
buildTargets: const NoOpBuildTargets(),
|
||||
),
|
||||
throwsToolExit(
|
||||
message:
|
||||
'Cannot generate a synthetic package when explicit-package-dependencies is enabled',
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
testUsingContext(
|
||||
'synthetic-package defaults to false if explicit-package-dependencies is enabled',
|
||||
() async {
|
||||
// Project directory setup for gen_l10n logic
|
||||
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
||||
|
||||
// Add generate:true to pubspec.yaml.
|
||||
final File pubspecFile = fileSystem.file('pubspec.yaml')..createSync();
|
||||
final String content = pubspecFile.readAsStringSync().replaceFirst(
|
||||
'\nflutter:\n',
|
||||
'\nflutter:\n generate: true\n',
|
||||
);
|
||||
pubspecFile.writeAsStringSync(content);
|
||||
|
||||
// Create an l10n.yaml file
|
||||
fileSystem.file('l10n.yaml').writeAsStringSync('');
|
||||
|
||||
final BufferLogger mockBufferLogger = BufferLogger.test();
|
||||
final Environment environment = Environment.test(
|
||||
fileSystem.currentDirectory,
|
||||
fileSystem: fileSystem,
|
||||
logger: mockBufferLogger,
|
||||
artifacts: Artifacts.test(),
|
||||
processManager: FakeProcessManager.any(),
|
||||
);
|
||||
// Will throw if build is called.
|
||||
final TestBuildSystem buildSystem = TestBuildSystem.all(null);
|
||||
|
||||
await expectLater(
|
||||
() => generateLocalizationsSyntheticPackage(
|
||||
environment: environment,
|
||||
buildSystem: buildSystem,
|
||||
buildTargets: const NoOpBuildTargets(),
|
||||
),
|
||||
returnsNormally,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user