Look for BUILD.gn files to identify ContextRoot(s) with GnWorkspace.

This rehabilitates language server support for Fuchsia.

This makes GnWorkspace more like PubWorkspace, not like BlazeWorkspace. The workspace is the location of `BUILD.gn` file (and is identical to the package, although I did not change this in this CL). And there must be also `.jiri_root` somewhere above it.

We don't look for `pubspec.yaml` files to decide that we have a new `ContextRoot`, instead we rely on `.dart_tool/package_config.json` created by `Pub` from `pubspec.yaml`. For GN, I had to specialize it to look for `BUILD.gn` files.

With this change `BUILD.gn` takes preference over any other signal, so we don't care if there are `pubspec.yaml` files.

Fixed: fuchsia:109640
Change-Id: I2277336bd377abb9d8c8c33529183e21b2f51c4e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/264280
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2022-10-19 17:57:50 +00:00 committed by Commit Queue
parent 2dc6b5dd55
commit eea6fb106d
9 changed files with 311 additions and 112 deletions

View file

@ -19,7 +19,6 @@ import 'package:analyzer/src/test_utilities/package_config_file_builder.dart';
import 'package:analyzer/src/util/file_paths.dart' as file_paths;
import 'package:analyzer/src/util/glob.dart';
import 'package:analyzer/src/workspace/blaze.dart';
import 'package:analyzer/src/workspace/gn.dart';
import 'package:analyzer/src/workspace/workspace.dart';
import 'package:analyzer_plugin/channel/channel.dart';
import 'package:analyzer_plugin/protocol/protocol.dart';
@ -438,8 +437,7 @@ class PluginManager {
// because we won't be running pub.
return _computeFiles(pluginFolder);
}
var workspace = BlazeWorkspace.find(resourceProvider, pluginFolder.path) ??
GnWorkspace.find(resourceProvider, pluginFolder.path);
var workspace = BlazeWorkspace.find(resourceProvider, pluginFolder.path);
if (workspace != null) {
// Similarly, we won't be running pub if we're in a workspace because
// there is exactly one version of each package.

View file

@ -15,7 +15,6 @@ import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/dart/ast/extensions.dart';
import 'package:analyzer/src/dart/element/inheritance_manager3.dart';
import 'package:analyzer/src/workspace/blaze.dart';
import 'package:analyzer/src/workspace/gn.dart';
import 'package:analyzer_plugin/protocol/protocol_common.dart'
show KytheEntry, KytheVName;
import 'package:path/path.dart' show relative;
@ -89,10 +88,6 @@ String _getPath(ResourceProvider provider, Element? e,
if (blazeWorkspace != null) {
return provider.pathContext.relative(path, from: blazeWorkspace.root);
}
var gnWorkspace = GnWorkspace.find(provider, path);
if (gnWorkspace != null) {
return provider.pathContext.relative(path, from: gnWorkspace.root);
}
if (path.lastIndexOf('CORPUS_NAME') != -1) {
return path.substring(path.lastIndexOf('CORPUS_NAME') + 12);
}

View file

@ -200,23 +200,34 @@ class ContextLocatorImpl implements ContextLocator {
packagesFolderToChooseRoot = foundPackages?.parent;
}
var rootFolder = _lowest2(
var buildGnFile = _findBuildGnFile(parent);
var rootFolder = _lowest([
optionsFolderToChooseRoot,
packagesFolderToChooseRoot,
);
buildGnFile?.parent,
]);
var workspace = _createWorkspace(parent, packagesFile);
var workspace = _createWorkspace(
folder: parent,
packagesFile: packagesFile,
buildGnFile: buildGnFile,
);
if (workspace is! BasicWorkspace) {
rootFolder = _lowest2(
rootFolder = _lowest([
rootFolder,
resourceProvider.getFolder(workspace.root),
);
]);
}
if (rootFolder == null) {
rootFolder = defaultRootFolder();
if (workspace is BasicWorkspace) {
workspace = _createWorkspace(rootFolder, packagesFile);
workspace = _createWorkspace(
folder: rootFolder,
packagesFile: packagesFile,
buildGnFile: buildGnFile,
);
}
}
@ -278,11 +289,14 @@ class ContextLocatorImpl implements ContextLocator {
if (packagesFile == null) {
localPackagesFile = _getPackagesFile(folder);
}
var buildGnFile = folder.getExistingFile(file_paths.buildGn);
//
// Create a context root for the given [folder] if at least one of the
// options and packages file is locally specified.
//
if (localPackagesFile != null || localOptionsFile != null) {
if (localPackagesFile != null ||
localOptionsFile != null ||
buildGnFile != null) {
if (optionsFile != null) {
localOptionsFile = optionsFile;
}
@ -290,7 +304,11 @@ class ContextLocatorImpl implements ContextLocator {
localPackagesFile = packagesFile;
}
var rootPackagesFile = localPackagesFile ?? containingRoot.packagesFile;
var workspace = _createWorkspace(folder, rootPackagesFile);
var workspace = _createWorkspace(
folder: folder,
packagesFile: rootPackagesFile,
buildGnFile: buildGnFile,
);
var root = ContextRootImpl(resourceProvider, folder, workspace);
root.packagesFile = rootPackagesFile;
root.optionsFile = localOptionsFile ?? containingRoot.optionsFile;
@ -365,7 +383,18 @@ class ContextLocatorImpl implements ContextLocator {
}
}
Workspace _createWorkspace(Folder folder, File? packagesFile) {
Workspace _createWorkspace({
required Folder folder,
required File? packagesFile,
required File? buildGnFile,
}) {
if (buildGnFile != null) {
var workspace = GnWorkspace.find(buildGnFile);
if (workspace != null) {
return workspace;
}
}
Packages packages;
if (packagesFile != null) {
packages = parsePackageConfigJsonFile(resourceProvider, packagesFile);
@ -378,8 +407,6 @@ class ContextLocatorImpl implements ContextLocator {
Workspace? workspace;
workspace = BlazeWorkspace.find(resourceProvider, rootPath,
lookForBuildFileSubstitutes: false);
workspace = _mostSpecificWorkspace(
workspace, GnWorkspace.find(resourceProvider, rootPath));
workspace = _mostSpecificWorkspace(workspace,
PackageBuildWorkspace.find(resourceProvider, packages, rootPath));
workspace = _mostSpecificWorkspace(
@ -388,6 +415,16 @@ class ContextLocatorImpl implements ContextLocator {
return workspace;
}
File? _findBuildGnFile(Folder folder) {
for (var current in folder.withAncestors) {
var file = current.getExistingFile(file_paths.buildGn);
if (file != null) {
return file;
}
}
return null;
}
File? _findDefaultOptionsFile(Workspace workspace) {
// TODO(scheglov) Create SourceFactory once.
var sourceFactory = workspace.createSourceFactory(null, null);
@ -516,19 +553,19 @@ class ContextLocatorImpl implements ContextLocator {
}
}
/// The [first] and [second] must be folders on the path from a file to
/// Every element in [folders] must be a folder on the path from a file to
/// the root of the file system. As such, they are either the same folder,
/// or one is strictly above the other.
static Folder? _lowest2(Folder? first, Folder? second) {
if (first != null) {
if (second != null) {
if (first.contains(second.path)) {
return second;
}
static Folder? _lowest(List<Folder?> folders) {
return folders.fold<Folder?>(null, (result, folder) {
if (result == null) {
return folder;
} else if (folder != null && result.contains(folder.path)) {
return folder;
} else {
return result;
}
return first;
}
return second;
});
}
/// Return `true` if the configuration of [existingRoot] is the same as

View file

@ -79,6 +79,11 @@ mixin ResourceProviderMixin {
return newFile(path, content);
}
File newBuildGnFile(String directoryPath, String content) {
String path = join(directoryPath, file_paths.buildGn);
return newFile(path, content);
}
File newFile(String path, String content) {
String convertedPath = convertPath(path);
return resourceProvider.newFile(convertedPath, content);

View file

@ -20,6 +20,9 @@ const String blazeBuild = 'BUILD';
/// to the workspace root.
const String blazeWorkspaceMarker = 'dart/config/ide/flutter.json';
/// File name of GN `BUILD.gn` files.
const String buildGn = 'BUILD.gn';
/// The name of the `.dart_tool` directory.
const String dotDartTool = '.dart_tool';

View file

@ -8,6 +8,7 @@ import 'package:analyzer/src/generated/sdk.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/source/package_map_resolver.dart';
import 'package:analyzer/src/summary/package_bundle_reader.dart';
import 'package:analyzer/src/util/file_paths.dart' as file_paths;
import 'package:analyzer/src/workspace/workspace.dart';
import 'package:collection/collection.dart';
import 'package:path/path.dart' as path;
@ -17,11 +18,6 @@ class GnWorkspace extends Workspace {
/// The name of the directory that identifies the root of the workspace.
static const String _jiriRootName = '.jiri_root';
/// The name of the file that identifies a set of GN Targets.
///
/// For Dart package purposes, a BUILD.gn file identifies a package.
static const String _buildFileName = 'BUILD.gn';
/// The resource provider used to access the file system.
final ResourceProvider provider;
@ -30,10 +26,12 @@ class GnWorkspace extends Workspace {
@override
final String root;
final File buildGnFile;
/// Information about packages available in the workspace.
final Packages packages;
GnWorkspace._(this.provider, this.root, this.packages);
GnWorkspace._(this.provider, this.root, this.buildGnFile, this.packages);
/// TODO(scheglov) Finish switching to [packages].
Map<String, List<Folder>> get packageMap {
@ -89,31 +87,28 @@ class GnWorkspace extends Workspace {
return null;
}
if (folder.getChildAssumingFile(_buildFileName).exists) {
if (folder.getChildAssumingFile(file_paths.buildGn).exists) {
return GnWorkspacePackage(folder.path, this);
}
}
return null;
}
/// Find the GN workspace that contains the given [filePath].
/// Find the GN workspace for the given [buildGnFile].
///
/// Return `null` if a workspace could not be found. For a workspace to be
/// found, both a `.jiri_root` file must be found, and at least one "packages"
/// file must be found in [filePath]'s output directory.
static GnWorkspace? find(ResourceProvider provider, String filePath) {
Resource resource = provider.getResource(filePath);
if (resource is File) {
filePath = resource.parent.path;
}
/// found, the `.jiri_root` folder must be found, and at least one
/// `<anything>package_config.json` file must be found in [buildGnFile]'s
/// output directory.
static GnWorkspace? find(File buildGnFile) {
var provider = buildGnFile.provider;
var startFolder = provider.getFolder(filePath);
for (var folder in startFolder.withAncestors) {
for (var folder in buildGnFile.parent.withAncestors) {
if (folder.getChildAssumingFolder(_jiriRootName).exists) {
// Found the .jiri_root file, must be a non-git workspace.
String root = folder.path;
var packagesFiles = _findPackagesFile(provider, root, filePath);
var packagesFiles = _findPackagesFile(provider, root, buildGnFile);
if (packagesFiles.isEmpty) {
return null;
}
@ -126,7 +121,7 @@ class GnWorkspace extends Workspace {
}
}
return GnWorkspace._(provider, root, Packages(packageMap));
return GnWorkspace._(provider, root, buildGnFile, Packages(packageMap));
}
}
return null;
@ -147,10 +142,11 @@ class GnWorkspace extends Workspace {
static List<File> _findPackagesFile(
ResourceProvider provider,
String root,
String filePath,
File buildGnFile,
) {
path.Context pathContext = provider.pathContext;
String sourceDirectory = pathContext.relative(filePath, from: root);
String sourceDirectory =
pathContext.relative(buildGnFile.parent.path, from: root);
var outDirectory = _getOutDirectory(root, provider);
if (outDirectory == null) {
return const <File>[];

View file

@ -10,6 +10,7 @@ import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
import 'package:analyzer/src/util/file_paths.dart' as file_paths;
import 'package:analyzer/src/workspace/basic.dart';
import 'package:analyzer/src/workspace/blaze.dart';
import 'package:analyzer/src/workspace/gn.dart';
import 'package:analyzer/src/workspace/pub.dart';
import 'package:analyzer/src/workspace/workspace.dart';
import 'package:test/test.dart';
@ -793,6 +794,35 @@ analyzer:
_assertAnalyzedFiles2(barRoot, [barFile]);
}
void test_locateRoots_multiple_files_gnWorkspace() {
var workspaceRootPath = '/workspace';
newFolder(workspaceRootPath);
newFolder('$workspaceRootPath/.jiri_root');
var outPath = '$workspaceRootPath/out/default';
var dartGenPath = '$outPath/dartlang/gen';
newFile('$workspaceRootPath/.fx-build-dir', '''
${getFolder(outPath).path}
''');
var myRootPath = '$workspaceRootPath/my';
var myRoot = newFolder(myRootPath);
var myBuildGn = newBuildGnFile(myRootPath, '');
var myFile1 = newFile('$myRootPath/lib/file1.dart', '');
var myFile2 = newFile('$myRootPath/lib/file2.dart', '');
newFile('$myRootPath/lib/file3.dart', '');
newFile('$dartGenPath/my/my_package_config.json', '');
var roots = contextLocator.locateRoots(
includedPaths: [myFile1.path, myFile2.path],
);
expect(roots, hasLength(1));
var myContextRoot = findRoot(roots, myRoot);
_assertGnWorkspace(myContextRoot.workspace, workspaceRootPath, myBuildGn);
_assertAnalyzedFiles2(myContextRoot, [myFile1, myFile2]);
}
void test_locateRoots_multiple_files_sameOptions_differentPackages() {
var fooPackagesFile = newPackageConfigJsonFile('/home/foo', '');
var barPackagesFile = newPackageConfigJsonFile('/home/bar', '');
@ -1439,6 +1469,42 @@ analyzer:
]);
}
test_locateRoots_single_dir_children_gnWorkspaces_noPubspecYaml() {
var workspaceRootPath = '/workspace';
newFolder(workspaceRootPath);
newFolder('$workspaceRootPath/.jiri_root');
var outPath = '$workspaceRootPath/out/default';
var dartGenPath = '$outPath/dartlang/gen';
newFile('$workspaceRootPath/.fx-build-dir', '''
${getFolder(outPath).path}
''');
var dartPath = '$workspaceRootPath/dart';
var fooRootPath = '$dartPath/foo';
var fooRoot = newFolder(fooRootPath);
var fooBuildGn = newBuildGnFile(fooRootPath, '');
newFile('$dartGenPath/dart/foo/foo_package_config.json', '');
var barRootPath = '$dartPath/bar';
var barRoot = newFolder(barRootPath);
var barBuildGn = newBuildGnFile(barRootPath, '');
newFile('$dartGenPath/dart/bar/bar_package_config.json', '');
var roots = contextLocator.locateRoots(
includedPaths: [
getFolder(dartPath).path,
],
);
expect(roots, hasLength(3));
var fooContextRoot = findRoot(roots, fooRoot);
_assertGnWorkspace(fooContextRoot.workspace, workspaceRootPath, fooBuildGn);
var barContextRoot = findRoot(roots, barRoot);
_assertGnWorkspace(barContextRoot.workspace, workspaceRootPath, barBuildGn);
}
void test_locateRoots_single_dir_directOptions_directPackages() {
Folder rootFolder = newFolder('/test/root');
File optionsFile = newAnalysisOptionsYamlFile('/test/root', '');
@ -1471,6 +1537,57 @@ analyzer:
expect(package1Root.packagesFile, packagesFile);
}
void test_locateRoots_single_dir_gnWorkspace_hasPubspecYaml() {
var workspaceRootPath = '/workspace';
newFolder(workspaceRootPath);
newFolder('$workspaceRootPath/.jiri_root');
var outPath = '$workspaceRootPath/out/default';
var dartGenPath = '$outPath/dartlang/gen';
newFile('$workspaceRootPath/.fx-build-dir', '''
${getFolder(outPath).path}
''');
var myRootPath = '$workspaceRootPath/my';
var myRoot = newFolder(myRootPath);
var myBuildGn = newBuildGnFile(myRootPath, '');
newFile('$dartGenPath/my/my_package_config.json', '');
newPubspecYamlFile(myRootPath, '');
var roots = contextLocator.locateRoots(
includedPaths: [myRoot.path],
);
expect(roots, hasLength(1));
var package1Root = findRoot(roots, myRoot);
_assertGnWorkspace(package1Root.workspace, workspaceRootPath, myBuildGn);
}
void test_locateRoots_single_dir_gnWorkspace_noPubspecYaml() {
var workspaceRootPath = '/workspace';
newFolder(workspaceRootPath);
newFolder('$workspaceRootPath/.jiri_root');
var outPath = '$workspaceRootPath/out/default';
var dartGenPath = '$outPath/dartlang/gen';
newFile('$workspaceRootPath/.fx-build-dir', '''
${getFolder(outPath).path}
''');
var myRootPath = '$workspaceRootPath/my';
var myRoot = newFolder(myRootPath);
var myBuildGn = newBuildGnFile(myRootPath, '');
newFile('$dartGenPath/my/my_package_config.json', '');
var roots = contextLocator.locateRoots(
includedPaths: [myRoot.path],
);
expect(roots, hasLength(1));
var package1Root = findRoot(roots, myRoot);
_assertGnWorkspace(package1Root.workspace, workspaceRootPath, myBuildGn);
}
void test_locateRoots_single_dir_inheritedOptions_directPackages() {
Folder rootFolder = newFolder('/test/root');
File optionsFile = newAnalysisOptionsYamlFile('/test', '');
@ -1519,6 +1636,34 @@ analyzer:
expect(contentRoot.packagesFile, packageConfigJsonFile);
}
void test_locateRoots_single_file_gnWorkspace() {
var workspaceRootPath = '/workspace';
newFolder(workspaceRootPath);
newFolder('$workspaceRootPath/.jiri_root');
var outPath = '$workspaceRootPath/out/default';
var dartGenPath = '$outPath/dartlang/gen';
newFile('$workspaceRootPath/.fx-build-dir', '''
${getFolder(outPath).path}
''');
var myRootPath = '$workspaceRootPath/my';
var myRoot = newFolder(myRootPath);
var myBuildGn = newBuildGnFile(myRootPath, '');
var myFile = newFile('$myRootPath/lib/a.dart', '');
newFile('$myRootPath/lib/b.dart', '');
newFile('$dartGenPath/my/my_package_config.json', '');
var roots = contextLocator.locateRoots(
includedPaths: [myFile.path],
);
expect(roots, hasLength(1));
var myContextRoot = findRoot(roots, myRoot);
_assertGnWorkspace(myContextRoot.workspace, workspaceRootPath, myBuildGn);
_assertAnalyzedFiles2(myContextRoot, [myFile]);
}
void test_locateRoots_single_file_inheritedOptions_directPackages() {
File optionsFile = newAnalysisOptionsYamlFile('/test', '');
File packagesFile = newPackageConfigJsonFile('/test/root', '');
@ -1535,6 +1680,32 @@ analyzer:
expect(package1Root.packagesFile, packagesFile);
}
void test_locateRoots_single_file_jiriRoot_noBuildGn_noPubspecYaml() {
var workspaceRootPath = '/workspace';
newFolder(workspaceRootPath);
newFolder('$workspaceRootPath/.jiri_root');
var outPath = '$workspaceRootPath/out/default';
var dartGenPath = '$outPath/dartlang/gen';
newFile('$workspaceRootPath/.fx-build-dir', '''
${getFolder(outPath).path}
''');
var myRootPath = '$workspaceRootPath/my';
var myFile = newFile('$myRootPath/lib/a.dart', '');
newFile('$myRootPath/lib/b.dart', '');
newFile('$dartGenPath/my/my_package_config.json', '');
var roots = contextLocator.locateRoots(
includedPaths: [myFile.path],
);
expect(roots, hasLength(1));
var root = findRoot(roots, getFolder('/'));
_assertBasicWorkspace(root.workspace, root.root.path);
_assertAnalyzedFiles2(root, [myFile]);
}
void test_locateRoots_single_file_notExisting() {
File optionsFile = newAnalysisOptionsYamlFile('/test', '');
File packagesFile = newPackageConfigJsonFile('/test/root', '');
@ -1586,6 +1757,17 @@ analyzer:
expect(workspace.root, root);
}
void _assertGnWorkspace(
Workspace workspace,
String posixRoot,
File buildGnFile,
) {
workspace as GnWorkspace;
var root = convertPath(posixRoot);
expect(workspace.root, root);
expect(workspace.buildGnFile, buildGnFile);
}
void _assertNotAnalyzed(ContextRoot root, List<String> posixPathList) {
for (var posixPath in posixPathList) {
var path = convertPath(posixPath);

View file

@ -370,10 +370,16 @@ class DeprecatedMemberUse_GnWorkspaceTest extends ContextResolutionTest {
@override
List<String> get collectionIncludedPaths => [workspaceRootPath];
String get genPath => '$outPath/dartlang/gen';
String get myPackageLibPath => '$myPackageRootPath/lib';
String get myPackageRootPath => '$workspaceRootPath/my';
Folder get outFolder => getFolder(outPath);
String get outPath => '$workspaceRootPath/out/default';
@override
File get testFile => getFile('$myPackageLibPath/my.dart');
@ -383,16 +389,19 @@ class DeprecatedMemberUse_GnWorkspaceTest extends ContextResolutionTest {
void setUp() {
super.setUp();
newFolder('$workspaceRootPath/.jiri_root');
newFile('$workspaceRootPath/.fx-build-dir', '''
${outFolder.path}
''');
newBuildGnFile(myPackageRootPath, '');
}
test_differentPackage() async {
newPubspecYamlFile('$workspaceRootPath/my', '');
newFile('$workspaceRootPath/my/BUILD.gn', '');
newBuildGnFile('$workspaceRootPath/aaa', '');
newPubspecYamlFile('$workspaceRootPath/aaa', '');
newFile('$workspaceRootPath/aaa/BUILD.gn', '');
_writeWorkspacePackagesFile({
var myPackageConfig = getFile('$genPath/my/my_package_config.json');
_writeWorkspacePackagesFile(myPackageConfig, {
'aaa': '$workspaceRootPath/aaa/lib',
'my': myPackageLibPath,
});
@ -412,10 +421,8 @@ void f(A a) {}
}
test_samePackage() async {
newPubspecYamlFile('$workspaceRootPath/my', '');
newFile('$workspaceRootPath/my/BUILD.gn', '');
_writeWorkspacePackagesFile({
var myPackageConfig = getFile('$genPath/my/my_package_config.json');
_writeWorkspacePackagesFile(myPackageConfig, {
'my': myPackageLibPath,
});
@ -439,7 +446,8 @@ void f(A a) {}
assertGnWorkspaceFor(testFile);
}
void _writeWorkspacePackagesFile(Map<String, String> nameToLibPath) {
void _writeWorkspacePackagesFile(
File file, Map<String, String> nameToLibPath) {
var packages = nameToLibPath.entries.map((entry) => '''{
"languageVersion": "2.2",
"name": "${entry.key}",
@ -447,9 +455,7 @@ void f(A a) {}
"rootUri": "${toUriStr(entry.value)}"
}''');
var buildDir = 'out/debug-x87_128';
var genPath = '$workspaceRootPath/$buildDir/dartlang/gen';
newFile('$genPath/foo_package_config.json', '''{
newFile(file.path, '''{
"configVersion": 2,
"packages": [ ${packages.join(', ')} ]
}''');

View file

@ -22,7 +22,7 @@ main() {
class GnWorkspacePackageTest with ResourceProviderMixin {
void test_contains_differentPackageInWorkspace() {
GnWorkspace workspace = _buildStandardGnWorkspace();
newFile('/ws/some/code/BUILD.gn', '');
newBuildGnFile('/ws/some/code', '');
var targetFile = newFile('/ws/some/code/lib/code.dart', '');
var package = workspace.findPackageFor(targetFile.path)!;
@ -36,7 +36,7 @@ class GnWorkspacePackageTest with ResourceProviderMixin {
void test_contains_differentWorkspace() {
GnWorkspace workspace = _buildStandardGnWorkspace();
newFile('/ws/some/code/BUILD.gn', '');
newBuildGnFile('/ws/some/code', '');
var targetFile = newFile('/ws/some/code/lib/code.dart', '');
var package = workspace.findPackageFor(targetFile.path)!;
@ -46,7 +46,7 @@ class GnWorkspacePackageTest with ResourceProviderMixin {
void test_contains_samePackage() {
GnWorkspace workspace = _buildStandardGnWorkspace();
newFile('/ws/some/code/BUILD.gn', '');
newBuildGnFile('/ws/some/code', '');
var targetFile = newFile('/ws/some/code/lib/code.dart', '');
var targetFile2 = newFile('/ws/some/code/lib/code2.dart', '');
var targetFile3 = newFile('/ws/some/code/lib/src/code3.dart', '');
@ -62,9 +62,9 @@ class GnWorkspacePackageTest with ResourceProviderMixin {
void test_contains_subPackage() {
GnWorkspace workspace = _buildStandardGnWorkspace();
newFile('/ws/some/code/BUILD.gn', '');
newBuildGnFile('/ws/some/code', '');
newFile('/ws/some/code/lib/code.dart', '');
newFile('/ws/some/code/testing/BUILD.gn', '');
newBuildGnFile('/ws/some/code/testing', '');
newFile('/ws/some/code/testing/lib/testing.dart', '');
var package =
@ -77,7 +77,7 @@ class GnWorkspacePackageTest with ResourceProviderMixin {
void test_findPackageFor_buildFileExists() {
GnWorkspace workspace = _buildStandardGnWorkspace();
newFile('/ws/some/code/BUILD.gn', '');
newBuildGnFile('/ws/some/code', '');
var targetFile = newFile('/ws/some/code/lib/code.dart', '');
var package = workspace.findPackageFor(targetFile.path)!;
@ -85,18 +85,9 @@ class GnWorkspacePackageTest with ResourceProviderMixin {
expect(package.workspace, equals(workspace));
}
void test_findPackageFor_missingBuildFile() {
GnWorkspace workspace = _buildStandardGnWorkspace();
newFile('/ws/some/code/lib/code.dart', '');
var package =
workspace.findPackageFor(convertPath('/ws/some/code/lib/code.dart'));
expect(package, isNull);
}
void test_packagesAvailableTo() {
GnWorkspace workspace = _buildStandardGnWorkspace();
newFile('/ws/some/code/BUILD.gn', '');
newBuildGnFile('/ws/some/code', '');
var libraryPath = newFile('/ws/some/code/lib/code.dart', '').path;
var package = workspace.findPackageFor(libraryPath)!;
var packages = package.packagesAvailableTo(libraryPath);
@ -130,8 +121,8 @@ class GnWorkspacePackageTest with ResourceProviderMixin {
]
}''');
newFolder('/ws/some/code');
var gnWorkspace =
GnWorkspace.find(resourceProvider, convertPath('/ws/some/code'))!;
var buildGnFile = newBuildGnFile('/ws/some/code', '');
var gnWorkspace = GnWorkspace.find(buildGnFile)!;
expect(gnWorkspace.isBlaze, isFalse);
return gnWorkspace;
}
@ -141,28 +132,15 @@ class GnWorkspacePackageTest with ResourceProviderMixin {
class GnWorkspaceTest with ResourceProviderMixin {
void test_find_noJiriRoot() {
newFolder('/workspace');
var workspace =
GnWorkspace.find(resourceProvider, convertPath('/workspace'));
var buildGnFile = newBuildGnFile('/workspace/some/code', '');
var workspace = GnWorkspace.find(buildGnFile);
expect(workspace, isNull);
}
void test_find_noPackagesFiles() {
newFolder('/workspace/.jiri_root');
newFolder('/workspace/some/code');
var workspace =
GnWorkspace.find(resourceProvider, convertPath('/workspace'));
expect(workspace, isNull);
}
void test_find_notAbsolute() {
expect(
() => GnWorkspace.find(resourceProvider, convertPath('not_absolute')),
throwsA(const TypeMatcher<ArgumentError>()));
}
void test_find_withRoot() {
newFolder('/workspace/.jiri_root');
newFolder('/workspace/some/code');
var buildGnFile = newBuildGnFile('/workspace/some/code', '');
newPubspecYamlFile('/workspace/some/code', '');
String buildDir = convertPath('out/debug-x87_128');
newFile('/workspace/.fx-build-dir', '$buildDir\n');
@ -170,14 +148,14 @@ class GnWorkspaceTest with ResourceProviderMixin {
'/workspace/out/debug-x87_128/dartlang/gen/some/code/foo_package_config.json',
'',
);
var workspace = GnWorkspace.find(
resourceProvider, convertPath('/workspace/some/code'))!;
var workspace = GnWorkspace.find(buildGnFile)!;
expect(workspace.root, convertPath('/workspace'));
}
void test_packages() {
newFolder('/workspace/.jiri_root');
newFolder('/workspace/some/code');
var buildGnFile = newBuildGnFile('/workspace/some/code', '');
newPubspecYamlFile('/workspace/some/code', '');
String buildDir = convertPath('out/debug-x87_128');
newFile('/workspace/.fx-build-dir', '$buildDir\n');
@ -196,8 +174,7 @@ class GnWorkspaceTest with ResourceProviderMixin {
}
]
}''');
var workspace = GnWorkspace.find(
resourceProvider, convertPath('/workspace/some/code'))!;
var workspace = GnWorkspace.find(buildGnFile)!;
expect(workspace.root, convertPath('/workspace'));
expect(
workspace.packages.packages,
@ -213,6 +190,7 @@ class GnWorkspaceTest with ResourceProviderMixin {
void test_packages_absoluteBuildDir() {
newFolder('/workspace/.jiri_root');
newFolder('/workspace/some/code');
var buildGnFile = newBuildGnFile('/workspace/some/code', '');
newPubspecYamlFile('/workspace/some/code', '');
String buildDir = convertPath('/workspace/out/debug-x87_128');
newFile('/workspace/.fx-build-dir', '$buildDir\n');
@ -231,8 +209,7 @@ class GnWorkspaceTest with ResourceProviderMixin {
}
]
}''');
var workspace = GnWorkspace.find(
resourceProvider, convertPath('/workspace/some/code'))!;
var workspace = GnWorkspace.find(buildGnFile)!;
expect(workspace.root, convertPath('/workspace'));
expect(
workspace.packages.packages,
@ -248,6 +225,7 @@ class GnWorkspaceTest with ResourceProviderMixin {
void test_packages_fallbackBuildDir() {
newFolder('/workspace/.jiri_root');
newFolder('/workspace/some/code');
var buildGnFile = newBuildGnFile('/workspace/some/code', '');
newPubspecYamlFile('/workspace/some/code', '');
String packageLocation = convertPath('/workspace/this/is/the/package');
Uri packageUri = resourceProvider.pathContext.toUri(packageLocation);
@ -264,8 +242,7 @@ class GnWorkspaceTest with ResourceProviderMixin {
}
]
}''');
var workspace = GnWorkspace.find(
resourceProvider, convertPath('/workspace/some/code'))!;
var workspace = GnWorkspace.find(buildGnFile)!;
expect(workspace.root, convertPath('/workspace'));
expect(
workspace.packages.packages,
@ -281,6 +258,7 @@ class GnWorkspaceTest with ResourceProviderMixin {
void test_packages_fallbackBuildDirWithUselessConfig() {
newFolder('/workspace/.jiri_root');
newFolder('/workspace/some/code');
var buildGnFile = newBuildGnFile('/workspace/some/code', '');
newPubspecYamlFile('/workspace/some/code', '');
newFile('/workspace/.fx-build-dir', '');
String packageLocation = convertPath('/workspace/this/is/the/package');
@ -298,8 +276,7 @@ class GnWorkspaceTest with ResourceProviderMixin {
}
]
}''');
var workspace = GnWorkspace.find(
resourceProvider, convertPath('/workspace/some/code'))!;
var workspace = GnWorkspace.find(buildGnFile)!;
expect(workspace.root, convertPath('/workspace'));
expect(
workspace.packages.packages,
@ -315,6 +292,7 @@ class GnWorkspaceTest with ResourceProviderMixin {
void test_packages_multipleCandidates() {
newFolder('/workspace/.jiri_root');
newFolder('/workspace/some/code');
var buildGnFile = newBuildGnFile('/workspace/some/code', '');
newPubspecYamlFile('/workspace/some/code', '');
String buildDir = convertPath('out/release-y22_256');
newFile('/workspace/.fx-build-dir', '$buildDir\n');
@ -349,8 +327,7 @@ class GnWorkspaceTest with ResourceProviderMixin {
}
]
}''');
var workspace = GnWorkspace.find(
resourceProvider, convertPath('/workspace/some/code'))!;
var workspace = GnWorkspace.find(buildGnFile)!;
expect(workspace.root, convertPath('/workspace'));
expect(
workspace.packages.packages,
@ -367,6 +344,7 @@ class GnWorkspaceTest with ResourceProviderMixin {
void test_packages_multipleFiles() {
newFolder('/workspace/.jiri_root');
newFolder('/workspace/some/code');
var buildGnFile = newBuildGnFile('/workspace/some/code', '');
newPubspecYamlFile('/workspace/some/code', '');
String buildDir = convertPath('out/debug-x87_128');
newFile('/workspace/.fx-build-dir', '$buildDir\n');
@ -401,8 +379,7 @@ class GnWorkspaceTest with ResourceProviderMixin {
}
]
}''');
var workspace = GnWorkspace.find(
resourceProvider, convertPath('/workspace/some/code'))!;
var workspace = GnWorkspace.find(buildGnFile)!;
expect(workspace.root, convertPath('/workspace'));
expect(
workspace.packages.packages,