diff --git a/pkg/analyzer/lib/src/workspace/pub.dart b/pkg/analyzer/lib/src/workspace/pub.dart index 0daefaeb873..841281ebc90 100644 --- a/pkg/analyzer/lib/src/workspace/pub.dart +++ b/pkg/analyzer/lib/src/workspace/pub.dart @@ -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]. diff --git a/pkg/analyzer/test/src/dart/analysis/context_locator_test.dart b/pkg/analyzer/test/src/dart/analysis/context_locator_test.dart index 0f36b26c4ef..11e0b10d05a 100644 --- a/pkg/analyzer/test/src/dart/analysis/context_locator_test.dart +++ b/pkg/analyzer/test/src/dart/analysis/context_locator_test.dart @@ -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);