7#if !defined(DART_PRECOMPILED_RUNTIME)
23#define CHECK_RESULT(result) \
24 if (Dart_IsError(result)) { \
25 ProcessError(Dart_GetError(result), kErrorExitCode); \
26 if (send_port_id != ILLEGAL_PORT) { \
27 Dart_CloseNativePort(send_port_id); \
30 Dart_ShutdownIsolate(); \
37DartDevIsolate::DartDevRunner DartDevIsolate::runner_ =
38 DartDevIsolate::DartDevRunner();
39bool DartDevIsolate::should_run_dart_dev_ =
false;
40bool DartDevIsolate::print_usage_error_ =
false;
41Monitor* DartDevIsolate::DartDevRunner::monitor_ =
new Monitor();
44char** DartDevIsolate::DartDevRunner::script_ =
nullptr;
45char** DartDevIsolate::DartDevRunner::package_config_override_ =
nullptr;
46std::unique_ptr<
char*[], void (*)(
char*[])>
47 DartDevIsolate::DartDevRunner::argv_ =
48 std::unique_ptr<
char*[],
void (*)(
char**)>(
nullptr, [](
char**) {});
49intptr_t DartDevIsolate::DartDevRunner::argc_ = 0;
60 (strcmp(script_uri,
"analyze") == 0) ||
61 (strcmp(script_uri,
"compilation-server") == 0) ||
62 (strcmp(script_uri,
"build") == 0) ||
63 (strcmp(script_uri,
"compile") == 0) ||
64 (strcmp(script_uri,
"create") == 0) ||
65 (strcmp(script_uri,
"development-service") == 0) ||
66 (strcmp(script_uri,
"devtools") == 0) ||
67 (strcmp(script_uri,
"doc") == 0) || (strcmp(script_uri,
"fix") == 0) ||
68 (strcmp(script_uri,
"format") == 0) ||
69 (strcmp(script_uri,
"info") == 0) || (strcmp(script_uri,
"pub") == 0) ||
70 (strcmp(script_uri,
"run") == 0) || (strcmp(script_uri,
"test") == 0) ||
71 (strcmp(script_uri,
"info") == 0) ||
72 (strcmp(script_uri,
"language-server") == 0) ||
73 (strcmp(script_uri,
"tooling-daemon") == 0) ||
75 (strncmp(script_uri,
"http://", 7) != 0) &&
76 (strncmp(script_uri,
"https://", 8) != 0) &&
77 (strncmp(script_uri,
"file://", 7) != 0) &&
78 (strncmp(script_uri,
"package:", 8) != 0) &&
79 (strncmp(script_uri,
"google3://", 10) != 0)));
82CStringUniquePtr DartDevIsolate::TryResolveArtifactPath(
const char* filename) {
94 snapshot_path =
Utils::SCreate(
"%s%s", dir_prefix.get(), filename);
117 return TryResolveArtifactPath(
"dartdev.dart.snapshot");
122 char** packages_file,
125 create_isolate_ = create_isolate;
126 dart_options_ = dart_options;
127 package_config_override_ = packages_file;
132 if (print_usage_error_) {
133 dart_options_->
Reset();
139 reinterpret_cast<uword>(
this));
141 FATAL(
"Failed to start DartDev thread: %d",
result);
148 dart_options_->
Reset();
149 dart_options_->
AddArguments(
const_cast<const char**
>(argv_.get()), argc_);
154 return message->value.as_array.values[index];
157void DartDevIsolate::DartDevRunner::DartDevResultCallback(
175 const bool mark_main_isolate_as_system_isolate = item3->value.as_bool;
176 if (mark_main_isolate_as_system_isolate) {
180 if (*script_ !=
nullptr) {
183 if (*package_config_override_ !=
nullptr) {
184 free(*package_config_override_);
185 *package_config_override_ =
nullptr;
190 *package_config_override_ =
Utils::StrDup(item2->value.as_string);
195 argc_ =
args->value.as_array.length;
198 auto deleter = [](
char**
args) {
199 for (intptr_t
i = 0;
i < argc_; ++
i) {
205 std::unique_ptr<char*[], void (*)(char**)>(
new char*[argc_], deleter);
206 for (intptr_t
i = 0;
i < argc_; ++
i) {
229 DartDevRunner::monitor_->Notify();
237void DartDevIsolate::DartDevRunner::RunCallback(
uword args) {
238 MonitorLocker locker_(DartDevRunner::monitor_);
239 DartDevRunner* runner =
reinterpret_cast<DartDevRunner*
>(
args);
244 flags.enable_asserts =
false;
245 flags.use_field_guards =
true;
246 flags.use_osr =
true;
247 flags.is_system_isolate =
true;
248 flags.branch_coverage =
false;
249 flags.coverage =
false;
251 char*
error =
nullptr;
254 runner->packages_file_, &
flags,
nullptr,
255 const_cast<char**
>(&
error));
257 if (dartdev_isolate ==
nullptr) {
274 ProcessError(
"Unable to find 'main' in root library 'dartdev'",
288 const intptr_t kNumIsolateArgs = 4;
290 isolate_args[0] = main_closure;
291 isolate_args[1] = runner->dart_options_->CreateRuntimeOptions();
292 isolate_args[2] = send_port;
299 kNumIsolateArgs, isolate_args);
309void DartDevIsolate::DartDevRunner::ProcessError(
const char* msg,
314 DartDevRunner::monitor_->Notify();
319 char** packages_file,
322 runner_.
Run(create_isolate, packages_file,
script, dart_options);
static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
static char * StrDup(const char *s)
static char * SCreate(const char *format,...) PRINTF_ATTRIBUTE(1
void AddArguments(const char **argv, int argc)
void AddArgument(const char *argument)
void Run(Dart_IsolateGroupCreateCallback create_isolate, char **package_config_override_, char **script, CommandLineOptions *dart_options)
DartDev_Result result() const
static CStringUniquePtr TryResolveDartDevSnapshotPath()
static DartDev_Result RunDartDev(Dart_IsolateGroupCreateCallback create_isolate, char **packages_file, char **script, CommandLineOptions *dart_options)
static bool ShouldParseCommand(const char *script_uri)
static CStringUniquePtr GetDirectoryPrefixFromResolvedExeName()
static CStringUniquePtr GetDirectoryPrefixFromUnresolvedExeName()
static bool Exists(Namespace *namespc, const char *path)
static bool ExistsUri(Namespace *namespc, const char *uri)
static constexpr int64_t kNoTimeout
WaitResult WaitMicros(int64_t micros)
static void set_mark_main_isolate_as_system_isolate(bool state)
static void SetGlobalExitCode(int exit_code)
static int Start(const char *name, ThreadStartFunction function, uword parameters)
Dart_Isolate(* Dart_IsolateGroupCreateCallback)(const char *script_uri, const char *main, const char *package_root, const char *package_config, Dart_IsolateFlags *flags, void *isolate_data, char **error)
struct _Dart_Handle * Dart_Handle
struct _Dart_Isolate * Dart_Isolate
#define CHECK_RESULT(result)
#define DART_DEV_ISOLATE_NAME
FlutterSemanticsFlag flags
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
const uint8_t uint32_t uint32_t GError ** error
static Dart_CObject * GetArrayItem(Dart_CObject *message, intptr_t index)
constexpr int kErrorExitCode
DART_EXPORT void Dart_EnterScope()
DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate)
CAllocUniquePtr< char > CStringUniquePtr
DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, Dart_Handle name, int number_of_arguments, Dart_Handle *arguments)
DART_EXPORT Dart_Handle Dart_True()
DART_EXPORT Dart_Handle Dart_RootLibrary()
DART_EXPORT void Dart_IsolateFlagsInitialize(Dart_IsolateFlags *flags)
DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name)
DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id)
DART_EXPORT bool Dart_CloseNativePort(Dart_Port native_port_id)
DART_EXPORT Dart_Handle Dart_RunLoop()
DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url)
DART_EXPORT Dart_Port Dart_NewNativePort(const char *name, Dart_NativeMessageHandler handler, bool handle_concurrently)
DART_EXPORT bool Dart_IsClosure(Dart_Handle object)
DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char *str)
union _Dart_CObject::@86 value