diff options
Diffstat (limited to 'source/compiler-core')
4 files changed, 28 insertions, 33 deletions
diff --git a/source/compiler-core/slang-downstream-compiler.h b/source/compiler-core/slang-downstream-compiler.h index 58b7c5be0..dc9e29185 100644 --- a/source/compiler-core/slang-downstream-compiler.h +++ b/source/compiler-core/slang-downstream-compiler.h @@ -419,10 +419,10 @@ public: virtual SlangResult calcArgs(const CompileOptions& options, CommandLine& cmdLine) = 0; virtual SlangResult parseOutput(const ExecuteResult& exeResult, DownstreamDiagnostics& output) = 0; - CommandLineDownstreamCompiler(const Desc& desc, const String& exeName) : + CommandLineDownstreamCompiler(const Desc& desc, const ExecutableLocation& exe) : Super(desc) { - m_cmdLine.setExecutableFilename(exeName); + m_cmdLine.setExecutableLocation(exe); } CommandLineDownstreamCompiler(const Desc& desc, const CommandLine& cmdLine) : diff --git a/source/compiler-core/slang-gcc-compiler-util.cpp b/source/compiler-core/slang-gcc-compiler-util.cpp index 034f349e0..5d72e675a 100644 --- a/source/compiler-core/slang-gcc-compiler-util.cpp +++ b/source/compiler-core/slang-gcc-compiler-util.cpp @@ -86,10 +86,10 @@ static Index _findVersionEnd(const UnownedStringSlice& in) return SLANG_FAIL; } -SlangResult GCCDownstreamCompilerUtil::calcVersion(const String& exeName, DownstreamCompiler::Desc& outDesc) +SlangResult GCCDownstreamCompilerUtil::calcVersion(const ExecutableLocation& exe, DownstreamCompiler::Desc& outDesc) { CommandLine cmdLine; - cmdLine.setExecutableFilename(exeName); + cmdLine.setExecutableLocation(exe); cmdLine.addArg("-v"); ExecuteResult exeRes; @@ -635,19 +635,13 @@ static SlangResult _parseGCCFamilyLine(const UnownedStringSlice& line, LineParse return SLANG_OK; } -/* static */SlangResult GCCDownstreamCompilerUtil::createCompiler(const String& path, const String& inExeName, RefPtr<DownstreamCompiler>& outCompiler) +/* static */SlangResult GCCDownstreamCompilerUtil::createCompiler(const ExecutableLocation& exe, RefPtr<DownstreamCompiler>& outCompiler) { - String exeName(inExeName); - if (path.getLength() > 0) - { - exeName = Path::combine(path, inExeName); - } - DownstreamCompiler::Desc desc; - SLANG_RETURN_ON_FAIL(GCCDownstreamCompilerUtil::calcVersion(exeName, desc)); + SLANG_RETURN_ON_FAIL(GCCDownstreamCompilerUtil::calcVersion(exe, desc)); RefPtr<CommandLineDownstreamCompiler> compiler(new GCCDownstreamCompiler(desc)); - compiler->m_cmdLine.setExecutableFilename(exeName); + compiler->m_cmdLine.setExecutableLocation(exe); outCompiler = compiler; return SLANG_OK; @@ -656,8 +650,9 @@ static SlangResult _parseGCCFamilyLine(const UnownedStringSlice& line, LineParse /* static */SlangResult GCCDownstreamCompilerUtil::locateGCCCompilers(const String& path, ISlangSharedLibraryLoader* loader, DownstreamCompilerSet* set) { SLANG_UNUSED(loader); + RefPtr<DownstreamCompiler> compiler; - if (SLANG_SUCCEEDED(createCompiler(path, "g++", compiler))) + if (SLANG_SUCCEEDED(createCompiler(ExecutableLocation(path, "g++"), compiler))) { set->addCompiler(compiler); } @@ -669,7 +664,7 @@ static SlangResult _parseGCCFamilyLine(const UnownedStringSlice& line, LineParse SLANG_UNUSED(loader); RefPtr<DownstreamCompiler> compiler; - if (SLANG_SUCCEEDED(createCompiler(path, "clang", compiler))) + if (SLANG_SUCCEEDED(createCompiler(ExecutableLocation(path, "clang"), compiler))) { set->addCompiler(compiler); } diff --git a/source/compiler-core/slang-gcc-compiler-util.h b/source/compiler-core/slang-gcc-compiler-util.h index b97144e35..b1ff791b0 100644 --- a/source/compiler-core/slang-gcc-compiler-util.h +++ b/source/compiler-core/slang-gcc-compiler-util.h @@ -12,28 +12,30 @@ struct GCCDownstreamCompilerUtil : public DownstreamCompilerBaseUtil /// Extracts version number into desc from text (assumes gcc/clang -v layout with a line with version) static SlangResult parseVersion(const UnownedStringSlice& text, const UnownedStringSlice& prefix, DownstreamCompiler::Desc& outDesc); - /// Runs the exeName, and extracts the version info into outDesc - static SlangResult calcVersion(const String& exeName, DownstreamCompiler::Desc& outDesc); + /// Runs the exe, and extracts the version info into outDesc + static SlangResult calcVersion(const ExecutableLocation& exe, DownstreamCompiler::Desc& outDesc); /// Calculate gcc family compilers (including clang) cmdLine arguments from options static SlangResult calcArgs(const CompileOptions& options, CommandLine& cmdLine); - /// Parse ExecuteResult into Output - static SlangResult parseOutput(const ExecuteResult& exeRes, DownstreamDiagnostics& outOutput); + /// Parse ExecuteResult into diagnostics + static SlangResult parseOutput(const ExecuteResult& exeRes, DownstreamDiagnostics& out); /// Calculate the output module filename static SlangResult calcModuleFilePath(const CompileOptions& options, StringBuilder& outPath); - /// Given options, calculate paths to products produced for a compilation + /// Given options, calculate paths to products/files produced for a compilation static SlangResult calcCompileProducts(const CompileOptions& options, ProductFlags flags, List<String>& outPaths); - /// Given a path and an exe name, detects if compiler is present, and if so adds to compiler set. - static SlangResult createCompiler(const String& path, const String& inExeName, RefPtr<DownstreamCompiler>& outCompiler); + /// Given the exe location, creates a DownstreamCompiler. + /// Note! Invoke/s the compiler to determine the compiler version number. + static SlangResult createCompiler(const ExecutableLocation& exe, RefPtr<DownstreamCompiler>& outCompiler); + /// Finds GCC compiler/s and adds them to the set static SlangResult locateGCCCompilers(const String& path, ISlangSharedLibraryLoader* loader, DownstreamCompilerSet* set); + /// Finds clang compiler/s and adds them to the set static SlangResult locateClangCompilers(const String& path, ISlangSharedLibraryLoader* loader, DownstreamCompilerSet* set); - }; class GCCDownstreamCompiler : public CommandLineDownstreamCompiler diff --git a/source/compiler-core/windows/slang-win-visual-studio-util.cpp b/source/compiler-core/windows/slang-win-visual-studio-util.cpp index dd9656c23..e1a0f6109 100644 --- a/source/compiler-core/windows/slang-win-visual-studio-util.cpp +++ b/source/compiler-core/windows/slang-win-visual-studio-util.cpp @@ -200,7 +200,7 @@ static SlangResult _find(int versionIndex, WinVisualStudioUtil::VersionPath& out String vswherePath = programFilesPath; vswherePath.append("\\Microsoft Visual Studio\\Installer\\vswhere"); - cmd.setExecutableFilename(vswherePath); + cmd.setExecutableLocation(ExecutableLocation(vswherePath)); StringBuilder versionName; WinVisualStudioUtil::append(version, versionName); @@ -305,22 +305,20 @@ static SlangResult _find(int versionIndex, WinVisualStudioUtil::VersionPath& out // To invoke cl we need to run the suitable vcvars. In order to run this we have to have MS CommandLine. // So here we build up a cl command line that is run by first running vcvars, and then executing cl with the parameters as passed to commandLine - CommandLine cmdLine; + // https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessa + // To run a batch file, you must start the command interpreter; set lpApplicationName to cmd.exe and set lpCommandLine to the + // following arguments: /c plus the name of the batch file. - cmdLine.setExecutableFilename("cmd.exe"); + CommandLine cmdLine; + cmdLine.setExecutableLocation(ExecutableLocation(ExecutableLocation::Type::Name, "cmd.exe")); + { String options[] = { "/q", "/c", "@prompt", "$" }; cmdLine.addArgs(options, SLANG_COUNT_OF(options)); } cmdLine.addArg("&&"); - - { - StringBuilder path; - path << versionPath.vcvarsPath; - path << "\\vcvarsall.bat"; - cmdLine.addArg(path); - } + cmdLine.addArg(Path::combine(versionPath.vcvarsPath, "vcvarsall.bat")); #if SLANG_PTR_IS_32 cmdLine.addArg("x86"); |
