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

Side by Side Diff: runtime/bin/platform.h

Issue 1145053002: Make Platform.executable return a fully qualified path the the executable (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Addressed review comments Created 5 years, 7 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
« no previous file with comments | « no previous file | runtime/bin/platform.cc » ('j') | runtime/bin/platform_android.cc » ('J')
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 #ifndef BIN_PLATFORM_H_ 5 #ifndef BIN_PLATFORM_H_
6 #define BIN_PLATFORM_H_ 6 #define BIN_PLATFORM_H_
7 7
8 #include "bin/builtin.h" 8 #include "bin/builtin.h"
9 9
10 10
(...skipping 21 matching lines...) Expand all
32 // Extracts the local hostname. 32 // Extracts the local hostname.
33 static bool LocalHostname(char* buffer, intptr_t buffer_length); 33 static bool LocalHostname(char* buffer, intptr_t buffer_length);
34 34
35 // Extracts the environment variables for the current process. The 35 // Extracts the environment variables for the current process. The
36 // array of strings returned must be deallocated using 36 // array of strings returned must be deallocated using
37 // FreeEnvironment. The number of elements in the array is returned 37 // FreeEnvironment. The number of elements in the array is returned
38 // in the count argument. 38 // in the count argument.
39 static char** Environment(intptr_t* count); 39 static char** Environment(intptr_t* count);
40 static void FreeEnvironment(char** env, intptr_t count); 40 static void FreeEnvironment(char** env, intptr_t count);
41 41
42 // Stores and gets the executable name. 42 static char* ResolveExecutablePath();
43
44 // Stores the executable name.
43 static void SetExecutableName(const char* executable_name) { 45 static void SetExecutableName(const char* executable_name) {
44 executable_name_ = executable_name; 46 executable_name_ = executable_name;
45 } 47 }
46 static const char* GetExecutableName() { 48 static const char* GetExecutableName() {
49 if (!executable_name_resolved_) {
50 // Try to resolve the executable path using platform specific APIs.
51 char* path = Platform::ResolveExecutablePath();
52 if (path != NULL) {
53 executable_name_ = path;
54 }
55 executable_name_resolved_ = true;
56 }
47 return executable_name_; 57 return executable_name_;
48 } 58 }
49 59
50 // Stores and gets the package root. 60 // Stores and gets the package root.
51 static void SetPackageRoot(const char* package_root) { 61 static void SetPackageRoot(const char* package_root) {
52 package_root_ = package_root; 62 package_root_ = package_root;
53 } 63 }
54 static const char* GetPackageRoot() { 64 static const char* GetPackageRoot() {
55 return package_root_; 65 return package_root_;
56 } 66 }
57 67
58 // Stores and gets the flags passed to the executable. 68 // Stores and gets the flags passed to the executable.
59 static void SetExecutableArguments(int script_index, char** argv) { 69 static void SetExecutableArguments(int script_index, char** argv) {
60 script_index_ = script_index; 70 script_index_ = script_index;
61 argv_ = argv; 71 argv_ = argv;
62 } 72 }
63 static int GetScriptIndex() { 73 static int GetScriptIndex() {
64 return script_index_; 74 return script_index_;
65 } 75 }
66 static char** GetArgv() { 76 static char** GetArgv() {
67 return argv_; 77 return argv_;
68 } 78 }
69 79
70 private: 80 private:
81 // The path to the executable.
71 static const char* executable_name_; 82 static const char* executable_name_;
83 // State to indicate whether the executable name has been resolved.
84 static bool executable_name_resolved_;
85
72 static const char* package_root_; 86 static const char* package_root_;
73 static int script_index_; 87 static int script_index_;
74 static char** argv_; // VM flags are argv_[1 ... script_index_ - 1] 88 static char** argv_; // VM flags are argv_[1 ... script_index_ - 1]
75 89
76 DISALLOW_ALLOCATION(); 90 DISALLOW_ALLOCATION();
77 DISALLOW_IMPLICIT_CONSTRUCTORS(Platform); 91 DISALLOW_IMPLICIT_CONSTRUCTORS(Platform);
78 }; 92 };
79 93
80 } // namespace bin 94 } // namespace bin
81 } // namespace dart 95 } // namespace dart
82 96
83 #endif // BIN_PLATFORM_H_ 97 #endif // BIN_PLATFORM_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/platform.cc » ('j') | runtime/bin/platform_android.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698