Don't use PubWorkspace for 'third_party/dart' locations.

These should be treated as BlazeWorkspace.

Bug: https://buganizer.corp.google.com/issues/273584249
Change-Id: Id7bf03d14d3304eb062be0d539cfac0c282ecec6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/296320
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2023-04-19 17:16:51 +00:00 committed by Commit Queue
parent 7880fd4ce5
commit ad30add7a3
2 changed files with 45 additions and 0 deletions

View file

@ -68,6 +68,9 @@ class PubWorkspace extends SimpleWorkspace {
for (var current in start.withAncestors) {
var pubspec = current.getChildAssumingFile(file_paths.pubspecYaml);
if (pubspec.exists) {
if (_isInThirdPartyDart(pubspec)) {
return null;
}
var root = current.path;
return PubWorkspace._(provider, packages, root, pubspec);
}
@ -83,6 +86,19 @@ class PubWorkspace extends SimpleWorkspace {
return null;
}
}
/// See https://buganizer.corp.google.com/issues/273584249
///
/// Check if `/home/workspace/third_party/dart/my/pubspec.yaml`
/// If so, we are in a Blaze workspace, and should not create Pub.
static bool _isInThirdPartyDart(File pubspec) {
final path = pubspec.path;
final pathContext = pubspec.provider.pathContext;
final pathComponents = pathContext.split(path);
return pathComponents.length > 4 &&
pathComponents[pathComponents.length - 3] == 'dart' &&
pathComponents[pathComponents.length - 4] == 'third_party';
}
}
/// Information about a package defined in a [PubWorkspace].

View file

@ -1636,6 +1636,35 @@ ${getFolder(outPath).path}
expect(contentRoot.packagesFile, packageConfigJsonFile);
}
/// See https://buganizer.corp.google.com/issues/273584249
void test_locateRoots_single_directory_blaze_hasPubspecYaml_thirdPartyDart() {
final workspacePath = '/home/workspace';
final thirdPartyDartPath = '$workspacePath/third_party/dart';
final myPackagePath = '$thirdPartyDartPath/my';
final myPackage = getFolder(myPackagePath);
newFile('$workspacePath/${file_paths.blazeWorkspaceMarker}', '');
final buildFile = newBlazeBuildFile(myPackagePath, '');
final pubspecYamlFile = newPubspecYamlFile(myPackagePath, '');
final myFile = newFile('$myPackagePath/lib/my.dart', '');
final roots = contextLocator.locateRoots(
includedPaths: [
myPackage.path,
],
);
expect(roots, hasLength(1));
final root = findRoot(roots, myPackage);
expect(root.includedPaths, unorderedEquals([myPackage.path]));
expect(root.excludedPaths, isEmpty);
expect(root.optionsFile, isNull);
expect(root.packagesFile, isNull);
_assertBlazeWorkspace(root.workspace, workspacePath);
_assertAnalyzedFiles2(root, [buildFile, pubspecYamlFile, myFile]);
}
void test_locateRoots_single_file_gnWorkspace() {
var workspaceRootPath = '/workspace';
newFolder(workspaceRootPath);