Skip to content

Commit

Permalink
implement LocalDependency
Browse files Browse the repository at this point in the history
  • Loading branch information
wx257osn2 committed Dec 21, 2024
1 parent 04c7855 commit cec12cf
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions src/Manifest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,22 @@ 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, SystemDependency>;
using Dependency =
std::variant<GitDependency, LocalDependency, SystemDependency>;

void
Profile::merge(const Profile& other) {
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 Down Expand Up @@ -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::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

0 comments on commit cec12cf

Please sign in to comment.