Skip to content

Commit

Permalink
[merge] K2 changes from local-target-system
Browse files Browse the repository at this point in the history
[all] K2 changes
  • Loading branch information
osdeverr authored Nov 12, 2024
2 parents e29f287 + ba32601 commit 91dc4b2
Show file tree
Hide file tree
Showing 43 changed files with 1,056 additions and 813 deletions.
11 changes: 4 additions & 7 deletions buildkit/re.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,17 @@ deps:
- vcpkg:yaml-cpp
- vcpkg:magic-enum
- vcpkg:cpp-httplib
- vcpkg:openssl
- github:osdeverr/fmt @re-9.1.0-1
- github:osdeverr/[email protected] [.libtool]
- github:osdeverr/[email protected] [semverpp]
- github:k2rate/ulib ^5.0.0 [/ulib]
- github:k2rate/ulib-process ^v1.0.2 [/ulib-process]
- github:osdeverr/ulib-env ^1.0.0 [/ulib-env]
- github:osdeverr/futile ^3.0.0 [/futile]

platform.windows:
deps:
- vcpkg:openssl@static-md
platform.!windows:
deps:
- vcpkg:openssl
- github:k2rate/ulib-json ^1.2.5
- github:k2rate/ulib-yaml-json ^1.0.0
- github:k2rate/ulib-yaml ^1.0.0

actions:
- run:
Expand Down
55 changes: 23 additions & 32 deletions buildkit/re/build/default_build_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,31 +170,30 @@ namespace re
return target;
}

YAML::Node DefaultBuildContext::LoadCachedParams(const fs::path &path)
ulib::yaml DefaultBuildContext::LoadCachedParams(const fs::path &path)
{
std::ifstream file{path / "re.user.yml"};

if (file.good())
{
auto yaml = YAML::Load(file);
file.close();

for (const auto &kv : yaml)
mVars.SetVar(mVars.Resolve(kv.first.Scalar()), mVars.Resolve(kv.second.Scalar()));
auto yaml = ulib::yaml::parse(futile::open(path / "re.user.yml").read());

for (const auto &kv : yaml.items())
mVars.SetVar(mVars.Resolve(kv.name()), mVars.Resolve(kv.value().scalar()));

return yaml;
}

return YAML::Node{YAML::Null};
return ulib::yaml{};
}

void DefaultBuildContext::SaveCachedParams(const fs::path &path, const YAML::Node &node)
void DefaultBuildContext::SaveCachedParams(const fs::path &path, const ulib::yaml &node)
{
std::ofstream file{path / "re.user.yml"};

YAML::Emitter emitter;
emitter << node;

file << emitter.c_str();
// std::system("pause");
// fmt::print("Saving: {}\nto: {}\n", node.dump().c_str(), (path / "re.user.yml").u8string().c_str());
futile::open(path / "re.user.yml", "w").write(node.dump());
}

void DefaultBuildContext::ResolveAllTargetDependencies(Target *pRootTarget)
Expand Down Expand Up @@ -289,27 +288,27 @@ namespace re
}

