Daniele Bartolini 9 лет назад
Родитель
Сommit
9d564fb7cb
3 измененных файлов с 35 добавлено и 26 удалено
  1. 32 8
      src/core/os.cpp
  2. 2 2
      src/core/os.h
  3. 1 16
      src/resource/compile_options.cpp

+ 32 - 8
src/core/os.cpp

@@ -330,15 +330,29 @@ namespace os
 #endif
 	}
 
-	int execute_process(const char* path, const char* args, StringStream& output)
+	int execute_process(const char* const* argv, StringStream& output)
 	{
-#if CROWN_PLATFORM_POSIX
 		TempAllocator512 ta;
-		DynamicString cmd(ta);
-		cmd += path;
-		cmd += " 2>&1 ";
-		cmd += args;
-		FILE* file = popen(cmd.c_str(), "r");
+		StringStream path(ta);
+
+		path << argv[0];
+		path << ' ';
+#if CROWN_PLATFORM_POSIX
+		path << "2>&1 ";
+#endif
+		for (s32 i = 1; argv[i] != NULL; ++i)
+		{
+			const char* arg = argv[i];
+			for (; *arg; ++arg)
+			{
+				if (*arg == ' ')
+					path << '\\';
+				path << *arg;
+			}
+			path << ' ';
+		}
+#if CROWN_PLATFORM_POSIX
+		FILE* file = popen(string_stream::c_str(path), "r");
 
 		char buf[1024];
 		while (fgets(buf, sizeof(buf), file) != NULL)
@@ -353,7 +367,17 @@ namespace os
 		PROCESS_INFORMATION process;
 		memset(&process, 0, sizeof(process));
 
-		int err = CreateProcess(path, (LPSTR)args, NULL, NULL, TRUE, 0, NULL, NULL, &info, &process);
+		int err = CreateProcess(argv[0]
+			, (LPSTR)string_stream::c_str(path)
+			, NULL
+			, NULL
+			, TRUE
+			, 0
+			, NULL
+			, NULL
+			, &info
+			, &process
+			);
 		CE_ASSERT(err != 0, "CreateProcess: GetLastError = %d", GetLastError());
 		CE_UNUSED(err);
 

+ 2 - 2
src/core/os.h

@@ -71,9 +71,9 @@ namespace os
 	/// Returns the value of the environment variable @a name.
 	const char* getenv(const char* name);
 
-	/// Executes the process @a path with the given @a args and returns its exit code.
+	/// Executes the process described by @a argv and returns its exit code.
 	/// It fills @a output with stdout and stderr.
-	int execute_process(const char* path, const char* args, StringStream& output);
+	int execute_process(const char* const* argv, StringStream& output);
 
 } // namespace os
 } // namespace crown

+ 1 - 16
src/resource/compile_options.cpp

@@ -169,22 +169,7 @@ void CompileOptions::add_dependency(const char* path)
 
 int CompileOptions::run_external_compiler(const char* const* argv, StringStream& output)
 {
-	TempAllocator512 ta;
-	StringStream ss(ta);
-
-	for (s32 i = 1; argv[i] != NULL; ++i)
-	{
-		const char* arg = argv[i];
-		for (; *arg; ++arg)
-		{
-			if (*arg == ' ')
-				ss << '\\';
-			ss << *arg;
-		}
-		ss << ' ';
-	}
-
-	return os::execute_process(argv[0], string_stream::c_str(ss), output);
+	return os::execute_process(argv, output);
 }
 
 } // namespace crown