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

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: 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_repo;
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 void check(String message, bool condition) {
19 if (!condition) {
20 print(message);
21 exit(1);
22 }
23 }
24
25 int firstIndexWhere(List l, bool test(e)) {
26 for (int i = 0; i < l.length; ++i) {
27 if (test(l[i])) return i;
28 }
29 return -1;
30 }
31
32 Future<String> getHash256(String channel, int revision, String download) {
33 var client = new http.Client();
34 var api = new storage.StorageApi(client);
35 return
36 api.objects.get('dart-archive',
37 'channels/$channel/release/$revision/$download.sha256sum',
38 downloadOptions: DownloadOptions.FullMedia)
39 .then((Media media) => ASCII.decodeStream(media.stream))
40 .whenComplete(client.close);
41 }
42
43 Future<String> getVersion(String channel, int revision) {
44 var client = new http.Client();
45 var api = new storage.StorageApi(client);
46 return api.objects.get('dart-archive',
47 'channels/$channel/release/$revision/VERSION',
48 downloadOptions: DownloadOptions.FullMedia)
49 .then((Media media) => JSON.fuse(ASCII).decoder.bind(media.stream).first)
50 .then((versionObject) => versionObject['version'])
51 .whenComplete(client.close);
52 }
53
54 Future modifyHomebrewFormulas(String channel, int revision) {
Søren Gjesse 2014/09/26 08:55:00 Wouldn't it be easier to have the full Ruby source
55 // Read script to lines, from file
56 Future<List<String>> getLines(String filename) {
57 final file = new File('$repository/$filename');
58 final lines = ASCII.decoder.fuse(new LineSplitter()).bind(file.openRead());
59 return lines.toList();
60 }
61
62 // Modify url, sha256, version lines
63 Future<List<String>> modifyLines(List<String> lines, String download) {
64 final int pos = firstIndexWhere(lines, (line) => line.contains(
65 "url 'https://storage.googleapis.com/dart-archive/channels/$channel")
66 && line.contains(download));
67 check("URL line not found", pos >= 0);
68 check("Version line not found", lines[pos - 1].contains("version '"));
69 check("sha256 line not found", lines[pos + 1].contains("sha256 '"));
70
71 final indent = new RegExp('^\\s*').stringMatch(lines[pos]);
72 lines[pos] =
73 "${indent}url 'https://storage.googleapis.com/dart-archive/channels/"
74 "$channel/release/$revision/$download'";
75 return getHash256(channel, revision, download)
76 .then((hashLine) {
77 final hash = new RegExp('[0-9a-fA-F]*').stringMatch(hashLine);
78 lines[pos + 1] = "${indent}sha256 '$hash'";
79 })
80 .then((_) => getVersion(channel, revision))
81 .then((version) {
82 lines[pos - 1] = "${indent}version '$version'";
83 return lines;
84 });
85 }
86
87 Future saveLines(List<String> lines, String filename) {
88 final file = new File('$repository/$filename');
89 return (file.openWrite()..writeAll(lines, '\n')..write('\n')).close();
90 }
91
92 // Write lines to file
93 return getLines('dartium.rb')
94 .then((lines) =>
95 modifyLines(lines, 'dartium/dartium-macos-ia32-release.zip'))
96 .then((lines) => saveLines(lines, 'dartium.rb'))
97 .then((_) => getLines('dart.rb'))
98 .then((lines) => modifyLines(lines, 'sdk/dartsdk-macos-x64-release.zip'))
99 .then((lines) => modifyLines(lines, 'sdk/dartsdk-macos-ia32-release.zip'))
100 .then((lines) => saveLines(lines, 'dart.rb'));
101 }
102
103 Future runGit(List<String> args) {
104 print("git ${args.join(' ')}");
105 return Process.run('git', args, workingDirectory: repository,
106 environment: gitEnvironment)
107 .then((result) {
108 print(result.stdout);
109 print(result.stderr);
110 });
111 }
112
113 main(args) {
114 final parser = new ArgParser()
115 ..addOption('revision', abbr: 'r')
116 ..addOption('channel', abbr: 'c', allowed: ['dev', 'stable'])
117 ..addOption('key', abbr: 'k');
118 final options = parser.parse(args);
119 final revision = options['revision'];
120 final channel = options['channel'];
121 final sshWrapper = Platform.script.resolve('ssh_with_key').toFilePath();
122 gitEnvironment = {'GIT_SSH': sshWrapper,
123 'SSH_KEY_PATH': options['key']};
124
125 Directory.systemTemp.createTemp('update_homebrew')
126 .then((tempDir) {
127 repository = tempDir.path;
128 })
129 .then((_) => runGit(
130 ['clone', 'git@github.com:dart-lang/homebrew-dart.git', '.']))
131 .then((_) => modifyHomebrewFormulas(channel, revision))
132 .then((_) => runGit(['commit', '-a', '-m',
133 'Updated $channel branch to revision $revision']))
134 .then((_) => runGit(['push']))
135 .whenComplete(() => new Directory(repository).delete(recursive: true));
136 }
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