Skip to content

Commit 95ecb4c

Browse files
authored
Merge pull request #245 from aminya/git-vcpkg
2 parents 0e89e7b + 42818f6 commit 95ecb4c

10 files changed

Lines changed: 85 additions & 20 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ include(${_project_options_SOURCE_DIR}/Index.cmake)
7777
# install vcpkg dependencies: - should be called before defining project()
7878
run_vcpkg(
7979
VCPKG_URL "https://github.com/microsoft/vcpkg.git"
80-
VCPKG_REV "0fa8459cf3a7caca7adc58f992bc32ff13630684"
80+
VCPKG_REV "6a3dd0874f153f8b375ec26210ea6d41dee3bb26"
8181
)
8282
8383
# Set the project name and language

docs/src/project_options_example.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ include(${_project_options_SOURCE_DIR}/Index.cmake)
3030
# install vcpkg dependencies: - should be called before defining project()
3131
run_vcpkg(
3232
VCPKG_URL "https://github.com/microsoft/vcpkg.git"
33-
VCPKG_REV "0fa8459cf3a7caca7adc58f992bc32ff13630684"
33+
VCPKG_REV "6a3dd0874f153f8b375ec26210ea6d41dee3bb26"
3434
ENABLE_VCPKG_UPDATE
3535
)
3636

src/Git.cmake

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,19 @@ function(git_switch_back)
465465
message(STATUS "Switch back failed. Trying to checkout previous branch")
466466
execute_process(
467467
COMMAND "${GIT_EXECUTABLE}" "checkout" "-" WORKING_DIRECTORY "${_fun_REPOSITORY_PATH}"
468-
COMMAND_ERROR_IS_FATAL LAST
468+
RESULT_VARIABLE _checkout_result
469469
)
470+
471+
# if the checkout failed, try to checkout the default branch
472+
if(NOT ${_checkout_result} EQUAL 0)
473+
message(STATUS "Checkout previous branch failed. Trying to checkout default branch")
474+
git_default_branch(default_branch REPOSITORY_PATH "${_fun_REPOSITORY_PATH}")
475+
execute_process(
476+
COMMAND "${GIT_EXECUTABLE}" "checkout" "${default_branch}"
477+
WORKING_DIRECTORY "${_fun_REPOSITORY_PATH}" COMMAND_ERROR_IS_FATAL LAST
478+
)
479+
endif()
480+
470481
endif()
471482
endif()
472483
endfunction()
@@ -512,3 +523,56 @@ function(git_wait)
512523
endif()
513524
endwhile()
514525
endfunction()
526+
527+
#[[.rst:
528+
529+
``git_default_branch``
530+
======================
531+
Get the default branch of the given repository. Defaults to master in case of failure
532+
533+
Input variables:
534+
- ``REPOSITORY_PATH``: The path to the repository
535+
536+
Output variables:
537+
- ``default_branch``: The variable to store the default branch in
538+
539+
540+
.. code:: cmake
541+
542+
git_default_branch(
543+
REPOSITORY_PATH
544+
"$ENV{HOME}/vcpkg"
545+
default_branch
546+
)
547+
548+
]]
549+
function(git_default_branch default_branch)
550+
# use git symbolic-ref refs/remotes/origin/HEAD to get the default branch
551+
552+
set(oneValueArgs REPOSITORY_PATH)
553+
cmake_parse_arguments(_fun "" "${oneValueArgs}" "" ${ARGN})
554+
555+
if("${_fun_REPOSITORY_PATH}" STREQUAL "")
556+
message(FATAL_ERROR "REPOSITORY_PATH is required")
557+
endif()
558+
559+
find_program(GIT_EXECUTABLE "git" REQUIRED)
560+
execute_process(
561+
COMMAND "${GIT_EXECUTABLE}" "symbolic-ref" "refs/remotes/origin/HEAD"
562+
OUTPUT_VARIABLE _default_branch
563+
WORKING_DIRECTORY "${_fun_REPOSITORY_PATH}"
564+
OUTPUT_STRIP_TRAILING_WHITESPACE
565+
RESULT_VARIABLE _default_branch_result
566+
)
567+
568+
if(${_default_branch_result} EQUAL 0)
569+
string(REGEX REPLACE "refs/remotes/origin/" "" _default_branch "${_default_branch}")
570+
else()
571+
message(
572+
WARNING "Could not get default branch of ${_fun_REPOSITORY_PATH}. Considering it as master"
573+
)
574+
set(_default_branch "master")
575+
endif()
576+
577+
set(${default_branch} ${_default_branch} PARENT_SCOPE)
578+
endfunction()

