Skip to content

Commit 06eea7c

Browse files
pqCommit Queue
authored andcommitted
multi-option context support for nested excludes
See: #54858 Should address failures seen in https://dart-review.googlesource.com/c/sdk/+/350342 Change-Id: Iedff9a0a4d44f96424a173f6a6bc655900ec8446 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/351521 Commit-Queue: Phil Quitslund <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent fde2222 commit 06eea7c

File tree

2 files changed

+284
-12
lines changed

2 files changed

+284
-12
lines changed

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ class ContextLocatorImpl implements ContextLocator {
272272
root.optionsFileMap[rootFolder] = optionsFile;
273273
}
274274

275-
root.excludedGlobs = _getExcludedGlobs(root);
275+
root.excludedGlobs = _getExcludedGlobs(optionsFile, workspace);
276276
roots.add(root);
277277
return root;
278278
}
@@ -315,6 +315,10 @@ class ContextLocatorImpl implements ContextLocator {
315315
if (localOptionsFile != null) {
316316
(containingRoot as ContextRootImpl).optionsFileMap[folder] =
317317
localOptionsFile;
318+
// Add excluded globs.
319+
var excludes =
320+
_getExcludedGlobs(localOptionsFile, containingRoot.workspace);
321+
containingRoot.excludedGlobs.addAll(excludes);
318322
}
319323

320324
//
@@ -343,7 +347,7 @@ class ContextLocatorImpl implements ContextLocator {
343347
containingRoot.excluded.add(folder);
344348
roots.add(root);
345349
containingRoot = root;
346-
excludedGlobs = _getExcludedGlobs(root);
350+
excludedGlobs = _getExcludedGlobs(root.optionsFile, workspace);
347351
root.excludedGlobs = excludedGlobs;
348352
}
349353
_createContextRootsIn(roots, visited, folder, excludedFolders,
@@ -481,19 +485,16 @@ class ContextLocatorImpl implements ContextLocator {
481485
return null;
482486
}
483487

484-
/// Return a list containing the glob patterns used to exclude files from the
485-
/// given context [root]. The patterns are extracted from the analysis options
486-
/// file associated with the context root. The list will be empty if there are
487-
/// no exclusion patterns in the options file, or if there is no options file
488-
/// associated with the context root.
489-
List<LocatedGlob> _getExcludedGlobs(ContextRootImpl root) {
488+
/// Return a list containing the glob patterns used to exclude files from
489+
/// analysis by the given [optionsFile]. The list will be empty if there is no
490+
/// options file or if there are no exclusion patterns in the options file.
491+
List<LocatedGlob> _getExcludedGlobs(File? optionsFile, Workspace workspace) {
490492
List<LocatedGlob> patterns = [];
491-
File? optionsFile = root.optionsFile;
492493
if (optionsFile != null) {
493494
try {
494-
var doc = AnalysisOptionsProvider(
495-
root.workspace.createSourceFactory(null, null))
496-
.getOptionsFromFile(optionsFile);
495+
var doc =
496+
AnalysisOptionsProvider(workspace.createSourceFactory(null, null))
497+
.getOptionsFromFile(optionsFile);
497498

498499
var analyzerOptions = doc.valueAt(AnalyzerOptions.analyzer);
499500
if (analyzerOptions is YamlMap) {

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

Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,110 @@ workspaces
483483
''');
484484
}
485485

486+
test_packageConfigWorkspace_multipleAnalysisOptions_nestedExclude() async {
487+
final workspaceRootPath = '/home';
488+
final testPackageRootPath = '$workspaceRootPath/test';
489+
final testPackageLibPath = '$testPackageRootPath/lib';
490+
491+
newPubspecYamlFile(testPackageRootPath, r'''
492+
name: test
493+
''');
494+
495+
newSinglePackageConfigJsonFile(
496+
packagePath: testPackageRootPath,
497+
name: 'test',
498+
);
499+
500+
newAnalysisOptionsYamlFile(testPackageRootPath, '');
501+
newFile('$testPackageLibPath/a.dart', '');
502+
503+
final nestedPath = '$testPackageLibPath/nested';
504+
newAnalysisOptionsYamlFile(nestedPath, r'''
505+
analyzer:
506+
exclude:
507+
- excluded/**
508+
''');
509+
newFile('$nestedPath/b.dart', '');
510+
newFile('$nestedPath/excluded/b.dart', '');
511+
512+
_assertWorkspaceCollectionText(workspaceRootPath, r'''
513+
contexts
514+
/home/test
515+
packagesFile: /home/test/.dart_tool/package_config.json
516+
workspace: workspace_0
517+
analyzedFiles
518+
/home/test/lib/a.dart
519+
uri: package:test/a.dart
520+
analysisOptions_0
521+
workspacePackage_0_0
522+
/home/test/lib/nested/b.dart
523+
uri: package:test/nested/b.dart
524+
analysisOptions_1
525+
workspacePackage_0_0
526+
analysisOptions
527+
analysisOptions_0: /home/test/analysis_options.yaml
528+
analysisOptions_1: /home/test/lib/nested/analysis_options.yaml
529+
workspaces
530+
workspace_0: PackageConfigWorkspace
531+
root: /home/test
532+
pubPackages
533+
workspacePackage_0_0: PubPackage
534+
root: /home/test
535+
''');
536+
}
537+
538+
test_packageConfigWorkspace_multipleAnalysisOptions_outerExclude() async {
539+
final workspaceRootPath = '/home';
540+
final testPackageRootPath = '$workspaceRootPath/test';
541+
final testPackageLibPath = '$testPackageRootPath/lib';
542+
543+
newPubspecYamlFile(testPackageRootPath, r'''
544+
name: test
545+
''');
546+
547+
newSinglePackageConfigJsonFile(
548+
packagePath: testPackageRootPath,
549+
name: 'test',
550+
);
551+
552+
newAnalysisOptionsYamlFile(testPackageRootPath, r'''
553+
analyzer:
554+
exclude:
555+
- excluded/**
556+
''');
557+
newFile('$testPackageLibPath/a.dart', '');
558+
newFile('$testPackageRootPath/excluded/b.dart', '');
559+
560+
final nestedPath = '$testPackageLibPath/nested';
561+
newAnalysisOptionsYamlFile(nestedPath, '');
562+
newFile('$nestedPath/b.dart', '');
563+
564+
_assertWorkspaceCollectionText(workspaceRootPath, r'''
565+
contexts
566+
/home/test
567+
packagesFile: /home/test/.dart_tool/package_config.json
568+
workspace: workspace_0
569+
analyzedFiles
570+
/home/test/lib/a.dart
571+
uri: package:test/a.dart
572+
analysisOptions_0
573+
workspacePackage_0_0
574+
/home/test/lib/nested/b.dart
575+
uri: package:test/nested/b.dart
576+
analysisOptions_1
577+
workspacePackage_0_0
578+
analysisOptions
579+
analysisOptions_0: /home/test/analysis_options.yaml
580+
analysisOptions_1: /home/test/lib/nested/analysis_options.yaml
581+
workspaces
582+
workspace_0: PackageConfigWorkspace
583+
root: /home/test
584+
pubPackages
585+
workspacePackage_0_0: PubPackage
586+
root: /home/test
587+
''');
588+
}
589+
486590
test_packageConfigWorkspace_multipleAnalysisOptions_overridingOptions() async {
487591
final workspaceRootPath = '/home';
488592
final testPackageRootPath = '$workspaceRootPath/test';
@@ -717,6 +821,49 @@ workspaces
717821
''');
718822
}
719823

824+
test_packageConfigWorkspace_singleAnalysisOptions_exclude() async {
825+
final workspaceRootPath = '/home';
826+
final testPackageRootPath = '$workspaceRootPath/test';
827+
final testPackageLibPath = '$testPackageRootPath/lib';
828+
829+
newPubspecYamlFile(testPackageRootPath, r'''
830+
name: test
831+
''');
832+
newSinglePackageConfigJsonFile(
833+
packagePath: testPackageRootPath,
834+
name: 'test',
835+
);
836+
newAnalysisOptionsYamlFile(testPackageRootPath, r'''
837+
analyzer:
838+
exclude:
839+
- lib/nested/**
840+
''');
841+
842+
newFile('$testPackageLibPath/a.dart', '');
843+
final nestedPath = '$testPackageLibPath/nested';
844+
newFile('$nestedPath/b.dart', '');
845+
846+
_assertWorkspaceCollectionText(workspaceRootPath, r'''
847+
contexts
848+
/home/test
849+
packagesFile: /home/test/.dart_tool/package_config.json
850+
workspace: workspace_0
851+
analyzedFiles
852+
/home/test/lib/a.dart
853+
uri: package:test/a.dart
854+
analysisOptions_0
855+
workspacePackage_0_0
856+
analysisOptions
857+
analysisOptions_0: /home/test/analysis_options.yaml
858+
workspaces
859+
workspace_0: PackageConfigWorkspace
860+
root: /home/test
861+
pubPackages
862+
workspacePackage_0_0: PubPackage
863+
root: /home/test
864+
''');
865+
}
866+
720867
test_packageConfigWorkspace_singleAnalysisOptions_multipleContexts() async {
721868
final workspaceRootPath = '/home';
722869
final testPackageRootPath = '$workspaceRootPath/test';
@@ -897,6 +1044,130 @@ workspaces
8971044
''');
8981045
}
8991046

1047+
@override
1048+
test_packageConfigWorkspace_multipleAnalysisOptions_nestedExclude() async {
1049+
final workspaceRootPath = '/home';
1050+
final testPackageRootPath = '$workspaceRootPath/test';
1051+
final testPackageLibPath = '$testPackageRootPath/lib';
1052+
1053+
newPubspecYamlFile(testPackageRootPath, r'''
1054+
name: test
1055+
''');
1056+
1057+
newSinglePackageConfigJsonFile(
1058+
packagePath: testPackageRootPath,
1059+
name: 'test',
1060+
);
1061+
1062+
newAnalysisOptionsYamlFile(testPackageRootPath, '');
1063+
newFile('$testPackageLibPath/a.dart', '');
1064+
1065+
final nestedPath = '$testPackageLibPath/nested';
1066+
newAnalysisOptionsYamlFile(nestedPath, r'''
1067+
analyzer:
1068+
exclude:
1069+
- excluded/**
1070+
''');
1071+
newFile('$nestedPath/b.dart', '');
1072+
newFile('$nestedPath/excluded/b.dart', '');
1073+
1074+
_assertWorkspaceCollectionText(workspaceRootPath, r'''
1075+
contexts
1076+
/home/test
1077+
packagesFile: /home/test/.dart_tool/package_config.json
1078+
workspace: workspace_0
1079+
analyzedFiles
1080+
/home/test/lib/a.dart
1081+
uri: package:test/a.dart
1082+
analysisOptions_0
1083+
workspacePackage_0_0
1084+
/home/test/lib/nested
1085+
packagesFile: /home/test/.dart_tool/package_config.json
1086+
workspace: workspace_1
1087+
analyzedFiles
1088+
/home/test/lib/nested/b.dart
1089+
uri: package:test/nested/b.dart
1090+
analysisOptions_1
1091+
workspacePackage_1_0
1092+
analysisOptions
1093+
analysisOptions_0: /home/test/analysis_options.yaml
1094+
analysisOptions_1: /home/test/lib/nested/analysis_options.yaml
1095+
workspaces
1096+
workspace_0: PackageConfigWorkspace
1097+
root: /home/test
1098+
pubPackages
1099+
workspacePackage_0_0: PubPackage
1100+
root: /home/test
1101+
workspace_1: PackageConfigWorkspace
1102+
root: /home/test
1103+
pubPackages
1104+
workspacePackage_1_0: PubPackage
1105+
root: /home/test
1106+
''');
1107+
}
1108+
1109+
@override
1110+
test_packageConfigWorkspace_multipleAnalysisOptions_outerExclude() async {
1111+
final workspaceRootPath = '/home';
1112+
final testPackageRootPath = '$workspaceRootPath/test';
1113+
final testPackageLibPath = '$testPackageRootPath/lib';
1114+
1115+
newPubspecYamlFile(testPackageRootPath, r'''
1116+
name: test
1117+
''');
1118+
1119+
newSinglePackageConfigJsonFile(
1120+
packagePath: testPackageRootPath,
1121+
name: 'test',
1122+
);
1123+
1124+
newAnalysisOptionsYamlFile(testPackageRootPath, r'''
1125+
analyzer:
1126+
exclude:
1127+
- excluded/**
1128+
''');
1129+
newFile('$testPackageLibPath/a.dart', '');
1130+
newFile('$testPackageRootPath/excluded/b.dart', '');
1131+
1132+
final nestedPath = '$testPackageLibPath/nested';
1133+
newAnalysisOptionsYamlFile(nestedPath, '');
1134+
newFile('$nestedPath/b.dart', '');
1135+
1136+
_assertWorkspaceCollectionText(workspaceRootPath, r'''
1137+
contexts
1138+
/home/test
1139+
packagesFile: /home/test/.dart_tool/package_config.json
1140+
workspace: workspace_0
1141+
analyzedFiles
1142+
/home/test/lib/a.dart
1143+
uri: package:test/a.dart
1144+
analysisOptions_0
1145+
workspacePackage_0_0
1146+
/home/test/lib/nested
1147+
packagesFile: /home/test/.dart_tool/package_config.json
1148+
workspace: workspace_1
1149+
analyzedFiles
1150+
/home/test/lib/nested/b.dart
1151+
uri: package:test/nested/b.dart
1152+
analysisOptions_1
1153+
workspacePackage_1_0
1154+
analysisOptions
1155+
analysisOptions_0: /home/test/analysis_options.yaml
1156+
analysisOptions_1: /home/test/lib/nested/analysis_options.yaml
1157+
workspaces
1158+
workspace_0: PackageConfigWorkspace
1159+
root: /home/test
1160+
pubPackages
1161+
workspacePackage_0_0: PubPackage
1162+
root: /home/test
1163+
workspace_1: PackageConfigWorkspace
1164+
root: /home/test
1165+
pubPackages
1166+
workspacePackage_1_0: PubPackage
1167+
root: /home/test
1168+
''');
1169+
}
1170+
9001171
@override
9011172
test_packageConfigWorkspace_multipleAnalysisOptions_overridingOptions() async {
9021173
final workspaceRootPath = '/home';

0 commit comments

Comments
 (0)