Skip to content

Commit 306bec3

Browse files
committed
fix: Add FileModifiedCallback
Used by the kernel during hot reloading to determine what to reload. When it's not set, hot reload takes a long time. Prepare some methods for eventual environment setup.
1 parent 6f28908 commit 306bec3

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

Diff for: src/dart_dll.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <bin/dartutils.h>
1010
#include <bin/dfe.h>
11+
#include <bin/file.h>
1112
#include <bin/gzip.h>
1213
#include <bin/loader.h>
1314
#include <bin/isolate_data.h>
@@ -30,6 +31,21 @@ extern const uint8_t* observatory_assets_archive;
3031
} // namespace bin
3132
} // namespace dart
3233

34+
static bool FileModifiedCallback(const char* url, int64_t since) {
35+
auto path = File::UriToPath(url);
36+
if (path == nullptr) {
37+
// If it isn't a file on local disk, we don't know if it has been
38+
// modified.
39+
return true;
40+
}
41+
int64_t data[File::kStatSize];
42+
File::Stat(nullptr, path.get(), data);
43+
if (data[File::kType] == File::kDoesNotExist) {
44+
return true;
45+
}
46+
return data[File::kModifiedTime] > since;
47+
}
48+
3349
Dart_Handle GetVMServiceAssetsArchiveCallback() {
3450
uint8_t* decompressed = NULL;
3551
intptr_t decompressed_len = 0;
@@ -161,6 +177,8 @@ bool DartDll_Initialize(const DartDllConfig& config) {
161177
std::cout << "Dart initialized, error was: "
162178
<< (initError != nullptr ? initError : "null") << std::endl;
163179

180+
Dart_SetFileModifiedCallback(&FileModifiedCallback);
181+
164182
return true;
165183
}
166184

Diff for: src/isolate_setup.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ Dart_Handle SetupCoreLibraries(Dart_Isolate isolate,
6969
}
7070
}
7171

72+
result = Dart_SetEnvironmentCallback(DartUtils::EnvironmentCallback);
73+
if (Dart_IsError(result)) return result;
74+
7275
// Setup the native resolver as the snapshot does not carry it.
7376
Builtin::SetNativeResolver(Builtin::kBuiltinLibrary);
7477
Builtin::SetNativeResolver(Builtin::kIOLibrary);
@@ -160,7 +163,11 @@ Dart_Isolate CreateVmServiceIsolate(const char* script_uri,
160163
return nullptr;
161164
}
162165

163-
// TODO -- Dart_SetEnvironmentCallback(DartUtils::EnvironmentCallback)
166+
Dart_EnterIsolate(isolate);
167+
Dart_EnterScope();
168+
Dart_SetEnvironmentCallback(DartUtils::EnvironmentCallback);
169+
Dart_ExitScope();
170+
Dart_ExitIsolate();
164171

165172
return isolate;
166173
}

0 commit comments

Comments
 (0)