Skip to content
Permalink
Browse files

Improve VS generator and configless mode.

  • Loading branch information...
egorpugin committed Feb 18, 2019
1 parent 728c47b commit ff907840f9b22de657e88a9b1a8e52264a079cc7
@@ -19,6 +19,7 @@ bin
*~
*.user

*.sln
*.aps
*.exe
*.dll
@@ -85,7 +85,7 @@ bool build(const String &s)
// local file or dir is preferable rather than some remote pkg
if (fs::exists(s))
return build(path(s));
return build({ s });
return build(Strings{ s });
}

PackageScriptPtr load(const path &file_or_dir)
@@ -368,6 +368,7 @@ static ::cl::alias override_package2("override", ::cl::desc("Alias for -override
static ::cl::opt<bool> list_overridden_packages("list-overridden-remote-packages", ::cl::desc("List overridden packages"));
static ::cl::opt<String> delete_overridden_package("delete-overridden-remote-package", ::cl::value_desc("package"), ::cl::desc("Delete overridden package from index"));
static ::cl::opt<path> delete_overridden_package_dir("delete-overridden-remote-package-dir", ::cl::value_desc("sdir"), ::cl::desc("Delete overridden dir packages"));
static ::cl::alias delete_overridden_package_dir2("delete-override", ::cl::desc("Alias for -delete-overridden-remote-package-dir"), ::cl::aliasopt(delete_overridden_package_dir));

// uri commands
extern bool gRunAppInContainer;
@@ -801,6 +802,9 @@ static ::cl::opt<bool, true> print_dependencies("print-dependencies", ::cl::loca
extern bool gOutputNoConfigSubdir;
static ::cl::opt<bool, true> output_no_config_subdir("output-no-config-subdir", ::cl::location(gOutputNoConfigSubdir), ::cl::sub(subcommand_generate));

// generated solution dir instead of .sw/...
//static ::cl::opt<String> generate_binary_dir("B", ::cl::desc("Explicitly specify a build directory."), ::cl::sub(subcommand_build), ::cl::init(SW_BINARY_DIR));

SUBCOMMAND_DECL(generate)
{
if (cl_generator.empty())
@@ -44,10 +44,7 @@ PackageScriptPtr CppDriver::load(const path &file_or_dir) const
LOG_INFO(logger, "Unknown config, trying in configless mode. Default mode is native (ASM/C/C++)");

path p = file_or_dir;
if (fs::is_directory(p))
;
else
p = p.parent_path();
p = fs::absolute(p);

auto b = std::make_unique<Build>();
b->Local = true;
@@ -991,7 +991,7 @@ void ProjectContext::printProject(
endBlock(true);
};

std::unordered_set<void *> rules;
Files rules;
for (auto &[p, sf] : nt)
{
if (sf->skip)
@@ -1000,12 +1000,12 @@ void ProjectContext::printProject(
if (g.type == GeneratorType::VisualStudio && ff.isGenerated())
{
auto gen = ff.getFileRecord().getGenerator();
if (rules.find(gen.get()) == rules.end())
{
rules.insert(gen.get());
auto rule = get_int_dir(nt, s.Settings) / "rules" / (p.filename().string() + ".rule");
write_file_if_not_exists(rule, "");

auto rule = get_int_dir(nt, s.Settings) / "rules" / (p.filename().string() + ".rule");
write_file_if_not_exists(rule, "");
if (rules.find(rule) == rules.end())
{
rules.insert(rule);

// VS crash
// beginBlockWithConfiguration(get_vs_file_type_by_ext(rule), s.Settings, { {"Include", rule.string()} });
@@ -1098,19 +1098,29 @@ void ProjectContext::printProject(
fctx.endBlock();
}

auto t = get_vs_file_type_by_ext(p);
beginBlock(toString(t), { { "Include", p.string() } });
add_excluded_from_build(s);
add_obj_file(t, p);
endBlock();
if (files_added.find(p) == files_added.end())
{
files_added.insert(p);

auto t = get_vs_file_type_by_ext(p);
beginBlock(toString(t), { { "Include", p.string() } });
add_excluded_from_build(s);
add_obj_file(t, p);
endBlock();
}
}
else if (g.type == GeneratorType::VisualStudio && ff.isGeneratedAtAll())
{
auto t = get_vs_file_type_by_ext(p);
beginBlock(toString(t), { { "Include", p.string() } });
add_excluded_from_build(s);
add_obj_file(t, p);
endBlock();
if (files_added.find(p) == files_added.end())
{
files_added.insert(p);

auto t = get_vs_file_type_by_ext(p);
beginBlock(toString(t), { { "Include", p.string() } });
add_excluded_from_build(s);
add_obj_file(t, p);
endBlock();
}
}
else
{
@@ -2279,7 +2279,7 @@ void Build::setupSolutionName(const path &file_or_dir)

bool dir = fs::is_directory(file_or_dir);
if (dir || isFrontendConfigFilename(file_or_dir))
ide_solution_name = fs::canonical(file_or_dir).filename().u8string();
ide_solution_name = fs::canonical(file_or_dir).parent_path().filename().u8string();
else
ide_solution_name = file_or_dir.stem().u8string();
}
@@ -2636,23 +2636,62 @@ void Build::load_configless(const path &file_or_dir)

bool dir = fs::is_directory(config_file_or_dir);

auto &s = solutions[0];
auto &exe = s.addExecutable(ide_solution_name);
bool read_deps_from_comments = false;
Strings comments;
if (!dir)
{
exe += file_or_dir;
// for generators
config = file_or_dir;

// read deps from comments
// read_deps_from_comments = true;
auto f = read_file(file_or_dir);

auto b = f.find("/*");
if (b != f.npos)
{
auto e = f.find("*/", b);
if (e != f.npos)
{
auto s = f.substr(b + 2, e - b - 2);
if (!s.empty())
comments.push_back(s);
}
}
}

if (!read_deps_from_comments)
createSolutions("", false);
for (auto &s : solutions)
{
for (auto &[p, d] : getPackageStore().resolved_packages)
current_solution = &s;
if (!dir)
{
//exe += file_or_dir;

for (auto &c : comments)
{
auto root = YAML::Load(c);
cppan_load(root, file_or_dir.stem().u8string());
}

if (s.children.size() == 1)
{
if (auto nt = s.children.begin()->second->as<NativeExecutedTarget>())
*nt += file_or_dir;
}

TargetsToBuild = s.children;
}
else
{
if (d.installed)
exe += std::make_shared<Dependency>(p.toString());
auto &exe = s.addExecutable(ide_solution_name);
bool read_deps_from_comments = false;

if (!read_deps_from_comments)
{
for (auto &[p, d] : getPackageStore().resolved_packages)
{
if (d.installed)
exe += std::make_shared<Dependency>(p.toString());
}
}
}
}
}
@@ -2697,6 +2736,7 @@ void Build::build_packages(const StringSet &pkgs)
getExecutor(e.get());
}

//
UnresolvedPackages upkgs;
for (auto &p : pkgs)
upkgs.insert(extractFromString(p));
@@ -355,7 +355,7 @@ struct SW_DRIVER_CPP_API Build : Solution, PackageScript
// other frontends
void cppan_load();
void cppan_load(const path &fn);
void cppan_load(const yaml &root);
void cppan_load(const yaml &root, const String &root_name = {});
bool cppan_check_config_root(const yaml &root);

public:
@@ -69,7 +69,7 @@ void Build::cppan_load(const path &fn)
cppan_load(root);
}

void Build::cppan_load(const yaml &root)
void Build::cppan_load(const yaml &root, const String &root_name)
{
if (!cppan_check_config_root(root))
return;
@@ -196,7 +196,7 @@ void Build::cppan_load(const yaml &root)
}
else
{
add_project(root, "");
add_project(root, root_name);
}

// remove unreferences projects
@@ -2824,8 +2824,10 @@ void NativeExecutedTarget::cppan_load_project(const yaml &root)
{
// some code was removed here
// check out original version (v1) if you encounter some errors
auto nppath = dependency.ppath / v;
dependency.ppath = nppath;

//auto nppath = dependency.ppath / v;
//dependency.ppath = nppath;

dependency.range = v;
};

0 comments on commit ff90784

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