Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 44 additions & 6 deletions lib/src/dartdoc_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,22 @@ class ToolDefinition {
List<String> command,
List<String> setupCommand,
String description,
ResourceProvider resourceProvider) {
ResourceProvider resourceProvider,
{List<String> compileArgs}) {
assert(command != null);
assert(command.isNotEmpty);
assert(description != null);
if (isDartExecutable(command[0])) {
return DartToolDefinition(
command, setupCommand, description, resourceProvider);
command, setupCommand, description, resourceProvider,
compileArgs: compileArgs ?? const []);
} else {
if (compileArgs != null && compileArgs.isNotEmpty) {
throw DartdocOptionError(
'Compile arguments may only be specified for Dart tools, but '
'compile-args of $compileArgs were specified for '
'$command.');
}
return ToolDefinition(command, setupCommand, description);
}
}
Expand Down Expand Up @@ -274,6 +282,9 @@ class SnapshotCache {
class DartToolDefinition extends ToolDefinition {
final ResourceProvider _resourceProvider;

/// A list of arguments to add to the snapshot compilation arguments.
final List<String> compileArgs;

/// Takes a list of args to modify, and returns the name of the executable
/// to run. If no snapshot file existed, then create one and modify the args
/// so that if they are executed with dart, will result in the snapshot being
Expand All @@ -295,7 +306,8 @@ class DartToolDefinition extends ToolDefinition {
'--ignore-unrecognized-flags',
'--verbosity=error',
'--snapshot=${_resourceProvider.pathContext.absolute(snapshotFile.path)}',
'--snapshot_kind=app-jit'
'--snapshot_kind=app-jit',
...compileArgs,
]);
} else {
await snapshot.snapshotValid();
Expand All @@ -307,8 +319,10 @@ class DartToolDefinition extends ToolDefinition {
}

DartToolDefinition(List<String> command, List<String> setupCommand,
String description, this._resourceProvider)
: super(command, setupCommand, description);
String description, this._resourceProvider,
{this.compileArgs = const []})
: assert(compileArgs != null),
super(command, setupCommand, description);
}

/// A configuration class that can interpret [ToolDefinition]s from a YAML map.
Expand All @@ -335,6 +349,7 @@ class ToolConfiguration {
for (var entry in yamlMap.entries) {
var name = entry.key.toString();
var toolMap = entry.value;
List<String> compileArgs;
String description;
List<String> command;
List<String> setupCommand;
Expand Down Expand Up @@ -376,6 +391,28 @@ class ToolConfiguration {

command = findCommand();
setupCommand = findCommand('setup_');

List<String> findArgs() {
const tagName = 'compile-args';
List<String> args;
if (toolMap.containsKey(tagName)) {
var compileArgs = toolMap[tagName];
if (compileArgs is String) {
args = [toolMap[tagName].toString()];
} else if (compileArgs is YamlList) {
args =
compileArgs.map<String>((node) => node.toString()).toList();
} else {
throw DartdocOptionError(
'Tool compile arguments must be a list of strings. The tool '
'$name has a $tagName entry that is a '
'${compileArgs.runtimeType}');
}
}
return args;
}

compileArgs = findArgs();
} else {
throw DartdocOptionError(
'Tools must be defined as a map of tool names to definitions. Tool '
Expand Down Expand Up @@ -421,7 +458,8 @@ class ToolConfiguration {
setupCommand;
}
newToolDefinitions[name] = ToolDefinition.fromCommand(
[executable] + command, setupCommand, description, resourceProvider);
[executable] + command, setupCommand, description, resourceProvider,
compileArgs: compileArgs ?? const []);
}
return ToolConfiguration._(newToolDefinitions, resourceProvider);
}
Expand Down
13 changes: 8 additions & 5 deletions lib/src/model/documentation_comment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,14 @@ mixin DocumentationComment
/// ```yaml
/// dartdoc:
/// tools:
/// # Prefixes the given input with "## "
/// # Path is relative to project root.
/// prefix: "bin/prefix.dart"
/// # Prints the date
/// date: "/bin/date"
/// prefix:
/// # Path is relative to project root.
/// command: ["bin/prefix.dart"]
/// description: "Prefixes the given input with '##'."
/// compile-args: ["--no-sound-null-safety"]
/// date:
/// command: ["/bin/date"]
/// description: "Prints the date"
/// ```
///
/// In code:
Expand Down
7 changes: 7 additions & 0 deletions test/tool_runner_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ void main() {
drill:
command: ["bin/drill.dart"]
description: "Puts holes in things."
compile-args: ["--no-sound-null-safety"]
snapshot_drill:
command: ["${snapshotFile.replaceAll(r'\', r'\\')}"]
description: "Puts holes in things, but faster."
Expand Down Expand Up @@ -104,6 +105,10 @@ echo:
});
// This test must come first, to verify that the first run creates
// a snapshot.
test('Tool definition includes compile arguments.', () async {
DartToolDefinition definition = runner.toolConfiguration.tools['drill'];
expect(definition.compileArgs, equals(['--no-sound-null-safety']));
});
test('can invoke a Dart tool, and second run is a snapshot.', () async {
var result = await runner.run(
['drill', r'--file=$INPUT'],
Expand All @@ -114,6 +119,8 @@ echo:
expect(result, contains('--file=<INPUT_FILE>'));
expect(result, contains('## `TEST INPUT`'));
expect(result, contains('Script location is in dartdoc tree.'));
// This shouldn't be in the args passed to the tool.
expect(result, isNot(contains('--no-sound-null-safety')));
expect(setupFile.existsSync(), isFalse);
result = await runner.run(
['drill', r'--file=$INPUT'],
Expand Down