summaryrefslogtreecommitdiff
path: root/source/core/slang-process-util.h
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-06-12 09:05:40 -0400
committerGitHub <noreply@github.com>2019-06-12 09:05:40 -0400
commit9d514e65f00dde0e309f33591f31fbf7f132a005 (patch)
tree7e3a751377651ef9eda06f0b1ad345af1796c596 /source/core/slang-process-util.h
parentfc083a75b94ac4b4e735b4a7ff566191b9123f74 (diff)
Runtime execution of Visual Studio Compiler (#978)
* Work in progress to be able to invoke VS from within code. * First pass at windows version of refactor of OSProcessSpawner * Closer to getting VS path lookup working. * Make OSString assignable/ctor able * Work out program files directory directly, so don't have to expand %%. * WIP: Improve handling of process spawning. * Add support for splitting input by line. * * Correctly locates visual studio install * Added functionality to invoke vs via cmd * Add option to execute the command line. * Handle in ProcessUtil for windows -> WinHandle. * Rename files slang-win-visual-studio-util.cpp/.h and slang-process-util.h * First pass at unix/linux version of ProcessUtil. * Fix reading Visual Studio path from the registry. * Get compiling on linux with. * Fix vcvarsall.bat name * Use ProcessUtil to execute external code. * Remove OSProcessSpawner. * Remove includes for "os.h" where no longer needed. * Fix tabbing issue in premake5.lua Remove test code from slang-test-main.cpp * Fix premake4.lua tabbing issue. * Small fixes to slang-process-util.h Init ExecuteResult on Win execute. * Improve comments. * Fix bug in StringUtil::calcLines - with oddly terminated source input being able to read past end. Make slang-generate use StringUtil over it's own impl. * Fix off by one bug in working out Visual Studio version. * Fix bug in calculating Visual Studio Version * Fix compilation on linux with string parameter being passed to messageFormat. * Remove erroneous use of kOSError codes - use Result.
Diffstat (limited to 'source/core/slang-process-util.h')
-rw-r--r--source/core/slang-process-util.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/source/core/slang-process-util.h b/source/core/slang-process-util.h
new file mode 100644
index 000000000..19ae7c0d1
--- /dev/null
+++ b/source/core/slang-process-util.h
@@ -0,0 +1,61 @@
+// slang-process-util.h
+#ifndef SLANG_PROCESS_UTIL_H
+#define SLANG_PROCESS_UTIL_H
+
+#include "slang-string.h"
+#include "slang-list.h"
+
+namespace Slang {
+
+struct CommandLine
+{
+ enum class ExecutableType
+ {
+ Unknown, ///< The executable is not specified
+ Path, ///< The executable is set as a path
+ Filename, ///< The executable is set as a filename
+ };
+
+ void addArg(const String& in) { m_args.add(in); }
+ void addArgs(const String* args, Int argsCount) { m_args.addRange(args, argsCount); }
+ void setExecutablePath(const String& path) { m_executableType = ExecutableType::Path; m_executable = path; }
+ void setExecutableFilename(const String& filename) { m_executableType = ExecutableType::Filename; m_executable = filename; }
+
+ /// Ctor
+ CommandLine():m_executableType(ExecutableType::Unknown) {}
+
+ ExecutableType m_executableType; ///< How the executable is specified
+ String m_executable; ///< Executable to run
+ List<String> m_args; ///< The parameters to pass
+};
+
+struct ExecuteResult
+{
+ void init()
+ {
+ resultCode = 0;
+ standardOutput = String();
+ standardError = String();
+ }
+
+ typedef int ResultCode;
+ ResultCode resultCode;
+ Slang::String standardOutput;
+ Slang::String standardError;
+};
+
+struct ProcessUtil
+{
+ /// Get the suffix used on this platform
+ static UnownedStringSlice getExecutableSuffix();
+
+ /// Output how the command line is executed on the target (with escaping and the such like)
+ static String getCommandLineString(const CommandLine& commandLine);
+
+ /// Execute the command line
+ static SlangResult execute(const CommandLine& commandLine, ExecuteResult& outExecuteResult);
+};
+
+}
+
+#endif // SLANG_PROCESS_UTIL_H