OLD | NEW |
| (Empty) |
1 // Copyright (c) 2015, the Dartino 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.md file. | |
4 | |
5 library fletchc.src.guess_configuration; | |
6 | |
7 import 'dart:io' show | |
8 File, | |
9 Link, | |
10 Platform, | |
11 Process; | |
12 | |
13 const String _FLETCH_VM = const String.fromEnvironment("fletch-vm"); | |
14 | |
15 Uri get executable { | |
16 return Uri.base.resolveUri(new Uri.file(Platform.resolvedExecutable)); | |
17 } | |
18 | |
19 bool _looksLikeFletchVm(Uri uri) { | |
20 return new File.fromUri(uri).existsSync(); | |
21 } | |
22 | |
23 // TODO(zerny): Guessing the VM path should only happen once and only if no | |
24 // prior configuration has happend. Make this a private method in | |
25 // fletch_compiler.dart | |
26 Uri guessFletchVm(Uri fletchVm, {bool mustExist: true}) { | |
27 if (fletchVm == null && _FLETCH_VM != null) { | |
28 // Use Uri.base here because _FLETCH_VM is a constant relative to the | |
29 // location of where the Dart VM was started, not relative to the C++ | |
30 // client. | |
31 fletchVm = Uri.base.resolve(_FLETCH_VM); | |
32 } else { | |
33 Uri uri = executable.resolve('fletch-vm'); | |
34 if (new File.fromUri(uri).existsSync()) { | |
35 fletchVm = uri; | |
36 } | |
37 } | |
38 if (fletchVm == null) { | |
39 if (!mustExist) return null; | |
40 throw new StateError(""" | |
41 Unable to guess the location of the fletch VM (fletchVm). | |
42 Try adding command-line option '-Dfletch-vm=<path to fletch VM>."""); | |
43 } else if (!_looksLikeFletchVm(fletchVm)) { | |
44 if (!mustExist) return null; | |
45 throw new StateError(""" | |
46 No fletch VM at '$fletchVm'. | |
47 Try adding command-line option '-Dfletch-vm=<path to fletch VM>."""); | |
48 } | |
49 return fletchVm; | |
50 } | |
51 | |
52 String _cachedFletchVersion; | |
53 | |
54 String get fletchVersion { | |
55 if (_cachedFletchVersion != null) return _cachedFletchVersion; | |
56 _cachedFletchVersion = const String.fromEnvironment('fletch.version'); | |
57 if (_cachedFletchVersion != null) return _cachedFletchVersion; | |
58 Uri fletchVm = guessFletchVm(null, mustExist: false); | |
59 if (fletchVm != null) { | |
60 String vmPath = fletchVm.toFilePath(); | |
61 return _cachedFletchVersion = | |
62 Process.runSync(vmPath, <String>["--version"]).stdout.trim(); | |
63 } | |
64 return _cachedFletchVersion = "version information not available"; | |
65 } | |
OLD | NEW |