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

Side by Side Diff: utils/pub/io.dart

Issue 12285010: Support relative paths in path dependencies. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Tweak some comments. Created 7 years, 10 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 | « utils/pub/hosted_source.dart ('k') | utils/pub/lock_file.dart » ('j') | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /// Helper functionality to make working with IO easier. 5 /// Helper functionality to make working with IO easier.
6 library io; 6 library io;
7 7
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:io'; 9 import 'dart:io';
10 import 'dart:isolate'; 10 import 'dart:isolate';
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 257
258 // Wait a bit and try again. 258 // Wait a bit and try again.
259 log.fine("Operation failed, retrying (attempt $attempts)."); 259 log.fine("Operation failed, retrying (attempt $attempts).");
260 return sleep(500).then(makeAttempt); 260 return sleep(500).then(makeAttempt);
261 }); 261 });
262 } 262 }
263 263
264 return makeAttempt(null); 264 return makeAttempt(null);
265 } 265 }
266 266
267 /// Creates a new symlink that creates an alias from [from] to [to]. Returns a 267 /// Creates a new symlink at path [symlink] that points to [target]. Returns a
268 /// [Future] which completes to the symlink file (i.e. [to]). 268 /// [Future] which completes to the path to the symlink file.
269 ///
270 /// If [relative] is true, creates a symlink with a relative path from the
271 /// symlink to the target. Otherwise, uses the [target] path unmodified.
269 /// 272 ///
270 /// Note that on Windows, only directories may be symlinked to. 273 /// Note that on Windows, only directories may be symlinked to.
271 Future<String> createSymlink(String from, String to) { 274 Future<String> createSymlink(String target, String symlink,
272 log.fine("Creating symlink ($to is a symlink to $from)"); 275 {bool relative: false}) {
276 if (relative) {
277 target = path.normalize(path.relative(target, from: path.dirname(symlink)));
278 }
279
280 log.fine("Creating $symlink pointing to $target");
273 281
274 var command = 'ln'; 282 var command = 'ln';
275 var args = ['-s', from, to]; 283 var args = ['-s', target, symlink];
276 284
277 if (Platform.operatingSystem == 'windows') { 285 if (Platform.operatingSystem == 'windows') {
278 // Call mklink on Windows to create an NTFS junction point. Only works on 286 // Call mklink on Windows to create an NTFS junction point. Only works on
279 // Vista or later. (Junction points are available earlier, but the "mklink" 287 // Vista or later. (Junction points are available earlier, but the "mklink"
280 // command is not.) I'm using a junction point (/j) here instead of a soft 288 // command is not.) I'm using a junction point (/j) here instead of a soft
281 // link (/d) because the latter requires some privilege shenanigans that 289 // link (/d) because the latter requires some privilege shenanigans that
282 // I'm not sure how to specify from the command line. 290 // I'm not sure how to specify from the command line.
283 command = 'mklink'; 291 command = 'mklink';
284 args = ['/j', to, from]; 292 args = ['/j', symlink, target];
285 } 293 }
286 294
287 // TODO(rnystrom): Check exit code and output? 295 // TODO(rnystrom): Check exit code and output?
288 return runProcess(command, args).then((result) => to); 296 return runProcess(command, args).then((result) => symlink);
289 } 297 }
290 298
291 /// Creates a new symlink that creates an alias from the `lib` directory of 299 /// Creates a new symlink that creates an alias at [symlink] that points to the
292 /// package [from] to [to]. Returns a [Future] which completes to the symlink 300 /// `lib` directory of package [target]. Returns a [Future] which completes to
293 /// file (i.e. [to]). If [from] does not have a `lib` directory, this shows a 301 /// the path to the symlink file. If [target] does not have a `lib` directory,
294 /// warning if appropriate and then does nothing. 302 /// this shows a warning if appropriate and then does nothing.
295 Future<String> createPackageSymlink(String name, String from, String to, 303 ///
296 {bool isSelfLink: false}) { 304 /// If [relative] is true, creates a symlink with a relative path from the
305 /// symlink to the target. Otherwise, uses the [target] path unmodified.
306 Future<String> createPackageSymlink(String name, String symlink, String target,
307 {bool isSelfLink: false, bool relative: false}) {
297 return defer(() { 308 return defer(() {
298 // See if the package has a "lib" directory. 309 // See if the package has a "lib" directory.
299 from = path.join(from, 'lib'); 310 target = path.join(target, 'lib');
300 log.fine("Creating ${isSelfLink ? "self" : ""}link for package '$name'."); 311 log.fine("Creating ${isSelfLink ? "self" : ""}link for package '$name'.");
301 if (dirExists(from)) return createSymlink(from, to); 312 if (dirExists(target)) {
313 return createSymlink(target, symlink, relative: relative);
314 }
302 315
303 // It's OK for the self link (i.e. the root package) to not have a lib 316 // It's OK for the self link (i.e. the root package) to not have a lib
304 // directory since it may just be a leaf application that only has 317 // directory since it may just be a leaf application that only has
305 // code in bin or web. 318 // code in bin or web.
306 if (!isSelfLink) { 319 if (!isSelfLink) {
307 log.warning('Warning: Package "$name" does not have a "lib" directory so ' 320 log.warning('Warning: Package "$name" does not have a "lib" directory so '
308 'you will not be able to import any libraries from it.'); 321 'you will not be able to import any libraries from it.');
309 } 322 }
310 323
311 return to; 324 return symlink;
312 }); 325 });
313 } 326 }
314 327
315 /// Resolves [target] relative to the location of pub.dart. 328 /// Resolves [target] relative to the location of pub.dart.
316 String relativeToPub(String target) { 329 String relativeToPub(String target) {
317 var scriptPath = new File(new Options().script).fullPathSync(); 330 var scriptPath = new File(new Options().script).fullPathSync();
318 331
319 // Walk up until we hit the "util(s)" directory. This lets us figure out where 332 // Walk up until we hit the "util(s)" directory. This lets us figure out where
320 // we are if this function is called from pub.dart, or one of the tests, 333 // we are if this function is called from pub.dart, or one of the tests,
321 // which also live under "utils", or from the SDK where pub is in "util". 334 // which also live under "utils", or from the SDK where pub is in "util".
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 const PubProcessResult(this.stdout, this.stderr, this.exitCode); 873 const PubProcessResult(this.stdout, this.stderr, this.exitCode);
861 874
862 bool get success => exitCode == 0; 875 bool get success => exitCode == 0;
863 } 876 }
864 877
865 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. 878 /// Gets a [Uri] for [uri], which can either already be one, or be a [String].
866 Uri _getUri(uri) { 879 Uri _getUri(uri) {
867 if (uri is Uri) return uri; 880 if (uri is Uri) return uri;
868 return Uri.parse(uri); 881 return Uri.parse(uri);
869 } 882 }
OLDNEW
« no previous file with comments | « utils/pub/hosted_source.dart ('k') | utils/pub/lock_file.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698