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

manifest: support path dependencies #1048

Merged
merged 6 commits into from
Dec 24, 2024
Merged
Changes from 2 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
59 changes: 52 additions & 7 deletions src/Manifest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,23 @@ struct GitDependency {
DepMetadata install() const;
};

struct LocalDependency {
std::string name;
std::string path;

DepMetadata install() const;
};

struct SystemDependency {
std::string name;
VersionReq versionReq;

DepMetadata install() const;
};

using Dependency =
std::variant<GitDependency, LocalDependency, SystemDependency>;

void
Profile::merge(const Profile& other) {
cxxflags.insert(other.cxxflags.begin(), other.cxxflags.end());
Expand Down Expand Up @@ -166,10 +176,8 @@ struct Manifest {
std::optional<toml::value> data = std::nullopt;

std::optional<Package> package = std::nullopt;
std::optional<std::vector<std::variant<GitDependency, SystemDependency>>>
dependencies = std::nullopt;
std::optional<std::vector<std::variant<GitDependency, SystemDependency>>>
devDependencies = std::nullopt;
std::optional<std::vector<Dependency>> dependencies = std::nullopt;
std::optional<std::vector<Dependency>> devDependencies = std::nullopt;

std::optional<Profile> profile = std::nullopt;
std::optional<Profile> devProfile = std::nullopt;
Expand Down Expand Up @@ -536,6 +544,16 @@ parseGitDep(const std::string& name, const toml::table& info) {
return { .name = name, .url = gitUrlStr, .target = target };
}

static LocalDependency
parseLocalDep(const std::string& name, const toml::table& info) {
validateDepName(name);
const auto& path = info.at("local");
if (!path.is_string()) {
throw PoacError("local dependency must be a path string");
}
return { .name = name, .path = path.as_string() };
}

static SystemDependency
parseSystemDep(const std::string& name, const toml::table& info) {
validateDepName(name);
Expand All @@ -548,7 +566,7 @@ parseSystemDep(const std::string& name, const toml::table& info) {
return { .name = name, .versionReq = VersionReq::parse(versionReq) };
}

static std::optional<std::vector<std::variant<GitDependency, SystemDependency>>>
static std::optional<std::vector<Dependency>>
parseDependencies(const char* key) {
Manifest& manifest = Manifest::instance();
const auto& table = toml::get<toml::table>(manifest.data.value());
Expand All @@ -558,7 +576,7 @@ parseDependencies(const char* key) {
}
const auto tomlDeps = toml::find<toml::table>(manifest.data.value(), key);

std::vector<std::variant<GitDependency, SystemDependency>> deps;
std::vector<Dependency> deps;
for (const auto& dep : tomlDeps) {
if (dep.second.is_table()) {
const auto& info = dep.second.as_table();
Expand All @@ -568,11 +586,15 @@ parseDependencies(const char* key) {
} else if (info.contains("system") && info.at("system").as_boolean()) {
deps.emplace_back(parseSystemDep(dep.first, info));
continue;
} else if (info.contains("local")) {
deps.emplace_back(parseLocalDep(dep.first, info));
continue;
}
}

throw PoacError(
"Only Git dependency and system dependency are supported for now: ",
"Only Git dependency, local dependency, and system dependency are "
"supported for now: ",
dep.first
);
}
Expand Down Expand Up @@ -619,6 +641,29 @@ GitDependency::install() const {
return { .includes = includes, .libs = "" };
}

DepMetadata
LocalDependency::install() const {
const fs::path installDir = fs::weakly_canonical(path);
if (fs::exists(installDir) && !fs::is_empty(installDir)) {
logger::debug("{} is already installed", name);
} else {
throw PoacError(installDir.string() + " can't be accessible as directory");
}

const fs::path includeDir = installDir / "include";
std::string includes = "-isystem";

if (fs::exists(includeDir) && fs::is_directory(includeDir)
&& !fs::is_empty(includeDir)) {
includes += includeDir.string();
} else {
includes += installDir.string();
}

// Currently, no libs are supported.
return { .includes = includes, .libs = "" };
}

DepMetadata
SystemDependency::install() const {
const std::string pkgConfigVer = versionReq.toPkgConfigString(name);
Expand Down
Loading