Skip to content

Commit 98b5285

Browse files
committed
Rewrite local package dependencies.
1 parent cf8c505 commit 98b5285

6 files changed

Lines changed: 24 additions & 35 deletions

File tree

src/common/config.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,15 @@ void Config::load(const yaml &root)
143143
{
144144
for (auto &d : get_sequence<path>(sd))
145145
{
146+
if (!fs::exists(d))
147+
continue;
146148
subdir = d.filename().string();
147149
reload(d);
148150
}
149151
subdir.clear();
150152
subdir_projects = std::move(projects);
153+
for (auto &[s,p] : subdir_projects)
154+
rd.known_local_packages.insert(p.pkg);
151155
}
152156

153157
load_settings(root);

src/common/package_store.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,9 @@ PackageStore::read_packages_from_file(path p, const String &config_name, bool di
427427
// allow relative project names
428428
c.allow_relative_project_names = true;
429429

430+
// allow loading local deps from subdirs
431+
c.allow_local_dependencies = true;
432+
430433
c.reload(p);
431434
return c;
432435
};

src/common/package_store.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ class PackageStore
6666
bool empty() const { return packages.empty(); }
6767
size_t size() const { return packages.size(); }
6868

69+
public:
70+
std::unordered_set<Package> known_local_packages;
71+
6972
private:
7073
PackageConfigs packages;
7174
std::set<std::unique_ptr<Config>> config_store;

src/common/project.cpp

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,7 @@ void Project::load(const yaml &root)
812812

813813
auto read_single_dep = [this, &read_version](const auto &d, Package dependency = Package())
814814
{
815+
bool local_ok = false;
815816
if (d.IsScalar())
816817
{
817818
auto p = extractFromStringAny(d.template as<String>());
@@ -834,39 +835,13 @@ void Project::load(const yaml &root)
834835
}
835836
if (d["local"].IsDefined() && allow_local_dependencies)
836837
{
837-
// WARNING!
838-
// probably this could be dangerous, maybe remove?
839-
// if set local dep for a secure file on the system
840-
// it will be read (or not?); how this affects system?
841-
// will not lead to exec shell code somehow or whatever?
842-
// ???
843-
auto lp = d["local"].template as<String>();
844-
auto ld = this->load_local_dependency(lp);
845-
if (!ld)
846-
{
847-
if (!dependency.ppath.empty() && !dependency.ppath.is_loc())
848-
{
849-
try
850-
{
851-
Packages p;
852-
p[dependency.ppath.toString()] = dependency;
853-
resolve_dependencies(p);
854-
}
855-
catch (const std::exception &)
856-
{
857-
// if not resolved, fail finally
858-
throw;
859-
}
860-
}
861-
862-
if (dependency.ppath.empty())
863-
throw std::runtime_error("Could not load local project: " + lp);
864-
}
865-
866-
if (dependency.ppath.is_relative() && rd.has_local_package(ld.value() / dependency.ppath))
867-
dependency.ppath = ld.value() / dependency.ppath;
868-
else // is this really needed?
869-
dependency.ppath = ld.value();
838+
auto p = d["local"].template as<String>();
839+
Package pkg;
840+
pkg.ppath = p;
841+
if (rd.known_local_packages.find(pkg) != rd.known_local_packages.end())
842+
local_ok = true;
843+
if (local_ok)
844+
dependency.ppath = p;
870845
}
871846
}
872847

@@ -886,7 +861,11 @@ void Project::load(const yaml &root)
886861
{
887862
// read other map fields
888863
if (d["version"].IsDefined())
864+
{
889865
read_version(dependency, d["version"].template as<String>());
866+
if (local_ok)
867+
dependency.version = Version(LOCAL_VERSION_NAME);
868+
}
890869
if (d["ref"].IsDefined())
891870
dependency.reference = d["ref"].template as<String>();
892871
if (d["reference"].IsDefined())

src/common/settings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ Settings &Settings::get(SettingsType type)
549549
{
550550
auto fn = CONFIG_ROOT "default";
551551
if (!fs::exists(fn))
552-
return;
552+
break;
553553
s.load(fn, SettingsType::System);
554554
};
555555
}

src/common/source.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
#include <fmt/format.h>
2323
#include <primitives/command.h>
24-
#include <primitives/overloads.h>
24+
#include <primitives/overload.h>
2525
#include <primitives/pack.h>
2626

2727
#include <regex>

0 commit comments

Comments
 (0)