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

Side by Side Diff: tools/apps/update_homebrew/bin/update_homebrew.dart

Issue 1170973002: update_homebrew: more fixes (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: method renaming Created 5 years, 6 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 import 'package:args/args.dart'; 11 import 'package:args/args.dart';
12 import 'package:googleapis/common/common.dart' show DownloadOptions, Media; 12 import 'package:googleapis/common/common.dart' show DownloadOptions, Media;
13 import 'package:googleapis/storage/v1.dart' as storage; 13 import 'package:googleapis/storage/v1.dart' as storage;
14 import 'package:http/http.dart' as http; 14 import 'package:http/http.dart' as http;
15 import 'package:stack_trace/stack_trace.dart'; 15 import 'package:stack_trace/stack_trace.dart';
16 16
17 String repository; // The path to the temporary git checkout of dart-homebrew. 17 String repository; // The path to the temporary git checkout of dart-homebrew.
18 Map gitEnvironment; // Pass a wrapper script for SSH to git in the environment. 18 Map gitEnvironment; // Pass a wrapper script for SSH to git in the environment.
19 19
20 const GITHUB_REPO = 'dart-lang/homebrew-dart'; 20 const GITHUB_REPO = 'dart-lang/homebrew-dart';
21 21
22 const CHANNELS = const ['dev', 'stable']; 22 const CHANNELS = const ['dev', 'stable'];
23 23
24 const SDK_FILES = const [ 24 const FILES = const [x64File, ia32File, dartiumFile, contentShellFile];
25 'sdk/dartsdk-macos-x64-release.zip',
26 'sdk/dartsdk-macos-ia32-release.zip'
27 ];
28 25
29 const DARTIUM_FILES = const [ 26 const urlBase = 'https://storage.googleapis.com/dart-archive/channels';
30 'dartium/dartium-macos-ia32-release.zip', 27 const x64File = 'sdk/dartsdk-macos-x64-release.zip';
31 'dartium/content_shell-macos-ia32-release.zip' 28 const ia32File = 'sdk/dartsdk-macos-ia32-release.zip';
32 ]; 29 const dartiumFile = 'dartium/dartium-macos-ia32-release.zip';
33 30 const contentShellFile = 'dartium/content_shell-macos-ia32-release.zip';
34 final FILES = []..addAll(SDK_FILES)..addAll(DARTIUM_FILES);
35 31
36 Future<String> getHash256( 32 Future<String> getHash256(
37 String channel, String revision, String download) async { 33 String channel, String revision, String download) async {
38 var client = new http.Client(); 34 var client = new http.Client();
39 try { 35 try {
40 var api = new storage.StorageApi(client); 36 var api = new storage.StorageApi(client);
41 var media = await api.objects.get('dart-archive', 37 var media = await api.objects.get('dart-archive',
42 'channels/$channel/release/$revision/$download.sha256sum', 38 'channels/$channel/release/$revision/$download.sha256sum',
43 downloadOptions: DownloadOptions.FullMedia); 39 downloadOptions: DownloadOptions.FullMedia);
44 40
(...skipping 13 matching lines...) Expand all
58 'dart-archive', 'channels/$channel/release/$revision/VERSION', 54 'dart-archive', 'channels/$channel/release/$revision/VERSION',
59 downloadOptions: DownloadOptions.FullMedia); 55 downloadOptions: DownloadOptions.FullMedia);
60 56
61 var versionObject = await JSON.fuse(ASCII).decoder.bind(media.stream).first; 57 var versionObject = await JSON.fuse(ASCII).decoder.bind(media.stream).first;
62 return versionObject['version']; 58 return versionObject['version'];
63 } finally { 59 } finally {
64 client.close(); 60 client.close();
65 } 61 }
66 } 62 }
67 63
68 Future setCurrentRevisions(Map revisions) async { 64 Future<Map> getCurrentRevisions() async {
65 var revisions = <String, String>{};
69 var lines = await (new File('$repository/dart.rb')).readAsLines(); 66 var lines = await (new File('$repository/dart.rb')).readAsLines();
70 67
71 for (var channel in CHANNELS) { 68 for (var channel in CHANNELS) {
72 /// This RegExp between release/ and /sdk matches 69 /// This RegExp between release/ and /sdk matches
73 /// * 1 digit followed by 70 /// * 1 digit followed by
74 /// * Any number of letters, numbers, dashes and dots 71 /// * Any number of letters, numbers, dashes and dots
75 /// This covers both numeric- and version-formatted revisions 72 /// This covers both numeric- and version-formatted revisions
76 /// 73 ///
77 /// Note: all of the regexp escape slashes `\` are double-escaped within the 74 /// Note: all of the regexp escape slashes `\` are double-escaped within the
78 /// Dart string 75 /// Dart string
79 final regExp = 76 final regExp =
80 new RegExp('channels/$channel/release/(\\d[\\w\\d\\-\\.]*)/sdk'); 77 new RegExp('channels/$channel/release/(\\d[\\w\\d\\-\\.]*)/sdk');
81 78
82 revisions[channel] = 79 revisions[channel] =
83 regExp.firstMatch(lines.firstWhere(regExp.hasMatch)).group(1); 80 regExp.firstMatch(lines.firstWhere(regExp.hasMatch)).group(1);
84 } 81 }
82 return revisions;
85 } 83 }
86 84
87 Future setHashes(Map revisions, Map hashes) { 85 Future<Map> getHashes(Map revisions) async {
88 List waitOn = []; 86 var hashes = <String, Map>{};
89 for (var channel in CHANNELS) { 87 for (var channel in CHANNELS) {
90 hashes[channel] = {}; 88 hashes[channel] = {};
91 for (var file in FILES) { 89 for (var file in FILES) {
92 waitOn.add(getHash256(channel, revisions[channel], file).then((hash) { 90 var hash = await getHash256(channel, revisions[channel], file);
93 hashes[channel][file] = hash; 91 hashes[channel][file] = hash;
94 }));
95 } 92 }
96 } 93 }
97 return Future.wait(waitOn); 94 return hashes;
98 } 95 }
99 96
100 Future writeHomebrewInfo(String channel, String revision) async { 97 Future writeHomebrewInfo(String channel, String revision) async {
101 var revisions = {}; 98 var revisions = await getCurrentRevisions();
102 var hashes = {};
103
104 await setCurrentRevisions(revisions);
105 99
106 if (revisions[channel] == revision) { 100 if (revisions[channel] == revision) {
107 print("Channel $channel is already at revision $revision in homebrew."); 101 print("Channel $channel is already at revision $revision in homebrew.");
108 exit(0); 102 exit(0);
109 } 103 }
110 revisions[channel] = revision; 104 revisions[channel] = revision;
111 await setHashes(revisions, hashes); 105 var hashes = await getHashes(revisions);
112 var devVersion = await getVersion('dev', revisions['dev']); 106 var devVersion = await getVersion('dev', revisions['dev']);
113 107
114 var stableVersion = await getVersion('stable', revisions['stable']); 108 var stableVersion = await getVersion('stable', revisions['stable']);
115 109
116 await (new File('$repository/dartium.rb').openWrite() 110 await new File('$repository/dartium.rb').writeAsString(
117 ..write(DartiumFile(revisions, hashes, devVersion, stableVersion))).close(); 111 createDartiumFormula(revisions, hashes, devVersion, stableVersion),
118 await (new File('$repository/dart.rb').openWrite() 112 flush: true);
119 ..write(DartFile(revisions, hashes, devVersion, stableVersion))).close(); 113 await new File('$repository/dart.rb').writeAsString(
114 createDartFormula(revisions, hashes, devVersion, stableVersion),
115 flush: true);
120 } 116 }
121 117
122 String DartiumFile( 118 String createDartiumFormula(
123 Map revisions, Map hashes, String devVersion, String stableVersion) { 119 Map revisions, Map hashes, String devVersion, String stableVersion) => '''
124 final urlBase = 'https://storage.googleapis.com/dart-archive/channels';
125 final dartiumFile = 'dartium/dartium-macos-ia32-release.zip';
126 final contentShellFile = 'dartium/content_shell-macos-ia32-release.zip';
127
128 return '''
129 require 'formula' 120 require 'formula'
130 121
131 class Dartium < Formula 122 class Dartium < Formula
132 homepage "https://www.dartlang.org" 123 homepage "https://www.dartlang.org"
133 124
134 version '$stableVersion' 125 version '$stableVersion'
135 url '$urlBase/stable/release/${revisions['stable']}/$dartiumFile' 126 url '$urlBase/stable/release/${revisions['stable']}/$dartiumFile'
136 sha256 '${hashes['stable'][dartiumFile]}' 127 sha256 '${hashes['stable'][dartiumFile]}'
137 128
138 devel do 129 devel do
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 To use with IntelliJ, set the Dartium execute home to: 165 To use with IntelliJ, set the Dartium execute home to:
175 #{prefix}/Chromium.app 166 #{prefix}/Chromium.app
176 EOS 167 EOS
177 end 168 end
178 169
179 test do 170 test do
180 system "#{bin}/dartium" 171 system "#{bin}/dartium"
181 end 172 end
182 end 173 end
183 '''; 174 ''';
184 }
185 175
186 String DartFile( 176 String createDartFormula(
187 Map revisions, Map hashes, String devVersion, String stableVersion) { 177 Map revisions, Map hashes, String devVersion, String stableVersion) => '''
188 final urlBase = 'https://storage.googleapis.com/dart-archive/channels';
189 final x64File = 'sdk/dartsdk-macos-x64-release.zip';
190 final ia32File = 'sdk/dartsdk-macos-ia32-release.zip';
191
192 return '''
193 require 'formula' 178 require 'formula'
194 179
195 class Dart < Formula 180 class Dart < Formula
196 homepage 'https://www.dartlang.org/' 181 homepage 'https://www.dartlang.org/'
197 182
198 version '$stableVersion' 183 version '$stableVersion'
199 if MacOS.prefer_64_bit? 184 if MacOS.prefer_64_bit?
200 url '$urlBase/stable/release/${revisions['stable']}/$x64File' 185 url '$urlBase/stable/release/${revisions['stable']}/$x64File'
201 sha256 '${hashes['stable'][x64File]}' 186 sha256 '${hashes['stable'][x64File]}'
202 else 187 else
(...skipping 28 matching lines...) Expand all
231 (testpath/'sample.dart').write <<-EOS.undent 216 (testpath/'sample.dart').write <<-EOS.undent
232 void main() { 217 void main() {
233 print(r"test message"); 218 print(r"test message");
234 } 219 }
235 EOS 220 EOS
236 221
237 assert_equal "test message\\n", shell_output("#{bin}/dart sample.dart") 222 assert_equal "test message\\n", shell_output("#{bin}/dart sample.dart")
238 end 223 end
239 end 224 end
240 '''; 225 ''';
241 }
242 226
243 Future runGit(List<String> args) async { 227 Future runGit(List<String> args) async {
244 print("git ${args.join(' ')}"); 228 print("git ${args.join(' ')}");
245 229
246 var result = await Process.run('git', args, 230 var result = await Process.run('git', args,
247 workingDirectory: repository, environment: gitEnvironment); 231 workingDirectory: repository, environment: gitEnvironment);
248 232
249 print(result.stdout); 233 print(result.stdout);
250 print(result.stderr); 234 print(result.stderr);
251 } 235 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 268
285 await runGit(['push']); 269 await runGit(['push']);
286 } finally { 270 } finally {
287 await tempDir.delete(recursive: true); 271 await tempDir.delete(recursive: true);
288 } 272 }
289 }, onError: (error, chain) { 273 }, onError: (error, chain) {
290 print(error); 274 print(error);
291 print(chain.terse); 275 print(chain.terse);
292 }); 276 });
293 } 277 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698