| // Copyright 2015 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| library mojom.command.check; |
| |
| import 'dart:async'; |
| import 'dart:io'; |
| |
| import 'package:args/args.dart'; |
| import 'package:args/command_runner.dart'; |
| import 'package:mojom/src/commands/mojom_command.dart'; |
| import 'package:mojom/src/generate.dart'; |
| import 'package:mojom/src/utils.dart'; |
| import 'package:path/path.dart' as path; |
| |
| class CheckCommand extends MojomCommand { |
| String get name => 'check'; |
| String get description => "Check bindings generated by the 'gen' command " |
| "against a canonical source"; |
| String get invocation => |
| 'mojom.dart check -c path/to/canon -r mojoms/ -o dart-packages/'; |
| |
| Directory _canon; |
| Directory _dartRoot; |
| |
| CheckCommand() { |
| argParser.addOption('canon', |
| abbr: 'c', |
| help: 'Directory containing canonical .mojom.dart bindings.'); |
| argParser.addOption('output', |
| abbr: 'o', |
| defaultsTo: Directory.current.path, |
| help: 'Directory containing Dart packages.'); |
| } |
| |
| run() async { |
| MojomCommand.setupLogging(); |
| await _validateArguments(); |
| var treeChecker = |
| new TreeChecker(mojoSdk, mojomRoot, _dartRoot, _canon, skips); |
| await treeChecker.check(); |
| return treeChecker.errors; |
| } |
| |
| _validateArguments() async { |
| await validateArguments(); |
| |
| if (argResults['canon'] == null) { |
| throw new CommandLineError("The 'tree-check' command requires a --canon" |
| " argument."); |
| } |
| _canon = new Directory(makeAbsolute(argResults['canon'])); |
| if (!await _canon.exists()) { |
| throw new CommandLineError("The specified canonical output directory: " |
| "$_canon does not exist."); |
| } |
| _dartRoot = new Directory(makeAbsolute(argResults['output'])); |
| if (!await _dartRoot.exists()) { |
| throw new CommandLineError( |
| 'Specified --output directory $_dartRoot does not exist'); |
| } |
| } |
| } |