Skip to content

Commit c0e90cb

Browse files
committed
Version 1.11.0-dev.5.3
Cherry-pick 19bb19d to dev Cherry-pick d5a34bd to dev Cherry-pick bbdc57e to dev Cherry-pick bd25e64 to dev Cherry-pick 5cc8fca to dev Cherry-pick ed72caa to dev Cherry-pick 82535a6 to dev Cherry-pick c05c8c6 to dev Cherry-pick f9e8852 to dev Cherry-pick 9a01a22 to dev Cherry-pick 3c85970 to dev
2 parents 23736d3 + 7a01514 commit c0e90cb

14 files changed

+100
-51
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_macos.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <mach-o/dyld.h>
99

10+
#include "bin/file.h"
1011
#include "bin/platform.h"
1112

1213
#include <crt_externs.h> // NOLINT
@@ -91,7 +92,10 @@ char* Platform::ResolveExecutablePath() {
9192
free(path);
9293
return NULL;
9394
}
94-
return path;
95+
// Return the canonical path as the returned path might contain symlinks.
96+
char* canon_path = File::GetCanonicalPath(path);
97+
free(path);
98+
return canon_path;
9599
}
96100

97101
} // namespace bin

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";

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

runtime/vm/dart_api_impl.cc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3182,10 +3182,20 @@ DART_EXPORT Dart_TypedData_Type Dart_GetTypeOfExternalTypedData(
31823182
Dart_Handle object) {
31833183
TRACE_API_CALL(CURRENT_FUNC);
31843184
intptr_t class_id = Api::ClassId(object);
3185-
if (RawObject::IsExternalTypedDataClassId(class_id) ||
3186-
RawObject::IsTypedDataViewClassId(class_id)) {
3185+
if (RawObject::IsExternalTypedDataClassId(class_id)) {
31873186
return GetType(class_id);
31883187
}
3188+
if (RawObject::IsTypedDataViewClassId(class_id)) {
3189+
// Check if data object of the view is external.
3190+
Isolate* isolate = Isolate::Current();
3191+
const Instance& view_obj = Api::UnwrapInstanceHandle(isolate, object);
3192+
ASSERT(!view_obj.IsNull());
3193+
const Instance& data_obj =
3194+
Instance::Handle(isolate, TypedDataView::Data(view_obj));
3195+
if (ExternalTypedData::IsExternalTypedData(data_obj)) {
3196+
return GetType(class_id);
3197+
}
3198+
}
31893199
return Dart_TypedData_kInvalid;
31903200
}
31913201

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: 21 additions & 17 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() {
@@ -60,23 +60,20 @@ void testShouldFailOutsidePath() {
6060
}
6161

6262
void testShouldSucceedWithSourcePlatformExecutable() {
63-
//print('*** Running normally');
64-
verify(Platform.executable);
63+
verify(Platform.resolvedExecutable);
6564
}
6665

6766
void testExeSymLinked(Directory dir) {
6867
var dirUri = new Uri.directory(dir.path);
6968
var link = new Link.fromUri(dirUri.resolve('dart_exe_link'));
70-
link.createSync(Platform.executable);
71-
//print('*** Creating a sym-link to the executable');
69+
link.createSync(Platform.resolvedExecutable);
7270
verify(link.path);
7371
}
7472

7573
void testPathToDirWithExeSymLinked(Directory dir) {
7674
var dirUri = new Uri.directory(dir.path);
7775
var link = new Link.fromUri(dirUri.resolve('dart_exe_link'));
78-
link.createSync(Platform.executable);
79-
//print('*** Path to a directory that contains a sym-link to dart bin');
76+
link.createSync(Platform.resolvedExecutable);
8077
verify('dart_exe_link', altPath: dir.path);
8178
}
8279

@@ -87,14 +84,13 @@ void testExeDirSymLinked(Directory dir) {
8784
var linkDirUri = dirUri.resolve('dart_bin_dir_link');
8885
var link = new Link.fromUri(linkDirUri);
8986

90-
var exeFile = new File(Platform.executable);
87+
var exeFile = new File(Platform.resolvedExecutable);
9188

9289
link.createSync(exeFile.parent.path);
9390

9491
var linkedBin =
9592
new Uri.directory(linkDirUri.toFilePath()).resolve(platformExeName);
9693

97-
//print('*** Running in a sym-linked directory');
9894
verify(linkedBin.toFilePath());
9995
}
10096

@@ -104,19 +100,17 @@ void testPathPointsToSymLinkedSDKPath(Directory dir) {
104100
var linkDirUri = dirUri.resolve('dart_bin_dir_link');
105101
var link = new Link.fromUri(linkDirUri);
106102

107-
var exeFile = new File(Platform.executable);
103+
var exeFile = new File(Platform.resolvedExecutable);
108104

109105
link.createSync(exeFile.parent.path);
110106

111-
//print('*** Path points to a sym-linked SDK dir');
112107
verify(platformExeName, altPath: link.path);
113108
}
114109

115110
void testPathToSDKDir() {
116-
var exeFile = new File(Platform.executable);
111+
var exeFile = new File(Platform.resolvedExecutable);
117112
var binDirPath = exeFile.parent.path;
118113

119-
//print('*** Running with PATH env set to environment - fixed in 16994 - thanks!');
120114
verify(platformExeName, altPath: binDirPath);
121115
}
122116

@@ -130,24 +124,34 @@ void withTempDir(void test(Directory dir)) {
130124
}
131125

132126
String get platformExeName {
133-
var raw = new Uri.file(Platform.executable);
127+
var raw = new Uri.file(Platform.resolvedExecutable);
134128
return raw.pathSegments.last;
135129
}
136130

137131
String get scriptPath => Platform.script.toFilePath();
138132

139133
void main() {
134+
// The same script is used for both running the tests and as for starting
135+
// child verifying the value of Platform.resolvedExecutable. If the
136+
// environment variable _SCRIPT_KEY is set this is a child process which
137+
// should print the value of Platform.resolvedExecutable.
140138
if (Platform.environment.containsKey(_SCRIPT_KEY)) {
141-
print(Platform.executable);
139+
print(Platform.resolvedExecutable);
142140
return;
143141
}
144142

145143
testDartExecShouldNotBeInCurrentDir();
146144
testShouldSucceedWithSourcePlatformExecutable(); /// 00: ok
147-
withTempDir(testExeSymLinked); /// 01: ok
145+
// dart:io does not support linking to files in Windows.
146+
if (!Platform.isWindows) {
147+
withTempDir(testExeSymLinked); /// 01: ok
148+
}
148149
withTempDir(testExeDirSymLinked); /// 02: ok
149150
testPathToSDKDir(); /// 03: ok
150151
withTempDir(testPathPointsToSymLinkedSDKPath); /// 04: ok
151-
withTempDir(testPathToDirWithExeSymLinked); /// 05: ok
152+
// dart:io does not support linking to files in Windows.
153+
if (!Platform.isWindows) {
154+
withTempDir(testPathToDirWithExeSymLinked); /// 05: ok
155+
}
152156
testShouldFailOutsidePath(); /// 06: ok
153157
}

tests/standalone/io/platform_test.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,21 @@ 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
3339
// location is used or long names ("\\?\" prefix) is used this
3440
// needs to be fixed.
35-
Expect.equals(Platform.executable.substring(1, 3), ':\\');
41+
Expect.equals(Platform.resolvedExecutable.substring(1, 3), ':\\');
3642
}
3743
// Move directory to be sure script is correct.
3844
var oldDir = Directory.current;

tests/standalone/standalone.status

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +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 == macos || $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-
26-
[ $runtime == vm && $system == windows ]
27-
io/platform_executable_test/06: RuntimeError # NEEDS TRIAGE (kevmoo)
28-
2920
[ $runtime == vm && $checked ]
3021
# These tests have type errors on purpose.
3122
io/process_invalid_arguments_test: Fail, OK
@@ -167,6 +158,7 @@ package/package_test: CompileTimeError
167158
[ $system == windows ]
168159
io/skipping_dart2js_compilations_test: Fail # Issue 19551.
169160
verbose_gc_to_bmu_test: Skip
161+
io/platform_resolved_executable_test/06: RuntimeError # Issue 23641
170162

171163
[ $arch != ia32 && $arch != x64 && $arch != simarm && $arch != simarmv5te && $mode == debug ]
172164
verified_mem_test: Skip # Not yet implemented.
@@ -219,10 +211,10 @@ io/issue_22637_test: Crash # cannot handle async/sync*/async* functions
219211
io/link_test: Crash # Instance of 'TypeOperator': type check unimplemented for _Nullary.
220212
io/link_uri_test: Crash # Instance of 'TypeOperator': type check unimplemented for _Nullary.
221213
io/observatory_test: Crash # Instance of 'TypeOperator': type check unimplemented for _Nullary.
222-
io/platform_executable_test/01: Crash # (try {test(tempDir);}finally {tempDir.deleteSync(recursive:true);}): try/finally
223-
io/platform_executable_test/02: Crash # (try {test(tempDir);}finally {tempDir.deleteSync(recursive:true);}): try/finally
224-
io/platform_executable_test/04: Crash # (try {test(tempDir);}finally {tempDir.deleteSync(recursive:true);}): try/finally
225-
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
226218
io/platform_test: Crash # Instance of 'TypeOperator': type check unimplemented for _Nullary.
227219
io/process_invalid_arguments_test: Crash # Instance of 'TypeOperator': type check unimplemented for _Nullary.
228220
io/raw_datagram_socket_test: Crash # Unhandled node

tools/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ MAJOR 1
2828
MINOR 11
2929
PATCH 0
3030
PRERELEASE 5
31-
PRERELEASE_PATCH 2
31+
PRERELEASE_PATCH 3

0 commit comments

Comments
 (0)