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

Unified Diff: tools/gardening/bin/create_shard_groups.dart

Issue 2756193002: Script finding the build bot group for a given shard. (Closed)
Patch Set: Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/gardening/bin/shard2group.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gardening/bin/create_shard_groups.dart
diff --git a/tools/gardening/bin/create_shard_groups.dart b/tools/gardening/bin/create_shard_groups.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b54a87765d9bbee658cd2f64bb81426214729daf
--- /dev/null
+++ b/tools/gardening/bin/create_shard_groups.dart
@@ -0,0 +1,99 @@
+// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Outputs source code for `part` used by `shard2group.dart`. Usage:
+// `dart bin/create_shard_groups.dart source.html >lib/src/shard_data.dart`.
+
+import 'dart:io';
+import 'dart:math' as math;
+
+const String groupsStartMark = r"<td class='DevStatus Alt first";
+const String groupsEndMark = r"<tr class='DevStatusSpacing'>";
+
+List<String> findGroups(List<String> source) {
+ List<String> result = <String>[];
+ bool started = false;
+
+ for (String line in source) {
+ if (line.contains(groupsStartMark)) started = true;
+ if (started) {
+ if (line.contains(groupsEndMark)) break;
+ String trimmed = line.trim();
+ if (!trimmed.startsWith('<')) {
+ result.add(trimmed);
+ }
+ }
+ }
+ return result;
+}
+
+const String shardsStartMark = groupsEndMark;
+const String shardsEndMark = r"<td class='DevStatusBox";
+const String shardsGroupStartMark = r"<td class='DevSlave Alt";
+const String shardMark = '/builders/';
+
+List<List<String>> findShards(List<String> source) {
+ List<List<String>> result = <List<String>>[];
+ List<String> shardResult;
+ bool started = false;
+
+ for (String line in source) {
+ if (line.contains(shardsStartMark)) started = true;
+ if (started) {
+ if (line.contains(shardsEndMark)) break;
+ String trimmed = line.trim();
+ int buildersIndex = trimmed.indexOf(shardMark);
+ if (buildersIndex >= 0) {
+ int quoteIndex = trimmed.indexOf("'", buildersIndex);
+ if (quoteIndex >= 0) {
+ // Found a shard name, add it.
+ shardResult.add(trimmed.substring(
+ buildersIndex + shardMark.length, quoteIndex));
+ } else {
+ // Unexpected source formatting, skip.
+ }
+ } else if (trimmed.contains(shardsGroupStartMark)) {
+ // This is a group separator, switch to next sublist.
+ if (shardResult != null) result.add(shardResult);
+ shardResult = <String>[];
+ }
+ }
+ }
+ return result;
+}
+
+main(List<String> args) {
+ if (args.length != 1) {
+ print('Usage: dart create_shard_groups.dart <darto-source-file>');
+ exit(1);
+ }
+
+ File dartoSourceFile = new File(args[0]);
+ List<String> dartoSource = dartoSourceFile.readAsLinesSync();
+
+ List<String> groups = findGroups(dartoSource);
+ List<String> shards = findShards(dartoSource);
+ int groupCount = math.min(groups.length, shards.length);
+
+ // Print the resulting Dart declaration.
+ print("""
+// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+//
+// ----- Generated by create_shard_groups.dart, do not edit! -----
+
+part of gardening.shard2group;
+
+const Map<String, List<String>> shardGroups = const {
+""");
+ for (int i = 0; i < groupCount; i++) {
+ print(" '${groups[i]}': const <String>[");
+ for (List<String> shard in shards[i]) {
+ print(" '$shard',");
+ }
+ print(" ],");
+ }
+ print('};');
+}
« no previous file with comments | « no previous file | tools/gardening/bin/shard2group.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698