[flutter_tools] reland: map file URIs to a multiroot scheme (#66405)
If a file scheme and one or more roots is provided, fall back to this mapping before the direct file path if the file path cannot be turned into a package URI. Use URI representation so that the transformation is resilient to the org-dartlang-app scheme used by the web builds. Fixes #66095 Fixes #66404
This commit is contained in:
@@ -96,7 +96,7 @@ void main() {
|
||||
'$build/app.dill',
|
||||
'--depfile',
|
||||
'$build/kernel_snapshot.d',
|
||||
'/lib/main.dart',
|
||||
'file:///lib/main.dart',
|
||||
], exitCode: 1),
|
||||
]);
|
||||
|
||||
@@ -130,7 +130,7 @@ void main() {
|
||||
'$build/app.dill',
|
||||
'--depfile',
|
||||
'$build/kernel_snapshot.d',
|
||||
'/lib/main.dart',
|
||||
'file:///lib/main.dart',
|
||||
], stdout: 'result $kBoundaryKey\n$kBoundaryKey\n$kBoundaryKey $build/app.dill 0\n'),
|
||||
]);
|
||||
|
||||
@@ -164,7 +164,7 @@ void main() {
|
||||
'$build/app.dill',
|
||||
'--depfile',
|
||||
'$build/kernel_snapshot.d',
|
||||
'/lib/main.dart',
|
||||
'file:///lib/main.dart',
|
||||
], stdout: 'result $kBoundaryKey\n$kBoundaryKey\n$kBoundaryKey $build/app.dill 0\n'),
|
||||
]);
|
||||
|
||||
@@ -201,7 +201,7 @@ void main() {
|
||||
'$build/kernel_snapshot.d',
|
||||
'foo',
|
||||
'bar',
|
||||
'/lib/main.dart',
|
||||
'file:///lib/main.dart',
|
||||
], stdout: 'result $kBoundaryKey\n$kBoundaryKey\n$kBoundaryKey $build/app.dill 0\n'),
|
||||
]);
|
||||
|
||||
@@ -235,7 +235,7 @@ void main() {
|
||||
'$build/app.dill',
|
||||
'--depfile',
|
||||
'$build/kernel_snapshot.d',
|
||||
'/lib/main.dart',
|
||||
'file:///lib/main.dart',
|
||||
], stdout: 'result $kBoundaryKey\n$kBoundaryKey\n$kBoundaryKey $build/app.dill 0\n'),
|
||||
]);
|
||||
|
||||
@@ -269,7 +269,7 @@ void main() {
|
||||
'$build/app.dill',
|
||||
'--depfile',
|
||||
'$build/kernel_snapshot.d',
|
||||
'/lib/main.dart',
|
||||
'file:///lib/main.dart',
|
||||
], stdout: 'result $kBoundaryKey\n$kBoundaryKey\n$kBoundaryKey $build/app.dill 0\n'),
|
||||
]);
|
||||
|
||||
@@ -318,7 +318,7 @@ void main() {
|
||||
'$build/app.dill',
|
||||
'--depfile',
|
||||
'$build/kernel_snapshot.d',
|
||||
'/lib/main.dart',
|
||||
'file:///lib/main.dart',
|
||||
], stdout: 'result $kBoundaryKey\n$kBoundaryKey\n$kBoundaryKey /build/653e11a8e6908714056a57cd6b4f602a/app.dill 0\n'),
|
||||
]);
|
||||
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/artifacts.dart';
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/base/terminal.dart';
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/build_info.dart';
|
||||
import 'package:flutter_tools/src/compile.dart';
|
||||
import 'package:flutter_tools/src/convert.dart';
|
||||
@@ -47,14 +47,22 @@ void main() {
|
||||
when(mockFrontendServer.exitCode).thenAnswer((_) async => 0);
|
||||
});
|
||||
|
||||
testUsingContext('batch compile single dart successful compilation', () async {
|
||||
testWithoutContext('batch compile single dart successful compilation', () async {
|
||||
when(mockFrontendServer.stdout)
|
||||
.thenAnswer((Invocation invocation) => Stream<List<int>>.fromFuture(
|
||||
Future<List<int>>.value(utf8.encode(
|
||||
'result abc\nline1\nline2\nabc\nabc /path/to/main.dart.dill 0'
|
||||
))
|
||||
));
|
||||
final KernelCompiler kernelCompiler = await kernelCompilerFactory.create(null);
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
final KernelCompiler kernelCompiler = KernelCompiler(
|
||||
artifacts: Artifacts.test(),
|
||||
fileSystem: MemoryFileSystem.test(),
|
||||
fileSystemRoots: <String>[],
|
||||
fileSystemScheme: '',
|
||||
logger: logger,
|
||||
processManager: mockProcessManager
|
||||
);
|
||||
final CompilerOutput output = await kernelCompiler.compile(sdkRoot: '/path/to/sdkroot',
|
||||
mainPath: '/path/to/main.dart',
|
||||
buildMode: BuildMode.debug,
|
||||
@@ -65,27 +73,29 @@ void main() {
|
||||
);
|
||||
|
||||
expect(mockFrontendServerStdIn.getAndClear(), isEmpty);
|
||||
expect(testLogger.errorText, equals('line1\nline2\n'));
|
||||
expect(logger.errorText, equals('line1\nline2\n'));
|
||||
expect(output.outputFilename, equals('/path/to/main.dart.dill'));
|
||||
final VerificationResult argVerification = verify(mockProcessManager.start(captureAny));
|
||||
expect(argVerification.captured.single, containsAll(<String>[
|
||||
'-Ddart.developer.causal_async_stacks=true',
|
||||
]));
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
OutputPreferences: () => OutputPreferences(showColor: false),
|
||||
Platform: kNoColorTerminalPlatform,
|
||||
Artifacts: () => Artifacts.test(),
|
||||
});
|
||||
|
||||
testUsingContext('passes correct AOT config to kernel compiler in aot/profile mode', () async {
|
||||
testWithoutContext('passes correct AOT config to kernel compiler in aot/profile mode', () async {
|
||||
when(mockFrontendServer.stdout)
|
||||
.thenAnswer((Invocation invocation) => Stream<List<int>>.fromFuture(
|
||||
Future<List<int>>.value(utf8.encode(
|
||||
'result abc\nline1\nline2\nabc\nabc /path/to/main.dart.dill 0'
|
||||
))
|
||||
));
|
||||
final KernelCompiler kernelCompiler = await kernelCompilerFactory.create(null);
|
||||
final KernelCompiler kernelCompiler = KernelCompiler(
|
||||
artifacts: Artifacts.test(),
|
||||
fileSystem: MemoryFileSystem.test(),
|
||||
fileSystemRoots: <String>[],
|
||||
fileSystemScheme: '',
|
||||
logger: BufferLogger.test(),
|
||||
processManager: mockProcessManager
|
||||
);
|
||||
await kernelCompiler.compile(sdkRoot: '/path/to/sdkroot',
|
||||
mainPath: '/path/to/main.dart',
|
||||
buildMode: BuildMode.profile,
|
||||
@@ -106,22 +116,23 @@ void main() {
|
||||
'--bytecode-options=source-positions',
|
||||
'-Ddart.developer.causal_async_stacks=false',
|
||||
]));
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
OutputPreferences: () => OutputPreferences(showColor: false),
|
||||
Platform: kNoColorTerminalPlatform,
|
||||
Artifacts: () => Artifacts.test(),
|
||||
});
|
||||
|
||||
|
||||
testUsingContext('passes correct AOT config to kernel compiler in aot/release mode', () async {
|
||||
testWithoutContext('passes correct AOT config to kernel compiler in aot/release mode', () async {
|
||||
when(mockFrontendServer.stdout)
|
||||
.thenAnswer((Invocation invocation) => Stream<List<int>>.fromFuture(
|
||||
Future<List<int>>.value(utf8.encode(
|
||||
'result abc\nline1\nline2\nabc\nabc /path/to/main.dart.dill 0'
|
||||
))
|
||||
));
|
||||
final KernelCompiler kernelCompiler = await kernelCompilerFactory.create(null);
|
||||
final KernelCompiler kernelCompiler = KernelCompiler(
|
||||
artifacts: Artifacts.test(),
|
||||
fileSystem: MemoryFileSystem.test(),
|
||||
fileSystemRoots: <String>[],
|
||||
fileSystemScheme: '',
|
||||
logger: BufferLogger.test(),
|
||||
processManager: mockProcessManager
|
||||
);
|
||||
await kernelCompiler.compile(sdkRoot: '/path/to/sdkroot',
|
||||
mainPath: '/path/to/main.dart',
|
||||
buildMode: BuildMode.release,
|
||||
@@ -142,21 +153,24 @@ void main() {
|
||||
'--bytecode-options=source-positions',
|
||||
'-Ddart.developer.causal_async_stacks=false',
|
||||
]));
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
OutputPreferences: () => OutputPreferences(showColor: false),
|
||||
Platform: kNoColorTerminalPlatform,
|
||||
Artifacts: () => Artifacts.test(),
|
||||
});
|
||||
|
||||
testUsingContext('batch compile single dart failed compilation', () async {
|
||||
testWithoutContext('batch compile single dart failed compilation', () async {
|
||||
when(mockFrontendServer.stdout)
|
||||
.thenAnswer((Invocation invocation) => Stream<List<int>>.fromFuture(
|
||||
Future<List<int>>.value(utf8.encode(
|
||||
'result abc\nline1\nline2\nabc\nabc'
|
||||
))
|
||||
));
|
||||
final KernelCompiler kernelCompiler = await kernelCompilerFactory.create(null);
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
final KernelCompiler kernelCompiler = KernelCompiler(
|
||||
artifacts: Artifacts.test(),
|
||||
fileSystem: MemoryFileSystem.test(),
|
||||
fileSystemRoots: <String>[],
|
||||
fileSystemScheme: '',
|
||||
logger: logger,
|
||||
processManager: mockProcessManager
|
||||
);
|
||||
final CompilerOutput output = await kernelCompiler.compile(sdkRoot: '/path/to/sdkroot',
|
||||
mainPath: '/path/to/main.dart',
|
||||
buildMode: BuildMode.debug,
|
||||
@@ -167,25 +181,27 @@ void main() {
|
||||
);
|
||||
|
||||
expect(mockFrontendServerStdIn.getAndClear(), isEmpty);
|
||||
expect(testLogger.errorText, equals('line1\nline2\n'));
|
||||
expect(logger.errorText, equals('line1\nline2\n'));
|
||||
expect(output, equals(null));
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
OutputPreferences: () => OutputPreferences(showColor: false),
|
||||
Platform: kNoColorTerminalPlatform,
|
||||
Artifacts: () => Artifacts.test(),
|
||||
});
|
||||
|
||||
testUsingContext('batch compile single dart abnormal compiler termination', () async {
|
||||
testWithoutContext('batch compile single dart abnormal compiler termination', () async {
|
||||
when(mockFrontendServer.exitCode).thenAnswer((_) async => 255);
|
||||
|
||||
when(mockFrontendServer.stdout)
|
||||
.thenAnswer((Invocation invocation) => Stream<List<int>>.fromFuture(
|
||||
Future<List<int>>.value(utf8.encode(
|
||||
'result abc\nline1\nline2\nabc\nabc'
|
||||
))
|
||||
));
|
||||
final KernelCompiler kernelCompiler = await kernelCompilerFactory.create(null);
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
final KernelCompiler kernelCompiler = KernelCompiler(
|
||||
artifacts: Artifacts.test(),
|
||||
fileSystem: MemoryFileSystem.test(),
|
||||
fileSystemRoots: <String>[],
|
||||
fileSystemScheme: '',
|
||||
logger: logger,
|
||||
processManager: mockProcessManager
|
||||
);
|
||||
final CompilerOutput output = await kernelCompiler.compile(
|
||||
sdkRoot: '/path/to/sdkroot',
|
||||
mainPath: '/path/to/main.dart',
|
||||
@@ -196,22 +212,24 @@ void main() {
|
||||
packagesPath: '.packages',
|
||||
);
|
||||
expect(mockFrontendServerStdIn.getAndClear(), isEmpty);
|
||||
expect(testLogger.errorText, equals('line1\nline2\n'));
|
||||
expect(logger.errorText, equals('line1\nline2\n'));
|
||||
expect(output, equals(null));
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
OutputPreferences: () => OutputPreferences(showColor: false),
|
||||
Platform: kNoColorTerminalPlatform,
|
||||
Artifacts: () => Artifacts.test(),
|
||||
});
|
||||
|
||||
testUsingContext('passes dartDefines to the kernel compiler', () async {
|
||||
testWithoutContext('passes dartDefines to the kernel compiler', () async {
|
||||
// Use unsuccessful result because it's easier to setup in test. We only care about arguments passed to the compiler.
|
||||
when(mockFrontendServer.exitCode).thenAnswer((_) async => 255);
|
||||
when(mockFrontendServer.stdout).thenAnswer((Invocation invocation) => Stream<List<int>>.fromFuture(
|
||||
Future<List<int>>.value(<int>[])
|
||||
));
|
||||
final KernelCompiler kernelCompiler = await kernelCompilerFactory.create(null);
|
||||
final KernelCompiler kernelCompiler = KernelCompiler(
|
||||
artifacts: Artifacts.test(),
|
||||
fileSystem: MemoryFileSystem.test(),
|
||||
fileSystemRoots: <String>[],
|
||||
fileSystemScheme: '',
|
||||
logger: BufferLogger.test(),
|
||||
processManager: mockProcessManager
|
||||
);
|
||||
await kernelCompiler.compile(sdkRoot: '/path/to/sdkroot',
|
||||
mainPath: '/path/to/main.dart',
|
||||
buildMode: BuildMode.debug,
|
||||
@@ -222,11 +240,34 @@ void main() {
|
||||
);
|
||||
|
||||
expect(latestCommand, containsAllInOrder(<String>['-DFOO=bar', '-DBAZ=qux']));
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
OutputPreferences: () => OutputPreferences(showColor: false),
|
||||
Platform: kNoColorTerminalPlatform,
|
||||
Artifacts: () => Artifacts.test(),
|
||||
});
|
||||
|
||||
testWithoutContext('maps a file to a multiroot scheme if providfed', () async {
|
||||
// Use unsuccessful result because it's easier to setup in test. We only care about arguments passed to the compiler.
|
||||
when(mockFrontendServer.exitCode).thenAnswer((_) async => 255);
|
||||
when(mockFrontendServer.stdout).thenAnswer((Invocation invocation) => Stream<List<int>>.fromFuture(
|
||||
Future<List<int>>.value(<int>[])
|
||||
));
|
||||
final KernelCompiler kernelCompiler = KernelCompiler(
|
||||
artifacts: Artifacts.test(),
|
||||
fileSystem: MemoryFileSystem.test(),
|
||||
fileSystemRoots: <String>[
|
||||
'/foo/bar/fizz',
|
||||
],
|
||||
fileSystemScheme: 'scheme',
|
||||
logger: BufferLogger.test(),
|
||||
processManager: mockProcessManager
|
||||
);
|
||||
await kernelCompiler.compile(sdkRoot: '/path/to/sdkroot',
|
||||
mainPath: '/foo/bar/fizz/main.dart',
|
||||
buildMode: BuildMode.debug,
|
||||
trackWidgetCreation: false,
|
||||
dartDefines: const <String>[],
|
||||
packageConfig: PackageConfig.empty,
|
||||
packagesPath: '.packages',
|
||||
);
|
||||
|
||||
expect(latestCommand, containsAll(<String>['scheme:///main.dart']));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:flutter_tools/src/artifacts.dart';
|
||||
import 'package:flutter_tools/src/base/common.dart';
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
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/convert.dart';
|
||||
@@ -40,6 +41,7 @@ void main() {
|
||||
artifacts: Artifacts.test(),
|
||||
processManager: mockProcessManager,
|
||||
logger: testLogger,
|
||||
platform: FakePlatform(operatingSystem: 'linux'),
|
||||
);
|
||||
|
||||
when(mockFrontendServer.stdin).thenReturn(mockFrontendServerStdIn);
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:flutter_tools/src/artifacts.dart';
|
||||
import 'package:flutter_tools/src/base/async_guard.dart';
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
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/convert.dart';
|
||||
@@ -40,6 +41,7 @@ void main() {
|
||||
logger: testLogger,
|
||||
processManager: mockProcessManager,
|
||||
artifacts: Artifacts.test(),
|
||||
platform: FakePlatform(operatingSystem: 'linux'),
|
||||
);
|
||||
|
||||
when(mockFrontendServer.stdin).thenReturn(mockFrontendServerStdIn);
|
||||
|
||||
@@ -34,4 +34,13 @@ void main() {
|
||||
|
||||
expect(() => TargetModel('foobar'), throwsAssertionError);
|
||||
});
|
||||
|
||||
testWithoutContext('toMultiRootPath maps different URIs', () async {
|
||||
expect(toMultiRootPath(Uri.parse('file:///a/b/c'), 'scheme', <String>['/a/b'], false), 'scheme:///c');
|
||||
expect(toMultiRootPath(Uri.parse('file:///d/b/c'), 'scheme', <String>['/a/b'], false), 'file:///d/b/c');
|
||||
expect(toMultiRootPath(Uri.parse('file:///a/b/c'), 'scheme', <String>['/d/b', '/a/b'], false), 'scheme:///c');
|
||||
expect(toMultiRootPath(Uri.parse('file:///a/b/c'), null, <String>[], false), 'file:///a/b/c');
|
||||
expect(toMultiRootPath(Uri.parse('org-dartlang-app:///a/b/c'), null, <String>[], false), 'org-dartlang-app:///a/b/c');
|
||||
expect(toMultiRootPath(Uri.parse('org-dartlang-app:///a/b/c'), 'scheme', <String>['/d/b'], false), 'org-dartlang-app:///a/b/c');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2059,6 +2059,7 @@ void main() {
|
||||
),
|
||||
flutterProject: FlutterProject.current(),
|
||||
target: null,
|
||||
platform: FakePlatform(operatingSystem: 'linux'),
|
||||
)).generator as DefaultResidentCompiler;
|
||||
|
||||
expect(residentCompiler.initializeFromDill,
|
||||
@@ -2093,6 +2094,7 @@ void main() {
|
||||
),
|
||||
flutterProject: FlutterProject.current(),
|
||||
target: null,
|
||||
platform: FakePlatform(operatingSystem: 'linux'),
|
||||
)).generator as DefaultResidentCompiler;
|
||||
|
||||
expect(residentCompiler.initializeFromDill,
|
||||
@@ -2126,7 +2128,7 @@ void main() {
|
||||
extraFrontEndOptions: <String>[],
|
||||
),
|
||||
flutterProject: FlutterProject.current(),
|
||||
target: null,
|
||||
target: null, platform: null,
|
||||
)).generator as DefaultResidentCompiler;
|
||||
|
||||
expect(residentCompiler.extraFrontEndOptions,
|
||||
|
||||
Reference in New Issue
Block a user