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:io'; | 7 import 'dart:io'; |
8 import 'dart:convert'; | 8 import 'dart:convert'; |
9 import 'dart:async'; | 9 import 'dart:async'; |
10 import 'package:http/http.dart' as http; | 10 import 'package:http/http.dart' as http; |
11 import 'package:args/args.dart'; | 11 import 'package:args/args.dart'; |
12 import 'package:googleapis/storage/v1.dart' as storage; | 12 import 'package:googleapis/storage/v1.dart' as storage; |
13 import 'package:googleapis/common/common.dart' show DownloadOptions, Media; | 13 import 'package:googleapis/common/common.dart' show DownloadOptions, Media; |
14 | 14 |
15 String repository; // The path to the temporary git checkout of dart-homebrew. | 15 String repository; // The path to the temporary git checkout of dart-homebrew. |
16 Map gitEnvironment; // Pass a wrapper script for SSH to git in the environment. | 16 Map gitEnvironment; // Pass a wrapper script for SSH to git in the environment. |
17 | 17 |
18 final CHANNELS = ['dev', 'stable']; | |
19 | |
20 final SDK_FILES = [ 'sdk/dartsdk-macos-x64-release.zip', | |
ricow1
2014/10/15 11:30:41
remove space before string (or at least be consist
Bill Hesse
2014/10/15 12:45:47
Done.
| |
21 'sdk/dartsdk-macos-ia32-release.zip' ]; | |
22 final DARTIUM_FILES = [ 'dartium/dartium-macos-ia32-release.zip' ]; | |
23 final FILES = []..addAll(SDK_FILES)..addAll(DARTIUM_FILES); | |
24 | |
25 | |
18 Future<String> getHash256(String channel, int revision, String download) { | 26 Future<String> getHash256(String channel, int revision, String download) { |
19 var client = new http.Client(); | 27 var client = new http.Client(); |
20 var api = new storage.StorageApi(client); | 28 var api = new storage.StorageApi(client); |
21 return | 29 return |
22 api.objects.get('dart-archive', | 30 api.objects.get('dart-archive', |
23 'channels/$channel/release/$revision/$download.sha256sum', | 31 'channels/$channel/release/$revision/$download.sha256sum', |
24 downloadOptions: DownloadOptions.FullMedia) | 32 downloadOptions: DownloadOptions.FullMedia) |
25 .then((Media media) => ASCII.decodeStream(media.stream)) | 33 .then((Media media) => ASCII.decodeStream(media.stream)) |
26 .then((hashLine) => new RegExp('[0-9a-fA-F]*').stringMatch(hashLine)) | 34 .then((hashLine) => new RegExp('[0-9a-fA-F]*').stringMatch(hashLine)) |
27 .whenComplete(client.close); | 35 .whenComplete(client.close); |
28 } | 36 } |
29 | 37 |
30 Future<String> getVersion(String channel, int revision) { | 38 Future<String> getVersion(String channel, int revision) { |
31 var client = new http.Client(); | 39 var client = new http.Client(); |
32 var api = new storage.StorageApi(client); | 40 var api = new storage.StorageApi(client); |
33 return api.objects.get('dart-archive', | 41 return api.objects.get('dart-archive', |
34 'channels/$channel/release/$revision/VERSION', | 42 'channels/$channel/release/$revision/VERSION', |
35 downloadOptions: DownloadOptions.FullMedia) | 43 downloadOptions: DownloadOptions.FullMedia) |
36 .then((Media media) => JSON.fuse(ASCII).decoder.bind(media.stream).first) | 44 .then((Media media) => JSON.fuse(ASCII).decoder.bind(media.stream).first) |
37 .then((versionObject) => versionObject['version']) | 45 .then((versionObject) => versionObject['version']) |
38 .whenComplete(client.close); | 46 .whenComplete(client.close); |
39 } | 47 } |
40 | 48 |
49 Future<Map> getCurrentRevisions() => new File('$repository/dart.rb') | |
ricow1
2014/10/15 11:30:41
don't use shorthand function notation for a multi
Bill Hesse
2014/10/15 12:45:47
Done. Simplified functions as well.
| |
50 .readAsLines() | |
51 .then((lines) { | |
52 revisionFromChannel(channel) { | |
53 final regExp = new RegExp('channels/$channel/release/(\\d*)/sdk'); | |
54 return regExp.firstMatch(lines.firstWhere(regExp.hasMatch)).group(1); | |
55 } | |
56 return new Map.fromIterable(CHANNELS, value: revisionFromChannel); | |
57 }); | |
58 | |
59 Future<Map> getHashes(Map revisions) { | |
60 Map hashes = new Map.fromIterable(CHANNELS, value: (_) => {}); | |
61 List waitOn = []; | |
62 for (var channel in CHANNELS) { | |
63 for (var file in FILES) { | |
64 waitOn.add(getHash256(channel, revisions[channel], file).then((hash) { | |
65 hashes[channel][file] = hash; | |
66 })); | |
67 } | |
68 } | |
69 return Future.wait(waitOn).then((_) => hashes); | |
70 } | |
71 | |
41 Future writeHomebrewInfo(String channel, int revision) { | 72 Future writeHomebrewInfo(String channel, int revision) { |
42 final buffer = new StringBuffer(); | 73 var revisions; |
43 final moduleName = (channel == 'dev') ? 'DartDev' : 'DartStable'; | 74 var hashes; |
44 buffer.writeln('module $moduleName'); | 75 var devVersion; |
45 final files = {'SDK64': 'sdk/dartsdk-macos-x64-release.zip', | 76 var stableVersion; |
46 'SDK32': 'sdk/dartsdk-macos-ia32-release.zip', | 77 return getCurrentRevisions().then((revs) { |
47 'DARTIUM': 'dartium/dartium-macos-ia32-release.zip'}; | 78 revisions = revs; |
48 return Future.forEach(files.keys, (key) { | 79 if (revisions[channel] == revision) { |
49 return getHash256(channel, revision, files[key]).then((hash) { | 80 print("Channel $channel is already at revision $revision in homebrew."); |
50 final file = "channels/$channel/release/$revision/${files[key]}"; | 81 exit(0); |
51 buffer.writeln(' ${key}_FILE = "$file"'); | 82 } |
52 buffer.writeln(' ${key}_HASH = "$hash"'); | 83 revisions[channel] = revision; |
53 }); | 84 return getHashes(revisions); |
54 }) | 85 }).then((returnedHashes) { |
55 .then((_) => getVersion(channel, revision)) | 86 hashes = returnedHashes; |
56 .then((version) { | 87 return getVersion('dev', revisions['dev']); |
57 buffer.writeln(' VERSION = "$version"'); | 88 }).then((version) { |
58 buffer.writeln('end'); | 89 devVersion = version; |
59 return (new File('$repository/data/${channel}_info.rb').openWrite() | 90 return getVersion('stable', revisions['stable']); |
60 ..write(buffer)) | 91 }).then((version) { |
61 .close(); | 92 stableVersion = version; |
62 }); | 93 return (new File('$repository/dartium.rb').openWrite() |
94 ..write(DartiumFile(revisions, hashes, devVersion, stableVersion))) | |
95 .close(); | |
96 }).then((_) { | |
97 return (new File('$repository/dart.rb').openWrite() | |
98 ..write(DartFile(revisions, hashes, devVersion, stableVersion))) | |
99 .close(); | |
100 }); | |
101 } | |
102 | |
103 String DartiumFile(Map revisions, | |
104 Map hashes, | |
105 String devVersion, | |
106 String stableVersion) { | |
107 final urlBase = 'https://storage.googleapis.com/dart-archive/channels'; | |
108 final dartiumFile = 'dartium/dartium-macos-ia32-release.zip'; | |
109 | |
110 return ''' | |
111 require 'formula' | |
112 | |
113 class Dartium < Formula | |
114 homepage "https://www.dartlang.org" | |
115 | |
116 version '$stableVersion' | |
117 url '$urlBase/stable/release/${revisions['stable']}/$dartiumFile' | |
118 sha256 '${hashes['stable'][dartiumFile]}' | |
119 | |
120 devel do | |
121 version '$devVersion' | |
122 url '$urlBase/dev/release/${revisions['dev']}/$dartiumFile' | |
123 sha256 '${hashes['dev'][dartiumFile]}' | |
124 end | |
125 | |
126 def shim_script target | |
127 <<-EOS.undent | |
128 #!/bin/bash | |
129 open "#{prefix}/#{target}" "\$@" | |
130 EOS | |
131 end | |
132 | |
133 def install | |
134 prefix.install Dir['*'] | |
135 (bin+"dartium").write shim_script "Chromium.app" | |
136 end | |
137 | |
138 def caveats; <<-EOS.undent | |
139 To use with IntelliJ, set the Dartium execute home to: | |
140 #{prefix}/Chromium.app | |
141 EOS | |
142 end | |
143 | |
144 test do | |
145 system "#{bin}/dartium" | |
146 end | |
147 end | |
148 '''; | |
149 } | |
150 | |
151 String DartFile(Map revisions, | |
152 Map hashes, | |
153 String devVersion, | |
154 String stableVersion) { | |
155 final urlBase = 'https://storage.googleapis.com/dart-archive/channels'; | |
156 final x64File = 'sdk/dartsdk-macos-x64-release.zip'; | |
157 final ia32File = 'sdk/dartsdk-macos-ia32-release.zip'; | |
158 | |
159 return ''' | |
160 require 'formula' | |
161 | |
162 class Dart < Formula | |
163 homepage 'https://www.dartlang.org/' | |
164 | |
165 version '$stableVersion' | |
166 if MacOS.prefer_64_bit? | |
167 url '$urlBase/stable/release/${revisions['stable']}/$x64File' | |
168 sha256 '${hashes['stable'][x64File]}' | |
169 else | |
170 url '$urlBase/stable/release/${revisions['stable']}/$ia32File' | |
171 sha256 '${hashes['stable'][ia32File]}' | |
172 end | |
173 | |
174 devel do | |
175 version '$devVersion' | |
176 if MacOS.prefer_64_bit? | |
177 url '$urlBase/dev/release/${revisions['dev']}/$x64File' | |
178 sha256 '${hashes['dev'][x64File]}' | |
179 else | |
180 url '$urlBase/dev/release/${revisions['dev']}/$ia32File' | |
181 sha256 '${hashes['dev'][ia32File]}' | |
182 end | |
183 end | |
184 | |
185 def install | |
186 libexec.install Dir['*'] | |
187 bin.install_symlink "#{libexec}/bin/dart" | |
188 bin.write_exec_script Dir["#{libexec}/bin/{pub,docgen,dart?*}"] | |
189 end | |
190 | |
191 def caveats; <<-EOS.undent | |
192 Please note the path to the Dart SDK: | |
193 #{opt_libexec} | |
194 EOS | |
195 end | |
196 | |
197 test do | |
198 (testpath/'sample.dart').write <<-EOS.undent | |
199 void main() { | |
200 print(r"test message"); | |
201 } | |
202 EOS | |
203 | |
204 assert_equal "test message\\n", shell_output("#{bin}/dart sample.dart") | |
205 end | |
206 end | |
207 '''; | |
63 } | 208 } |
64 | 209 |
65 Future runGit(List<String> args) { | 210 Future runGit(List<String> args) { |
66 print("git ${args.join(' ')}"); | 211 print("git ${args.join(' ')}"); |
67 return Process.run('git', args, workingDirectory: repository, | 212 return Process.run('git', args, workingDirectory: repository, |
68 environment: gitEnvironment) | 213 environment: gitEnvironment) |
69 .then((result) { | 214 .then((result) { |
70 print(result.stdout); | 215 print(result.stdout); |
71 print(result.stderr); | 216 print(result.stderr); |
72 }); | 217 }); |
(...skipping 21 matching lines...) Expand all Loading... | |
94 repository = tempDir.path; | 239 repository = tempDir.path; |
95 }) | 240 }) |
96 .then((_) => runGit( | 241 .then((_) => runGit( |
97 ['clone', 'git@github.com:dart-lang/homebrew-dart.git', '.'])) | 242 ['clone', 'git@github.com:dart-lang/homebrew-dart.git', '.'])) |
98 .then((_) => writeHomebrewInfo(channel, revision)) | 243 .then((_) => writeHomebrewInfo(channel, revision)) |
99 .then((_) => runGit(['commit', '-a', '-m', | 244 .then((_) => runGit(['commit', '-a', '-m', |
100 'Updated $channel branch to revision $revision'])) | 245 'Updated $channel branch to revision $revision'])) |
101 .then((_) => runGit(['push'])) | 246 .then((_) => runGit(['push'])) |
102 .whenComplete(() => new Directory(repository).delete(recursive: true)); | 247 .whenComplete(() => new Directory(repository).delete(recursive: true)); |
103 } | 248 } |
OLD | NEW |