uppsrc_ide_r14075.diff

Proposed patch for uppsrc/ide directory (since 14075 revision) - Sender Ghost, 02/24/2020 09:17 PM

Download (6.7 KB)

View differences:

uppsrc/ide/Builders/Builders.h
77 77
	String Info_plist; // apple bundle Info.plist
78 78
};
79 79

  
80
struct ClangTidyBuilder : CppBuilder {
81
	virtual void AddFlags(Index<String>& cfg);
82
	virtual bool BuildPackage(const String& package, Vector<String>& linkfile, Vector<String>& immfile,
83
	    String& linkoptions, const Vector<String>& all_uses, const Vector<String>& all_libraries, int optimize);
84
	virtual bool Link(const Vector<String>& linkfile, const String& linkoptions, bool createmap);
85
	virtual bool Preprocess(const String& package, const String& file, const String& target, bool asmout);
86

  
87
	String CompilerName() const;
88
};
89

  
80 90
struct OwcBuilder : CppBuilder {
81 91
	typedef OwcBuilder CLASSNAME;
82 92

  
......
166 176
INITIALIZE(MscBuilder)
167 177
INITIALIZE(JavaBuilder)
168 178
INITIALIZE(AndroidBuilder)
179
INITIALIZE(ClangTidyBuilder)
169 180
INITIALIZE(ScriptBuilder)
170 181

  
171 182
#endif
uppsrc/ide/Builders/Builders.upp
19 19
	GccBuilder.cpp,
20 20
	MscBuilder.cpp,
21 21
	JavaBuilder.cpp,
22
	ClangTidyBuilder.cpp,
22 23
	ScriptBuilder.cpp,
23 24
	Cocoa.cpp,
24 25
	Android readonly separator,
uppsrc/ide/Builders/ClangTidyBuilder.cpp
1
#include "Builders.h"
2

  
3
void ClangTidyBuilder::AddFlags(Index<String>& cfg)
4
{
5
	cfg.FindAdd("CLANG");
6
}
7

  
8
String ClangTidyBuilder::CompilerName() const
9
{
10
	if(!IsNull(compiler)) return compiler;
11
	return "clang-tidy";
12
}
13

  
14
bool ClangTidyBuilder::BuildPackage(const String& package, Vector<String>& linkfile, Vector<String>& immfile, String& linkoptions, const Vector<String>& all_uses, const Vector<String>& all_libraries, int optimize)
15
{
16
	SaveBuildInfo(package);
17

  
18
	int i;
19
	String packagepath = PackagePath(package);
20
	Package pkg;
21
	pkg.Load(packagepath);
22
	String packagedir = GetFileFolder(packagepath);
23
	ChDir(packagedir);
24
	PutVerbose("cd " + packagedir);
25
	IdeConsoleBeginGroup(package);
26
	Vector<String> obj;
27

  
28
	bool is_shared = HasFlag("SO");
29
	String shared_ext = (HasFlag("WIN32") ? ".dll" : ".so");
30

  
31
	Vector<String> sfile, isfile;
32
	Vector<String> soptions, isoptions;
33
	bool           error = false;
34

  
35
	Index<String> noblitz;
36

  
37
	bool blitz = HasFlag("BLITZ");
38
	bool release = !HasFlag("DEBUG");
39
	bool objectivec = HasFlag("OBJC");
40
#ifdef PLATFORM_MACOS
41
	objectivec = true;
42
#endif
43

  
44
	for(i = 0; i < pkg.GetCount(); i++) {
45
		if(!IdeIsBuilding())
46
			return false;
47
		if(!pkg[i].separator) {
48
			String gop = Gather(pkg[i].option, config.GetKeys());
49
			Vector<String> srcfile = CustomStep(pkg[i], package, error);
50
			if(srcfile.GetCount() == 0)
51
				error = true;
52
			for(int j = 0; j < srcfile.GetCount(); j++) {
53
				String fn = srcfile[j];
54
				String ext = GetSrcType(fn);
55
				if(findarg(ext, ".c", ".cpp", ".cc", ".cxx") >= 0 ||
56
				   objectivec && findarg(ext, ".mm", ".m") >= 0 ||
57
				   +
58
				   (!release && blitz && ext == ".icpp")) {
59
					sfile.Add(fn);
60
					soptions.Add(gop);
61
				}
62
				else
63
				if(ext == ".icpp") {
64
					isfile.Add(fn);
65
					isoptions.Add(gop);
66
				}
67
				else
68
				if(ext == ".o")
69
					obj.Add(fn);
70
				else
71
				if(ext == ".a" || ext == ".so")
72
					linkfile.Add(fn);
73
				if(pkg[i].noblitz)
74
					noblitz.Add(fn);
75
			}
76
		}
77
	}
78

  
79
	String cc(" -- -c");
80
	for(String s : pkg_config)
81
		cc << " `pkg-config --cflags " << s << "`";
82
	cc << ' ' << IncludesDefinesTargetTime(package, pkg);
83

  
84
	if(HasFlag("WIN32")/* && HasFlag("MT")*/)
85
		cc << " -mthreads";
86
	if(HasFlag("DEBUG_MINIMAL"))
87
		cc << (HasFlag("WIN32") ? " -g1" : " -ggdb -g1");
88
	if(HasFlag("DEBUG_FULL"))
89
		cc << (HasFlag("WIN32") ? " -g2" : " -ggdb -g2");
90
	String fuse_cxa_atexit;
91
	if(is_shared /*&& !HasFlag("MAIN")*/) {
92
		cc << " -shared -fPIC";
93
		fuse_cxa_atexit = " -fuse-cxa-atexit";
94
	}
95
	if(!HasFlag("SHARED") && !is_shared)
96
		cc << " -static ";
97
	cc << ' ' << Gather(pkg.option, config.GetKeys());
98
	cc << " -fexceptions";
99

  
100
	if(!release)
101
		cc << " -D_DEBUG " << debug_options;
102
	else
103
		cc << ' ' << release_options;
104

  
105
	if(pkg.nowarnings)
106
		cc << " -w";
107

  
108
	Blitz b;
109
	if(blitz) {
110
		BlitzBuilderComponent bc(this);
111
		b = bc.MakeBlitzStep(sfile, soptions, obj, immfile, ".o", noblitz, package);
112
	}
113

  
114
	if(blitz && b.build) {
115
		PutConsole("BLITZ:" + b.info);
116
		int slot = AllocSlot();
117
		String exec = CompilerName();
118
		exec << " " << GetHostPathQ(b.path) << cc;
119
		if(slot < 0 || !Run(String().Cat() << Join(exec, cpp_options) << ' '
120
		                    << GetHostPathQ(b.path)
121
		                    << " -o " << GetHostPathQ(b.object), slot, GetHostPath(b.object), b.count))
122
			error = true;
123
	}
124

  
125
	int first_ifile = sfile.GetCount();
126
	sfile.AppendPick(pick(isfile));
127
	soptions.AppendPick(pick(isoptions));
128

  
129
	for(i = 0; i < sfile.GetCount(); i++) {
130
		if(!IdeIsBuilding())
131
			return false;
132
		String fn = sfile[i];
133
		String ext = ToLower(GetFileExt(fn));
134
		bool init = (i >= first_ifile);
135
		String objfile = CatAnyPath(outdir, GetFileTitle(fn) + ".o");
136
		if(HdependFileTime(fn) > GetFileTime(GetHostPath(objfile))) {
137
			PutConsole(GetFileName(fn));
138
			int time = msecs();
139
			bool execerr = false;
140
			String exec = CompilerName();
141
			exec << " " << GetHostPathQ(fn) << cc;
142
			if(ext == ".c")
143
				exec << Join(" -x c", c_options) << ' ';
144
			else if(ext == ".s" || ext == ".S")
145
				exec << " -x assembler-with-cpp ";
146
			else
147
			if (ext == ".m")
148
				exec << fuse_cxa_atexit << " -x objective-c ";
149
			else
150
			if (ext == ".mm")
151
				exec << fuse_cxa_atexit << Join(" -x objective-c++ ", cpp_options) << ' ';
152
			else
153
				exec << fuse_cxa_atexit << Join(" -x c++", cpp_options) << ' ';
154
			exec << soptions[i] << " -o " << GetHostPathQ(objfile);
155
			PutVerbose(exec);
156
			int slot = AllocSlot();
157
			execerr = (slot < 0 || !Run(exec, slot, GetHostPath(objfile), 1));
158
			if(execerr)
159
				DeleteFile(objfile);
160
			error |= execerr;
161
			PutVerbose("compiled in " + GetPrintTime(time));
162
		}
163
		immfile.Add(objfile);
164
		if(init)
165
			linkfile.Add(objfile);
166
		else
167
			obj.Add(objfile);
168
	}
169

  
170
	if(error) {
171
		IdeConsoleEndGroup();
172
		return false;
173
	}
174

  
175
	return true;
176
}
177

  
178
bool ClangTidyBuilder::Link(const Vector<String>& linkfile, const String& linkoptions, bool createmap)
179
{
180
	if(!Wait())
181
		return false;
182

  
183
	return true;
184
}
185

  
186
bool ClangTidyBuilder::Preprocess(const String& package, const String& file, const String& target, bool asmout)
187
{
188
	return true;
189
}
190

  
191
Builder *CreateClangTidyBuilder()
192
{
193
	return new ClangTidyBuilder;
194
}
195

  
196
INITIALIZER(ClangTidyBuilder)
197
{
198
	RegisterBuilder("CLANGTIDY", CreateClangTidyBuilder);
199
}