-
Notifications
You must be signed in to change notification settings - Fork 1
/
cl.hxx
177 lines (159 loc) · 5.15 KB
/
cl.hxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/**
* @file cl.hxx
* @author John Parent (john.parent@kitware.com)
* @brief A C++ wrapper header file for the MSVC c and c++ compilers and linkers
* created for the Spack package manager.
* Eclipses the names cl.exe and link.exe in the PATH during Spackc runtime,
* intercepting calls to the compiler/linker and injecting Spack specific logic
* and flags into the compiler and link interfaces for MSVC driven compilation
*
* This header files specificies the interface with which the compiler
* wrapper interacts with the Spack build env, and the associated calls to
* the compiler and linker
* @date 2023-10-20
* @copyright Copyright 2013-2023 Lawrence Livermore National Security, LLC and other
* Spack Project Developers. See the top-level COPYRIGHT file for details.
* SPDX-License-Identifier: (Apache-2.0 OR MIT)
*
*/
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <strsafe.h>
#include "version.hxx"
#define BUFSIZE 4096
typedef std::vector<std::string> StrList;
struct SpackEnvState{
std::string addDebugFlags;
StrList SpackFFlags;
StrList SpackCFlags;
StrList SpackCxxFlags;
StrList SpackLdFlags;
StrList SpackLdLibs;
StrList SpackCompilerExtraRPaths;
StrList SpackCompilerImplicitRPaths;
StrList SpackIncludeDirs;
StrList SpackLinkDirs;
StrList SpackCompilerFlagsKeep;
StrList SpackCompilerFlagsReplace;
StrList SpackEnvPath;
StrList SpackSystemDirs;
StrList SpackRPathDirs;
std::string SpackCCRPathArg;
std::string SpackCXXRPathArg;
std::string SpackFCRPathArg;
std::string SpackF77RPathArg;
std::string SpackLinkerArg;
std::string Spack;
std::string SpackInstDir;
std::string SpackCC;
std::string SpackCXX;
std::string SpackFC;
std::string SpackF77;
std::string SpackRoot;
static SpackEnvState loadSpackEnvState();
};
class SpackException : public std::exception {
public:
SpackException(std::string msg) : message(msg) {}
char const* what();
protected:
std::string message;
};
class SpackUnknownCompilerException : public SpackException {
using SpackException::SpackException;
public:
char const * what();
};
class SpackCompilerException : public SpackException {
using SpackException::SpackException;
public:
char const * what();
};
class SpackCompilerContextException : public SpackException {
using SpackException::SpackException;
public:
char const * what();
};
class ToolChainInvocation{
public:
ToolChainInvocation(std::string command, char const* const* cli);
virtual ~ToolChainInvocation();
virtual void interpolateSpackEnv(SpackEnvState &spackenv);
virtual void invokeToolchain();
protected:
virtual void parse_command_args(char const* const* cli);
virtual void setupExecute();
bool pipeChildtoStdOut();
virtual void loadToolchainDependentSpackVars(SpackEnvState &spackenv) = 0;
virtual void executeToolChainChild();
virtual void createChildPipes();
std::string composeIncludeArg(std::string &include);
std::string composeLibPathArg(std::string &libPath);
void addExtraLibPaths(StrList paths);
std::string composeCLI();
virtual void cleanupHandles();
virtual void safeHandleCleanup(HANDLE &handle);
std::string command;
std::string lang;
StrList CommandArgs;
StrList includeArgs;
StrList libDirArgs;
StrList libArgs;
HANDLE ChildStdOut_Rd;
HANDLE ChildStdOut_Wd;
PROCESS_INFORMATION procInfo;
STARTUPINFOW startInfo;
std::string spackCommand;
};
/**
* @brief ClInvocation exposes an interface driving invocations of
* cl.exe and defines the parameters of the call to said executable
*/
class ClInvocation : public ToolChainInvocation {
public:
using ToolChainInvocation::ToolChainInvocation;
private:
void loadToolchainDependentSpackVars(SpackEnvState &spackenv);
std::string lang = "c/c++";
};
/**
* @brief ClInvocation exposes an interface driving invocations of
* link.exe and defines the parameters of the call to said executable
*/
class LdInvocation : public ToolChainInvocation {
public:
using ToolChainInvocation::ToolChainInvocation;
private:
void loadToolchainDependentSpackVars(SpackEnvState &spackenv);
std::string lang = "link";
};
/**
* @brief ClInvocation exposes an interface driving invocations of
* ifx.exe and defines the parameters of the call to said executable
*/
class IntelFortranInvocation : public ToolChainInvocation {
public:
using ToolChainInvocation::ToolChainInvocation;
private:
void loadToolchainDependentSpackVars(SpackEnvState &spackenv);
std::string lang = "intel fortran";
};
class ToolChainFactory{
public:
static std::unique_ptr<ToolChainInvocation> ParseToolChain(int argc, char const* const * argv);
private:
static void stripPathandExe(std::string &command);
static void stripExe(std::string &command);
static void stripPath(std::string &command);
enum Language {
cpp,
intelFortran,
link
};
const static std::map<std::string, Language> SupportedTools;
};