OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2017, 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 // Outputs source code for `part` used by `shard2group.dart`. Usage: |
| 6 // `dart bin/create_shard_groups.dart source.html >lib/src/shard_data.dart`. |
| 7 |
| 8 import 'dart:io'; |
| 9 import 'dart:math' as math; |
| 10 |
| 11 const String groupsStartMark = r"<td class='DevStatus Alt first"; |
| 12 const String groupsEndMark = r"<tr class='DevStatusSpacing'>"; |
| 13 |
| 14 List<String> findGroups(List<String> source) { |
| 15 List<String> result = <String>[]; |
| 16 bool started = false; |
| 17 |
| 18 for (String line in source) { |
| 19 if (line.contains(groupsStartMark)) started = true; |
| 20 if (started) { |
| 21 if (line.contains(groupsEndMark)) break; |
| 22 String trimmed = line.trim(); |
| 23 if (!trimmed.startsWith('<')) { |
| 24 result.add(trimmed); |
| 25 } |
| 26 } |
| 27 } |
| 28 return result; |
| 29 } |
| 30 |
| 31 const String shardsStartMark = groupsEndMark; |
| 32 const String shardsEndMark = r"<td class='DevStatusBox"; |
| 33 const String shardsGroupStartMark = r"<td class='DevSlave Alt"; |
| 34 const String shardMark = '/builders/'; |
| 35 |
| 36 List<List<String>> findShards(List<String> source) { |
| 37 List<List<String>> result = <List<String>>[]; |
| 38 List<String> shardResult; |
| 39 bool started = false; |
| 40 |
| 41 for (String line in source) { |
| 42 if (line.contains(shardsStartMark)) started = true; |
| 43 if (started) { |
| 44 if (line.contains(shardsEndMark)) break; |
| 45 String trimmed = line.trim(); |
| 46 int buildersIndex = trimmed.indexOf(shardMark); |
| 47 if (buildersIndex >= 0) { |
| 48 int quoteIndex = trimmed.indexOf("'", buildersIndex); |
| 49 if (quoteIndex >= 0) { |
| 50 // Found a shard name, add it. |
| 51 shardResult.add(trimmed.substring( |
| 52 buildersIndex + shardMark.length, quoteIndex)); |
| 53 } else { |
| 54 // Unexpected source formatting, skip. |
| 55 } |
| 56 } else if (trimmed.contains(shardsGroupStartMark)) { |
| 57 // This is a group separator, switch to next sublist. |
| 58 if (shardResult != null) result.add(shardResult); |
| 59 shardResult = <String>[]; |
| 60 } |
| 61 } |
| 62 } |
| 63 return result; |
| 64 } |
| 65 |
| 66 main(List<String> args) { |
| 67 if (args.length != 1) { |
| 68 print('Usage: dart create_shard_groups.dart <darto-source-file>'); |
| 69 exit(1); |
| 70 } |
| 71 |
| 72 File dartoSourceFile = new File(args[0]); |
| 73 List<String> dartoSource = dartoSourceFile.readAsLinesSync(); |
| 74 |
| 75 List<String> groups = findGroups(dartoSource); |
| 76 List<String> shards = findShards(dartoSource); |
| 77 int groupCount = math.min(groups.length, shards.length); |
| 78 |
| 79 // Print the resulting Dart declaration. |
| 80 print(""" |
| 81 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 82 // for details. All rights reserved. Use of this source code is governed by a |
| 83 // BSD-style license that can be found in the LICENSE file. |
| 84 // |
| 85 // ----- Generated by create_shard_groups.dart, do not edit! ----- |
| 86 |
| 87 part of gardening.shard2group; |
| 88 |
| 89 const Map<String, List<String>> shardGroups = const { |
| 90 """); |
| 91 for (int i = 0; i < groupCount; i++) { |
| 92 print(" '${groups[i]}': const <String>["); |
| 93 for (List<String> shard in shards[i]) { |
| 94 print(" '$shard',"); |
| 95 } |
| 96 print(" ],"); |
| 97 } |
| 98 print('};'); |
| 99 } |
OLD | NEW |