Skip to content

Commit 14ff0ca

Browse files
keertipCommit Queue
authored andcommitted
[stable] Fix resolving package includes in options file.
Fixes #56047 Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/376500 Cherry-pick-request: #56457 Change-Id: I3cb5ee316e4fe5564c0e5234d08566fec84de759 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380205 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Kevin Chisholm <[email protected]> Reviewed-by: Phil Quitslund <[email protected]>
1 parent 061b0b2 commit 14ff0ca

File tree

4 files changed

+105
-22
lines changed

4 files changed

+105
-22
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
### Tools
44

5+
#### Analyzer
6+
7+
- Fix for resolving `include:` in `analysis_options.yaml` file in a nested
8+
folder in the workspace. [#56047][]
9+
10+
[#56047]: https://github.com/dart-lang/sdk/issues/56047
11+
512
#### Wasm compiler (dart2wasm)
613

714
- Fix source maps generated by `dart compile wasm` when optimizations are

pkg/analysis_server/test/lsp/diagnostic_test.dart

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -505,19 +505,12 @@ version: latest
505505

506506
/// Ensure lints included from another package work when there are multiple
507507
/// workspace folders.
508-
///
509-
/// https://github.com/dart-lang/sdk/issues/56047
510-
@skippedTest
511508
Future<void> test_lints_includedFromPackage() async {
512-
// FailingTest() doesn't handle timeouts so this is marked as skipped.
513-
// Needs to be manually updated when
514-
// https://github.com/dart-lang/sdk/issues/56047 is fixed.
515-
516509
var rootWorkspacePath = '$packagesRootPath/root';
517510

518511
// Set up a project with an analysis_options that enables a lint.
519512
var lintsPackagePath = '$rootWorkspacePath/my_lints';
520-
newFile('$lintsPackagePath/lib/pubspec.yaml', '''
513+
newFile('$lintsPackagePath/pubspec.yaml', '''
521514
name: my_lints
522515
''');
523516
newFile('$lintsPackagePath/lib/analysis_options.yaml', '''
@@ -529,11 +522,9 @@ linter:
529522

530523
// Set up a project that imports the analysis_options and violates the lint.
531524
var projectPackagePath = '$rootWorkspacePath/my_project';
532-
writePackageConfig(
533-
projectPackagePath,
534-
config: (PackageConfigFileBuilder()
535-
..add(name: 'my_lints', rootPath: lintsPackagePath)),
536-
);
525+
writePackageConfig(projectPackagePath,
526+
config: (PackageConfigFileBuilder()
527+
..add(name: 'my_lints', rootPath: lintsPackagePath)));
537528
newFile('$projectPackagePath/analysis_options.yaml', '''
538529
include: package:my_lints/analysis_options.yaml
539530

pkg/analyzer/lib/src/dart/analysis/context_locator.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -312,15 +312,6 @@ class ContextLocatorImpl implements ContextLocator {
312312
}
313313
var buildGnFile = folder.getExistingFile(file_paths.buildGn);
314314

315-
if (localOptionsFile != null) {
316-
(containingRoot as ContextRootImpl).optionsFileMap[folder] =
317-
localOptionsFile;
318-
// Add excluded globs.
319-
var excludes =
320-
_getExcludedGlobs(localOptionsFile, containingRoot.workspace);
321-
containingRoot.excludedGlobs.addAll(excludes);
322-
}
323-
324315
//
325316
// Create a context root for the given [folder] if a packages or build file
326317
// is locally specified.
@@ -350,6 +341,15 @@ class ContextLocatorImpl implements ContextLocator {
350341
excludedGlobs = _getExcludedGlobs(root.optionsFile, workspace);
351342
root.excludedGlobs = excludedGlobs;
352343
}
344+
345+
if (localOptionsFile != null) {
346+
(containingRoot as ContextRootImpl).optionsFileMap[folder] =
347+
localOptionsFile;
348+
// Add excluded globs.
349+
var excludes =
350+
_getExcludedGlobs(localOptionsFile, containingRoot.workspace);
351+
containingRoot.excludedGlobs.addAll(excludes);
352+
}
353353
_createContextRootsIn(roots, visited, folder, excludedFolders,
354354
containingRoot, excludedGlobs, optionsFile, packagesFile);
355355
}

pkg/analyzer/test/src/dart/analysis/analysis_context_collection_test.dart

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,91 @@ workspaces
629629
root: /home/test/nested
630630
''');
631631
}
632+
633+
test_packageConfigWorkspace_singleAnalysisOptions_with_include() {
634+
var workspaceRootPath = '/home';
635+
636+
var fooPackagePath = '$workspaceRootPath/foo';
637+
newFile('$fooPackagePath/pubspec.yaml', '''
638+
name: foo
639+
''');
640+
newFile('$fooPackagePath/lib/included.yaml', r'''
641+
linter:
642+
rules:
643+
- empty_statements
644+
''');
645+
var packageConfigFileBuilder = PackageConfigFileBuilder()
646+
..add(name: 'foo', rootPath: fooPackagePath);
647+
newPackageConfigJsonFile(
648+
fooPackagePath,
649+
packageConfigFileBuilder.toContent(toUriStr: toUriStr),
650+
);
651+
652+
var testPackagePath = '$workspaceRootPath/test';
653+
packageConfigFileBuilder.add(name: 'test', rootPath: testPackagePath);
654+
655+
newPackageConfigJsonFile(
656+
testPackagePath,
657+
packageConfigFileBuilder.toContent(toUriStr: toUriStr),
658+
);
659+
newFile('$testPackagePath/pubspec.yaml', '''
660+
name: test
661+
''');
662+
663+
var optionsFile = newAnalysisOptionsYamlFile(testPackagePath, r'''
664+
include: package:foo/included.yaml
665+
666+
linter:
667+
rules:
668+
- unnecessary_parenthesis
669+
''');
670+
newFile('$testPackagePath/lib/a.dart', '');
671+
672+
var collection = _newCollection(includedPaths: [workspaceRootPath]);
673+
var analysisContext = collection.contextFor(testPackagePath);
674+
var analysisOptions =
675+
analysisContext.getAnalysisOptionsForFile(optionsFile);
676+
677+
expect(
678+
analysisOptions.lintRules.map((e) => e.name),
679+
unorderedEquals(['empty_statements', 'unnecessary_parenthesis']),
680+
);
681+
682+
_assertWorkspaceCollectionText(workspaceRootPath, r'''
683+
contexts
684+
/home/foo
685+
packagesFile: /home/foo/.dart_tool/package_config.json
686+
workspace: workspace_0
687+
analyzedFiles
688+
/home/test
689+
packagesFile: /home/test/.dart_tool/package_config.json
690+
workspace: workspace_1
691+
analyzedFiles
692+
/home/test/lib/a.dart
693+
uri: package:test/a.dart
694+
analysisOptions_0
695+
workspacePackage_1_0
696+
analysisOptions
697+
analysisOptions_0: /home/test/analysis_options.yaml
698+
workspaces
699+
workspace_0: PackageConfigWorkspace
700+
root: /home/foo
701+
workspace_1: PackageConfigWorkspace
702+
root: /home/test
703+
pubPackages
704+
workspacePackage_1_0: PubPackage
705+
root: /home/test
706+
''');
707+
}
708+
709+
AnalysisContextCollectionImpl _newCollection(
710+
{required List<String> includedPaths}) {
711+
return AnalysisContextCollectionImpl(
712+
resourceProvider: resourceProvider,
713+
includedPaths: includedPaths,
714+
sdkPath: sdkRoot.path,
715+
);
716+
}
632717
}
633718

634719
mixin AnalysisContextCollectionTestMixin on ResourceProviderMixin {

0 commit comments

Comments
 (0)