From 9d514e65f00dde0e309f33591f31fbf7f132a005 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Wed, 12 Jun 2019 09:05:40 -0400 Subject: 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. --- source/core/slang-process-util.h | 61 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 source/core/slang-process-util.h (limited to 'source/core/slang-process-util.h') 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 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 -- cgit v1.2.3