Skip to content
Permalink
Browse files

Enable clang and clangcl detection. Some cleanups.

  • Loading branch information...
egorpugin committed Jul 10, 2019
1 parent e324d50 commit 8abbaeb21e7e2b808e5e9cb3b096fbc873551278
@@ -12,8 +12,12 @@

#include <sw/manager/storage.h>

#include <boost/thread/lock_types.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <primitives/executor.h>

#include <regex>

namespace sw
{

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

static Version gatherVersion(const path &program, const String &arg = "--version", const String &in_regex = {})
{
static std::regex r_default("(\\d+)\\.(\\d+)\\.(\\d+)(\\.(\\d+))?");

std::regex r_in;
if (!in_regex.empty())
r_in.assign(in_regex);

auto &r = in_regex.empty() ? r_default : r_in;

Version V;
builder::detail::ResolvableCommand c; // for nice program resolving
c.setProgram(program);
if (!arg.empty())
c.arguments = { arg };
error_code ec;
c.execute(ec);

if (c.pid == -1)
throw SW_RUNTIME_ERROR(normalize_path(program) + ": " + ec.message());

std::smatch m;
if (std::regex_search(c.err.text.empty() ? c.out.text : c.err.text, m, r))
{
if (m[5].matched)
V = { std::stoi(m[1].str()), std::stoi(m[2].str()), std::stoi(m[3].str()), std::stoi(m[5].str()) };
else
V = { std::stoi(m[1].str()), std::stoi(m[2].str()), std::stoi(m[3].str()) };
}
return V;
}

Version getVersion(const SwBuilderContext &swctx, const path &program, const String &arg, const String &in_regex)
{
auto &vs = swctx.getVersionStorage();
static boost::upgrade_mutex m;

boost::upgrade_lock lk(m);
auto i = vs.versions.find(program);
if (i != vs.versions.end())
return i->second;

boost::upgrade_to_unique_lock lk2(lk);

vs.versions[program] = gatherVersion(program, arg, in_regex);
return vs.versions[program];
}

}

@@ -48,4 +48,9 @@ struct SW_BUILDER_API SwBuilderContext : SwManagerContext
mutable std::mutex csm;
};

SW_BUILDER_API
Version getVersion(
const SwBuilderContext &swctx, const path &program,
const String &arg = "--version", const String &in_regex = {});

} // namespace sw
@@ -18,7 +18,6 @@

#include "build.h"

//#include <sw/driver/build.h>
#include <sw/support/filesystem.h>

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

std::unique_ptr<Build> load(const SwContext &swctx, const path &file_or_dir)
{
SW_UNIMPLEMENTED;

/*auto f = resolveConfig(file_or_dir);
if (!f || !Build::isFrontendConfigFilename(f.value()))
{
if (f && !Build::isFrontendConfigFilename(f.value()))
LOG_INFO(logger, "Unknown config, trying in configless mode. Default mode is native (ASM/C/C++)");
path p = file_or_dir;
p = fs::absolute(p);
auto b = std::make_unique<Build>(swctx);
b->Local = true;
b->setSourceDirectory(fs::is_directory(p) ? p : p.parent_path());
b->load(p, true);
return b;
}
auto b = std::make_unique<Build>(swctx);
b->Local = true;
b->setSourceDirectory(f.value().parent_path());
b->load(f.value());
return b;*/
}

void run(const SwContext &swctx, const PackageId &package)
{
SW_UNIMPLEMENTED;
//auto b = std::make_unique<Build>(swctx);
//b->run_package(package.toString());
}

std::optional<String> read_config(const path &file_or_dir)
{
SW_UNIMPLEMENTED;
/*auto f = findConfig(file_or_dir);
if (!f)
return {};
return read_file(f.value());*/
}

}
@@ -25,12 +25,9 @@
namespace sw
{

struct Build;
struct PackageId;
struct SwContext;

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

struct FetchOptions : SourceDownloadOptions
@@ -99,22 +99,33 @@ static sw::TargetSettings compilerTypeFromStringCaseI(const String &in)
sw::TargetSettings ts;

if (0);
// exact
/*else if (boost::iequals(compiler, "clang"))
return CompilerType::Clang;
else if (boost::iequals(compiler, "clangcl") || boost::iequals(compiler, "clang-cl"))
return CompilerType::ClangCl;
/*
// starts with
else if (boost::istarts_with(compiler, "appleclang") || boost::iequals(compiler, "apple-clang"))
return CompilerType::AppleClang;
else if (boost::istarts_with(compiler, "gnu") || boost::iequals(compiler, "gcc") || boost::iequals(compiler, "g++"))
return CompilerType::GNU;*/
else if (compiler == "clang")
{
ts["native"]["program"]["c"] = "org.LLVM.clang";
ts["native"]["program"]["cpp"] = "org.LLVM.clangpp";
}
else if (compiler == "clangcl" || compiler == "clang-cl")
{
ts["native"]["program"]["c"] = "org.LLVM.clangcl";
ts["native"]["program"]["cpp"] = "org.LLVM.clangcl";
}
else if (compiler == "msvc" || compiler == "vs")
{
ts["native"]["program"]["c"] = "com.Microsoft.VisualStudio.VC.cl";
ts["native"]["program"]["cpp"] = "com.Microsoft.VisualStudio.VC.cl";
ts["native"]["program"]["asm"] = "com.Microsoft.VisualStudio.VC.ml";
}
else
{
ts["native"]["program"]["c"] = compiler;
ts["native"]["program"]["cpp"] = compiler;
}
return ts;
}

0 comments on commit 8abbaeb

Please sign in to comment.
You can’t perform that action at this time.