Skip to content

Commit f726874

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Support for --cache in 'dart analyze'.
Bug: #45267 Change-Id: I503227ac59a3562e79d3654c405debaf5d0c764c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212420 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 5ea90ee commit f726874

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

pkg/dartdev/lib/src/analysis_server.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ class AnalysisServer {
2727
this.packagesFile,
2828
this.sdkPath,
2929
this.analysisRoots, {
30+
this.cacheDirectoryPath,
3031
@required this.commandName,
3132
@required this.argResults,
3233
});
3334

35+
final String cacheDirectoryPath;
3436
final File packagesFile;
3537
final Directory sdkPath;
3638
final List<FileSystemEntity> analysisRoots;
@@ -87,6 +89,7 @@ class AnalysisServer {
8789
'--disable-server-feature-search',
8890
'--sdk',
8991
sdkPath.path,
92+
if (cacheDirectoryPath != null) '--cache=$cacheDirectoryPath',
9093
if (packagesFile != null) '--packages=${packagesFile.path}',
9194
];
9295

pkg/dartdev/lib/src/commands/analyze.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ class AnalyzeCommand extends DartdevCommand {
4444
help: 'Treat warning level issues as fatal.', defaultsTo: true)
4545

4646
// Options hidden by default.
47+
..addOption(
48+
'cache',
49+
valueHelp: 'path',
50+
help: 'Override the location of the analysis cache.',
51+
hide: !verbose,
52+
)
4753
..addOption(
4854
'format',
4955
valueHelp: 'value',
@@ -107,6 +113,7 @@ class AnalyzeCommand extends DartdevCommand {
107113
_packagesFile(),
108114
io.Directory(sdk.sdkPath),
109115
targets,
116+
cacheDirectoryPath: argResults['cache'],
110117
commandName: 'analyze',
111118
argResults: argResults,
112119
);

pkg/dartdev/test/commands/analyze_test.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,22 @@ void f() {
424424
});
425425
});
426426

427+
test('--cache', () {
428+
var cache = project(name: 'cache');
429+
430+
p = project(mainSrc: 'var v = 0;');
431+
var result = p.runSync([
432+
'analyze',
433+
'--cache=${cache.dirPath}',
434+
p.mainPath,
435+
]);
436+
437+
expect(result.exitCode, 0);
438+
expect(result.stderr, isEmpty);
439+
expect(result.stdout, contains('No issues found!'));
440+
expect(cache.findDirectory('.analysis-driver'), isNotNull);
441+
});
442+
427443
group('display mode', () {
428444
final sampleInfoJson = {
429445
'severity': 'INFO',

pkg/dartdev/test/utils.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ dev_dependencies:
141141
String get absolutePathToDartdevFile =>
142142
path.join(sdkRootPath, 'pkg', 'dartdev', 'bin', 'dartdev.dart');
143143

144+
Directory findDirectory(String name) {
145+
var directory = Directory(path.join(dir.path, name));
146+
return directory.existsSync() ? directory : null;
147+
}
148+
144149
File findFile(String name) {
145150
var file = File(path.join(dir.path, name));
146151
return file.existsSync() ? file : null;

0 commit comments

Comments
 (0)