Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1233)

Side by Side Diff: mojo/dart/mojom/bin/generate.dart

Issue 1136503002: Create wrapper script around mojom's generate.dart in the Sky package. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Rebase Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/dart/mojom/README.md ('k') | mojo/dart/mojom/lib/README.md » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /*
6 * This script should be invoked via 'pub run' for an application that consumes
7 * pub packages containing generated Mojo bindings (.mojom.dart files).
8 *
9 * It should be invoked as follows after 'pub get':
10 * $ pub run mojom:generate
11 */
12
13 import 'dart:async';
14 import 'dart:io';
15
16 import 'package:args/args.dart' as args;
17 import 'package:path/path.dart' as path;
18
19 bool verbose;
20 bool dryRun;
21
22 bool isMojomDart(String path) => path.endsWith('.mojom.dart');
23
24 // Copies .mojom.dart files from a particular package's mojom directory to
25 // the mojom package directory.
26 //
27 // mojomDirectory: A pub packages mojom directory, i.e. $PACKAGE/mojom.
28 // mojomPackage: The mojom package directory.
29 copyMojomDirContents(Directory mojomDirectory, Directory mojomPackage) async {
30 assert(await mojomDirectory.exists());
31 await for (var mojoms in mojomDirectory.list(recursive: true)) {
32 if (mojoms is! File) continue;
33 if (!isMojomDart(mojoms.path)) continue;
34 if (verbose) print("Found $mojoms");
35
36 final relative = path.relative(mojoms.path, from: mojomDirectory.path);
37 final dest = path.join(mojomPackage.path, relative);
38 final destDirectory = new Directory(path.dirname(dest));
39
40 if (verbose || dryRun) {
41 print('Copying $mojoms to $dest');
42 }
43
44 if (!dryRun) {
45 final File source = new File(mojoms.path);
46 if (verbose) print("Ensuring $destDirectory exists");
47 await destDirectory.create(recursive: true);
48 source.copy(dest);
49 }
50 }
51 }
52
53 // If a package has a mojom directory, uses copyMojomDirContents to install them
54 // in the mojom package.
55 //
56 // package: The directory of a pub package in an application's packages
57 // directory.
58 // mojoPackage: The mojom package directory in an application's packages
59 // directory
60 installPackageMojoms(Directory package, Directory mojomPackage) async {
61 if (package.path == mojomPackage.path) return;
62 if (verbose) print("package = $package");
63 final mojomDirectory = new Directory(path.join(package.path, 'mojom'));
64 if (verbose) print("looking for = $mojomDirectory");
65 if (await mojomDirectory.exists()) {
66 copyMojomDirContents(mojomDirectory, mojomPackage);
67 } else if (verbose) {
68 print("$mojomDirectory not found");
69 }
70 }
71
72 main(List<String> arguments) async {
73 final parser = new args.ArgParser()
74 ..addOption('package-root',
75 abbr: 'p',
76 defaultsTo: path.join(Directory.current.path, 'packages'),
77 help: 'An absolute path to an application\'s package root')
78 ..addOption('additional-mojom-dir',
79 abbr: 'a',
80 allowMultiple: true,
81 help: 'Absolute path to an additional directory containing mojom.dart'
82 'files to put in the mojom package. May be specified multiple times.')
83 ..addFlag('dry-run',
84 abbr: 'd',
85 defaultsTo: false,
86 help: 'Print the copy operations that would have been run, but'
87 'do not copy anything.')
88 ..addFlag('verbose', abbr: 'v', defaultsTo: false);
89 final result = parser.parse(arguments);
90 verbose = result['verbose'];
91 dryRun = result['dry-run'];
92
93 final packages = new Directory(result['package-root']);
94 if (!packages.isAbsolute) {
95 print("The --package-root parameter should be an absolute path.");
96 exit(1);
97 }
98 if (verbose) print("packages = $packages");
99 if (!(await packages.exists())) {
100 print("The packages directory $packages does not exist");
101 exit(1);
102 }
103
104 var additional_mojom_dirs = [];
105 for (var mojom_dir_path in result['additional-mojom-dir']) {
106 final mojom_dir = new Directory(mojom_dir_path);
107 if (!mojom_dir.isAbsolute) {
108 print("All --additional-mojom-dir parameters should be absolute paths.");
109 exit(1);
110 }
111 if (!(await mojom_dir.exists())) {
112 print("The additional mojom directory $mojom_dir does not exist");
113 exit(1);
114 }
115 additional_mojom_dirs.add(mojom_dir);
116 }
117 if (verbose) print("additional_mojom_dirs = $additional_mojom_dirs");
118
119 final mojomPackage = new Directory(path.join(packages.path, 'mojom'));
120 if (verbose) print("mojom package = $mojomPackage");
121 if (!(await mojomPackage.exists())) {
122 print("The mojom package directory $mojomPackage does not exist");
123 exit(1);
124 }
125
126 await for (var package in packages.list()) {
127 if (package is Directory) {
128 installPackageMojoms(package, mojomPackage);
129 }
130 }
131
132 for (var mojom_dir in additional_mojom_dirs) {
133 copyMojomDirContents(mojom_dir, mojomPackage);
134 }
135 }
OLDNEW
« no previous file with comments | « mojo/dart/mojom/README.md ('k') | mojo/dart/mojom/lib/README.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698