Prechádzať zdrojové kódy

device: parse CompileOptions only once

Daniele Bartolini 7 rokov pred
rodič
commit
d1eef13e70

+ 11 - 6
src/device/main_linux.cpp

@@ -820,11 +820,6 @@ int main(int argc, char** argv)
 		return main_unit_tests();
 		return main_unit_tests();
 	}
 	}
 #endif // CROWN_BUILD_UNIT_TESTS
 #endif // CROWN_BUILD_UNIT_TESTS
-	if (cl.has_option("compile") || cl.has_option("server"))
-	{
-		if (main_data_compiler(argc, argv) != EXIT_SUCCESS || !cl.has_option("continue"))
-			return EXIT_FAILURE;
-	}
 
 
 	InitMemoryGlobals m;
 	InitMemoryGlobals m;
 	CE_UNUSED(m);
 	CE_UNUSED(m);
@@ -833,7 +828,17 @@ int main(int argc, char** argv)
 	bool quit = false;
 	bool quit = false;
 	int ec = opts.parse(&quit);
 	int ec = opts.parse(&quit);
 
 
-	if (ec == EXIT_SUCCESS && !quit)
+	if (quit)
+		return ec;
+
+	if (ec == EXIT_SUCCESS && (opts._do_compile || opts._server))
+	{
+		ec = main_data_compiler(opts);
+		if (!opts._do_continue)
+			return ec;
+	}
+
+	if (ec == EXIT_SUCCESS)
 		ec = s_ldvc.run(&opts);
 		ec = s_ldvc.run(&opts);
 
 
 	return ec;
 	return ec;

+ 11 - 6
src/device/main_windows.cpp

@@ -709,11 +709,6 @@ int main(int argc, char** argv)
 		return main_unit_tests();
 		return main_unit_tests();
 	}
 	}
 #endif // CROWN_BUILD_UNIT_TESTS
 #endif // CROWN_BUILD_UNIT_TESTS
-	if (cl.has_option("compile") || cl.has_option("server"))
-	{
-		if (main_data_compiler(argc, argv) != EXIT_SUCCESS || !cl.has_option("continue"))
-			return EXIT_FAILURE;
-	}
 
 
 	InitMemoryGlobals m;
 	InitMemoryGlobals m;
 	CE_UNUSED(m);
 	CE_UNUSED(m);
@@ -722,7 +717,17 @@ int main(int argc, char** argv)
 	bool quit = false;
 	bool quit = false;
 	int ec = opts.parse(&quit);
 	int ec = opts.parse(&quit);
 
 
-	if (ec == EXIT_SUCCESS && !quit)
+	if (quit)
+		return ec;
+
+	if (ec == EXIT_SUCCESS && (opts._do_compile || opts._server))
+	{
+		ec = main_data_compiler(opts);
+		if (!opts._do_continue)
+			return ec;
+	}
+
+	if (ec == EXIT_SUCCESS)
 		ec = s_wdvc.run(&opts);
 		ec = s_wdvc.run(&opts);
 
 
 	WSACleanup();
 	WSACleanup();

+ 1 - 11
src/resource/data_compiler.cpp

@@ -533,18 +533,8 @@ struct InitMemoryGlobals
 	}
 	}
 };
 };
 
 
-int main_data_compiler(int argc, char** argv)
+int main_data_compiler(const DeviceOptions& opts)
 {
 {
-	InitMemoryGlobals m;
-	CE_UNUSED(m);
-
-	DeviceOptions opts(default_allocator(), argc, (const char**)argv);
-	bool quit = false;
-	CE_UNUSED(quit);
-	int ec = opts.parse(&quit);
-	if (ec == EXIT_FAILURE)
-		return EXIT_FAILURE;
-
 	console_server_globals::init();
 	console_server_globals::init();
 	console_server()->listen(CROWN_DEFAULT_COMPILER_PORT, opts._wait_console);
 	console_server()->listen(CROWN_DEFAULT_COMPILER_PORT, opts._wait_console);
 
 

+ 2 - 1
src/resource/data_compiler.h

@@ -9,6 +9,7 @@
 #include "core/filesystem/file_monitor.h"
 #include "core/filesystem/file_monitor.h"
 #include "core/filesystem/filesystem_disk.h"
 #include "core/filesystem/filesystem_disk.h"
 #include "device/console_server.h"
 #include "device/console_server.h"
+#include "device/device_options.h"
 #include "resource/types.h"
 #include "resource/types.h"
 #include <setjmp.h>
 #include <setjmp.h>
 
 
@@ -84,6 +85,6 @@ struct DataCompiler
 	static const u32 COMPILER_NOT_FOUND = UINT32_MAX;
 	static const u32 COMPILER_NOT_FOUND = UINT32_MAX;
 };
 };
 
 
-int main_data_compiler(int argc, char** argv);
+int main_data_compiler(const DeviceOptions& opts);
 
 
 } // namespace crown
 } // namespace crown