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

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

Issue 608693004: Add tools script to update homebrew, the MacOS SDK updating solution. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments, move generated files to subdir. Created 6 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « tools/apps/update_homebrew/bin/ssh_with_key ('k') | tools/apps/update_homebrew/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library update_homebrew;
6
7 import 'dart:io';
8 import 'dart:convert';
9 import 'dart:async';
10 import 'package:http/http.dart' as http;
11 import 'package:args/args.dart';
12 import 'package:googleapis/storage/v1.dart' as storage;
13 import 'package:googleapis/common/common.dart' show DownloadOptions, Media;
14
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.
17
18 Future<String> getHash256(String channel, int revision, String download) {
19 var client = new http.Client();
20 var api = new storage.StorageApi(client);
21 return
22 api.objects.get('dart-archive',
23 'channels/$channel/release/$revision/$download.sha256sum',
24 downloadOptions: DownloadOptions.FullMedia)
25 .then((Media media) => ASCII.decodeStream(media.stream))
26 .then((hashLine) => new RegExp('[0-9a-fA-F]*').stringMatch(hashLine))
27 .whenComplete(client.close);
28 }
29
30 Future<String> getVersion(String channel, int revision) {
31 var client = new http.Client();
32 var api = new storage.StorageApi(client);
33 return api.objects.get('dart-archive',
34 'channels/$channel/release/$revision/VERSION',
35 downloadOptions: DownloadOptions.FullMedia)
36 .then((Media media) => JSON.fuse(ASCII).decoder.bind(media.stream).first)
37 .then((versionObject) => versionObject['version'])
38 .whenComplete(client.close);
39 }
40
41 Future writeHomebrewInfo(String channel, int revision) {
42 final buffer = new StringBuffer();
43 final moduleName = (channel == 'dev') ? 'DartDev' : 'DartStable';
44 buffer.writeln('module $moduleName');
45 final files = {'SDK64': 'sdk/dartsdk-macos-x64-release.zip',
46 'SDK32': 'sdk/dartsdk-macos-ia32-release.zip',
47 'DARTIUM': 'dartium/dartium-macos-ia32-release.zip'};
48 return Future.forEach(files.keys, (key) {
49 return getHash256(channel, revision, files[key]).then((hash) {
50 final file = "channels/$channel/release/$revision/${files[key]}";
51 buffer.writeln(' ${key}_FILE = "$file"');
52 buffer.writeln(' ${key}_HASH = "$hash"');
53 })
54 })
55 .then((_) => getVersion(channel, revision))
56 .then((version) {
57 buffer.writeln(' VERSION = "$version"');
58 buffer.writeln('end');
59 return (new File('$repository/data/${channel}_info.rb').openWrite()
60 ..write(buffer))
61 .close();
62 });
63 }
64
65 Future runGit(List<String> args) {
66 print("git ${args.join(' ')}");
67 return Process.run('git', args, workingDirectory: repository,
68 environment: gitEnvironment)
69 .then((result) {
70 print(result.stdout);
71 print(result.stderr);
72 });
73 }
74
75 main(args) {
76 final parser = new ArgParser()
77 ..addOption('revision', abbr: 'r')
78 ..addOption('channel', abbr: 'c', allowed: ['dev', 'stable'])
79 ..addOption('key', abbr: 'k');
80 final options = parser.parse(args);
81 final revision = options['revision'];
82 final channel = options['channel'];
83 final sshWrapper = Platform.script.resolve('ssh_with_key').toFilePath();
84 gitEnvironment = {'GIT_SSH': sshWrapper,
85 'SSH_KEY_PATH': options['key']};
86
87 Directory.systemTemp.createTemp('update_homebrew')
88 .then((tempDir) {
89 repository = tempDir.path;
90 })
91 .then((_) => runGit(
92 ['clone', 'git@github.com:dart-lang/homebrew-dart.git', '.']))
93 .then((_) => writeHomebrewInfo(channel, revision))
94 .then((_) => runGit(['add', '${channel}_info.rb']))
95 .then((_) => runGit(['commit', '-a', '-m',
96 'Updated $channel branch to revision $revision']))
97 .then((_) => runGit(['push']))
98 .whenComplete(() => new Directory(repository).delete(recursive: true));
99 }
OLDNEW
« no previous file with comments | « tools/apps/update_homebrew/bin/ssh_with_key ('k') | tools/apps/update_homebrew/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698