Skip to content

Commit

Permalink
Added support for bitbucket repositories (#256)
Browse files Browse the repository at this point in the history
* Added support for bitbucket repositories:
* added variable BITBUCKET_REPOSITORY
* added short syntax in form "bb:user/repo"
* added description of that to readme.md

* Added test for bitbucket short syntax

* Used elseif syntax in handling of git services (github, gitlab, bitbucket).

* Added HEMRND/TestingFramework example located on bitbucket.org

* Reformatted CMakeLists.txt in TestingFramework example

* Bumped version of TestingFramework. It supports older version of c++ standard.

Co-authored-by: Paweł Gorgoń <[email protected]>
  • Loading branch information
pgorgon-hem and pgorgon-hem authored Jun 8, 2021
1 parent 9675d46 commit 91585e3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ CPMAddPackage("uri#tag")
CPMAddPackage("uri@version#tag")
```

In the shorthand syntax if the URI is of the form `gh:user/name`, it is interpreted as GitHub URI and converted to `https://github.com/user/name.git`. If the URI is of the form `gl:user/name`, it is interpreted as a [GitLab](https://gitlab.com/explore/) URI and coverted to `https://gitlab.com/user/name.git`. Otherwise the URI used verbatim as a git URL. All packages added using the shorthand syntax will be added using the [EXCLUDE_FROM_ALL](https://cmake.org/cmake/help/latest/prop_tgt/EXCLUDE_FROM_ALL.html) flag.
In the shorthand syntax if the URI is of the form `gh:user/name`, it is interpreted as GitHub URI and converted to `https://github.com/user/name.git`. If the URI is of the form `gl:user/name`, it is interpreted as a [GitLab](https://gitlab.com/explore/) URI and converted to `https://gitlab.com/user/name.git`. If the URI is of the form `bb:user/name`, it is interpreted as a [Bitbucket](https://bitbucket.org/) URI and converted to `https://bitbucket.org/user/name.git`. Otherwise the URI used verbatim as a git URL. All packages added using the shorthand syntax will be added using the [EXCLUDE_FROM_ALL](https://cmake.org/cmake/help/latest/prop_tgt/EXCLUDE_FROM_ALL.html) flag.

The single-argument syntax also works for URLs:

Expand Down
10 changes: 7 additions & 3 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ function(cpm_parse_add_package_single_arg arg outArgs)
elseif(scheme STREQUAL "gl")
set(out "GITLAB_REPOSITORY;${uri}")
set(packageType "git")
elseif(scheme STREQUAL "bb")
set(out "BITBUCKET_REPOSITORY;${uri}")
set(packageType "git")
# A CPM-specific scheme was not found. Looks like this is a generic URL so try to determine
# type
elseif(arg MATCHES ".git/?(@|#|$)")
Expand Down Expand Up @@ -369,6 +372,7 @@ function(CPMAddPackage)
DOWNLOAD_ONLY
GITHUB_REPOSITORY
GITLAB_REPOSITORY
BITBUCKET_REPOSITORY
GIT_REPOSITORY
SOURCE_DIR
DOWNLOAD_COMMAND
Expand Down Expand Up @@ -399,10 +403,10 @@ function(CPMAddPackage)

if(DEFINED CPM_ARGS_GITHUB_REPOSITORY)
set(CPM_ARGS_GIT_REPOSITORY "https://github.com/${CPM_ARGS_GITHUB_REPOSITORY}.git")
endif()

if(DEFINED CPM_ARGS_GITLAB_REPOSITORY)
elseif(DEFINED CPM_ARGS_GITLAB_REPOSITORY)
set(CPM_ARGS_GIT_REPOSITORY "https://gitlab.com/${CPM_ARGS_GITLAB_REPOSITORY}.git")
elseif(DEFINED CPM_ARGS_BITBUCKET_REPOSITORY)
set(CPM_ARGS_GIT_REPOSITORY "https://bitbucket.org/${CPM_ARGS_BITBUCKET_REPOSITORY}.git")
endif()

if(DEFINED CPM_ARGS_GIT_REPOSITORY)
Expand Down
7 changes: 7 additions & 0 deletions examples/TestingFramework/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)

project(CPMTestingFrameworkExample)

include(../../cmake/CPM.cmake)
CPMAddPackage("bb:HEMRND/[email protected]")
add_test_suites(TESTS SomeTest)
19 changes: 19 additions & 0 deletions examples/TestingFramework/SomeTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <HEM/TestingFramework.hpp>

using namespace fakeit;

class ITest {
public:
virtual int getInt() = 0;
};

TEST_CASE("Testing Framework Test") {
constexpr int someIntValue = 123456;

Mock<ITest> testMock;
When(Method(testMock, getInt)).Return(someIntValue);

int readValue = testMock.get().getInt();

REQUIRE(readValue == someIntValue);
}
6 changes: 6 additions & 0 deletions test/unit/parse_add_package_single_arg.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ assert_equal("GITLAB_REPOSITORY;foo/bar" "${args}")
cpm_parse_add_package_single_arg("gl:foo/Bar" args)
assert_equal("GITLAB_REPOSITORY;foo/Bar" "${args}")

cpm_parse_add_package_single_arg("bb:foo/bar" args)
assert_equal("BITBUCKET_REPOSITORY;foo/bar" "${args}")

cpm_parse_add_package_single_arg("bb:foo/Bar" args)
assert_equal("BITBUCKET_REPOSITORY;foo/Bar" "${args}")

cpm_parse_add_package_single_arg("https://github.com/cpm-cmake/[email protected]" args)
assert_equal("GIT_REPOSITORY;https://github.com/cpm-cmake/CPM.cmake.git;VERSION;0.30.5" "${args}")

Expand Down

0 comments on commit 91585e3

Please sign in to comment.