Skip to content

Commit

Permalink
let super reference file in project dir
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDeegan committed Aug 21, 2024
1 parent e271596 commit 54b0bfe
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 31 deletions.
2 changes: 1 addition & 1 deletion inc/maiken/app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ class Applications : public Constants {

std::vector<Application const*> applicationsFor(Project const& project) const {
std::vector<Application const*> ret;
for (auto const& profile : m_apps.at(project.dir().real())) ret.emplace_back(profile.second);
for (auto const& profile : m_apps.at(project.file())) ret.emplace_back(profile.second);
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion mkn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
name: mkn
version: master
property:
DATE: 20-AUG-2024
DATE: 21-AUG-2024

parent: bin
mode: none
Expand Down
45 changes: 31 additions & 14 deletions src/maiken.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,23 +192,40 @@ void maiken::Application::setSuper() {
if (sup) return;
if (project().root()[STR_SUPER]) {
mkn::kul::os::PushDir pushd(project().dir().real());
mkn::kul::Dir d(project().root()[STR_SUPER].Scalar());
if (!d) KEXIT(1, "Super does not exist in project: " + project().dir().real());
std::string super(d.real());
if (super == project().dir().real())
KEXIT(1, "Super cannot reference itself: " + project().dir().real());
d = mkn::kul::Dir(super);
try {
sup = Applications::INSTANCE().getOrCreate(*maiken::Projects::INSTANCE().getOrCreate(d), "");
sup->resolveProperties();
} catch (std::exception const& e) {
KLOG(ERR) << e.what();
KEXIT(1, "Possible super cycle detected: " + project().dir().real());

auto const& super_string = project().root()[STR_SUPER].Scalar();
if (auto file = mkn::kul::File{super_string}; file.is()) {
if (file.real() == project().file())
KEXIT(1, "Super cannot reference itself: " + project().dir().real());
try {
sup = Applications::INSTANCE().getOrCreate(*maiken::Projects::INSTANCE().getOrCreate(file),
"");
sup->resolveProperties();
} catch (std::exception const& e) {
KLOG(ERR) << e.what();
KEXIT(1, "Possible super cycle detected: " + project().dir().real());
}
} else {
mkn::kul::Dir d{super_string};
if (!d) KEXIT(1, "Super does not exist in project: " + project().dir().real());
std::string super(d.real());
if (super == project().dir().real())
KEXIT(1, "Super cannot reference itself: " + project().dir().real());
d = mkn::kul::Dir(super);
try {
sup =
Applications::INSTANCE().getOrCreate(*maiken::Projects::INSTANCE().getOrCreate(d), "");
sup->resolveProperties();
} catch (std::exception const& e) {
KLOG(ERR) << e.what();
KEXIT(1, "Possible super cycle detected: " + project().dir().real());
}
}

auto cycle = sup;
while (cycle) {
if (cycle->project().dir() == project().dir())
KEXIT(1, "Super cycle detected: " + project().dir().real());
if (cycle->project().file() == project().file())
KEXIT(1, "Super cycle detected: " + project().file());
cycle = cycle->sup;
}
for (auto const& p : sup->properties())
Expand Down
14 changes: 7 additions & 7 deletions src/maiken/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,35 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
maiken::Application* maiken::Applications::getOrCreate(maiken::Project const& proj,
std::string const& _profile, bool setup)
KTHROW(mkn::kul::Exception) {
std::string pDir(proj.dir().real());
std::string pFile(proj.file());
std::string profile = _profile.empty() ? "@" : _profile;
if (!m_apps.count(pDir) || !m_apps[pDir].count(profile)) {
if (!m_apps.count(pFile) || !m_apps[pFile].count(profile)) {
auto app = std::make_unique<Application>(proj, _profile);
auto pp = app.get();
m_appPs.push_back(std::move(app));
m_apps[pDir][profile] = pp;
m_apps[pFile][profile] = pp;
if (setup) {
mkn::kul::os::PushDir pushd(proj.dir());
pp->setup();
}
}
return m_apps[pDir][profile];
return m_apps[pFile][profile];
}

maiken::Application* maiken::Applications::getOrCreateRoot(maiken::Project const& proj,
std::string const& _profile, bool setup)
KTHROW(mkn::kul::Exception) {
std::string pDir(proj.dir().real());
std::string pFile(proj.file());
std::string profile = _profile.empty() ? "@" : _profile;
if (!m_apps.count(pDir) || !m_apps[pDir].count(profile)) {
if (!m_apps.count(pFile) || !m_apps[pFile].count(profile)) {
auto* pp = getOrCreate(proj, _profile, /*setup = */ false);
pp->ro = 1;
if (setup) {
mkn::kul::os::PushDir pushd(proj.dir());
pp->setup();
}
}
return m_apps[pDir][profile];
return m_apps[pFile][profile];
}

maiken::Application* maiken::Applications::getOrNullptr(std::string const& project) {
Expand Down
7 changes: 4 additions & 3 deletions src/maiken/build/bin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,13 @@ class Executioner : public Constants {
KOUT(NON) << cpc.cmd();
else {
if (AppVars::INSTANCE().dump()) {
auto const eol = mkn::kul::os::EOL();
std::string base = mkn::kul::File(cpc.file()).name();
mkn::kul::io::Writer(mkn::kul::File(base + ".txt", cmdLogDir)) << cpc.cmd();
mkn::kul::io::Writer(mkn::kul::File(base + ".txt", cmdLogDir)) << cpc.cmd() << eol;
if (cpc.outs().size())
mkn::kul::io::Writer(mkn::kul::File(base + ".txt", outLogDir)) << cpc.outs();
mkn::kul::io::Writer(mkn::kul::File(base + ".txt", outLogDir)) << cpc.outs() << eol;
if (cpc.errs().size())
mkn::kul::io::Writer(mkn::kul::File(base + ".txt", errLogDir)) << cpc.errs();
mkn::kul::io::Writer(mkn::kul::File(base + ".txt", errLogDir)) << cpc.errs() << eol;
}

#if defined(_MKN_WITH_MKN_RAM_) && defined(_MKN_WITH_IO_CEREAL_)
Expand Down
7 changes: 4 additions & 3 deletions src/maiken/build/obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,13 @@ void maiken::Application::compile(std::queue<std::pair<maiken::Source, std::stri
KOUT(NON) << cpc.cmd();

if (AppVars::INSTANCE().dump()) {
auto const eol = mkn::kul::os::EOL();
std::string base = mkn::kul::File(cpc.file()).name();
mkn::kul::io::Writer(mkn::kul::File(base + ".txt", cmdLogDir)) << cpc.cmd();
mkn::kul::io::Writer(mkn::kul::File(base + ".txt", cmdLogDir)) << cpc.cmd() << eol;
if (cpc.outs().size())
mkn::kul::io::Writer(mkn::kul::File(base + ".txt", outLogDir)) << cpc.outs();
mkn::kul::io::Writer(mkn::kul::File(base + ".txt", outLogDir)) << cpc.outs() << eol;
if (cpc.errs().size())
mkn::kul::io::Writer(mkn::kul::File(base + ".txt", errLogDir)) << cpc.errs();
mkn::kul::io::Writer(mkn::kul::File(base + ".txt", errLogDir)) << cpc.errs() << eol;
}

std::lock_guard<std::mutex> lock(mute);
Expand Down
2 changes: 1 addition & 1 deletion src/maiken/setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void sub_initializer(Application const& app, std::vector<YAML::Node> const& node

auto const process = [&](auto n) {
if (n[STR_SUB] && n[STR_SUB].IsScalar()) {
for (auto const& line : mkn::kul::String::LINES(n[STR_SUB].Scalar())) {
for (auto const& line : mkn::kul::cli::asArgs(n[STR_SUB].Scalar())) {
auto pInfo = ProjectInfo::PARSE_LINE(line);
mkn::kul::Dir local{pInfo.local};
if (!local)
Expand Down
2 changes: 1 addition & 1 deletion src/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ maiken::ProjectInfo maiken::ProjectInfo::PARSE_LINE(std::string const& line) {
if (version.size() == 0 && scm.size() && !Github::GET_LATEST(scm, version)) version = "";
#endif

return {local, profiles, proj, version, scm};
return {local, profiles, proj, version, scm.size() ? scm : proj};
}

mkn::kul::yaml::Validator maiken::Project::validator() const {
Expand Down

0 comments on commit 54b0bfe

Please sign in to comment.