Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions dwds/test/fixtures/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,12 @@ class TestContext {
_webRunner = ResidentWebRunner(
mainUri: entry,
urlTunneler: debugSettings.urlEncoder,
projectDirectory: p.toUri(project.absolutePackageDirectory),
projectDirectory: Directory(project.absolutePackageDirectory).uri,
packageConfigFile: project.packageConfigFile,
packageUriMapper: packageUriMapper,
fileSystemRoots: [p.toUri(project.absolutePackageDirectory)],
fileSystemRoots: [
Directory(project.absolutePackageDirectory).uri,
],
fileSystemScheme: 'org-dartlang-app',
outputPath: outputDir.path,
compilerOptions: compilerOptions,
Expand Down
15 changes: 12 additions & 3 deletions dwds/test/fixtures/project.dart
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,18 @@ class TestProject {
_fixturesCopy.deleteSync(recursive: true);
} on FileSystemException catch (_) {
// On Windows, the build daemon process might still be accessing the
// working directory, so wait a second and then try again.
await Future.delayed(const Duration(seconds: 1));
_fixturesCopy.deleteSync(recursive: true);
// working directory, so try again with an exponential backoff.
var seconds = 1;
final maxAttempts = 3;
for (var attempt = 0; attempt < maxAttempts; attempt++) {
try {
_fixturesCopy.deleteSync(recursive: true);
break;
} on FileSystemException catch (_) {
await Future.delayed(Duration(seconds: seconds));
seconds *= 2;
}
}
}
}

Expand Down
19 changes: 12 additions & 7 deletions frontend_server_common/lib/src/asset_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class TestAssetServer implements AssetReader {
// Fallback to "application/octet-stream" on null which
// makes no claims as to the structure of the data.
static const String _defaultMimeType = 'application/octet-stream';
final Uri _projectDirectory;
final FileSystem _fileSystem;
final HttpServer _httpServer;
final Map<String, Uint8List> _files = {};
Expand All @@ -41,6 +42,7 @@ class TestAssetServer implements AssetReader {
this._httpServer,
this._packageUriMapper,
this.internetAddress,
this._projectDirectory,
this._fileSystem,
this._sdkLayout,
) {
Expand All @@ -65,6 +67,7 @@ class TestAssetServer implements AssetReader {
/// trace.
static Future<TestAssetServer> start(
String sdkDirectory,
Uri projectDirectory,
FileSystem fileSystem,
String index,
String hostname,
Expand All @@ -75,8 +78,8 @@ class TestAssetServer implements AssetReader {
final address = (await InternetAddress.lookup(hostname)).first;
final httpServer = await HttpServer.bind(address, port);
final sdkLayout = TestSdkLayout.createDefault(sdkDirectory);
final server = TestAssetServer(
index, httpServer, packageUriMapper, address, fileSystem, sdkLayout);
final server = TestAssetServer(index, httpServer, packageUriMapper, address,
projectDirectory, fileSystem, sdkLayout);
return server;
}

Expand All @@ -94,7 +97,7 @@ class TestAssetServer implements AssetReader {
final headers = <String, String>{};

if (request.url.path.endsWith('.html')) {
final indexFile = _fileSystem.file(index);
final indexFile = _fileSystem.file(_projectDirectory.resolve(index));
if (indexFile.existsSync()) {
headers[HttpHeaders.contentTypeHeader] = 'text/html';
headers[HttpHeaders.contentLengthHeader] =
Expand Down Expand Up @@ -244,8 +247,7 @@ class TestAssetServer implements AssetReader {
// If this is a dart file, it must be on the local file system and is
// likely coming from a source map request. The tool doesn't currently
// consider the case of Dart files as assets.
final dartFile =
_fileSystem.file(_fileSystem.currentDirectory.uri.resolve(path));
final dartFile = _fileSystem.file(_projectDirectory.resolve(path));
if (dartFile.existsSync()) {
return dartFile;
}
Expand All @@ -255,7 +257,10 @@ class TestAssetServer implements AssetReader {
// The file might have been a package file which is signaled by a
// `/packages/<package>/<path>` request.
if (segments.first == 'packages') {
final resolved = _packageUriMapper.serverPathToResolvedUri(path);
var resolved = _packageUriMapper.serverPathToResolvedUri(path);
if (resolved != null) {
resolved = _projectDirectory.resolveUri(resolved);
}
final packageFile = _fileSystem.file(resolved);
if (packageFile.existsSync()) {
return packageFile;
Expand Down Expand Up @@ -311,7 +316,7 @@ class TestAssetServer implements AssetReader {
}

String _parseBasePathFromIndexHtml(String index) {
final file = _fileSystem.file(index);
final file = _fileSystem.file(_projectDirectory.resolve(index));
if (!file.existsSync()) {
throw StateError('Index file $index is not found');
}
Expand Down
24 changes: 11 additions & 13 deletions frontend_server_common/lib/src/devfs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,11 @@ class WebDevFS {

final TestSdkLayout sdkLayout;
final CompilerOptions compilerOptions;
late final Directory _savedCurrentDirectory;

Future<Uri> create() async {
_savedCurrentDirectory = fileSystem.currentDirectory;

fileSystem.currentDirectory = projectDirectory.toFilePath();

assetServer = await TestAssetServer.start(
sdkLayout.sdkDirectory,
projectDirectory,
fileSystem,
index,
hostname,
Expand All @@ -71,7 +67,6 @@ class WebDevFS {
}

Future<void> dispose() {
fileSystem.currentDirectory = _savedCurrentDirectory;
return assetServer.close();
}

Expand All @@ -84,7 +79,8 @@ class WebDevFS {
required bool fullRestart,
}) async {
final mainPath = mainUri.toFilePath();
final outputDirectoryPath = fileSystem.file(mainPath).parent.path;
final outputDirectory = fileSystem.directory(
fileSystem.file(projectDirectory.resolve(mainPath)).parent.path);
final entryPoint = mainUri.toString();

var prefix = '';
Expand All @@ -103,7 +99,10 @@ class WebDevFS {
final bootstrap = '${prefix}main_module.bootstrap.js';

assetServer.writeFile(
entryPoint, fileSystem.file(mainPath).readAsStringSync());
entryPoint,
fileSystem
.file(projectDirectory.resolve(mainPath))
.readAsStringSync());
assetServer.writeFile(stackMapper, stackTraceMapper.readAsStringSync());

switch (ddcModuleFormat) {
Expand Down Expand Up @@ -199,14 +198,13 @@ class WebDevFS {
File metadataFile;
List<String> modules;
try {
final parentDirectory = fileSystem.directory(outputDirectoryPath);
codeFile =
parentDirectory.childFile('${compilerOutput.outputFilename}.sources');
outputDirectory.childFile('${compilerOutput.outputFilename}.sources');
manifestFile =
parentDirectory.childFile('${compilerOutput.outputFilename}.json');
outputDirectory.childFile('${compilerOutput.outputFilename}.json');
sourcemapFile =
parentDirectory.childFile('${compilerOutput.outputFilename}.map');
metadataFile = parentDirectory
outputDirectory.childFile('${compilerOutput.outputFilename}.map');
metadataFile = outputDirectory
.childFile('${compilerOutput.outputFilename}.metadata');
modules = assetServer.write(
codeFile, manifestFile, sourcemapFile, metadataFile);
Expand Down
3 changes: 1 addition & 2 deletions frontend_server_common/lib/src/frontend_server_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,6 @@ class ResidentCompiler {
if (compilerOptions.moduleFormat == ModuleFormat.ddc)
'--dartdevc-module-format=ddc'
];

_logger.info(args.join(' '));
final workingDirectory = projectDirectory.toFilePath();
_server = await Process.start(sdkLayout.dartAotRuntimePath, args,
Expand Down Expand Up @@ -657,7 +656,7 @@ String _toMultiRootPath(
for (final fileSystemRoot in fileSystemRoots) {
final rootPath = fileSystemRoot.toFilePath(windows: Platform.isWindows);
if (filePath.startsWith(rootPath)) {
return '$scheme://${filePath.substring(rootPath.length)}';
return '$scheme:///${filePath.substring(rootPath.length)}';
}
}
return fileUri.toString();
Expand Down
Loading