Skip to content

Commit c05c8c6

Browse files
committed
Revert change to Platform.excutable and add Platform.resolvedExecutable
The change to Platform.excutable in e03ab17 was a breaking change and it has been reverted. A new getter Platform.resolvedExecutable has been added to provide the the fully qualified path of the executable. BUG=#16994 [email protected], [email protected], [email protected] Review URL: https://codereview.chromium.org//1180623006.
1 parent 9d3e7c3 commit c05c8c6

File tree

10 files changed

+68
-29
lines changed

10 files changed

+68
-29
lines changed

runtime/bin/io_natives.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ namespace bin {
4040
V(Platform_PathSeparator, 0) \
4141
V(Platform_LocalHostname, 0) \
4242
V(Platform_ExecutableName, 0) \
43+
V(Platform_ResolvedExecutableName, 0) \
4344
V(Platform_Environment, 0) \
4445
V(Platform_ExecutableArguments, 0) \
4546
V(Platform_PackageRoot, 0) \

runtime/bin/platform.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace dart {
1313
namespace bin {
1414

1515
const char* Platform::executable_name_ = NULL;
16-
bool Platform::executable_name_resolved_ = false;
16+
const char* Platform::resolved_executable_name_ = NULL;
1717
const char* Platform::package_root_ = NULL;
1818
int Platform::script_index_ = 1;
1919
char** Platform::argv_ = NULL;
@@ -51,6 +51,16 @@ void FUNCTION_NAME(Platform_ExecutableName)(Dart_NativeArguments args) {
5151
}
5252

5353

54+
void FUNCTION_NAME(Platform_ResolvedExecutableName)(Dart_NativeArguments args) {
55+
if (Platform::GetResolvedExecutableName() != NULL) {
56+
Dart_SetReturnValue(
57+
args, Dart_NewStringFromCString(Platform::GetResolvedExecutableName()));
58+
} else {
59+
Dart_SetReturnValue(args, Dart_Null());
60+
}
61+
}
62+
63+
5464
void FUNCTION_NAME(Platform_ExecutableArguments)(Dart_NativeArguments args) {
5565
int end = Platform::GetScriptIndex();
5666
char** argv = Platform::GetArgv();

runtime/bin/platform.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,14 @@ class Platform {
4646
executable_name_ = executable_name;
4747
}
4848
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) {
5053
// 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;
54+
resolved_executable_name_ = Platform::ResolveExecutablePath();
5655
}
57-
return executable_name_;
56+
return resolved_executable_name_;
5857
}
5958

6059
// Stores and gets the package root.
@@ -80,8 +79,8 @@ class Platform {
8079
private:
8180
// The path to the executable.
8281
static const char* executable_name_;
83-
// State to indicate whether the executable name has been resolved.
84-
static bool executable_name_resolved_;
82+
// The path to the resolved executable.
83+
static const char* resolved_executable_name_;
8584

8685
static const char* package_root_;
8786
static int script_index_;

runtime/bin/platform_patch.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ patch class _Platform {
1010
native "Platform_OperatingSystem";
1111
/* patch */ static _localHostname() native "Platform_LocalHostname";
1212
/* patch */ static _executable() native "Platform_ExecutableName";
13+
/* patch */ static _resolvedExecutable()
14+
native "Platform_ResolvedExecutableName";
1315
/* patch */ static _environment() native "Platform_Environment";
1416
/* patch */ static List<String> _executableArguments()
1517
native "Platform_ExecutableArguments";

sdk/lib/_internal/compiler/js_lib/io_patch.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ class _Platform {
221221
throw new UnsupportedError("Platform._executable");
222222
}
223223
@patch
224+
static _resolvedExecutable() {
225+
throw new UnsupportedError("Platform._resolvedExecutable");
226+
}
227+
@patch
224228
static List<String> _executableArguments() {
225229
throw new UnsupportedError("Platform._executableArguments");
226230
}

sdk/lib/io/platform.dart

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,24 @@ class Platform {
131131
* Returns the path of the executable used to run the script in this
132132
* isolate.
133133
*
134-
* If supported by the platform the returned path will be absolute.
134+
* The path returned is the literal path used to run the script. This
135+
* path might be relative or just be a name from which the executable
136+
* was found by searching the `PATH`.
135137
*
136-
* If the execution environment does not support [executable] an empty
137-
* string is returned.
138+
* To get the absolute path to the resolved executable use
139+
* [resolvedExecutable].
138140
*/
139141
static String get executable => _Platform.executable;
140142

143+
/**
144+
* Returns the path of the executable used to run the script in this
145+
* isolate after it has been resolved by the OS.
146+
*
147+
* This is the absolute path, with all symlinks resolved, to the
148+
* executable used to run the script.
149+
*/
150+
static String get resolvedExecutable => _Platform.resolvedExecutable;
151+
141152
/**
142153
* Returns the absolute URI of the script being run in this
143154
* isolate.

sdk/lib/io/platform_impl.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class _Platform {
1010
external static String _operatingSystem();
1111
external static _localHostname();
1212
external static _executable();
13+
external static _resolvedExecutable();
1314
/**
1415
* Retrieve the entries of the process environment.
1516
*
@@ -31,6 +32,7 @@ class _Platform {
3132
external static String _version();
3233

3334
static String executable = _executable();
35+
static String resolvedExecutable = _resolvedExecutable();
3436
static String packageRoot = _packageRoot();
3537

3638
// Cache the OS environemnt. This can be an OSError instance if

tests/standalone/io/platform_executable_test.dart renamed to tests/standalone/io/platform_resolved_executable_test.dart

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void verify(String exePath, {String altPath}) {
3535
}
3636

3737
var result = processResult.stdout.trim();
38-
expectEquals(Platform.executable, result);
38+
expectEquals(Platform.resolvedExecutable, result);
3939
}
4040

4141
void testDartExecShouldNotBeInCurrentDir() {
@@ -51,20 +51,20 @@ void testShouldSucceedWithEmptyPathEnvironment() {
5151
}
5252

5353
void testShouldSucceedWithSourcePlatformExecutable() {
54-
verify(Platform.executable);
54+
verify(Platform.resolvedExecutable);
5555
}
5656

5757
void testExeSymLinked(Directory dir) {
5858
var dirUri = new Uri.directory(dir.path);
5959
var link = new Link.fromUri(dirUri.resolve('dart_exe_link'));
60-
link.createSync(Platform.executable);
60+
link.createSync(Platform.resolvedExecutable);
6161
verify(link.path);
6262
}
6363

6464
void testPathToDirWithExeSymLinked(Directory dir) {
6565
var dirUri = new Uri.directory(dir.path);
6666
var link = new Link.fromUri(dirUri.resolve('dart_exe_link'));
67-
link.createSync(Platform.executable);
67+
link.createSync(Platform.resolvedExecutable);
6868
verify('dart_exe_link', altPath: dir.path);
6969
}
7070

@@ -75,7 +75,7 @@ void testExeDirSymLinked(Directory dir) {
7575
var linkDirUri = dirUri.resolve('dart_bin_dir_link');
7676
var link = new Link.fromUri(linkDirUri);
7777

78-
var exeFile = new File(Platform.executable);
78+
var exeFile = new File(Platform.resolvedExecutable);
7979

8080
link.createSync(exeFile.parent.path);
8181

@@ -91,15 +91,15 @@ void testPathPointsToSymLinkedSDKPath(Directory dir) {
9191
var linkDirUri = dirUri.resolve('dart_bin_dir_link');
9292
var link = new Link.fromUri(linkDirUri);
9393

94-
var exeFile = new File(Platform.executable);
94+
var exeFile = new File(Platform.resolvedExecutable);
9595

9696
link.createSync(exeFile.parent.path);
9797

9898
verify(platformExeName, altPath: link.path);
9999
}
100100

101101
void testPathToSDKDir() {
102-
var exeFile = new File(Platform.executable);
102+
var exeFile = new File(Platform.resolvedExecutable);
103103
var binDirPath = exeFile.parent.path;
104104

105105
verify(platformExeName, altPath: binDirPath);
@@ -115,15 +115,19 @@ void withTempDir(void test(Directory dir)) {
115115
}
116116

117117
String get platformExeName {
118-
var raw = new Uri.file(Platform.executable);
118+
var raw = new Uri.file(Platform.resolvedExecutable);
119119
return raw.pathSegments.last;
120120
}
121121

122122
String get scriptPath => Platform.script.toFilePath();
123123

124124
void main() {
125+
// The same script is used for both running the tests and as for starting
126+
// child verifying the value of Platform.resolvedExecutable. If the
127+
// environment variable _SCRIPT_KEY is set this is a child process which
128+
// should print the value of Platform.resolvedExecutable.
125129
if (Platform.environment.containsKey(_SCRIPT_KEY)) {
126-
print(Platform.executable);
130+
print(Platform.resolvedExecutable);
127131
return;
128132
}
129133

tests/standalone/io/platform_test.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,15 @@ test() {
2424
Expect.isTrue(hostname is String && hostname != "");
2525
var environment = Platform.environment;
2626
Expect.isTrue(environment is Map<String, String>);
27-
Expect.isTrue(Platform.executable.contains('dart'));
2827
if (!Platform.isWindows) {
29-
Expect.isTrue(Platform.executable.startsWith('/'));
28+
Expect.isTrue(Platform.executable.endsWith('dart'));
29+
Expect.isTrue(Platform.resolvedExecutable.endsWith('dart'));
30+
} else {
31+
Expect.isTrue(Platform.executable.endsWith('dart.exe'));
32+
Expect.isTrue(Platform.resolvedExecutable.endsWith('dart.exe'));
33+
}
34+
if (!Platform.isWindows) {
35+
Expect.isTrue(Platform.resolvedExecutable.startsWith('/'));
3036
} else {
3137
// This assumes that tests (both locally and on the bots) are
3238
// running off a location referred to by a drive letter. If a UNC

tests/standalone/standalone.status

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ io/directory_fuzz_test: Skip
3535
# This is expected as MacOS by default runs with a very low number
3636
# of allowed open files ('ulimit -n' says something like 256).
3737
io/socket_many_connections_test: Skip
38-
io/platform_executable_test/06: RuntimeError
38+
io/platform_resolved_executable_test/06: RuntimeError
3939

4040
[ $compiler == none && ($runtime == drt || $runtime == dartium || $runtime == ContentShellOnAndroid) ]
4141
typed_array_test: Fail # Issue 13921
@@ -211,10 +211,10 @@ io/issue_22637_test: Crash # (test()async{server=... cannot handle async/sync*/
211211
io/link_test: Crash # Instance of 'TypeOperator': type check unimplemented for _Nullary.
212212
io/link_uri_test: Crash # Instance of 'TypeOperator': type check unimplemented for _Nullary.
213213
io/observatory_test: Crash # Instance of 'TypeOperator': type check unimplemented for _Nullary.
214-
io/platform_executable_test/01: Crash # (try {test(tempDir);}finally {tempDir.deleteSync(recursive:true);}): try/finally
215-
io/platform_executable_test/02: Crash # (try {test(tempDir);}finally {tempDir.deleteSync(recursive:true);}): try/finally
216-
io/platform_executable_test/04: Crash # (try {test(tempDir);}finally {tempDir.deleteSync(recursive:true);}): try/finally
217-
io/platform_executable_test/05: Crash # (try {test(tempDir);}finally {tempDir.deleteSync(recursive:true);}): try/finally
214+
io/platform_resolved_executable_test/01: Crash # (try {test(tempDir);}finally {tempDir.deleteSync(recursive:true);}): try/finally
215+
io/platform_resolved_executable_test/02: Crash # (try {test(tempDir);}finally {tempDir.deleteSync(recursive:true);}): try/finally
216+
io/platform_resolved_executable_test/04: Crash # (try {test(tempDir);}finally {tempDir.deleteSync(recursive:true);}): try/finally
217+
io/platform_resolved_executable_test/05: Crash # (try {test(tempDir);}finally {tempDir.deleteSync(recursive:true);}): try/finally
218218
io/platform_test: Crash # Instance of 'TypeOperator': type check unimplemented for _Nullary.
219219
io/process_invalid_arguments_test: Crash # Instance of 'TypeOperator': type check unimplemented for _Nullary.
220220
io/raw_datagram_socket_test: Crash # (switch (event){case... Unhandled node

0 commit comments

Comments
 (0)