Skip to content

Commit 82535a6

Browse files
committed
Resolve the executable path on Mac OS when sym-linked
Don't try to test sym-linked files on Windows as Junctions only support directories. This helps to locate the Dart SDK (if any) from the path of the dart executable. On Linux the use of /proc/self/exe already takes care of this. [email protected] BUG= Review URL: https://codereview.chromium.org//1178643007.
1 parent b652e0f commit 82535a6

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

runtime/bin/platform_win.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "platform/globals.h"
66
#if defined(TARGET_OS_WINDOWS)
77

8+
#include "bin/file.h"
89
#include "bin/platform.h"
910
#include "bin/log.h"
1011
#include "bin/socket.h"
@@ -97,7 +98,10 @@ char* Platform::ResolveExecutablePath() {
9798
}
9899
char* path = StringUtils::WideToUtf8(tmp_buffer);
99100
free(tmp_buffer);
100-
return path;
101+
// Return the canonical path as the returned path might contain symlinks.
102+
char* canon_path = File::GetCanonicalPath(path);
103+
free(path);
104+
return canon_path;
101105
}
102106

103107
} // namespace bin

tests/standalone/io/platform_executable_test.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,30 +44,27 @@ void testDartExecShouldNotBeInCurrentDir() {
4444
}
4545

4646
void testShouldSucceedWithEmptyPathEnvironment() {
47-
var command = Platform.isWindows ? 'dir' : 'ls';
47+
var command = Platform.isWindows ? 'cmd' : 'ls';
4848
Process.runSync(command, [],
4949
includeParentEnvironment: false,
5050
environment: {_SCRIPT_KEY: 'yes', 'PATH': ''});
5151
}
5252

5353
void testShouldSucceedWithSourcePlatformExecutable() {
54-
//print('*** Running normally');
5554
verify(Platform.executable);
5655
}
5756

5857
void testExeSymLinked(Directory dir) {
5958
var dirUri = new Uri.directory(dir.path);
6059
var link = new Link.fromUri(dirUri.resolve('dart_exe_link'));
6160
link.createSync(Platform.executable);
62-
//print('*** Creating a sym-link to the executable');
6361
verify(link.path);
6462
}
6563

6664
void testPathToDirWithExeSymLinked(Directory dir) {
6765
var dirUri = new Uri.directory(dir.path);
6866
var link = new Link.fromUri(dirUri.resolve('dart_exe_link'));
6967
link.createSync(Platform.executable);
70-
//print('*** Path to a directory that contains a sym-link to dart bin');
7168
verify('dart_exe_link', altPath: dir.path);
7269
}
7370

@@ -85,7 +82,6 @@ void testExeDirSymLinked(Directory dir) {
8582
var linkedBin =
8683
new Uri.directory(linkDirUri.toFilePath()).resolve(platformExeName);
8784

88-
//print('*** Running in a sym-linked directory');
8985
verify(linkedBin.toFilePath());
9086
}
9187

@@ -99,15 +95,13 @@ void testPathPointsToSymLinkedSDKPath(Directory dir) {
9995

10096
link.createSync(exeFile.parent.path);
10197

102-
//print('*** Path points to a sym-linked SDK dir');
10398
verify(platformExeName, altPath: link.path);
10499
}
105100

106101
void testPathToSDKDir() {
107102
var exeFile = new File(Platform.executable);
108103
var binDirPath = exeFile.parent.path;
109104

110-
//print('*** Running with PATH env set to environment - fixed in 16994 - thanks!');
111105
verify(platformExeName, altPath: binDirPath);
112106
}
113107

@@ -135,10 +129,16 @@ void main() {
135129

136130
testDartExecShouldNotBeInCurrentDir();
137131
testShouldSucceedWithSourcePlatformExecutable(); /// 00: ok
138-
withTempDir(testExeSymLinked); /// 01: ok
132+
// dart:io does not support linking to files in Windows.
133+
if (!Platform.isWindows) {
134+
withTempDir(testExeSymLinked); /// 01: ok
135+
}
139136
withTempDir(testExeDirSymLinked); /// 02: ok
140137
testPathToSDKDir(); /// 03: ok
141138
withTempDir(testPathPointsToSymLinkedSDKPath); /// 04: ok
142-
withTempDir(testPathToDirWithExeSymLinked); /// 05: ok
139+
// dart:io does not support linking to files in Windows.
140+
if (!Platform.isWindows) {
141+
withTempDir(testPathToDirWithExeSymLinked); /// 05: ok
142+
}
143143
testShouldSucceedWithEmptyPathEnvironment(); /// 06: ok
144144
}

tests/standalone/standalone.status

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@ javascript_compatibility_errors_test/none: Fail, OK # Not possible to exclude o
1717
package/package_isolate_test: Fail # Issue 12474
1818
io/observatory_test: Fail
1919

20-
[ $runtime == vm && $system == windows ]
21-
io/platform_executable_test/01: RuntimeError # Issue 16994
22-
io/platform_executable_test/02: RuntimeError # Issue 16994
23-
io/platform_executable_test/04: RuntimeError # Issue 16994
24-
io/platform_executable_test/05: RuntimeError # Issue 16994
25-
io/platform_executable_test/06: RuntimeError # NEEDS TRIAGE (kevmoo)
26-
2720
[ $runtime == vm && $checked ]
2821
# These tests have type errors on purpose.
2922
io/process_invalid_arguments_test: Fail, OK

0 commit comments

Comments
 (0)