Skip to content

Commit 8abbaeb

Browse files
committed
Enable clang and clangcl detection. Some cleanups.
1 parent e324d50 commit 8abbaeb

16 files changed

Lines changed: 262 additions & 757 deletions

File tree

src/sw/builder/sw_context.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@
1212

1313
#include <sw/manager/storage.h>
1414

15+
#include <boost/thread/lock_types.hpp>
16+
#include <boost/thread/shared_mutex.hpp>
1517
#include <primitives/executor.h>
1618

19+
#include <regex>
20+
1721
namespace sw
1822
{
1923

@@ -66,5 +70,53 @@ void SwBuilderContext::clearFileStorages()
6670
file_storage.reset();
6771
}
6872

73+
static Version gatherVersion(const path &program, const String &arg = "--version", const String &in_regex = {})
74+
{
75+
static std::regex r_default("(\\d+)\\.(\\d+)\\.(\\d+)(\\.(\\d+))?");
76+
77+
std::regex r_in;
78+
if (!in_regex.empty())
79+
r_in.assign(in_regex);
80+
81+
auto &r = in_regex.empty() ? r_default : r_in;
82+
83+
Version V;
84+
builder::detail::ResolvableCommand c; // for nice program resolving
85+
c.setProgram(program);
86+
if (!arg.empty())
87+
c.arguments = { arg };
88+
error_code ec;
89+
c.execute(ec);
90+
91+
if (c.pid == -1)
92+
throw SW_RUNTIME_ERROR(normalize_path(program) + ": " + ec.message());
93+
94+
std::smatch m;
95+
if (std::regex_search(c.err.text.empty() ? c.out.text : c.err.text, m, r))
96+
{
97+
if (m[5].matched)
98+
V = { std::stoi(m[1].str()), std::stoi(m[2].str()), std::stoi(m[3].str()), std::stoi(m[5].str()) };
99+
else
100+
V = { std::stoi(m[1].str()), std::stoi(m[2].str()), std::stoi(m[3].str()) };
101+
}
102+
return V;
103+
}
104+
105+
Version getVersion(const SwBuilderContext &swctx, const path &program, const String &arg, const String &in_regex)
106+
{
107+
auto &vs = swctx.getVersionStorage();
108+
static boost::upgrade_mutex m;
109+
110+
boost::upgrade_lock lk(m);
111+
auto i = vs.versions.find(program);
112+
if (i != vs.versions.end())
113+
return i->second;
114+
115+
boost::upgrade_to_unique_lock lk2(lk);
116+
117+
vs.versions[program] = gatherVersion(program, arg, in_regex);
118+
return vs.versions[program];
119+
}
120+
69121
}
70122

src/sw/builder/sw_context.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,9 @@ struct SW_BUILDER_API SwBuilderContext : SwManagerContext
4848
mutable std::mutex csm;
4949
};
5050

51+
SW_BUILDER_API
52+
Version getVersion(
53+
const SwBuilderContext &swctx, const path &program,
54+
const String &arg = "--version", const String &in_regex = {});
55+
5156
} // namespace sw

src/sw/client/build.cpp

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
#include "build.h"
2020

21-
//#include <sw/driver/build.h>
2221
#include <sw/support/filesystem.h>
2322

2423
#include <primitives/exceptions.h>
@@ -31,48 +30,11 @@ DECLARE_STATIC_LOGGER(logger, "build");
3130
namespace sw
3231
{
3332

34-
std::unique_ptr<Build> load(const SwContext &swctx, const path &file_or_dir)
35-
{
36-
SW_UNIMPLEMENTED;
37-
38-
/*auto f = resolveConfig(file_or_dir);
39-
if (!f || !Build::isFrontendConfigFilename(f.value()))
40-
{
41-
if (f && !Build::isFrontendConfigFilename(f.value()))
42-
LOG_INFO(logger, "Unknown config, trying in configless mode. Default mode is native (ASM/C/C++)");
43-
44-
path p = file_or_dir;
45-
p = fs::absolute(p);
46-
47-
auto b = std::make_unique<Build>(swctx);
48-
b->Local = true;
49-
b->setSourceDirectory(fs::is_directory(p) ? p : p.parent_path());
50-
b->load(p, true);
51-
return b;
52-
}
53-
54-
auto b = std::make_unique<Build>(swctx);
55-
b->Local = true;
56-
b->setSourceDirectory(f.value().parent_path());
57-
b->load(f.value());
58-
59-
return b;*/
60-
}
61-
6233
void run(const SwContext &swctx, const PackageId &package)
6334
{
6435
SW_UNIMPLEMENTED;
6536
//auto b = std::make_unique<Build>(swctx);
6637
//b->run_package(package.toString());
6738
}
6839

69-
std::optional<String> read_config(const path &file_or_dir)
70-
{
71-
SW_UNIMPLEMENTED;
72-
/*auto f = findConfig(file_or_dir);
73-
if (!f)
74-
return {};
75-
return read_file(f.value());*/
76-
}
77-
7840
}

src/sw/client/build.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,9 @@
2525
namespace sw
2626
{
2727

28-
struct Build;
2928
struct PackageId;
3029
struct SwContext;
3130

32-
std::optional<String> read_config(const path &file_or_dir);
33-
std::unique_ptr<Build> load(const SwContext &swctx, const path &file_or_dir);
3431
void run(const SwContext &swctx, const PackageId &package);
3532

3633
struct FetchOptions : SourceDownloadOptions

src/sw/client/command/build.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,33 @@ static sw::TargetSettings compilerTypeFromStringCaseI(const String &in)
9999
sw::TargetSettings ts;
100100

101101
if (0);
102-
// exact
103-
/*else if (boost::iequals(compiler, "clang"))
104-
return CompilerType::Clang;
105-
else if (boost::iequals(compiler, "clangcl") || boost::iequals(compiler, "clang-cl"))
106-
return CompilerType::ClangCl;
102+
/*
107103
// starts with
108104
else if (boost::istarts_with(compiler, "appleclang") || boost::iequals(compiler, "apple-clang"))
109105
return CompilerType::AppleClang;
110106
else if (boost::istarts_with(compiler, "gnu") || boost::iequals(compiler, "gcc") || boost::iequals(compiler, "g++"))
111107
return CompilerType::GNU;*/
108+
else if (compiler == "clang")
109+
{
110+
ts["native"]["program"]["c"] = "org.LLVM.clang";
111+
ts["native"]["program"]["cpp"] = "org.LLVM.clangpp";
112+
}
113+
else if (compiler == "clangcl" || compiler == "clang-cl")
114+
{
115+
ts["native"]["program"]["c"] = "org.LLVM.clangcl";
116+
ts["native"]["program"]["cpp"] = "org.LLVM.clangcl";
117+
}
112118
else if (compiler == "msvc" || compiler == "vs")
113119
{
114120
ts["native"]["program"]["c"] = "com.Microsoft.VisualStudio.VC.cl";
115121
ts["native"]["program"]["cpp"] = "com.Microsoft.VisualStudio.VC.cl";
116122
ts["native"]["program"]["asm"] = "com.Microsoft.VisualStudio.VC.ml";
117123
}
124+
else
125+
{
126+
ts["native"]["program"]["c"] = compiler;
127+
ts["native"]["program"]["cpp"] = compiler;
128+
}
118129
return ts;
119130
}
120131

0 commit comments

Comments
 (0)