OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library update_homebrew; | 5 library update_homebrew; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:convert'; | 8 import 'dart:convert'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 'sdk/dartsdk-macos-ia32-release.zip' | 26 'sdk/dartsdk-macos-ia32-release.zip' |
27 ]; | 27 ]; |
28 | 28 |
29 const DARTIUM_FILES = const [ | 29 const DARTIUM_FILES = const [ |
30 'dartium/dartium-macos-ia32-release.zip', | 30 'dartium/dartium-macos-ia32-release.zip', |
31 'dartium/content_shell-macos-ia32-release.zip' | 31 'dartium/content_shell-macos-ia32-release.zip' |
32 ]; | 32 ]; |
33 | 33 |
34 final FILES = []..addAll(SDK_FILES)..addAll(DARTIUM_FILES); | 34 final FILES = []..addAll(SDK_FILES)..addAll(DARTIUM_FILES); |
35 | 35 |
36 Future<String> getHash256(String channel, int revision, String download) async { | 36 Future<String> getHash256( |
| 37 String channel, String revision, String download) async { |
37 var client = new http.Client(); | 38 var client = new http.Client(); |
38 try { | 39 try { |
39 var api = new storage.StorageApi(client); | 40 var api = new storage.StorageApi(client); |
40 var media = await api.objects.get('dart-archive', | 41 var media = await api.objects.get('dart-archive', |
41 'channels/$channel/release/$revision/$download.sha256sum', | 42 'channels/$channel/release/$revision/$download.sha256sum', |
42 downloadOptions: DownloadOptions.FullMedia); | 43 downloadOptions: DownloadOptions.FullMedia); |
43 | 44 |
44 var hashLine = await ASCII.decodeStream(media.stream); | 45 var hashLine = await ASCII.decodeStream(media.stream); |
45 return new RegExp('[0-9a-fA-F]*').stringMatch(hashLine); | 46 return new RegExp('[0-9a-fA-F]*').stringMatch(hashLine); |
46 } finally { | 47 } finally { |
47 client.close(); | 48 client.close(); |
48 } | 49 } |
49 } | 50 } |
50 | 51 |
51 Future<String> getVersion(String channel, int revision) async { | 52 Future<String> getVersion(String channel, String revision) async { |
52 var client = new http.Client(); | 53 var client = new http.Client(); |
53 try { | 54 try { |
54 var api = new storage.StorageApi(client); | 55 var api = new storage.StorageApi(client); |
55 | 56 |
56 var media = await api.objects.get( | 57 var media = await api.objects.get( |
57 'dart-archive', 'channels/$channel/release/$revision/VERSION', | 58 'dart-archive', 'channels/$channel/release/$revision/VERSION', |
58 downloadOptions: DownloadOptions.FullMedia); | 59 downloadOptions: DownloadOptions.FullMedia); |
59 | 60 |
60 var versionObject = await JSON.fuse(ASCII).decoder.bind(media.stream).first; | 61 var versionObject = await JSON.fuse(ASCII).decoder.bind(media.stream).first; |
61 return versionObject['version']; | 62 return versionObject['version']; |
62 } finally { | 63 } finally { |
63 client.close(); | 64 client.close(); |
64 } | 65 } |
65 } | 66 } |
66 | 67 |
67 Future setCurrentRevisions(Map revisions) async { | 68 Future setCurrentRevisions(Map revisions) async { |
68 var lines = await (new File('$repository/dart.rb')).readAsLines(); | 69 var lines = await (new File('$repository/dart.rb')).readAsLines(); |
69 | 70 |
70 for (var channel in CHANNELS) { | 71 for (var channel in CHANNELS) { |
71 final regExp = new RegExp('channels/$channel/release/(\\d*)/sdk'); | 72 /// This RegExp between release/ and /sdk matches |
| 73 /// * 1 digit followed by |
| 74 /// * Any number of letters, numbers, dashes and dots |
| 75 /// This covers both numeric- and version-formatted revisions |
| 76 /// |
| 77 /// Note: all of the regexp escape slashes `\` are double-escaped within the |
| 78 /// Dart string |
| 79 final regExp = |
| 80 new RegExp('channels/$channel/release/(\\d[\\w\\d\\-\\.]*)/sdk'); |
| 81 |
72 revisions[channel] = | 82 revisions[channel] = |
73 regExp.firstMatch(lines.firstWhere(regExp.hasMatch)).group(1); | 83 regExp.firstMatch(lines.firstWhere(regExp.hasMatch)).group(1); |
74 } | 84 } |
75 } | 85 } |
76 | 86 |
77 Future setHashes(Map revisions, Map hashes) { | 87 Future setHashes(Map revisions, Map hashes) { |
78 List waitOn = []; | 88 List waitOn = []; |
79 for (var channel in CHANNELS) { | 89 for (var channel in CHANNELS) { |
80 hashes[channel] = {}; | 90 hashes[channel] = {}; |
81 for (var file in FILES) { | 91 for (var file in FILES) { |
82 waitOn.add(getHash256(channel, revisions[channel], file).then((hash) { | 92 waitOn.add(getHash256(channel, revisions[channel], file).then((hash) { |
83 hashes[channel][file] = hash; | 93 hashes[channel][file] = hash; |
84 })); | 94 })); |
85 } | 95 } |
86 } | 96 } |
87 return Future.wait(waitOn); | 97 return Future.wait(waitOn); |
88 } | 98 } |
89 | 99 |
90 Future writeHomebrewInfo(String channel, int revision) async { | 100 Future writeHomebrewInfo(String channel, String revision) async { |
91 var revisions = {}; | 101 var revisions = {}; |
92 var hashes = {}; | 102 var hashes = {}; |
93 | 103 |
94 await setCurrentRevisions(revisions); | 104 await setCurrentRevisions(revisions); |
95 | 105 |
96 if (revisions[channel] == revision) { | 106 if (revisions[channel] == revision) { |
97 print("Channel $channel is already at revision $revision in homebrew."); | 107 print("Channel $channel is already at revision $revision in homebrew."); |
98 exit(0); | 108 exit(0); |
99 } | 109 } |
100 revisions[channel] = revision; | 110 revisions[channel] = revision; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 | 284 |
275 await runGit(['push']); | 285 await runGit(['push']); |
276 } finally { | 286 } finally { |
277 await tempDir.delete(recursive: true); | 287 await tempDir.delete(recursive: true); |
278 } | 288 } |
279 }, onError: (error, chain) { | 289 }, onError: (error, chain) { |
280 print(error); | 290 print(error); |
281 print(chain.terse); | 291 print(chain.terse); |
282 }); | 292 }); |
283 } | 293 } |
OLD | NEW |