aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-11-03 06:11:09 +0100
committerdec05eba <dec05eba@protonmail.com>2020-11-03 06:11:09 +0100
commit1a6c67af3851748a0a604e3b3e99bd63f3f576a0 (patch)
treecdf4c0fe3ede4c4b966941a6bb3dd0af6ca0a769 /src
parent396598030927a8e531bd68ba3b382f86645af6c6 (diff)
Remove ability to use git projects as dependencies. Users can add them as git submodules instead
Diffstat (limited to 'src')
-rw-r--r--src/Conf.cpp82
-rw-r--r--src/GitRepository.cpp104
-rw-r--r--src/GlobalLib.cpp89
3 files changed, 0 insertions, 275 deletions
diff --git a/src/Conf.cpp b/src/Conf.cpp
index 74c311c..12421e0 100644
--- a/src/Conf.cpp
+++ b/src/Conf.cpp
@@ -649,11 +649,6 @@ namespace sibs
{
//delete dependency;
}
-
- for(GitDependency *dependency : gitDependencies)
- {
- //delete dependency;
- }
*/
}
@@ -1112,83 +1107,6 @@ namespace sibs
dependency->version = dependencyVersionResult.unwrap();
packageListDependencies.emplace_back(dependency);
}
- else if(value.isObject())
- {
- enum class DepType
- {
- NONE,
- GIT
- };
-
- DepType depType = DepType::NONE;
- for(auto it : value.asObject())
- {
- DepType fieldDepType = DepType::NONE;
- if(it.first == "git" || it.first == "branch" || it.first == "revision")
- fieldDepType = DepType::GIT;
-
- if(fieldDepType == DepType::NONE)
- {
- string errMsg = "Invalid dependency object field \"";
- errMsg += it.first;
- errMsg += "\"";
- throw ParserException(errMsg);
- }
-
- if(depType != DepType::NONE && fieldDepType != depType)
- {
- switch(depType)
- {
- case DepType::GIT:
- {
- string errMsg = "Invalid dependency object field \"";
- errMsg += it.first;
- errMsg += "\" is invalid for a git dependency";
- throw ParserException(errMsg);
- }
- default:
- throw ParserException("Invalid dependency object");
- }
- }
- depType = fieldDepType;
- }
-
- switch(depType)
- {
- case DepType::GIT:
- {
- auto gitIt = value.asObject().find("git");
- if(gitIt == value.asObject().end())
- {
- throw ParserException("Required field \"git\" is missing from git dependency. Expected an url to location of git repository");
- }
-
- auto branchIt = value.asObject().find("branch");
- string branch;
- if(branchIt == value.asObject().end())
- branch = "master";
- else
- branch = string(branchIt->second.data, branchIt->second.size);
-
- auto revisionIt = value.asObject().find("revision");
- string revision;
- if(revisionIt == value.asObject().end())
- revision = "HEAD";
- else
- revision = string(revisionIt->second.data, revisionIt->second.size);
-
- GitDependency *dependency = new GitDependency();
- dependency->name = string(name.data, name.size);
- dependency->url = string(gitIt->second.data, gitIt->second.size);
- dependency->branch = branch;
- dependency->revision = revision;
- gitDependencies.emplace_back(dependency);
- break;
- }
- default:
- throw ParserException("Invalid dependency object");
- }
- }
else
throw ParserException("Expected field under dependencies to be a single value or an object, was a list");
}
diff --git a/src/GitRepository.cpp b/src/GitRepository.cpp
deleted file mode 100644
index 7818bdb..0000000
--- a/src/GitRepository.cpp
+++ /dev/null
@@ -1,104 +0,0 @@
-#include "../include/GitRepository.hpp"
-#include "../include/Dependency.hpp"
-#include <git2.h>
-#include <string>
-#include <cassert>
-
-using namespace std;
-
-static bool libgitInitialized = false;
-
-namespace sibs
-{
- void gitInit()
- {
- if(!libgitInitialized)
- {
- libgitInitialized = true;
- // TODO: Call git_libgit2_shutdown in destructor? dont really need to do that though
- git_libgit2_init();
- }
- }
-
- Result<bool> buildGitError(int error, const string &errorPrefix)
- {
- const git_error *e = giterr_last();
- string errMsg = errorPrefix;
- errMsg += ": ";
- errMsg += to_string(error);
- errMsg += "/";
- errMsg += to_string(e->klass);
- errMsg += ": ";
- errMsg += e->message;
- return Result<bool>::Err(errMsg, error);
- }
-
- Result<bool> GitRepository::clone(GitDependency *gitDependency, const FileString &repoDirPath)
- {
- // TODO: Use git dependency revision when cloning
- gitInit();
- git_repository *repo;
- git_clone_options options = GIT_CLONE_OPTIONS_INIT;
- options.checkout_branch = gitDependency->branch.c_str();
- int error = git_clone(&repo, gitDependency->url.c_str(), toUtf8(repoDirPath).c_str(), &options);
- if(error != 0)
- return buildGitError(error, "Failed to clone git repository");
-
- git_repository_free(repo);
- return Result<bool>::Ok(true);
- }
-
- Result<bool> GitRepository::pull(GitDependency *gitDependency, const FileString &repoDirPath)
- {
- gitInit();
- int error;
-
- git_repository *repo;
- error = git_repository_open(&repo, toUtf8(repoDirPath).c_str());
- if(error != 0)
- return buildGitError(error, "Failed to open git repository");
-
- git_remote *remote;
- error = git_remote_lookup(&remote, repo, "origin");
- if(error != 0)
- return buildGitError(error, "Failed to do remote lookup for git repository");
-
- // TODO: Setup option to be able to use callback for progress (for output in console) and handling credentials
- error = git_remote_fetch(remote, NULL, NULL, "pull");
- if(error != 0)
- {
- Result<bool> err = buildGitError(error, "Failed to do remote fetch for git repository");
- git_remote_free(remote);
- git_repository_free(repo);
- return err;
- }
-
- git_reference *ref;
- error = git_reference_dwim(&ref, repo, gitDependency->branch.c_str());
- if(error != 0)
- {
- Result<bool> err = buildGitError(error, "Failed to do reference lookup for git repository");
- git_remote_free(remote);
- git_repository_free(repo);
- return err;
- }
-
- git_annotated_commit *annotatedCommit;
- error = git_annotated_commit_from_ref(&annotatedCommit, repo, ref);
- if(error != 0)
- {
- Result<bool> err = buildGitError(error, "Failed to get commit from ref");
- git_annotated_commit_free(annotatedCommit);
- git_remote_free(remote);
- git_repository_free(repo);
- return err;
- }
-
- assert(false);
-
- git_annotated_commit_free(annotatedCommit);
- git_remote_free(remote);
- git_repository_free(repo);
- return Result<bool>::Ok(true);
- }
-}
diff --git a/src/GlobalLib.cpp b/src/GlobalLib.cpp
index 9ad3d77..8ad1678 100644
--- a/src/GlobalLib.cpp
+++ b/src/GlobalLib.cpp
@@ -7,7 +7,6 @@
#include "../include/Archive.hpp"
#include "../include/CmakeModule.hpp"
#include "../include/Dependency.hpp"
-#include "../include/GitRepository.hpp"
#include "../include/VersionParser.hpp"
using namespace std;
@@ -50,8 +49,6 @@ namespace sibs
// We also need to verify that the archive was removed after extracting it, otherwise the extracted
// package could be corrupted. The archive is only removed after extracting is done.
- // TODO: Find a way to verify that the git repo was cloned fully without interruption, or add .finished files
- // for every download
Result<FileString> libPathResult = getHomeDir();
if (!libPathResult)
@@ -116,38 +113,6 @@ namespace sibs
}
}
}
-
- for(GitDependency *gitDependency : parentConfig.getGitDependencies())
- {
- Result<bool> gitLibLinkerFlagsResult = GlobalLib::getLibsLinkerFlags(parentConfig, globalLibRootDir, gitDependency, staticLinkerFlagCallbackFunc, dynamicLinkerFlagCallbackFunc, globalIncludeDirCallback);
- if(!gitLibLinkerFlagsResult)
- {
- if(gitLibLinkerFlagsResult.getErrorCode() == GlobalLib::DependencyError::DEPENDENCY_NOT_FOUND)
- {
- printf("Dependency %s not found in global lib, trying to download from git\n", gitDependency->name.c_str());
- // TODO: Download several dependencies at the same time by adding them to a list
- // and then iterate them and download them all using several threads.
- // All dependecies should be downloaded at the same time, this includes dependencies of dependencies.
- // If a dependency is missing, fail build BEFORE downloading dependencies and before compiling anything.
- // You do not want to possibly wait several minutes only for build to fail when there is no compilation error.
-
- // TODO: If return error is invalid url, then the message should be converted to
- // invalid package name/version. A check should be done if it is the name or version
- // that is invalid.
- Result<bool> downloadDependencyResult = GlobalLib::downloadDependency(gitDependency, parentConfig.platform);
- if(!downloadDependencyResult)
- return downloadDependencyResult;
-
- gitLibLinkerFlagsResult = GlobalLib::getLibsLinkerFlags(parentConfig, globalLibRootDir, gitDependency, staticLinkerFlagCallbackFunc, dynamicLinkerFlagCallbackFunc, globalIncludeDirCallback);
- if(!gitLibLinkerFlagsResult)
- return gitLibLinkerFlagsResult;
- }
- else
- {
- return gitLibLinkerFlagsResult;
- }
- }
- }
return Result<bool>::Ok(true);
}
@@ -191,37 +156,6 @@ namespace sibs
return GlobalLib::getLibsLinkerFlagsCommon(parentConfig, packageDir, name, staticLinkerFlagCallbackFunc, dynamicLinkerFlagCallbackFunc, globalIncludeDirCallback);
}
- Result<bool> GlobalLib::getLibsLinkerFlags(const SibsConfig &parentConfig, const FileString &globalLibRootDir, GitDependency *gitDependency, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallbackFunc, GlobalIncludeDirCallbackFunc globalIncludeDirCallback)
- {
- Result<bool> packageExistsResult = validatePackageExists(globalLibRootDir, gitDependency->name);
- if (packageExistsResult.isErr())
- return packageExistsResult;
-
-#if OS_FAMILY == OS_FAMILY_POSIX
- FileString namePlatformNative = gitDependency->name;
- FileString versionPlatformNative = gitDependency->revision;
-#else
- FileString namePlatformNative = utf8To16(gitDependency->name);
- FileString versionPlatformNative = utf8To16(gitDependency->revision);
-#endif
-
- FileString packageDir = globalLibRootDir + TINYDIR_STRING("/");
- packageDir += namePlatformNative;
- packageDir += TINYDIR_STRING("/");
- packageDir += versionPlatformNative;
-
- // TODO: Check path is valid git repository by using git_repository_open_ext
-
- // TODO: Pull if revision == HEAD, fail build if there are conflicts.
- // TODO: When building a sibs project, put a symlink in libs directory.
- // This allows you to have dependency on a project and make changes to it without pushing
- // to remote before the dependant project can see the changes.
- //GitRepository gitRepo;
- //gitRepo.pull(gitDependency, packageDir);
-
- return GlobalLib::getLibsLinkerFlagsCommon(parentConfig, packageDir, gitDependency->name, staticLinkerFlagCallbackFunc, dynamicLinkerFlagCallbackFunc, globalIncludeDirCallback);
- }
-
Result<bool> GlobalLib::getLibsLinkerFlagsCommon(const SibsConfig &parentConfig, const FileString &packageDir, const string &dependencyName, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallbackFunc, GlobalIncludeDirCallbackFunc globalIncludeDirCallback)
{
FileString projectConfFilePath = packageDir;
@@ -352,27 +286,4 @@ namespace sibs
#endif
return archiveExtractResult;
}
-
- Result<bool> GlobalLib::downloadDependency(GitDependency *dependency, Platform platform)
- {
- Result<FileString> libPathResult = getHomeDir();
- if (!libPathResult)
- return Result<bool>::Err(libPathResult);
- FileString libPath = libPathResult.unwrap();
- libPath += TINYDIR_STRING("/.cache/sibs/lib/");
- libPath += toFileString(asString(platform));
- libPath += TINYDIR_STRING("/");
- libPath += toFileString(dependency->name);
-
- // We dont care if the directory already exists. Nothing will happen if it does
- Result<bool> createLibDirResult = createDirectoryRecursive(libPath.c_str());
- if(!createLibDirResult)
- return createLibDirResult;
-
- libPath += TINYDIR_STRING("/");
- libPath += toFileString(dependency->revision);
-
- GitRepository gitRepo;
- return gitRepo.clone(dependency, libPath);
- }
}