Chromium Code Reviews| Index: tools/apps/update_homebrew/bin/update_homebrew.dart |
| diff --git a/tools/apps/update_homebrew/bin/update_homebrew.dart b/tools/apps/update_homebrew/bin/update_homebrew.dart |
| index 1fe8f0ad4026e6a724d9dff53e945190ead2140d..a1b005f640a4d9c97f4f766141d68e5c2094bd0e 100644 |
| --- a/tools/apps/update_homebrew/bin/update_homebrew.dart |
| +++ b/tools/apps/update_homebrew/bin/update_homebrew.dart |
| @@ -15,6 +15,14 @@ import 'package:googleapis/common/common.dart' show DownloadOptions, Media; |
| String repository; // The path to the temporary git checkout of dart-homebrew. |
| Map gitEnvironment; // Pass a wrapper script for SSH to git in the environment. |
| +final CHANNELS = ['dev', 'stable']; |
| + |
| +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.
|
| + 'sdk/dartsdk-macos-ia32-release.zip' ]; |
| +final DARTIUM_FILES = [ 'dartium/dartium-macos-ia32-release.zip' ]; |
| +final FILES = []..addAll(SDK_FILES)..addAll(DARTIUM_FILES); |
| + |
| + |
| Future<String> getHash256(String channel, int revision, String download) { |
| var client = new http.Client(); |
| var api = new storage.StorageApi(client); |
| @@ -38,28 +46,165 @@ Future<String> getVersion(String channel, int revision) { |
| .whenComplete(client.close); |
| } |
| +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.
|
| + .readAsLines() |
| + .then((lines) { |
| + revisionFromChannel(channel) { |
| + final regExp = new RegExp('channels/$channel/release/(\\d*)/sdk'); |
| + return regExp.firstMatch(lines.firstWhere(regExp.hasMatch)).group(1); |
| + } |
| + return new Map.fromIterable(CHANNELS, value: revisionFromChannel); |
| + }); |
| + |
| +Future<Map> getHashes(Map revisions) { |
| + Map hashes = new Map.fromIterable(CHANNELS, value: (_) => {}); |
| + List waitOn = []; |
| + for (var channel in CHANNELS) { |
| + for (var file in FILES) { |
| + waitOn.add(getHash256(channel, revisions[channel], file).then((hash) { |
| + hashes[channel][file] = hash; |
| + })); |
| + } |
| + } |
| + return Future.wait(waitOn).then((_) => hashes); |
| +} |
| + |
| Future writeHomebrewInfo(String channel, int revision) { |
| - final buffer = new StringBuffer(); |
| - final moduleName = (channel == 'dev') ? 'DartDev' : 'DartStable'; |
| - buffer.writeln('module $moduleName'); |
| - final files = {'SDK64': 'sdk/dartsdk-macos-x64-release.zip', |
| - 'SDK32': 'sdk/dartsdk-macos-ia32-release.zip', |
| - 'DARTIUM': 'dartium/dartium-macos-ia32-release.zip'}; |
| - return Future.forEach(files.keys, (key) { |
| - return getHash256(channel, revision, files[key]).then((hash) { |
| - final file = "channels/$channel/release/$revision/${files[key]}"; |
| - buffer.writeln(' ${key}_FILE = "$file"'); |
| - buffer.writeln(' ${key}_HASH = "$hash"'); |
| - }); |
| - }) |
| - .then((_) => getVersion(channel, revision)) |
| - .then((version) { |
| - buffer.writeln(' VERSION = "$version"'); |
| - buffer.writeln('end'); |
| - return (new File('$repository/data/${channel}_info.rb').openWrite() |
| - ..write(buffer)) |
| - .close(); |
| - }); |
| + var revisions; |
| + var hashes; |
| + var devVersion; |
| + var stableVersion; |
| + return getCurrentRevisions().then((revs) { |
| + revisions = revs; |
| + if (revisions[channel] == revision) { |
| + print("Channel $channel is already at revision $revision in homebrew."); |
| + exit(0); |
| + } |
| + revisions[channel] = revision; |
| + return getHashes(revisions); |
| + }).then((returnedHashes) { |
| + hashes = returnedHashes; |
| + return getVersion('dev', revisions['dev']); |
| + }).then((version) { |
| + devVersion = version; |
| + return getVersion('stable', revisions['stable']); |
| + }).then((version) { |
| + stableVersion = version; |
| + return (new File('$repository/dartium.rb').openWrite() |
| + ..write(DartiumFile(revisions, hashes, devVersion, stableVersion))) |
| + .close(); |
| + }).then((_) { |
| + return (new File('$repository/dart.rb').openWrite() |
| + ..write(DartFile(revisions, hashes, devVersion, stableVersion))) |
| + .close(); |
| + }); |
| +} |
| + |
| +String DartiumFile(Map revisions, |
| + Map hashes, |
| + String devVersion, |
| + String stableVersion) { |
| + final urlBase = 'https://storage.googleapis.com/dart-archive/channels'; |
| + final dartiumFile = 'dartium/dartium-macos-ia32-release.zip'; |
| + |
| + return ''' |
| +require 'formula' |
| + |
| +class Dartium < Formula |
| + homepage "https://www.dartlang.org" |
| + |
| + version '$stableVersion' |
| + url '$urlBase/stable/release/${revisions['stable']}/$dartiumFile' |
| + sha256 '${hashes['stable'][dartiumFile]}' |
| + |
| + devel do |
| + version '$devVersion' |
| + url '$urlBase/dev/release/${revisions['dev']}/$dartiumFile' |
| + sha256 '${hashes['dev'][dartiumFile]}' |
| + end |
| + |
| + def shim_script target |
| + <<-EOS.undent |
| + #!/bin/bash |
| + open "#{prefix}/#{target}" "\$@" |
| + EOS |
| + end |
| + |
| + def install |
| + prefix.install Dir['*'] |
| + (bin+"dartium").write shim_script "Chromium.app" |
| + end |
| + |
| + def caveats; <<-EOS.undent |
| + To use with IntelliJ, set the Dartium execute home to: |
| + #{prefix}/Chromium.app |
| + EOS |
| + end |
| + |
| + test do |
| + system "#{bin}/dartium" |
| + end |
| +end |
| +'''; |
| +} |
| + |
| +String DartFile(Map revisions, |
| + Map hashes, |
| + String devVersion, |
| + String stableVersion) { |
| + final urlBase = 'https://storage.googleapis.com/dart-archive/channels'; |
| + final x64File = 'sdk/dartsdk-macos-x64-release.zip'; |
| + final ia32File = 'sdk/dartsdk-macos-ia32-release.zip'; |
| + |
| + return ''' |
| +require 'formula' |
| + |
| +class Dart < Formula |
| + homepage 'https://www.dartlang.org/' |
| + |
| + version '$stableVersion' |
| + if MacOS.prefer_64_bit? |
| + url '$urlBase/stable/release/${revisions['stable']}/$x64File' |
| + sha256 '${hashes['stable'][x64File]}' |
| + else |
| + url '$urlBase/stable/release/${revisions['stable']}/$ia32File' |
| + sha256 '${hashes['stable'][ia32File]}' |
| + end |
| + |
| + devel do |
| + version '$devVersion' |
| + if MacOS.prefer_64_bit? |
| + url '$urlBase/dev/release/${revisions['dev']}/$x64File' |
| + sha256 '${hashes['dev'][x64File]}' |
| + else |
| + url '$urlBase/dev/release/${revisions['dev']}/$ia32File' |
| + sha256 '${hashes['dev'][ia32File]}' |
| + end |
| + end |
| + |
| + def install |
| + libexec.install Dir['*'] |
| + bin.install_symlink "#{libexec}/bin/dart" |
| + bin.write_exec_script Dir["#{libexec}/bin/{pub,docgen,dart?*}"] |
| + end |
| + |
| + def caveats; <<-EOS.undent |
| + Please note the path to the Dart SDK: |
| + #{opt_libexec} |
| + EOS |
| + end |
| + |
| + test do |
| + (testpath/'sample.dart').write <<-EOS.undent |
| + void main() { |
| + print(r"test message"); |
| + } |
| + EOS |
| + |
| + assert_equal "test message\\n", shell_output("#{bin}/dart sample.dart") |
| + end |
| +end |
| +'''; |
| } |
| Future runGit(List<String> args) { |