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

Side by Side Diff: pkg/dartino_compiler/lib/src/guess_configuration.dart

Issue 1659163007: Rename fletch -> dartino (Closed) Base URL: https://github.com/dartino/sdk.git@master
Patch Set: address comments Created 4 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
OLDNEW
(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 dartino_compiler.src.guess_configuration;
6
7 import 'dart:io' show
8 File,
9 Link,
10 Platform,
11 Process;
12
13 const String _DARTINO_VM = const String.fromEnvironment("dartino-vm");
14
15 Uri get executable {
16 return Uri.base.resolveUri(new Uri.file(Platform.resolvedExecutable));
17 }
18
19 bool _looksLikeDartinoVm(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 // dartino_compiler.dart
26 Uri guessDartinoVm(Uri dartinoVm, {bool mustExist: true}) {
27 if (dartinoVm == null && _DARTINO_VM != null) {
28 // Use Uri.base here because _DARTINO_VM is a constant relative to the
29 // location of where the Dart VM was started, not relative to the C++
30 // client.
31 dartinoVm = Uri.base.resolve(_DARTINO_VM);
32 } else {
33 Uri uri = executable.resolve('dartino-vm');
34 if (new File.fromUri(uri).existsSync()) {
35 dartinoVm = uri;
36 }
37 }
38 if (dartinoVm == null) {
39 if (!mustExist) return null;
40 throw new StateError("""
41 Unable to guess the location of the dartino VM (dartinoVm).
42 Try adding command-line option '-Ddartino-vm=<path to dartino VM>.""");
43 } else if (!_looksLikeDartinoVm(dartinoVm)) {
44 if (!mustExist) return null;
45 throw new StateError("""
46 No dartino VM at '$dartinoVm'.
47 Try adding command-line option '-Ddartino-vm=<path to dartino VM>.""");
48 }
49 return dartinoVm;
50 }
51
52 String _cachedDartinoVersion;
53
54 String get dartinoVersion {
55 if (_cachedDartinoVersion != null) return _cachedDartinoVersion;
56 _cachedDartinoVersion = const String.fromEnvironment('dartino.version');
57 if (_cachedDartinoVersion != null) return _cachedDartinoVersion;
58 Uri dartinoVm = guessDartinoVm(null, mustExist: false);
59 if (dartinoVm != null) {
60 String vmPath = dartinoVm.toFilePath();
61 return _cachedDartinoVersion =
62 Process.runSync(vmPath, <String>["--version"]).stdout.trim();
63 }
64 return _cachedDartinoVersion = "version information not available";
65 }
OLDNEW
« no previous file with comments | « pkg/dartino_compiler/lib/src/function_codegen.dart ('k') | pkg/dartino_compiler/lib/src/hub/client_commands.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698