aboutsummaryrefslogtreecommitdiff
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
parent396598030927a8e531bd68ba3b382f86645af6c6 (diff)
Remove ability to use git projects as dependencies. Users can add them as git submodules instead
-rw-r--r--CMakeLists.txt5
-rw-r--r--README.md1
-rw-r--r--include/Conf.hpp6
-rw-r--r--include/Dependency.hpp23
-rw-r--r--include/GitRepository.hpp16
-rw-r--r--include/GlobalLib.hpp3
-rw-r--r--src/Conf.cpp82
-rw-r--r--src/GitRepository.cpp104
-rw-r--r--src/GlobalLib.cpp89
-rw-r--r--tests/src/confTest/confTest.cpp14
-rw-r--r--tests/src/confTest/validProject.conf1
-rw-r--r--tests/src/main.cpp2
-rw-r--r--tests/src/platformTest.cpp2
-rw-r--r--tests/src/versionTest.cpp2
14 files changed, 6 insertions, 344 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1febc5e..719e984 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -17,7 +17,6 @@ set(SOURCE_FILES
src/Archive.cpp
src/CmakeModule.cpp
src/Package.cpp
- src/GitRepository.cpp
src/Platform.cpp
src/Version.cpp
src/VersionParser.cpp
@@ -37,9 +36,9 @@ add_executable(sibs ${SOURCE_FILES})
include_directories(${CURL_INCLUDE_DIR} ${LibArchive_INCLUDE_DIR} "depends/libninja/include")
if(WIN32)
- target_link_libraries(sibs ${CURL_LIBRARIES} ${LibArchive_LIBRARIES} "${CMAKE_CURRENT_SOURCE_DIR}/static/windows/git2.lib")
+ target_link_libraries(sibs ${CURL_LIBRARIES} ${LibArchive_LIBRARIES})
target_compile_options(sibs PRIVATE /Wall)
else()
- target_link_libraries(sibs ${CURL_LIBRARIES} ${LibArchive_LIBRARIES} -lgit2)
+ target_link_libraries(sibs ${CURL_LIBRARIES} ${LibArchive_LIBRARIES})
target_compile_options(sibs PRIVATE -Wall -Wextra -Werror=return-type -fdiagnostics-show-option -fexceptions)
endif()
diff --git a/README.md b/README.md
index 53a9a24..785540e 100644
--- a/README.md
+++ b/README.md
@@ -97,7 +97,6 @@ authors = ["DEC05EBA <0xdec05eba@gmail.com>"]
[dependencies]
catch2 = "0.1.0"
xxhash = "0.1.0"
-cisb = { git = "https://github.com/DEC05EBA/cisb.git", branch = "master", revision = "c0c46a4" }
[lang.c]
version = "c11"
diff --git a/include/Conf.hpp b/include/Conf.hpp
index dbe89d4..12164ea 100644
--- a/include/Conf.hpp
+++ b/include/Conf.hpp
@@ -277,11 +277,6 @@ namespace sibs
{
return packageListDependencies;
}
-
- virtual const std::vector<GitDependency*>& getGitDependencies() const
- {
- return gitDependencies;
- }
virtual const FileString& getProjectPath() const
{
@@ -464,7 +459,6 @@ namespace sibs
FileString testPath;
PackageType packageType;
std::vector<PackageListDependency*> packageListDependencies;
- std::vector<GitDependency*> gitDependencies;
std::vector<Platform> platforms;
std::unordered_map<std::string, std::string> defines;
OptimizationLevel optimizationLevel;
diff --git a/include/Dependency.hpp b/include/Dependency.hpp
index f505503..4660a05 100644
--- a/include/Dependency.hpp
+++ b/include/Dependency.hpp
@@ -8,7 +8,6 @@
namespace sibs
{
class PackageListDependency;
- class GitDependency;
class Dependency
{
@@ -16,7 +15,6 @@ namespace sibs
enum class Source
{
PACKAGE_LIST,
- GIT
};
virtual ~Dependency(){}
@@ -28,12 +26,6 @@ namespace sibs
assert(getSource() == Source::PACKAGE_LIST);
return (PackageListDependency*)this;
}
-
- const GitDependency* asGitDependency() const
- {
- assert(getSource() == Source::GIT);
- return (GitDependency*)this;
- }
};
class PackageListDependency : public Dependency
@@ -48,21 +40,6 @@ namespace sibs
std::string name;
PackageVersionRange version;
};
-
- class GitDependency : public Dependency
- {
- public:
- virtual ~GitDependency(){}
- virtual Source getSource() const
- {
- return Source::GIT;
- }
-
- std::string name;
- std::string url;
- std::string branch;
- std::string revision;
- };
}
#endif //SIBS_DEPENDENCY_HPP
diff --git a/include/GitRepository.hpp b/include/GitRepository.hpp
deleted file mode 100644
index 98399a0..0000000
--- a/include/GitRepository.hpp
+++ /dev/null
@@ -1,16 +0,0 @@
-#pragma once
-
-#include "Result.hpp"
-#include "FileUtil.hpp"
-
-namespace sibs
-{
- class GitDependency;
-
- class GitRepository
- {
- public:
- static Result<bool> clone(GitDependency *gitDependency, const FileString &repoDirPath);
- static Result<bool> pull(GitDependency *gitDependency, const FileString &repoDirPath);
- };
-}
diff --git a/include/GlobalLib.hpp b/include/GlobalLib.hpp
index b6ac60c..92739df 100644
--- a/include/GlobalLib.hpp
+++ b/include/GlobalLib.hpp
@@ -8,7 +8,6 @@
namespace sibs
{
class PackageListDependency;
- class GitDependency;
class GlobalLib
{
@@ -22,9 +21,7 @@ namespace sibs
static Result<bool> getLibs(const std::vector<PackageListDependency*> &libs, const SibsConfig &parentConfig, const FileString &globalLibRootDir, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallbackFunc, GlobalIncludeDirCallbackFunc globalIncludeDirCallback);
static Result<bool> validatePackageExists(const FileString &globalLibRootDir, const std::string &name);
static Result<bool> getLibsLinkerFlags(const SibsConfig &parentConfig, const FileString &globalLibRootDir, const std::string &name, const PackageVersionRange &versionRange, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallbackFunc, GlobalIncludeDirCallbackFunc globalIncludeDirCallback);
- static Result<bool> getLibsLinkerFlags(const SibsConfig &parentConfig, const FileString &globalLibRootDir, GitDependency *gitDependency, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallbackFunc, GlobalIncludeDirCallbackFunc globalIncludeDirCallback);
static Result<bool> downloadDependency(PackageListDependency *dependency, Platform platform);
- static Result<bool> downloadDependency(GitDependency *dependency, Platform platform);
private:
static Result<bool> getLibsLinkerFlagsCommon(const SibsConfig &parentConfig, const FileString &packageDir, const std::string &dependencyName, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallbackFunc, GlobalIncludeDirCallbackFunc globalIncludeDirCallback);
};
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);
- }
}
diff --git a/tests/src/confTest/confTest.cpp b/tests/src/confTest/confTest.cpp
index ec8a563..68e2225 100644
--- a/tests/src/confTest/confTest.cpp
+++ b/tests/src/confTest/confTest.cpp
@@ -1,4 +1,4 @@
-#include <catch.hpp>
+#include <catch2/catch.hpp>
#include "../../../include/Conf.hpp"
using namespace sibs;
@@ -32,18 +32,6 @@ TEST_CASE("parse config")
REQUIRE(catch2Dependency->name == "catch2");
REQUIRE(catch2Dependency->version.toString() == ">=1.0.0 and <2.0.0");
- REQUIRE(sibsConfig.getGitDependencies().size() == 1);
- for(auto *dep : sibsConfig.getGitDependencies())
- {
- REQUIRE(dep->getSource() == Dependency::Source::GIT);
- }
- const Dependency *sfmlAllDependency = sibsConfig.getGitDependencies()[0];
- const GitDependency *sfmlAllDependencyGit = sfmlAllDependency->asGitDependency();
- REQUIRE(sfmlAllDependencyGit->name == "sfml-all");
- REQUIRE(sfmlAllDependencyGit->url == "https://github.com/DEC05EBA/sfml-all.git");
- REQUIRE(sfmlAllDependencyGit->branch == "master");
- REQUIRE(sfmlAllDependencyGit->revision == "HEAD");
-
REQUIRE(sibsConfig.shouldUseCmake());
REQUIRE(sibsConfig.getCmakeDir() == TINYDIR_STRING("tests/src/confTest/cmakeGlobal"));
diff --git a/tests/src/confTest/validProject.conf b/tests/src/confTest/validProject.conf
index c5232c6..cd3f9cc 100644
--- a/tests/src/confTest/validProject.conf
+++ b/tests/src/confTest/validProject.conf
@@ -7,7 +7,6 @@ platforms = ["linux64", "win64"]
[dependencies]
xxhash = "0.1.0" # random comment at end of line
catch2 = "1.0.0"
-sfml-all = { git = "https://github.com/DEC05EBA/sfml-all.git", branch = "master" }
# cmake building is currrently not implemented, but it is intended to work like this
[cmake]
diff --git a/tests/src/main.cpp b/tests/src/main.cpp
index b3143fb..4ed06df 100644
--- a/tests/src/main.cpp
+++ b/tests/src/main.cpp
@@ -1,2 +1,2 @@
#define CATCH_CONFIG_MAIN
-#include <catch.hpp>
+#include <catch2/catch.hpp>
diff --git a/tests/src/platformTest.cpp b/tests/src/platformTest.cpp
index aecc3e4..dfa3923 100644
--- a/tests/src/platformTest.cpp
+++ b/tests/src/platformTest.cpp
@@ -1,4 +1,4 @@
-#include <catch.hpp>
+#include <catch2/catch.hpp>
#include "../../include/Platform.hpp"
using namespace sibs;
diff --git a/tests/src/versionTest.cpp b/tests/src/versionTest.cpp
index 48a8838..307496f 100644
--- a/tests/src/versionTest.cpp
+++ b/tests/src/versionTest.cpp
@@ -1,4 +1,4 @@
-#include <catch.hpp>
+#include <catch2/catch.hpp>
#include "../../include/VersionParser.hpp"
using namespace sibs;