// Setting up the package sources for this target
for (const auto &kv : desc.pRootTarget->resolved_config["package-sources"])
for (const auto &kv : desc.pRootTarget->resolved_config["package-sources"].items())
{
auto repo_id = kv.first.Scalar();
auto repo_id = kv.name();

if (kv.second.IsScalar())
if (kv.value().is_scalar())
{
auto client = RePackageClient{kv.second.Scalar()};
auto client = RePackageClient{kv.value().scalar()};
auto resolver = std::make_unique<RePackageDepResolver>(mEnv.get(), this, repo_id, std::move(client));

mEnv->AddDepResolver(repo_id, resolver.get());
mDepResolvers.emplace_back(std::move(resolver));
}
else
{
auto &settings = kv.second;
auto &settings = kv.value();

auto client = RePackageClient{settings["url"].Scalar()};
auto client = RePackageClient{settings["url"].scalar()};

for (const auto &kv : settings["headers"])
for (const auto &kv : settings["headers"].items())
{
client.AddRequestHeader(kv.first.Scalar(), kv.second.Scalar());
client.AddRequestHeader(kv.name(), kv.value().scalar());
}

auto resolver = std::make_unique<RePackageDepResolver>(mEnv.get(), this, repo_id, std::move(client));
Expand Down Expand Up @@ -476,7 +475,7 @@ namespace re

for (const auto &path : path_cfg)
{
auto final_path = desc.pRootTarget->build_var_scope->Resolve(path.Scalar());
auto final_path = desc.pRootTarget->build_var_scope->Resolve(path.scalar());
ulib::add_path(final_path);
}

Expand Down Expand Up @@ -777,18 +776,10 @@ namespace re

if (should_merge_configs)
{
std::ifstream t1{dir / "re.yml._old"};
std::ifstream t2{template_dir / "re.yml"};

auto old_config = YAML::Load(t1);
auto new_config = YAML::Load(t2);

std::ofstream out{dir / "re.yml"};

YAML::Emitter emitter;
emitter << MergeYamlNodes(old_config, new_config);
auto old_config = ulib::yaml::parse(futile::open(dir / "re.yml._old").read());
auto new_config = ulib::yaml::parse(futile::open(template_dir / "re.yml").read());

out << emitter.c_str();
futile::open(dir / "re.yml").write(MergeYamlNodes(old_config, new_config).dump());

Warn(fg(fmt::color::light_yellow),
"WARN: Merged the existing re.yml with the one specified in the '{}'"
Expand Down
11 changes: 6 additions & 5 deletions buildkit/re/build/default_build_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <re/user_output.h>

#include "environment_var_namespace.h"
#include <ulib/yaml.h>

namespace re
{
Expand All @@ -20,23 +21,23 @@ namespace re
return mVars;
}

inline void SetVar(const std::string &key, std::string value)
inline void SetVar(ulib::string_view key, std::string value)
{
mVars.SetVar(key, value);
}
inline std::optional<std::string> GetVar(const std::string &key)
inline std::optional<ulib::string> GetVar(ulib::string_view key)
{
return mVars.GetVar(key);
}
inline void RemoveVar(const std::string &key)
inline void RemoveVar(ulib::string_view key)
{
mVars.RemoveVar(key);
}

Target &LoadTarget(const fs::path &path);

YAML::Node LoadCachedParams(const fs::path &path);
void SaveCachedParams(const fs::path &path, const YAML::Node &node);
ulib::yaml LoadCachedParams(const fs::path &path);
void SaveCachedParams(const fs::path &path, const ulib::yaml &node);

void ResolveAllTargetDependencies(Target *pRootTarget);

Expand Down
2 changes: 1 addition & 1 deletion buildkit/re/build/environment_var_namespace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace re
{
std::optional<std::string> EnvironmentVarNamespace::GetVar(const std::string &key) const
std::optional<ulib::string> EnvironmentVarNamespace::GetVar(ulib::string_view key) const
{
if (auto var = ulib::getenv(ulib::u8(key)))
return ulib::sstr(*var);
Expand Down
2 changes: 1 addition & 1 deletion buildkit/re/build/environment_var_namespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace re
{
struct EnvironmentVarNamespace : public IVarNamespace
{
std::optional<std::string> GetVar(const std::string& key) const;
std::optional<ulib::string> GetVar(ulib::string_view key) const;
};
}
4 changes: 4 additions & 0 deletions buildkit/re/build/ninja_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

#include <fstream>

#include <ulib/format.h>
#include <ulib/fmt/list.h>
#include <ulib/fmt/path.h>

namespace re
{
class FmtOstreamWrapper
Expand Down
32 changes: 16 additions & 16 deletions buildkit/re/build_desc.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ namespace re

struct BuildTool
{
std::string name;
std::string path;
ulib::string name;
ulib::string path;
};

struct BuildRule
{
std::string name;
std::string tool;
std::string cmdline;
std::string description;
ulib::string name;
ulib::string tool;
ulib::string cmdline;
ulib::string description;

BuildVars vars;
};
Expand All @@ -46,13 +46,13 @@ namespace re
{
BuildTargetType type;

std::string rule;
std::string in;
std::string out;
ulib::string rule;
ulib::string in;
ulib::string out;

BuildVars vars;

std::vector<std::string> deps;
std::vector<ulib::string> deps;

const Target *pSourceTarget = nullptr;
const SourceFile *pSourceFile = nullptr;
Expand All @@ -62,8 +62,8 @@ namespace re
{
fs::path out_dir;

std::string object_out_format;
std::string artifact_out_format;
ulib::string object_out_format;
ulib::string artifact_out_format;

// Vars that go in the very beginning of the build file
BuildVars init_vars;
Expand All @@ -78,7 +78,7 @@ namespace re
std::vector<BuildRule> rules;
std::vector<BuildTarget> targets;

std::vector<std::string> subninjas;
std::vector<ulib::string> subninjas;

Target *pRootTarget = nullptr;
Target *pBuildTarget = nullptr;
Expand All @@ -87,17 +87,17 @@ namespace re

tsl::ordered_map<const Target *, fs::path> artifacts;

std::string GetObjectDirectory(const std::string &module) const
ulib::string GetObjectDirectory(ulib::string_view module) const
{
return init_vars.at("re_target_object_directory_" + module);
}

std::string GetArtifactDirectory(const std::string &module) const
ulib::string GetArtifactDirectory(ulib::string_view module) const
{
return init_vars.at("re_target_artifact_directory_" + module);
}

bool HasArtifactsFor(const std::string &module) const
bool HasArtifactsFor(ulib::string_view module) const
{
return init_vars.find("re_target_artifact_directory_" + module) != init_vars.end();
}
Expand Down
Loading

0 comments on commit 91dc4b2

Please sign in to comment.