| OLD | NEW |
| 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 28 matching lines...) Expand all Loading... |
| 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 static char* ResolveExecutablePath(); | 42 static char* ResolveExecutablePath(); |
| 43 | 43 |
| 44 // Stores the executable name. | 44 // Stores the executable name. |
| 45 static void SetExecutableName(const char* executable_name) { | 45 static void SetExecutableName(const char* executable_name) { |
| 46 executable_name_ = executable_name; | 46 executable_name_ = executable_name; |
| 47 } | 47 } |
| 48 static const char* GetExecutableName() { | 48 static const char* GetExecutableName() { |
| 49 if (!executable_name_resolved_) { | 49 return executable_name_; |
| 50 } |
| 51 static const char* GetResolvedExecutableName() { |
| 52 if (resolved_executable_name_ == NULL) { |
| 50 // Try to resolve the executable path using platform specific APIs. | 53 // Try to resolve the executable path using platform specific APIs. |
| 51 char* path = Platform::ResolveExecutablePath(); | 54 resolved_executable_name_ = Platform::ResolveExecutablePath(); |
| 52 if (path != NULL) { | |
| 53 executable_name_ = path; | |
| 54 } | |
| 55 executable_name_resolved_ = true; | |
| 56 } | 55 } |
| 57 return executable_name_; | 56 return resolved_executable_name_; |
| 58 } | 57 } |
| 59 | 58 |
| 60 // Stores and gets the package root. | 59 // Stores and gets the package root. |
| 61 static void SetPackageRoot(const char* package_root) { | 60 static void SetPackageRoot(const char* package_root) { |
| 62 package_root_ = package_root; | 61 package_root_ = package_root; |
| 63 } | 62 } |
| 64 static const char* GetPackageRoot() { | 63 static const char* GetPackageRoot() { |
| 65 return package_root_; | 64 return package_root_; |
| 66 } | 65 } |
| 67 | 66 |
| 68 // Stores and gets the flags passed to the executable. | 67 // Stores and gets the flags passed to the executable. |
| 69 static void SetExecutableArguments(int script_index, char** argv) { | 68 static void SetExecutableArguments(int script_index, char** argv) { |
| 70 script_index_ = script_index; | 69 script_index_ = script_index; |
| 71 argv_ = argv; | 70 argv_ = argv; |
| 72 } | 71 } |
| 73 static int GetScriptIndex() { | 72 static int GetScriptIndex() { |
| 74 return script_index_; | 73 return script_index_; |
| 75 } | 74 } |
| 76 static char** GetArgv() { | 75 static char** GetArgv() { |
| 77 return argv_; | 76 return argv_; |
| 78 } | 77 } |
| 79 | 78 |
| 80 private: | 79 private: |
| 81 // The path to the executable. | 80 // The path to the executable. |
| 82 static const char* executable_name_; | 81 static const char* executable_name_; |
| 83 // State to indicate whether the executable name has been resolved. | 82 // The path to the resolved executable. |
| 84 static bool executable_name_resolved_; | 83 static const char* resolved_executable_name_; |
| 85 | 84 |
| 86 static const char* package_root_; | 85 static const char* package_root_; |
| 87 static int script_index_; | 86 static int script_index_; |
| 88 static char** argv_; // VM flags are argv_[1 ... script_index_ - 1] | 87 static char** argv_; // VM flags are argv_[1 ... script_index_ - 1] |
| 89 | 88 |
| 90 DISALLOW_ALLOCATION(); | 89 DISALLOW_ALLOCATION(); |
| 91 DISALLOW_IMPLICIT_CONSTRUCTORS(Platform); | 90 DISALLOW_IMPLICIT_CONSTRUCTORS(Platform); |
| 92 }; | 91 }; |
| 93 | 92 |
| 94 } // namespace bin | 93 } // namespace bin |
| 95 } // namespace dart | 94 } // namespace dart |
| 96 | 95 |
| 97 #endif // BIN_PLATFORM_H_ | 96 #endif // BIN_PLATFORM_H_ |
| OLD | NEW |