Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

let super reference file in project dir #100

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions inc/maiken/app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class KUL_PUBLISH Application : public Constants {

void preSetupValidation() KTHROW(Exception);
void postSetupValidation() KTHROW(Exception);
void resolveProperties() KTHROW(Exception);
This& resolveProperties() KTHROW(Exception);
void resolveLang() KTHROW(Exception);
static void parseDependencyString(std::string s, mkn::kul::hash::set::String& include);

Expand Down 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
41 changes: 27 additions & 14 deletions src/maiken.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,23 +192,36 @@ 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();
auto const gOrC = [&](auto const& in) {
try {
return &Applications::INSTANCE()
.getOrCreate(*maiken::Projects::INSTANCE().getOrCreate(in), "")
->resolveProperties();
} catch (std::exception const& e) {
KLOG(ERR) << e.what();
KEXIT(1, "Possible super cycle detected: " + project().dir().real());
}
};

if (auto const file = mkn::kul::File{super_string}; file.is()) {
if (file.real() == project().file())
KEXIT(1, "Super cannot reference itself: " + project().dir().real());
sup = gOrC(file);
} else {
//
mkn::kul::Dir const dir{super_string};
if (!dir) KEXIT(1, "Super does not exist in project: " + project().dir().real());
if (dir.real() == project().dir().real())
KEXIT(1, "Super cannot reference itself: " + project().dir().real());
sup = gOrC(dir);
}

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
3 changes: 2 additions & 1 deletion src/maiken/properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "maiken.hpp"

void maiken::Application::resolveProperties() KTHROW(maiken::Exception) {
maiken::Application& maiken::Application::resolveProperties() KTHROW(maiken::Exception) {
ps.setDeletedKey("--DELETED--");
for (YAML::const_iterator it = project().root()[STR_PROPERTY].begin();
it != project().root()[STR_PROPERTY].end(); ++it)
Expand All @@ -41,6 +41,7 @@ void maiken::Application::resolveProperties() KTHROW(maiken::Exception) {
if (ps.count(it->first.as<std::string>())) ps.erase(it->first.as<std::string>());
ps[it->first.as<std::string>()] = s;
}
return *this;
}

std::shared_ptr<std::tuple<std::string, int, int>> maiken::Properties::KEY(
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
Loading