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

Side by Side Diff: mojo/public/dart/third_party/test/lib/src/runner/browser/polymer.dart

Issue 1346773002: Stop running pub get at gclient sync time and fix build bugs (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 3 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
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library test.runner.browser.polymer;
6
7 import 'dart:io';
8
9 import 'package:glob/glob.dart';
10 import 'package:path/path.dart' as p;
11 import 'package:yaml/yaml.dart';
12
13 /// Whether the package being tested uses the Polymer transforemrs at all.
14 ///
15 /// This will be `null` until [_initialize] is called.
16 bool _usesPolymer;
17
18 /// The set of entry points passed in to the polymer transformer's config.
19 ///
20 /// This will be `null` if no entrypoints are declared, indicating that all
21 /// entrypoints are supported.
22 Set<String> _entrypoints;
23
24 /// The $includes for the polymer transformer.
25 Set<Glob> _includes;
26
27 /// The $excludes for the polymer transformer.
28 Set<Glob> _excludes;
29
30 /// Returns whether [path] is an entrypoint transformed by the Polymer
31 /// transformer.
32 ///
33 /// The Polymer transformer creates a bootstrapping wrapper script around the
34 /// entrypoints it's run on, so we need to know that so we can fetch the correct
35 /// source map file.
36 bool isPolymerEntrypoint(String path) {
37 if (_usesPolymer == null) _initialize();
38 if (!_usesPolymer) return false;
39
40 if (_excludes != null) {
41 // If there are any excludes, it must not match any of them.
42 for (var exclude in _excludes) {
43 if (exclude.matches(path)) return false;
44 }
45 }
46
47 // If there are any includes, it must match one of them.
48 if (_includes != null && !_includes.any((include) => include.matches(path))) {
49 return false;
50 }
51
52 if (_entrypoints == null) return true;
53 return _entrypoints.contains(path);
54 }
55
56 /// Initializes [_usesPolymer], [_entrypoints], [_includes], and [_excludes]
57 /// based on the contents of the pubspec.
58 ///
59 /// This doesn't need to do any validation of the pubspec, since pub itself does
60 /// that before running the test executable.
61 void _initialize() {
62 _usesPolymer = false;
63
64 var pubspec = loadYaml(new File("pubspec.yaml").readAsStringSync());
65
66 var transformers = pubspec['transformers'];
67 if (transformers == null) {
68 return;
69 }
70
71 for (var phase in transformers) {
72 var phases = phase is List ? phase : [phase];
73 for (var transformer in phases) {
74 if (transformer is String) {
75 if (transformer != "polymer") continue;
76 _usesPolymer = true;
77 return;
78 }
79
80 if (transformer.keys.single != "polymer") continue;
81 _usesPolymer = true;
82
83 var configuration = transformer.values.single;
84
85 var entrypoints = configuration["entry_points"];
86 if (entrypoints != null) _entrypoints = entrypoints.toSet();
87
88 _includes = _parseGlobField(configuration, r"$includes");
89 _excludes = _parseGlobField(configuration, r"$excludes");
90 return;
91 }
92 }
93 }
94
95 /// Parses a glob field (either `$include` or `$exclude`).
96 Set<Glob> _parseGlobField(YamlMap configuration, String name) {
97 if (!configuration.containsKey(name)) return null;
98 var field = configuration[name];
99
100 if (field is String) {
101 return new Set.from([new Glob(field, context: p.url, recursive: true)]);
102 }
103
104 return new Set.from(field.map((node) {
105 return new Glob(node, context: p.url, recursive: true);
106 }));
107 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698