Skip to content

Commit

Permalink
fix: Add FileModifiedCallback
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fuzzybinary committed Oct 4, 2024
1 parent 6f28908 commit 306bec3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/dart_dll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <bin/dartutils.h>
#include <bin/dfe.h>
#include <bin/file.h>
#include <bin/gzip.h>
#include <bin/loader.h>
#include <bin/isolate_data.h>
Expand All @@ -30,6 +31,21 @@ extern const uint8_t* observatory_assets_archive;
} // namespace bin
} // namespace dart

static bool FileModifiedCallback(const char* url, int64_t since) {
auto path = File::UriToPath(url);
if (path == nullptr) {
// If it isn't a file on local disk, we don't know if it has been
// modified.
return true;
}
int64_t data[File::kStatSize];
File::Stat(nullptr, path.get(), data);
if (data[File::kType] == File::kDoesNotExist) {
return true;
}
return data[File::kModifiedTime] > since;
}

Dart_Handle GetVMServiceAssetsArchiveCallback() {
uint8_t* decompressed = NULL;
intptr_t decompressed_len = 0;
Expand Down Expand Up @@ -161,6 +177,8 @@ bool DartDll_Initialize(const DartDllConfig& config) {
std::cout << "Dart initialized, error was: "
<< (initError != nullptr ? initError : "null") << std::endl;

Dart_SetFileModifiedCallback(&FileModifiedCallback);

return true;
}

Expand Down
9 changes: 8 additions & 1 deletion src/isolate_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ Dart_Handle SetupCoreLibraries(Dart_Isolate isolate,
}
}

result = Dart_SetEnvironmentCallback(DartUtils::EnvironmentCallback);
if (Dart_IsError(result)) return result;

// Setup the native resolver as the snapshot does not carry it.
Builtin::SetNativeResolver(Builtin::kBuiltinLibrary);
Builtin::SetNativeResolver(Builtin::kIOLibrary);
Expand Down Expand Up @@ -160,7 +163,11 @@ Dart_Isolate CreateVmServiceIsolate(const char* script_uri,
return nullptr;
}

// TODO -- Dart_SetEnvironmentCallback(DartUtils::EnvironmentCallback)
Dart_EnterIsolate(isolate);
Dart_EnterScope();
Dart_SetEnvironmentCallback(DartUtils::EnvironmentCallback);
Dart_ExitScope();
Dart_ExitIsolate();

return isolate;
}
Expand Down

0 comments on commit 306bec3

Please sign in to comment.