src/Vcpkg.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Or by specifying the options
156156
157157
run_vcpkg(
158158
VCPKG_URL "https://github.com/microsoft/vcpkg.git"
159-
VCPKG_REV "0fa8459cf3a7caca7adc58f992bc32ff13630684"
159+
VCPKG_REV "6a3dd0874f153f8b375ec26210ea6d41dee3bb26"
160160
ENABLE_VCPKG_UPDATE
161161
)
162162

tests/install/vcpkg.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
2-
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json",
2+
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
33
"name": "another-project",
44
"version-string": "0.1.0",
5-
"builtin-baseline": "8dbd66f5a7821ced1ed57696b50375a977006813",
5+
"builtin-baseline": "6a3dd0874f153f8b375ec26210ea6d41dee3bb26",
66
"dependencies": [
77
{
88
"name": "eigen3",
9-
"version>=": "3.4.0"
9+
"version>=": "3.4.0#2"
1010
},
1111
{
1212
"name": "fmt",
13-
"version>=": "8.1.1"
13+
"version>=": "9.1.0#1"
1414
}
1515
]
1616
}

tests/myproj/include/mylib/lib.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// test external pac
44
#include <Eigen/Dense>
55
#include <fmt/core.h>
6-
#include <fmt/ostream.h>
6+
#include <fmt/ranges.h>
77

88
// test std libraries
99
#include <iostream>
@@ -24,7 +24,7 @@ int some_fun() {
2424
auto eigen_vec = Eigen::VectorXd::LinSpaced(10, 0, 1);
2525

2626
// print the vector
27-
fmt::print("{}", eigen_vec);
27+
fmt::print("[{}]", fmt::join(eigen_vec, ", "));
2828

2929
return 0;
3030
}

tests/myproj/src/main/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// test external pac
22
#include <Eigen/Dense>
33
#include <fmt/core.h>
4-
#include <fmt/ostream.h>
4+
#include <fmt/ranges.h>
55

66
// test std libraries
77
#include <iostream>
@@ -19,11 +19,11 @@ int main() {
1919
fmt::print("Hello from fmt{}", "!");
2020

2121
Eigen::VectorXd eigen_vec = Eigen::Vector3d(1, 2, 3);
22-
fmt::print("{}", eigen_vec);
22+
fmt::print("[{}]", fmt::join(eigen_vec, ", "));
2323

2424
#if !defined(__MINGW32__) && !defined(__MSYS__) // TODO fails
2525
Eigen::VectorXd eigen_vec2 = Eigen::VectorXd::LinSpaced(10, 0, 1);
26-
fmt::print("{}", eigen_vec2);
26+
fmt::print("[{}]", fmt::join(eigen_vec2, ", "));
2727
#endif
2828

2929
// trigger address sanitizer

tests/myproj/src/mylib2/lib.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// test external pac
22
#include <Eigen/Dense>
33
#include <fmt/core.h>
4-
#include <fmt/ostream.h>
4+
#include <fmt/ranges.h>
55

66
// test std libraries
77
#include <iostream>
@@ -19,11 +19,11 @@ int some_fun2() {
1919
fmt::print("Hello from fmt{}", "!");
2020

2121
Eigen::VectorXd eigen_vec = Eigen::Vector3d(1, 2, 3);
22-
fmt::print("{}", eigen_vec);
22+
fmt::print("[{}]", fmt::join(eigen_vec, ", "));
2323

2424
#if !defined(__MINGW32__) && !defined(__MSYS__) // TODO fails
2525
Eigen::VectorXd eigen_vec2 = Eigen::VectorXd::LinSpaced(10, 0, 1);
26-
fmt::print("{}", eigen_vec2);
26+
fmt::print("[{}]", fmt::join(eigen_vec2, ", "));
2727
#endif
2828

2929
return 0;

tests/myproj/vcpkg.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
2-
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json",
2+
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
33
"name": "myproject",
44
"version-string": "0.1.0",
5-
"builtin-baseline": "8dbd66f5a7821ced1ed57696b50375a977006813",
5+
"builtin-baseline": "6a3dd0874f153f8b375ec26210ea6d41dee3bb26",
66
"dependencies": [
77
{
88
"name": "eigen3",
9-
"version>=": "3.4.0"
9+
"version>=": "3.4.0#2"
1010
},
1111
{
1212
"name": "fmt",
13-
"version>=": "8.1.1"
13+
"version>=": "9.1.0#1"
1414
}
1515
]
1616
}

tests/rpi4-vcpkg/vcpkg.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
23
"name": "example",
34
"version-string": "0.1.0",
45
"dependencies": [

0 commit comments

Comments
 (0)