Unverified Commit 82a6f9bf authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] remove most use of global packages path (#60231)

The global packages path could cause tests to fail when it would be overriden to unexpected (in test setup) values. Remove most usage and make it a configuration on buildInfo, along with most other build information. Cleanup the asset builder to require the .packages path and the resident runners to no longer require it, since they already have the information in build_info.

It needs to stick around for the fuchsia deps we do not control.

Filled #60232 for remaining work.
parent 9322c808
......@@ -790,6 +790,7 @@ Future<void> buildPluginsAsAar(
BuildMode.release, // Plugins are built as release.
null, // Plugins don't define flavors.
treeShakeIcons: androidBuildInfo.buildInfo.treeShakeIcons,
packagesPath: androidBuildInfo.buildInfo.packagesPath,
),
),
target: '',
......
......@@ -51,7 +51,7 @@ abstract class AssetBundle {
Future<int> build({
String manifestPath = defaultManifestPath,
String assetDirPath,
String packagesPath,
@required String packagesPath,
bool includeDefaultFonts = true,
bool reportLicensedPackages = false,
});
......@@ -122,12 +122,11 @@ class ManifestAssetBundle implements AssetBundle {
Future<int> build({
String manifestPath = defaultManifestPath,
String assetDirPath,
String packagesPath,
@required String packagesPath,
bool includeDefaultFonts = true,
bool reportLicensedPackages = false,
}) async {
assetDirPath ??= getAssetBuildDirectory();
packagesPath ??= globals.fs.path.absolute(globalPackagesPath);
FlutterManifest flutterManifest;
try {
flutterManifest = FlutterManifest.createFromPath(
......
......@@ -29,6 +29,7 @@ class BuildInfo {
this.dartExperiments = const <String>[],
@required this.treeShakeIcons,
this.performanceMeasurementFile,
this.packagesPath = '.packages',
});
final BuildMode mode;
......@@ -44,6 +45,12 @@ class BuildInfo {
/// Mode-Flavor (e.g. Release-Paid).
final String flavor;
/// The path to the .packages file to use for compilation.
///
/// This is used by package:package_config to locate the actual package_config.json
/// file. If not provded, defaults to `.packages`.
final String packagesPath;
final List<String> fileSystemRoots;
final String fileSystemScheme;
......@@ -156,6 +163,8 @@ class BuildInfo {
'PERFORMANCE_MEASUREMENT_FILE': performanceMeasurementFile,
if (bundleSkSLPath != null)
'BUNDLE_SKSL_PATH': bundleSkSLPath,
if (packagesPath != null)
'PACKAGE_CONFIG': packagesPath,
};
}
}
......
......@@ -140,7 +140,7 @@ class WebAssetServer implements AssetReader {
int port,
UrlTunneller urlTunneller,
bool useSseForDebugProxy,
BuildMode buildMode,
BuildInfo buildInfo,
bool enableDwds,
Uri entrypoint,
ExpressionCompiler expressionCompiler, {
......@@ -156,7 +156,7 @@ class WebAssetServer implements AssetReader {
}
final HttpServer httpServer = await HttpServer.bind(address, port);
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
globals.fs.file(globalPackagesPath),
globals.fs.file(buildInfo.packagesPath),
logger: globals.logger,
);
final Map<String, String> digests = <String, String>{};
......@@ -173,7 +173,7 @@ class WebAssetServer implements AssetReader {
}
// In release builds deploy a simpler proxy server.
if (buildMode != BuildMode.debug) {
if (buildInfo.mode != BuildMode.debug) {
final ReleaseAssetServer releaseAssetServer = ReleaseAssetServer(
entrypoint,
fileSystem: globals.fs,
......@@ -589,7 +589,7 @@ class WebDevFS implements DevFS {
@required this.packagesFilePath,
@required this.urlTunneller,
@required this.useSseForDebugProxy,
@required this.buildMode,
@required this.buildInfo,
@required this.enableDwds,
@required this.entrypoint,
@required this.expressionCompiler,
......@@ -603,7 +603,7 @@ class WebDevFS implements DevFS {
final String packagesFilePath;
final UrlTunneller urlTunneller;
final bool useSseForDebugProxy;
final BuildMode buildMode;
final BuildInfo buildInfo;
final bool enableDwds;
final bool testMode;
final ExpressionCompiler expressionCompiler;
......@@ -670,7 +670,7 @@ class WebDevFS implements DevFS {
port,
urlTunneller,
useSseForDebugProxy,
buildMode,
buildInfo,
enableDwds,
entrypoint,
expressionCompiler,
......
......@@ -66,7 +66,7 @@ class DwdsWebRunnerFactory extends WebRunnerFactory {
}
}
const String kExitMessage = 'Failed to establish connection with the application '
const String kExitMessage = 'Failed to establish connection with the application '
'instance in Chrome.\nThis can happen if the websocket connection used by the '
'web tooling is unable to correctly establish a connection, for example due to a firewall.';
......@@ -447,7 +447,7 @@ class _ResidentWebRunner extends ResidentWebRunner {
packagesFilePath: packagesFilePath,
urlTunneller: urlTunneller,
useSseForDebugProxy: debuggingOptions.webUseSseForDebugProxy,
buildMode: debuggingOptions.buildInfo.mode,
buildInfo: debuggingOptions.buildInfo,
enableDwds: _enableDwds,
entrypoint: globals.fs.file(target).uri,
expressionCompiler: expressionCompiler,
......@@ -639,7 +639,7 @@ class _ResidentWebRunner extends ResidentWebRunner {
final bool rebuildBundle = assetBundle.needsBuild();
if (rebuildBundle) {
globals.printTrace('Updating assets');
final int result = await assetBundle.build();
final int result = await assetBundle.build(packagesPath: debuggingOptions.buildInfo.packagesPath);
if (result != 0) {
return UpdateFSReport(success: false);
}
......
......@@ -58,8 +58,10 @@ class WebEntrypointTarget extends Target {
final bool shouldInitializePlatform = environment.defines[kInitializePlatform] == 'true';
final bool hasPlugins = environment.defines[kHasWebPlugins] == 'true';
final Uri importUri = environment.fileSystem.file(targetFile).absolute.uri;
// TODO(jonahwilliams): support configuration of this file.
const String packageFile = '.packages';
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
environment.projectDir.childFile('.packages'),
environment.fileSystem.file(packageFile),
logger: environment.logger,
);
......@@ -156,7 +158,8 @@ class Dart2JSTarget extends Target {
final BuildMode buildMode = getBuildModeForName(environment.defines[kBuildMode]);
final String specPath = globals.fs.path.join(
globals.artifacts.getArtifactPath(Artifact.flutterWebSdk), 'libraries.json');
final String packageFile = globalPackagesPath;
// TODO(jonahwilliams): support configuration of this file.
const String packageFile = '.packages';
final File outputKernel = environment.buildDir.childFile('app.dill');
final File outputFile = environment.buildDir.childFile('main.dart.js');
final List<String> dartDefines = decodeDartDefines(environment.defines, kDartDefines);
......
......@@ -20,7 +20,6 @@ import 'build_system/targets/common.dart';
import 'build_system/targets/icon_tree_shaker.dart';
import 'cache.dart';
import 'convert.dart';
import 'dart/package_map.dart';
import 'devfs.dart';
import 'globals.dart' as globals;
import 'project.dart';
......@@ -95,7 +94,7 @@ class BundleBuilder {
mainPath ??= defaultMainPath;
depfilePath ??= defaultDepfilePath;
assetDirPath ??= getAssetBuildDirectory();
packagesPath ??= globals.fs.path.absolute(globalPackagesPath);
packagesPath ??= globals.fs.path.absolute('.packages');
final FlutterProject flutterProject = FlutterProject.current();
await buildWithAssemble(
buildMode: buildInfo.mode,
......@@ -192,12 +191,12 @@ Future<void> buildWithAssemble({
Future<AssetBundle> buildAssets({
String manifestPath,
String assetDirPath,
String packagesPath,
@required String packagesPath,
bool includeDefaultFonts = true,
bool reportLicensedPackages = false,
}) async {
assetDirPath ??= getAssetBuildDirectory();
packagesPath ??= globals.fs.path.absolute(globalPackagesPath);
packagesPath ??= globals.fs.path.absolute(packagesPath);
// Build the asset bundle.
final AssetBundle assetBundle = AssetBundleFactory.instance.createBundle();
......
......@@ -415,7 +415,6 @@ class HotRunnerFactory {
applicationBinary: applicationBinary,
hostIsIde: hostIsIde,
projectRootPath: projectRootPath,
packagesFilePath: packagesFilePath,
dillOutputPath: dillOutputPath,
stayResident: stayResident,
ipv6: ipv6,
......
......@@ -486,7 +486,6 @@ class AppDomain extends Domain {
debuggingOptions: options,
applicationBinary: applicationBinary,
projectRootPath: projectRootPath,
packagesFilePath: packagesFilePath,
dillOutputPath: dillOutputPath,
ipv6: ipv6,
hostIsIde: true,
......
......@@ -536,7 +536,6 @@ class RunCommand extends RunCommandBase {
? null
: globals.fs.file(applicationBinaryPath),
projectRootPath: stringArg('project-root'),
packagesFilePath: globalResults['packages'] as String,
dillOutputPath: stringArg('output-dill'),
stayResident: stayResident,
ipv6: ipv6,
......
......@@ -296,7 +296,7 @@ class TestCommand extends FlutterCommand {
Future<void> _buildTestAsset() async {
final AssetBundle assetBundle = AssetBundleFactory.instance.createBundle();
final int build = await assetBundle.build();
final int build = await assetBundle.build(packagesPath: '.packages');
if (build != 0) {
throwToolExit('Error: Failed to build asset bundle');
}
......
......@@ -13,6 +13,7 @@ import '../base/logger.dart';
const String kPackagesFileName = '.packages';
// No touching!
String get globalPackagesPath => _globalPackagesPath ?? kPackagesFileName;
set globalPackagesPath(String value) {
......@@ -55,7 +56,7 @@ Future<PackageConfig> loadPackageConfigWithLogging(File file, {
message += '\nDid you run this command from the same directory as your pubspec.yaml file?';
}
logger.printError(message);
throwToolExit(null);
throwToolExit(file.path);
}
);
}
......@@ -321,7 +321,7 @@ Future<List<Plugin>> findPlugins(FlutterProject project) async {
final List<Plugin> plugins = <Plugin>[];
final String packagesFile = globals.fs.path.join(
project.directory.path,
globalPackagesPath,
'.packages',
);
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
globals.fs.file(packagesFile),
......
......@@ -26,7 +26,6 @@ import 'bundle.dart';
import 'cache.dart';
import 'codegen.dart';
import 'compile.dart';
import 'dart/package_map.dart';
import 'devfs.dart';
import 'device.dart';
import 'features.dart';
......@@ -60,7 +59,7 @@ class FlutterDevice {
fileSystemScheme: fileSystemScheme,
targetModel: targetModel,
dartDefines: buildInfo.dartDefines,
packagesPath: globalPackagesPath,
packagesPath: buildInfo.packagesPath,
extraFrontEndOptions: buildInfo.extraFrontEndOptions,
artifacts: globals.artifacts,
processManager: globals.processManager,
......@@ -113,7 +112,7 @@ class FlutterDevice {
dartDefines: buildInfo.dartDefines,
librariesSpec: globals.fs.file(globals.artifacts
.getArtifactPath(Artifact.flutterWebLibrariesJson)).uri.toString(),
packagesPath: globalPackagesPath,
packagesPath: buildInfo.packagesPath,
artifacts: globals.artifacts,
processManager: globals.processManager,
logger: globals.logger,
......@@ -136,7 +135,7 @@ class FlutterDevice {
trackWidgetCreation: buildInfo.trackWidgetCreation,
dartDefines: buildInfo.dartDefines,
),
packagesPath: globalPackagesPath,
packagesPath: buildInfo.packagesPath,
artifacts: globals.artifacts,
processManager: globals.processManager,
logger: globals.logger,
......@@ -683,16 +682,15 @@ abstract class ResidentRunner {
ResidentRunner(
this.flutterDevices, {
this.target,
this.debuggingOptions,
@required this.debuggingOptions,
String projectRootPath,
String packagesFilePath,
this.ipv6,
this.stayResident = true,
this.hotMode = true,
String dillOutputPath,
}) : mainPath = findMainDartFile(target),
packagesFilePath = debuggingOptions.buildInfo.packagesPath,
projectRootPath = projectRootPath ?? globals.fs.currentDirectory.path,
packagesFilePath = packagesFilePath ?? globals.fs.path.absolute(globalPackagesPath),
_dillOutputPath = dillOutputPath,
artifactDirectory = dillOutputPath == null
? globals.fs.systemTempDirectory.createTempSync('flutter_tool.')
......
......@@ -13,12 +13,11 @@ import 'resident_runner.dart';
import 'tracing.dart';
import 'vmservice.dart';
// TODO(mklim): Test this, flutter/flutter#23031.
class ColdRunner extends ResidentRunner {
ColdRunner(
List<FlutterDevice> devices, {
String target,
DebuggingOptions debuggingOptions,
@required DebuggingOptions debuggingOptions,
this.traceStartup = false,
this.awaitFirstFrameWhenTracing = true,
this.applicationBinary,
......
......@@ -67,12 +67,11 @@ class HotRunner extends ResidentRunner {
HotRunner(
List<FlutterDevice> devices, {
String target,
DebuggingOptions debuggingOptions,
@required DebuggingOptions debuggingOptions,
this.benchmarkMode = false,
this.applicationBinary,
this.hostIsIde = false,
String projectRootPath,
String packagesFilePath,
String dillOutputPath,
bool stayResident = true,
bool ipv6 = false,
......@@ -80,7 +79,6 @@ class HotRunner extends ResidentRunner {
target: target,
debuggingOptions: debuggingOptions,
projectRootPath: projectRootPath,
packagesFilePath: packagesFilePath,
stayResident: stayResident,
hotMode: true,
dillOutputPath: dillOutputPath,
......@@ -157,7 +155,7 @@ class HotRunner extends ResidentRunner {
final UpdateFSReport results = UpdateFSReport(success: true);
final List<Uri> invalidated = <Uri>[Uri.parse(libraryId)];
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
globals.fs.file(globalPackagesPath),
globals.fs.file(debuggingOptions.buildInfo.packagesPath),
logger: globals.logger,
);
for (final FlutterDevice device in flutterDevices) {
......@@ -343,7 +341,7 @@ class HotRunner extends ResidentRunner {
final List<Future<bool>> startupTasks = <Future<bool>>[];
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
globals.fs.file(globalPackagesPath),
globals.fs.file(debuggingOptions.buildInfo.packagesPath),
logger: globals.logger,
);
for (final FlutterDevice device in flutterDevices) {
......@@ -407,7 +405,7 @@ class HotRunner extends ResidentRunner {
final bool rebuildBundle = assetBundle.needsBuild();
if (rebuildBundle) {
globals.printTrace('Updating assets');
final int result = await assetBundle.build();
final int result = await assetBundle.build(packagesPath: '.packages');
if (result != 0) {
return UpdateFSReport(success: false);
}
......@@ -1289,7 +1287,7 @@ class ProjectFileInvalidator {
Future<PackageConfig> _createPackageConfig(String packagesPath) {
return loadPackageConfigWithLogging(
_fileSystem.file(globalPackagesPath),
_fileSystem.file(packagesPath),
logger: _logger,
);
}
......
......@@ -685,6 +685,7 @@ abstract class FlutterCommand extends Command<void> {
bundleSkSLPath: bundleSkSLPath,
dartExperiments: experiments,
performanceMeasurementFile: performanceMeasurementFile,
packagesPath: globalResults['packages'] as String ?? '.packages'
);
}
......
......@@ -14,7 +14,6 @@ import '../base/io.dart';
import '../build_info.dart';
import '../bundle.dart';
import '../convert.dart';
import '../dart/package_map.dart';
import '../device.dart';
import '../globals.dart' as globals;
import '../project.dart';
......@@ -138,7 +137,7 @@ class FlutterTesterDevice extends Device {
'--run-forever',
'--non-interactive',
'--enable-dart-profiling',
'--packages=$globalPackagesPath',
'--packages=${debuggingOptions.buildInfo.packagesPath}',
];
if (debuggingOptions.debuggingEnabled) {
if (debuggingOptions.startPaused) {
......
......@@ -782,7 +782,6 @@ class TestHotRunnerFactory extends HotRunnerFactory {
applicationBinary: applicationBinary,
hostIsIde: hostIsIde,
projectRootPath: projectRootPath,
packagesFilePath: packagesFilePath,
dillOutputPath: dillOutputPath,
stayResident: stayResident,
ipv6: ipv6,
......
......@@ -68,7 +68,7 @@ $fontsSection
String expectedAssetManifest,
) async {
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(manifestPath: 'pubspec.yaml');
await bundle.build(manifestPath: 'pubspec.yaml', packagesPath: '.packages');
for (final String packageName in packages) {
for (final String packageFont in packageFonts) {
......@@ -122,7 +122,7 @@ $fontsSection
writePubspecFile('p/p/pubspec.yaml', 'test_package');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(manifestPath: 'pubspec.yaml');
await bundle.build(manifestPath: 'pubspec.yaml', packagesPath: '.packages');
expect(bundle.entries.length, 3); // LICENSE, AssetManifest, FontManifest
expect(bundle.entries.containsKey('FontManifest.json'), isTrue);
}, overrides: <Type, Generator>{
......
......@@ -74,7 +74,7 @@ $assetsSection
bool expectExists = true,
}) async {
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(manifestPath: 'pubspec.yaml');
await bundle.build(manifestPath: 'pubspec.yaml', packagesPath: '.packages');
for (final String packageName in packages) {
for (final String asset in assets) {
......@@ -129,7 +129,7 @@ $assetsSection
writePubspecFile('p/p/pubspec.yaml', 'test_package');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(manifestPath: 'pubspec.yaml');
await bundle.build(manifestPath: 'pubspec.yaml', packagesPath: '.packages');
expect(bundle.entries.length, 3); // LICENSE, AssetManifest, FontManifest
const String expectedAssetManifest = '{}';
expect(
......@@ -157,7 +157,7 @@ $assetsSection
writeAssets('p/p/', assets);
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(manifestPath: 'pubspec.yaml');
await bundle.build(manifestPath: 'pubspec.yaml', packagesPath: '.packages');
expect(bundle.entries.length, 3); // LICENSE, AssetManifest, FontManifest
const String expectedAssetManifest = '{}';
expect(
......@@ -589,7 +589,7 @@ $assetsSection
writeAssets('p/p/', assetsOnDisk);
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(manifestPath: 'pubspec.yaml');
await bundle.build(manifestPath: 'pubspec.yaml', packagesPath: '.packages');
expect(bundle.entries['AssetManifest.json'], isNull,
reason: 'Invalid pubspec.yaml should not generate AssetManifest.json' );
......
......@@ -37,7 +37,7 @@ void main() {
testUsingContext('nonempty', () async {
final AssetBundle ab = AssetBundleFactory.instance.createBundle();
expect(await ab.build(), 0);
expect(await ab.build(packagesPath: '.packages'), 0);
expect(ab.entries.length, greaterThan(0));
}, overrides: <Type, Generator>{
FileSystem: () => testFileSystem,
......@@ -50,7 +50,7 @@ void main() {
..writeAsStringSync('');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(manifestPath: 'pubspec.yaml');
await bundle.build(manifestPath: 'pubspec.yaml', packagesPath: '.packages');
expect(bundle.entries.length, 1);
const String expectedAssetManifest = '{}';
expect(
......@@ -74,7 +74,7 @@ flutter:
- assets/foo/
''');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(manifestPath: 'pubspec.yaml');
await bundle.build(manifestPath: 'pubspec.yaml', packagesPath: '.packages');
// Expected assets:
// - asset manifest
// - font manifest
......@@ -89,7 +89,7 @@ flutter:
..setLastModifiedSync(packageFile.lastModifiedSync().add(const Duration(hours: 1)));
expect(bundle.needsBuild(manifestPath: 'pubspec.yaml'), true);
await bundle.build(manifestPath: 'pubspec.yaml');
await bundle.build(manifestPath: 'pubspec.yaml', packagesPath: '.packages');
// Expected assets:
// - asset manifest
// - font manifest
......@@ -114,7 +114,7 @@ flutter:
''');
globals.fs.file('.packages').createSync();
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(manifestPath: 'pubspec.yaml');
await bundle.build(manifestPath: 'pubspec.yaml', packagesPath: '.packages');
// Expected assets:
// - asset manifest
// - font manifest
......@@ -140,7 +140,7 @@ name: example''')
// asset manifest and not updated. This is due to the devfs not
// supporting file deletion.
expect(bundle.needsBuild(manifestPath: 'pubspec.yaml'), true);
await bundle.build(manifestPath: 'pubspec.yaml');
await bundle.build(manifestPath: 'pubspec.yaml', packagesPath: '.packages');
// Expected assets:
// - asset manifest
// - font manifest
......@@ -168,7 +168,7 @@ flutter:
''');
globals.fs.file('.packages').createSync();
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(manifestPath: 'pubspec.yaml');
await bundle.build(manifestPath: 'pubspec.yaml', packagesPath: '.packages');
// Expected assets:
// - asset manifest
// - font manifest
......@@ -205,7 +205,7 @@ assets:
- assets/foo/bar.txt
''');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(manifestPath: 'pubspec.yaml');
await bundle.build(manifestPath: 'pubspec.yaml', packagesPath: '.packages');
final DevFSStringContent assetManifest = bundle.entries['AssetManifest.json']
as DevFSStringContent;
......@@ -214,7 +214,7 @@ assets:
final DevFSStringContent license = bundle.entries['NOTICES']
as DevFSStringContent;
await bundle.build(manifestPath: 'pubspec.yaml');
await bundle.build(manifestPath: 'pubspec.yaml', packagesPath: '.packages');
expect(assetManifest, bundle.entries['AssetManifest.json']);
expect(fontManifest, bundle.entries['FontManifest.json']);
......@@ -238,7 +238,7 @@ flutter:
''');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
expect(await bundle.build(manifestPath: 'pubspec.yaml'), 0);
expect(await bundle.build(manifestPath: 'pubspec.yaml', packagesPath: '.packages'), 0);
expect(bundle.additionalDependencies.single.path, contains('DOES_NOT_EXIST_RERUN_FOR_WILDCARD'));
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
......@@ -259,7 +259,7 @@ flutter:
''');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
expect(await bundle.build(manifestPath: 'pubspec.yaml'), 0);
expect(await bundle.build(manifestPath: 'pubspec.yaml', packagesPath: '.packages'), 0);
expect(bundle.additionalDependencies, isEmpty);
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
......@@ -293,7 +293,7 @@ flutter:
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
globals.fs.file('foo/bar/fizz.txt').createSync(recursive: true);
expect(await bundle.build(manifestPath: 'pubspec.yaml'), 0);
expect(await bundle.build(manifestPath: 'pubspec.yaml', packagesPath: '.packages'), 0);
expect(bundle.additionalDependencies, isEmpty);
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
......@@ -327,7 +327,7 @@ flutter:
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
globals.fs.file('foo/bar/fizz.txt').createSync(recursive: true);
await bundle.build(manifestPath: 'pubspec.yaml');
await bundle.build(manifestPath: 'pubspec.yaml', packagesPath: '.packages');
expect(bundle.entries, hasLength(4));
expect(bundle.needsBuild(manifestPath: 'pubspec.yaml'), false);
......@@ -369,7 +369,7 @@ flutter:
''');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
expect(await bundle.build(manifestPath: 'pubspec.yaml'), 1);
expect(await bundle.build(manifestPath: 'pubspec.yaml', packagesPath: '.packages'), 1);
expect(testLogger.errorText, contains('This asset was included from package foo'));
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
......@@ -392,7 +392,7 @@ flutter:
''');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
expect(await bundle.build(manifestPath: 'pubspec.yaml'), 1);
expect(await bundle.build(manifestPath: 'pubspec.yaml', packagesPath: '.packages'), 1);
expect(testLogger.errorText, isNot(contains('This asset was included from')));
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
......@@ -426,7 +426,7 @@ flutter:
''');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
expect(await bundle.build(manifestPath: 'pubspec.yaml'), 0);
expect(await bundle.build(manifestPath: 'pubspec.yaml', packagesPath: '.packages'), 0);
expect((bundle.entries['FontManifest.json'] as DevFSStringContent).string, '[]');
expect((bundle.entries['AssetManifest.json'] as DevFSStringContent).string, '{}');
expect(testLogger.errorText, contains(
......
......@@ -72,7 +72,7 @@ flutter:
}
AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(manifestPath: 'pubspec.yaml');
await bundle.build(manifestPath: 'pubspec.yaml', packagesPath: '.packages');
// The main asset file, /a/b/c/foo, and its variants exist.
for (final String asset in assets) {
......@@ -82,7 +82,7 @@ flutter:
globals.fs.file(fixPath('a/b/c/foo')).deleteSync();
bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(manifestPath: 'pubspec.yaml');
await bundle.build(manifestPath: 'pubspec.yaml', packagesPath: '.packages');
// Now the main asset file, /a/b/c/foo, does not exist. This is OK because
// the /a/b/c/*/foo variants do exist.
......
......@@ -106,6 +106,7 @@ void main() {
extraFrontEndOptions: <String>['--enable-experiment=non-nullable', 'bar'],
extraGenSnapshotOptions: <String>['--enable-experiment=non-nullable', 'fizz'],
bundleSkSLPath: 'foo/bar/baz.sksl.json',
packagesPath: 'foo/.packages',
);
expect(buildInfo.toEnvironmentConfig(), <String, String>{
......@@ -117,6 +118,7 @@ void main() {
'EXTRA_FRONT_END_OPTIONS': '--enable-experiment%3Dnon-nullable,bar',
'EXTRA_GEN_SNAPSHOT_OPTIONS': '--enable-experiment%3Dnon-nullable,fizz',
'BUNDLE_SKSL_PATH': 'foo/bar/baz.sksl.json',
'PACKAGE_CONFIG': 'foo/.packages',
});
});
......
......@@ -11,7 +11,6 @@ import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/build_system/depfile.dart';
import 'package:flutter_tools/src/build_system/targets/common.dart';
import 'package:flutter_tools/src/build_system/targets/web.dart';
import 'package:flutter_tools/src/dart/package_map.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:mockito/mockito.dart';
import 'package:process/process.dart';
......@@ -44,10 +43,9 @@ void main() {
setUp(() {
testbed = Testbed(setup: () {
final File packagesFile = globals.fs.file(globals.fs.path.join('foo', '.packages'))
globals.fs.file('.packages')
..createSync(recursive: true)
..writeAsStringSync('foo:lib/\n');
globalPackagesPath = packagesFile.path;
..writeAsStringSync('foo:foo/lib/\n');
globals.fs.currentDirectory.childDirectory('bar').createSync();
processManager = FakeProcessManager.list(<FakeCommand>[]);
......@@ -229,7 +227,7 @@ void main() {
...kDart2jsLinuxArgs,
'-o',
environment.buildDir.childFile('app.dill').absolute.path,
'--packages=${globals.fs.path.join('foo', '.packages')}',
'--packages=.packages',
'-Ddart.vm.profile=true',
'--cfe-only',
environment.buildDir.childFile('main.dart').absolute.path,
......@@ -263,7 +261,7 @@ void main() {
'--enable-experiment=non-nullable',
'-o',
environment.buildDir.childFile('app.dill').absolute.path,
'--packages=${globals.fs.path.join('foo', '.packages')}',
'--packages=.packages',
'-Ddart.vm.profile=true',
'--cfe-only',
environment.buildDir.childFile('main.dart').absolute.path,
......@@ -294,7 +292,7 @@ void main() {
...kDart2jsLinuxArgs,
'-o',
environment.buildDir.childFile('app.dill').absolute.path,
'--packages=${globals.fs.path.join('foo', '.packages')}',
'--packages=.packages',
'-Ddart.vm.profile=true',
'--cfe-only',
environment.buildDir.childFile('main.dart').absolute.path,
......@@ -324,7 +322,7 @@ void main() {
...kDart2jsLinuxArgs,
'-o',
environment.buildDir.childFile('app.dill').absolute.path,
'--packages=${globals.fs.path.join('foo', '.packages')}',
'--packages=.packages',
'-Ddart.vm.product=true',
'--cfe-only',
environment.buildDir.childFile('main.dart').absolute.path,
......@@ -354,7 +352,7 @@ void main() {
...kDart2jsLinuxArgs,
'-o',
environment.buildDir.childFile('app.dill').absolute.path,
'--packages=${globals.fs.path.join('foo', '.packages')}',
'--packages=.packages',
'-Ddart.vm.product=true',
'--cfe-only',
environment.buildDir.childFile('main.dart').absolute.path,
......@@ -403,7 +401,7 @@ void main() {
...kDart2jsLinuxArgs,
'-o',
environment.buildDir.childFile('app.dill').absolute.path,
'--packages=${globals.fs.path.join('foo', '.packages')}',
'--packages=.packages',
'-Ddart.vm.product=true',
'-DFOO=bar',
'-DBAZ=qux',
......@@ -437,7 +435,7 @@ void main() {
...kDart2jsLinuxArgs,
'-o',
environment.buildDir.childFile('app.dill').absolute.path,
'--packages=${globals.fs.path.join('foo', '.packages')}',
'--packages=.packages',
'-Ddart.vm.profile=true',
'-DFOO=bar',
'-DBAZ=qux',
......
......@@ -77,7 +77,10 @@ void main() {
final MockFlutterDevice mockFlutterDevice = MockFlutterDevice();
when(mockFlutterDevice.device).thenReturn(mockDevice);
final List<FlutterDevice> devices = <FlutterDevice>[mockFlutterDevice];
final int result = await ColdRunner(devices).run();
final int result = await ColdRunner(
devices,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug),
).run();
expect(result, 1);
expect(testLogger.errorText, matches(r'Tried to run .*, but that file does not exist\.'));
......
......@@ -7,7 +7,6 @@ import 'dart:async';
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/dart/package_map.dart';
import 'package:vm_service/vm_service.dart' as vm_service;
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/io.dart';
......@@ -163,7 +162,7 @@ void main() {
});
testUsingContext('Does not hot restart when device does not support it', () async {
fileSystem.file(globalPackagesPath)
fileSystem.file('.packages')
..createSync(recursive: true)
..writeAsStringSync('\n');
// Setup mocks
......@@ -175,7 +174,10 @@ void main() {
final List<FlutterDevice> devices = <FlutterDevice>[
FlutterDevice(mockDevice, generator: residentCompiler, buildInfo: BuildInfo.debug)..devFS = mockDevFs,
];
final OperationResult result = await HotRunner(devices).restart(fullRestart: true);
final OperationResult result = await HotRunner(
devices,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug),
).restart(fullRestart: true);
// Expect hot restart failed.
expect(result.isOk, false);
expect(result.message, 'hotRestart not supported');
......@@ -188,7 +190,7 @@ void main() {
});
testUsingContext('Does not hot restart when one of many devices does not support it', () async {
fileSystem.file(globalPackagesPath)
fileSystem.file('.packages')
..createSync(recursive: true)
..writeAsStringSync('\n');
// Setup mocks
......@@ -203,7 +205,10 @@ void main() {
FlutterDevice(mockDevice, generator: residentCompiler, buildInfo: BuildInfo.debug)..devFS = mockDevFs,
FlutterDevice(mockHotDevice, generator: residentCompiler, buildInfo: BuildInfo.debug)..devFS = mockDevFs,
];
final OperationResult result = await HotRunner(devices).restart(fullRestart: true);
final OperationResult result = await HotRunner(
devices,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug)
).restart(fullRestart: true);
// Expect hot restart failed.
expect(result.isOk, false);
expect(result.message, 'hotRestart not supported');
......@@ -302,7 +307,10 @@ void main() {
..vmService = fakeVmServiceHost.vmService
..devFS = mockDevFs,
];
final HotRunner hotRunner = HotRunner(devices);
final HotRunner hotRunner = HotRunner(
devices,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug),
);
final OperationResult result = await hotRunner.restart(fullRestart: true);
// Expect hot restart was successful.
expect(hotRunner.uri, mockDevFs.baseUri);
......@@ -317,7 +325,7 @@ void main() {
});
testUsingContext('setup function fails', () async {
fileSystem.file(globalPackagesPath)
fileSystem.file('.packages')
..createSync(recursive: true)
..writeAsStringSync('\n');
final MockDevice mockDevice = MockDevice();
......@@ -327,7 +335,10 @@ void main() {
final List<FlutterDevice> devices = <FlutterDevice>[
FlutterDevice(mockDevice, generator: residentCompiler, buildInfo: BuildInfo.debug),
];
final OperationResult result = await HotRunner(devices).restart(fullRestart: true);
final OperationResult result = await HotRunner(
devices,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug),
).restart(fullRestart: true);
expect(result.isOk, false);
expect(result.message, 'setupHotRestart failed');
}, overrides: <Type, Generator>{
......@@ -339,7 +350,7 @@ void main() {
});
testUsingContext('hot restart supported', () async {
fileSystem.file(globalPackagesPath)
fileSystem.file('.packages')
..createSync(recursive: true)
..writeAsStringSync('\n');
// Setup mocks
......@@ -389,7 +400,10 @@ void main() {
..vmService = fakeVmServiceHost.vmService
..devFS = mockDevFs,
];
final HotRunner hotRunner = HotRunner(devices);
final HotRunner hotRunner = HotRunner(
devices,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug),
);
final OperationResult result = await hotRunner.restart(fullRestart: true);
// Expect hot restart successful.
expect(hotRunner.uri, mockDevFs.baseUri);
......@@ -413,7 +427,7 @@ void main() {
});
testUsingContext('shutdown hook called after signal', () async {
fileSystem.file(globalPackagesPath)
fileSystem.file('.packages')
..createSync(recursive: true)
..writeAsStringSync('\n');
final MockDevice mockDevice = MockDevice();
......@@ -423,7 +437,10 @@ void main() {
final List<FlutterDevice> devices = <FlutterDevice>[
FlutterDevice(mockDevice, generator: residentCompiler, buildInfo: BuildInfo.debug),
];
await HotRunner(devices).cleanupAfterSignal();
await HotRunner(
devices,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug)
).cleanupAfterSignal();
expect(shutdownTestingConfig.shutdownHookCalled, true);
}, overrides: <Type, Generator>{
HotRunnerConfig: () => shutdownTestingConfig,
......@@ -434,7 +451,7 @@ void main() {
});
testUsingContext('shutdown hook called after app stop', () async {
fileSystem.file(globalPackagesPath)
fileSystem.file('.packages')
..createSync(recursive: true)
..writeAsStringSync('\n');
final MockDevice mockDevice = MockDevice();
......@@ -444,7 +461,10 @@ void main() {
final List<FlutterDevice> devices = <FlutterDevice>[
FlutterDevice(mockDevice, generator: residentCompiler, buildInfo: BuildInfo.debug),
];
await HotRunner(devices).preExit();
await HotRunner(
devices,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug)
).preExit();
expect(shutdownTestingConfig.shutdownHookCalled, true);
}, overrides: <Type, Generator>{
HotRunnerConfig: () => shutdownTestingConfig,
......@@ -465,7 +485,7 @@ void main() {
testUsingContext('Exits with code 2 when when HttpException is thrown '
'during VM service connection', () async {
fileSystem.file(globalPackagesPath)
fileSystem.file('.packages')
..createSync(recursive: true)
..writeAsStringSync('\n');
......
......@@ -8,7 +8,6 @@ import 'package:file/file.dart';
import 'package:file/memory.dart';
import 'package:file_testing/file_testing.dart';
import 'package:flutter_tools/src/base/time.dart';
import 'package:flutter_tools/src/dart/package_map.dart';
import 'package:flutter_tools/src/features.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/ios/xcodeproj.dart';
......@@ -107,7 +106,7 @@ void main() {
// Set up a simple .packages file for all the tests to use, pointing to one package.
dummyPackageDirectory = fs.directory('/pubcache/apackage/lib/');
packagesFile = fs.file(fs.path.join(flutterProject.directory.path, globalPackagesPath));
packagesFile = fs.file(fs.path.join(flutterProject.directory.path, '.packages'));
packagesFile..createSync(recursive: true)
..writeAsStringSync('apackage:file://${dummyPackageDirectory.path}\n');
});
......
......@@ -5,7 +5,6 @@
import 'dart:async';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/dart/package_map.dart';
import 'package:vm_service/vm_service.dart' as vm_service;
import 'package:file/memory.dart';
import 'package:file_testing/file_testing.dart';
......@@ -93,9 +92,8 @@ void main() {
setUp(() {
testbed = Testbed(setup: () {
globals.fs.file(globalPackagesPath)
..createSync(recursive: true)
..writeAsStringSync('\n');
globals.fs.file('.packages')
.writeAsStringSync('\n');
globals.fs.file(globals.fs.path.join('build', 'app.dill'))
..createSync(recursive: true)
..writeAsStringSync('ABC');
......@@ -1124,6 +1122,7 @@ void main() {
final FlutterDevice device = FlutterDevice(mockDevice, buildInfo: BuildInfo.debug);
final ResidentRunner residentRunner = HotRunner(
<FlutterDevice>[device],
debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug)
);
expect(await residentRunner.listFlutterViews(), isEmpty);
......
......@@ -16,7 +16,6 @@ import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/build_runner/devfs_web.dart';
import 'package:flutter_tools/src/build_runner/resident_web_runner.dart';
import 'package:flutter_tools/src/compile.dart';
import 'package:flutter_tools/src/dart/package_map.dart';
import 'package:flutter_tools/src/dart/pub.dart';
import 'package:flutter_tools/src/devfs.dart';
import 'package:flutter_tools/src/device.dart';
......@@ -116,7 +115,7 @@ void main() {
});
testbed = Testbed(
setup: () {
globals.fs.file(globalPackagesPath)
globals.fs.file('.packages')
..createSync(recursive: true)
..writeAsStringSync('\n');
residentWebRunner = DwdsWebRunnerFactory().createWebRunner(
......@@ -127,8 +126,6 @@ void main() {
stayResident: true,
urlTunneller: null,
) as ResidentWebRunner;
globals.fs.currentDirectory.childFile('.packages')
.writeAsStringSync('\n');
},
overrides: <Type, Generator>{
Pub: () => MockPub(),
......
......@@ -9,7 +9,6 @@ import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/compile.dart';
import 'package:flutter_tools/src/dart/package_map.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/test/test_compiler.dart';
import 'package:mockito/mockito.dart';
......@@ -32,7 +31,7 @@ void main() {
fileSystem.file('pubspec.yaml').createSync();
fileSystem.file('.packages').writeAsStringSync('flutter_test:flutter_test/');
fileSystem.file('test/foo.dart').createSync(recursive: true);
fileSystem.file(globalPackagesPath)
fileSystem.file('.packages')
..createSync()
..writeAsStringSync('flutter_test:flutter_test/');
residentCompiler = MockResidentCompiler();
......
......@@ -416,7 +416,7 @@ void main() {
packagesFilePath: '.packages',
urlTunneller: null,
useSseForDebugProxy: true,
buildMode: BuildMode.debug,
buildInfo: BuildInfo.debug,
enableDwds: false,
entrypoint: Uri.base,
testMode: true,
......@@ -510,7 +510,7 @@ void main() {
packagesFilePath: '.packages',
urlTunneller: null,
useSseForDebugProxy: true,
buildMode: BuildMode.debug,
buildInfo: BuildInfo.debug,
enableDwds: false,
entrypoint: Uri.base,
testMode: true,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment