diff --git a/README.md b/README.md index 3ef58dfe..0725cd70 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ include(${_project_options_SOURCE_DIR}/Index.cmake) # install vcpkg dependencies: - should be called before defining project() run_vcpkg( VCPKG_URL "https://github.com/microsoft/vcpkg.git" - VCPKG_REV "0fa8459cf3a7caca7adc58f992bc32ff13630684" + VCPKG_REV "6a3dd0874f153f8b375ec26210ea6d41dee3bb26" ) # Set the project name and language diff --git a/docs/src/project_options_example.md b/docs/src/project_options_example.md index 1fe14ea0..3e7f98d6 100644 --- a/docs/src/project_options_example.md +++ b/docs/src/project_options_example.md @@ -30,7 +30,7 @@ include(${_project_options_SOURCE_DIR}/Index.cmake) # install vcpkg dependencies: - should be called before defining project() run_vcpkg( VCPKG_URL "https://github.com/microsoft/vcpkg.git" - VCPKG_REV "0fa8459cf3a7caca7adc58f992bc32ff13630684" + VCPKG_REV "6a3dd0874f153f8b375ec26210ea6d41dee3bb26" ENABLE_VCPKG_UPDATE ) diff --git a/src/Git.cmake b/src/Git.cmake index 5ba604d6..b494d8f3 100644 --- a/src/Git.cmake +++ b/src/Git.cmake @@ -465,8 +465,19 @@ function(git_switch_back) message(STATUS "Switch back failed. Trying to checkout previous branch") execute_process( COMMAND "${GIT_EXECUTABLE}" "checkout" "-" WORKING_DIRECTORY "${_fun_REPOSITORY_PATH}" - COMMAND_ERROR_IS_FATAL LAST + RESULT_VARIABLE _checkout_result ) + + # if the checkout failed, try to checkout the default branch + if(NOT ${_checkout_result} EQUAL 0) + message(STATUS "Checkout previous branch failed. Trying to checkout default branch") + git_default_branch(default_branch REPOSITORY_PATH "${_fun_REPOSITORY_PATH}") + execute_process( + COMMAND "${GIT_EXECUTABLE}" "checkout" "${default_branch}" + WORKING_DIRECTORY "${_fun_REPOSITORY_PATH}" COMMAND_ERROR_IS_FATAL LAST + ) + endif() + endif() endif() endfunction() @@ -512,3 +523,56 @@ function(git_wait) endif() endwhile() endfunction() + +#[[.rst: + +``git_default_branch`` +====================== +Get the default branch of the given repository. Defaults to master in case of failure + +Input variables: +- ``REPOSITORY_PATH``: The path to the repository + +Output variables: +- ``default_branch``: The variable to store the default branch in + + +.. code:: cmake + + git_default_branch( + REPOSITORY_PATH + "$ENV{HOME}/vcpkg" + default_branch + ) + +]] +function(git_default_branch default_branch) + # use git symbolic-ref refs/remotes/origin/HEAD to get the default branch + + set(oneValueArgs REPOSITORY_PATH) + cmake_parse_arguments(_fun "" "${oneValueArgs}" "" ${ARGN}) + + if("${_fun_REPOSITORY_PATH}" STREQUAL "") + message(FATAL_ERROR "REPOSITORY_PATH is required") + endif() + + find_program(GIT_EXECUTABLE "git" REQUIRED) + execute_process( + COMMAND "${GIT_EXECUTABLE}" "symbolic-ref" "refs/remotes/origin/HEAD" + OUTPUT_VARIABLE _default_branch + WORKING_DIRECTORY "${_fun_REPOSITORY_PATH}" + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE _default_branch_result + ) + + if(${_default_branch_result} EQUAL 0) + string(REGEX REPLACE "refs/remotes/origin/" "" _default_branch "${_default_branch}") + else() + message( + WARNING "Could not get default branch of ${_fun_REPOSITORY_PATH}. Considering it as master" + ) + set(_default_branch "master") + endif() + + set(${default_branch} ${_default_branch} PARENT_SCOPE) +endfunction() diff --git a/src/Vcpkg.cmake b/src/Vcpkg.cmake index 114c2f22..8848cc45 100644 --- a/src/Vcpkg.cmake +++ b/src/Vcpkg.cmake @@ -156,7 +156,7 @@ Or by specifying the options run_vcpkg( VCPKG_URL "https://github.com/microsoft/vcpkg.git" - VCPKG_REV "0fa8459cf3a7caca7adc58f992bc32ff13630684" + VCPKG_REV "6a3dd0874f153f8b375ec26210ea6d41dee3bb26" ENABLE_VCPKG_UPDATE ) diff --git a/tests/install/vcpkg.json b/tests/install/vcpkg.json index 7c556b53..e04facb5 100644 --- a/tests/install/vcpkg.json +++ b/tests/install/vcpkg.json @@ -1,16 +1,16 @@ { - "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json", + "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", "name": "another-project", "version-string": "0.1.0", - "builtin-baseline": "8dbd66f5a7821ced1ed57696b50375a977006813", + "builtin-baseline": "6a3dd0874f153f8b375ec26210ea6d41dee3bb26", "dependencies": [ { "name": "eigen3", - "version>=": "3.4.0" + "version>=": "3.4.0#2" }, { "name": "fmt", - "version>=": "8.1.1" + "version>=": "9.1.0#1" } ] } diff --git a/tests/myproj/include/mylib/lib.hpp b/tests/myproj/include/mylib/lib.hpp index 6ecad59b..f74c7bad 100644 --- a/tests/myproj/include/mylib/lib.hpp +++ b/tests/myproj/include/mylib/lib.hpp @@ -3,7 +3,7 @@ // test external pac #include #include -#include +#include // test std libraries #include @@ -24,7 +24,7 @@ int some_fun() { auto eigen_vec = Eigen::VectorXd::LinSpaced(10, 0, 1); // print the vector - fmt::print("{}", eigen_vec); + fmt::print("[{}]", fmt::join(eigen_vec, ", ")); return 0; } diff --git a/tests/myproj/src/main/main.cpp b/tests/myproj/src/main/main.cpp index 3dc72141..25cc0b59 100644 --- a/tests/myproj/src/main/main.cpp +++ b/tests/myproj/src/main/main.cpp @@ -1,7 +1,7 @@ // test external pac #include #include -#include +#include // test std libraries #include @@ -19,11 +19,11 @@ int main() { fmt::print("Hello from fmt{}", "!"); Eigen::VectorXd eigen_vec = Eigen::Vector3d(1, 2, 3); - fmt::print("{}", eigen_vec); + fmt::print("[{}]", fmt::join(eigen_vec, ", ")); #if !defined(__MINGW32__) && !defined(__MSYS__) // TODO fails Eigen::VectorXd eigen_vec2 = Eigen::VectorXd::LinSpaced(10, 0, 1); - fmt::print("{}", eigen_vec2); + fmt::print("[{}]", fmt::join(eigen_vec2, ", ")); #endif // trigger address sanitizer diff --git a/tests/myproj/src/mylib2/lib.cpp b/tests/myproj/src/mylib2/lib.cpp index 38458dce..01524a76 100644 --- a/tests/myproj/src/mylib2/lib.cpp +++ b/tests/myproj/src/mylib2/lib.cpp @@ -1,7 +1,7 @@ // test external pac #include #include -#include +#include // test std libraries #include @@ -19,11 +19,11 @@ int some_fun2() { fmt::print("Hello from fmt{}", "!"); Eigen::VectorXd eigen_vec = Eigen::Vector3d(1, 2, 3); - fmt::print("{}", eigen_vec); + fmt::print("[{}]", fmt::join(eigen_vec, ", ")); #if !defined(__MINGW32__) && !defined(__MSYS__) // TODO fails Eigen::VectorXd eigen_vec2 = Eigen::VectorXd::LinSpaced(10, 0, 1); - fmt::print("{}", eigen_vec2); + fmt::print("[{}]", fmt::join(eigen_vec2, ", ")); #endif return 0; diff --git a/tests/myproj/vcpkg.json b/tests/myproj/vcpkg.json index 4c2f4ac3..a2cddbdb 100644 --- a/tests/myproj/vcpkg.json +++ b/tests/myproj/vcpkg.json @@ -1,16 +1,16 @@ { - "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json", + "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", "name": "myproject", "version-string": "0.1.0", - "builtin-baseline": "8dbd66f5a7821ced1ed57696b50375a977006813", + "builtin-baseline": "6a3dd0874f153f8b375ec26210ea6d41dee3bb26", "dependencies": [ { "name": "eigen3", - "version>=": "3.4.0" + "version>=": "3.4.0#2" }, { "name": "fmt", - "version>=": "8.1.1" + "version>=": "9.1.0#1" } ] } diff --git a/tests/rpi4-vcpkg/vcpkg.json b/tests/rpi4-vcpkg/vcpkg.json index 5aa0e59b..27a8baa3 100644 --- a/tests/rpi4-vcpkg/vcpkg.json +++ b/tests/rpi4-vcpkg/vcpkg.json @@ -1,4 +1,5 @@ { + "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", "name": "example", "version-string": "0.1.0", "dependencies": [