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

Unified 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, 11 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 side-by-side diff with in-line comments
Download patch
Index: pkg/dartino_compiler/lib/src/guess_configuration.dart
diff --git a/pkg/dartino_compiler/lib/src/guess_configuration.dart b/pkg/dartino_compiler/lib/src/guess_configuration.dart
new file mode 100644
index 0000000000000000000000000000000000000000..855c3d10812eb2dbaae23d3ea098b72e1e42a4e4
--- /dev/null
+++ b/pkg/dartino_compiler/lib/src/guess_configuration.dart
@@ -0,0 +1,65 @@
+// Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE.md file.
+
+library dartino_compiler.src.guess_configuration;
+
+import 'dart:io' show
+ File,
+ Link,
+ Platform,
+ Process;
+
+const String _DARTINO_VM = const String.fromEnvironment("dartino-vm");
+
+Uri get executable {
+ return Uri.base.resolveUri(new Uri.file(Platform.resolvedExecutable));
+}
+
+bool _looksLikeDartinoVm(Uri uri) {
+ return new File.fromUri(uri).existsSync();
+}
+
+// TODO(zerny): Guessing the VM path should only happen once and only if no
+// prior configuration has happend. Make this a private method in
+// dartino_compiler.dart
+Uri guessDartinoVm(Uri dartinoVm, {bool mustExist: true}) {
+ if (dartinoVm == null && _DARTINO_VM != null) {
+ // Use Uri.base here because _DARTINO_VM is a constant relative to the
+ // location of where the Dart VM was started, not relative to the C++
+ // client.
+ dartinoVm = Uri.base.resolve(_DARTINO_VM);
+ } else {
+ Uri uri = executable.resolve('dartino-vm');
+ if (new File.fromUri(uri).existsSync()) {
+ dartinoVm = uri;
+ }
+ }
+ if (dartinoVm == null) {
+ if (!mustExist) return null;
+ throw new StateError("""
+Unable to guess the location of the dartino VM (dartinoVm).
+Try adding command-line option '-Ddartino-vm=<path to dartino VM>.""");
+ } else if (!_looksLikeDartinoVm(dartinoVm)) {
+ if (!mustExist) return null;
+ throw new StateError("""
+No dartino VM at '$dartinoVm'.
+Try adding command-line option '-Ddartino-vm=<path to dartino VM>.""");
+ }
+ return dartinoVm;
+}
+
+String _cachedDartinoVersion;
+
+String get dartinoVersion {
+ if (_cachedDartinoVersion != null) return _cachedDartinoVersion;
+ _cachedDartinoVersion = const String.fromEnvironment('dartino.version');
+ if (_cachedDartinoVersion != null) return _cachedDartinoVersion;
+ Uri dartinoVm = guessDartinoVm(null, mustExist: false);
+ if (dartinoVm != null) {
+ String vmPath = dartinoVm.toFilePath();
+ return _cachedDartinoVersion =
+ Process.runSync(vmPath, <String>["--version"]).stdout.trim();
+ }
+ return _cachedDartinoVersion = "version information not available";
+}
« 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