Skip to content

Commit 2138fdc

Browse files
committed
Improve building local projects. Add xml mime type.
1 parent fa00ca4 commit 2138fdc

5 files changed

Lines changed: 47 additions & 17 deletions

File tree

src/client/main.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,8 @@ void default_run()
450450
check_spec_file();
451451

452452
Config c;
453+
c.allow_relative_project_names = true;
454+
c.allow_local_dependencies = true;
453455
auto &deps = Settings::get_local_settings().dependencies;
454456
if (deps.empty())
455457
{
@@ -505,7 +507,10 @@ void load_current_config()
505507
try
506508
{
507509
// load local settings for storage dir
508-
Config().load_current_config();
510+
Config c;
511+
c.allow_relative_project_names = true;
512+
c.allow_local_dependencies = true;
513+
c.load_current_config();
509514
}
510515
catch (...)
511516
{

src/common/package_store.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -414,20 +414,26 @@ PackageStore::read_packages_from_file(path p, const String &config_name, bool di
414414
sname = cppan_fn.parent_path().filename().string();
415415
p = cppan_fn;
416416
}
417-
else if (fs::exists(main_fn))
418-
{
419-
read_from_cpp(main_fn);
420-
p = main_fn;
421-
sname = p.filename().stem().string();
422-
cpp_fn = p;
423-
}
424417
else
425418
{
426-
LOG_DEBUG(logger, "No candidates {cppan.yml|main.cpp} for reading in directory " + p.string() +
427-
". Assuming default config.");
419+
if (!fs::exists(main_fn) && fs::exists("main.c"))
420+
main_fn = "main.c";
428421

429-
conf = build_spec_file(p);
430-
sname = p.filename().string();
422+
if (fs::exists(main_fn))
423+
{
424+
read_from_cpp(main_fn);
425+
p = main_fn;
426+
sname = p.filename().stem().string();
427+
cpp_fn = p;
428+
}
429+
else
430+
{
431+
LOG_DEBUG(logger, "No candidates {cppan.yml|main.c[pp]} for reading in directory " + p.string() +
432+
". Assuming default config.");
433+
434+
conf = build_spec_file(p);
435+
sname = p.filename().string();
436+
}
431437
}
432438
}
433439
else

src/common/project.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ using MimeType = String;
3636
using MimeTypes = std::set<MimeType>;
3737

3838
const MimeTypes source_mime_types{
39+
"application/xml",
40+
"text/xml",
41+
3942
"inode/x-empty", // empty file
4043

4144
"text/x-asm",
@@ -825,7 +828,11 @@ void Project::load(const yaml &root)
825828
if (dependency.ppath.empty())
826829
throw std::runtime_error("Could not load local project: " + lp);
827830
}
828-
dependency.ppath = ld.value();
831+
832+
if (dependency.ppath.is_relative() && rd.has_local_package(ld.value() / dependency.ppath))
833+
dependency.ppath = ld.value() / dependency.ppath;
834+
else // is this really needed?
835+
dependency.ppath = ld.value();
829836
}
830837
}
831838

@@ -1055,9 +1062,11 @@ void Project::load(const yaml &root)
10551062
}
10561063
if (defaults_allowed && iempty)
10571064
{
1058-
std::function<void(const String &, const String &)> autodetect_source_dir;
1059-
autodetect_source_dir = [this, &autodetect_source_dir](const String &current, const String &next = String())
1065+
std::function<void(const Strings &)> autodetect_source_dir;
1066+
autodetect_source_dir = [this, &autodetect_source_dir](const Strings &dirs)
10601067
{
1068+
const auto &current = dirs[0];
1069+
const auto &next = dirs[1];
10611070
if (fs::exists(current))
10621071
{
10631072
if (fs::exists("include"))
@@ -1081,11 +1090,12 @@ void Project::load(const yaml &root)
10811090
{
10821091
// now check next dir
10831092
if (!next.empty())
1084-
autodetect_source_dir(next, "");
1093+
autodetect_source_dir({ dirs.begin() + 1, dirs.end() });
10851094
}
10861095
}
10871096
};
1088-
autodetect_source_dir("src", "lib");
1097+
// keep empty entry at the end
1098+
autodetect_source_dir({ "src", "source", "sources", "lib", "" });
10891099
}
10901100
include_directories.public_.insert("${BDIR}");
10911101

src/common/settings.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ void Settings::load_main(const yaml &root, const SettingsType type)
204204
if (type == SettingsType::Local)
205205
{
206206
Project p;
207+
p.allow_relative_project_names = true;
208+
p.allow_local_dependencies = true;
207209
p.load(root);
208210
dependencies = p.dependencies;
209211
}

src/printers/cmake.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,6 +1805,7 @@ else())");
18051805

18061806
// aliases
18071807
{
1808+
// target type
18081809
const String tt = d.flags[pfExecutable] ? "add_executable" : "add_library";
18091810

18101811
config_section_title(ctx, "aliases");
@@ -1823,6 +1824,12 @@ else())");
18231824
add_aliases(".");
18241825
add_aliases("::");
18251826

1827+
if (d.flags[pfLocalProject])
1828+
{
1829+
ctx.addLine(tt + "(" + d.ppath.back() + " ALIAS ${this})");
1830+
ctx.emptyLines();
1831+
}
1832+
18261833
if (!p.aliases.empty())
18271834
{
18281835
ctx.addLine("# user-defined");

0 commit comments

Comments
 (0)