From d333b7c40cd311d011ff426aba1644c785d6e0d4 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Fri, 10 Nov 2023 13:22:01 -0800 Subject: [PATCH 01/20] feat: support shallow and single branch clones in Git --- src/Git.cmake | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/Git.cmake b/src/Git.cmake index 33cad874..b925ca7f 100644 --- a/src/Git.cmake +++ b/src/Git.cmake @@ -12,11 +12,19 @@ Input variables: - ``REPOSITORY_PATH``: The path to the repository - ``REMOTE_URL``: The url of the remote to add - ``REMOTE_NAME``: The name of the remote to add (defaults to the remote user) +- ``SHALLOW_SINCE``: Create a shallow clone with a history after the specified time. date should be in format of `git log --date=raw`. +- ``BRANCH``: Only clone the given branch - ``FORCE_CLONE``: Force the clone even if the directory exists - ]] function(git_clone) - set(oneValueArgs REPOSITORY_PATH REMOTE_URL REMOTE_NAME FORCE_CLONE) + set(oneValueArgs + REPOSITORY_PATH + REMOTE_URL + REMOTE_NAME + SHALLOW_SINCE + BRANCH + FORCE_CLONE + ) cmake_parse_arguments(_fun "" "${oneValueArgs}" "" ${ARGN}) if("${_fun_REPOSITORY_PATH}" STREQUAL "" OR "${_fun_REMOTE_URL}" STREQUAL "") @@ -29,14 +37,23 @@ function(git_clone) find_program(GIT_EXECUTABLE "git" REQUIRED) get_filename_component(_fun_REPOSITORY_PARENT_PATH "${_fun_REPOSITORY_PATH}" DIRECTORY) + + set(GIT_ARGS "clone" "${_fun_REMOTE_URL}" "${_fun_REPOSITORY_PATH}") + + if(NOT "${_fun_SHALLOW_SINCE}" STREQUAL "") + list(APPEND GIT_ARGS "--shallow-since=${_fun_SHALLOW_SINCE}") + endif() + + if(NOT "${_fun_BRANCH}" STREQUAL "") + list(APPEND GIT_ARGS "--single-branch" "--branch=${_fun_BRANCH}") + endif() + execute_process( - COMMAND "${GIT_EXECUTABLE}" "clone" "${_fun_REMOTE_URL}" - WORKING_DIRECTORY "${_fun_REPOSITORY_PARENT_PATH}" COMMAND_ERROR_IS_FATAL LAST + COMMAND "${GIT_EXECUTABLE}" ${GIT_ARGS} WORKING_DIRECTORY "${_fun_REPOSITORY_PARENT_PATH}" + COMMAND_ERROR_IS_FATAL LAST ) else() - message( - STATUS "Repository already exists at ${_fun_REPOSITORY_PATH}. Waiting for git lock file.." - ) + message(STATUS "Repository already exists at ${_fun_REPOSITORY_PATH}.") git_wait(REPOSITORY_PATH "${_fun_REPOSITORY_PATH}") if(NOT EXISTS "${_fun_REPOSITORY_PATH}/.git") @@ -389,6 +406,8 @@ function(git_wait) set(counter 0) + message(STATUS "Waiting for git lock file...[${counter}/${_fun_TIMEOUT_COUNTER}]") + # wait until .git/index is present (in case a parallel clone is running) while(NOT EXISTS "${_fun_REPOSITORY_PATH}/.git/index" OR EXISTS "${_fun_REPOSITORY_PATH}/.git/index.lock" From 554cdf9d0307882a5a008188d0c1b79568835944 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 15 Nov 2023 12:06:37 -0800 Subject: [PATCH 02/20] docs: add examples for the git clone and git checkout --- src/Git.cmake | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/Git.cmake b/src/Git.cmake index b925ca7f..6f63b679 100644 --- a/src/Git.cmake +++ b/src/Git.cmake @@ -15,6 +15,40 @@ Input variables: - ``SHALLOW_SINCE``: Create a shallow clone with a history after the specified time. date should be in format of `git log --date=raw`. - ``BRANCH``: Only clone the given branch - ``FORCE_CLONE``: Force the clone even if the directory exists + +Simple example: + +.. code:: cmake + + git_clone( + REPOSITORY_PATH + "./vcpkg" + REMOTE_URL + "https://github.com/microsoft/vcpkg.git" + ) + +Example for a shallow clone and checking out of a specific revision: + +.. code:: cmake + + git_clone( + REPOSITORY_PATH + "$ENV{HOME}/vcpkg" + REMOTE_URL + "https://github.com/microsoft/vcpkg.git" + SHALLOW_SINCE + "1686087993 -0700" + BRANCH + "master" + ) + git_checkout( + REPOSITORY_PATH + "$ENV{HOME}/vcpkg" + REVISION + ecd22cc3acc8ee3c406e566db1e19ece1f17f409 + ) + + ]] function(git_clone) set(oneValueArgs @@ -132,6 +166,23 @@ Input variables: - ``REPOSITORY_PATH``: The path to the repository - ``REVISION``: The revision to checkout +.. code:: cmake + + git_checkout( + REPOSITORY_PATH + "$ENV{HOME}/vcpkg" + REVISION + ecd22cc3acc8ee3c406e566db1e19ece1f17f409 + ) + +.. code:: cmake + + git_checkout( + REPOSITORY_PATH + "./some_repo" + REVISION + v1.0.0 + ) ]] function(git_checkout) set(oneValueArgs REPOSITORY_PATH REVISION) From 374335f8c50ecf65406d6fef85a01b2b6280e0d8 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 15 Nov 2023 12:07:43 -0800 Subject: [PATCH 03/20] chore: v0.33.0 [skip ci] --- README.md | 2 +- docs/src/project_options_example.md | 2 +- package.json | 1 + src/DynamicProjectOptions.cmake | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5e242947..0164a9dd 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ endif() # Add project_options from https://github.com/aminya/project_options # Change the version in the following URL to update the package (watch the releases of the repository for future updates) -set(PROJECT_OPTIONS_VERSION "v0.32.2") +set(PROJECT_OPTIONS_VERSION "v0.33.0") FetchContent_Declare( _project_options URL https://github.com/aminya/project_options/archive/refs/tags/${PROJECT_OPTIONS_VERSION}.zip) diff --git a/docs/src/project_options_example.md b/docs/src/project_options_example.md index d901e283..4909d37d 100644 --- a/docs/src/project_options_example.md +++ b/docs/src/project_options_example.md @@ -20,7 +20,7 @@ endif() # Add project_options from https://github.com/aminya/project_options # Change the version in the following URL to update the package (watch the releases of the repository for future updates) -set(PROJECT_OPTIONS_VERSION "v0.32.2") +set(PROJECT_OPTIONS_VERSION "v0.33.0") FetchContent_Declare( _project_options URL https://github.com/aminya/project_options/archive/refs/tags/${PROJECT_OPTIONS_VERSION}.zip) diff --git a/package.json b/package.json index 9468670d..58784423 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,5 @@ { "name": "project_options", + "version": "0.33.0", "homepage": "http://aminya.github.io/project_options" } diff --git a/src/DynamicProjectOptions.cmake b/src/DynamicProjectOptions.cmake index 7a9c6cd1..22c0956d 100644 --- a/src/DynamicProjectOptions.cmake +++ b/src/DynamicProjectOptions.cmake @@ -55,7 +55,7 @@ Here is an example of how to use ``dynamic_project_options``: # Add project_options from https://github.com/aminya/project_options # Change the version in the following URL to update the package (watch the releases of the repository for future updates) - set(PROJECT_OPTIONS_VERSION "v0.32.2") + set(PROJECT_OPTIONS_VERSION "v0.33.0") FetchContent_Declare( _project_options URL https://github.com/aminya/project_options/archive/refs/tags/${PROJECT_OPTIONS_VERSION}.zip) From 9896ae379f6a64442c4c472efd127657c9f33881 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 16 Jan 2024 22:00:14 -0800 Subject: [PATCH 04/20] fix: skip pull and checkouts if the revision is already correct --- README.md | 1 - src/Git.cmake | 28 ++++++++++++++++++++++++---- src/Vcpkg.cmake | 3 +-- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 0164a9dd..a4acbdc3 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,6 @@ include(${_project_options_SOURCE_DIR}/Index.cmake) run_vcpkg( VCPKG_URL "https://github.com/microsoft/vcpkg.git" VCPKG_REV "0fa8459cf3a7caca7adc58f992bc32ff13630684" - ENABLE_VCPKG_UPDATE ) # Set the project name and language diff --git a/src/Git.cmake b/src/Git.cmake index 6f63b679..7515e1f1 100644 --- a/src/Git.cmake +++ b/src/Git.cmake @@ -126,15 +126,18 @@ endfunction() Pull the given repository -It will temporarily switch back to the previous branch if the head is detached for updating +If ``TARGET_REVISION`` is given, the pull is skipped if the current revision is the same as the target revision. + +It will temporarily switch back to the previous branch if the head is detached for updating. Input variables: - ``REPOSITORY_PATH``: The path to the repository +- ``TARGET_REVISION``: if the current revision of the repository is the same as this given revision, the pull is skipped ]] function(git_pull) - set(oneValueArgs REPOSITORY_PATH) + set(oneValueArgs REPOSITORY_PATH TARGET_REVISION) cmake_parse_arguments(_fun "" "${oneValueArgs}" "" ${ARGN}) if("${_fun_REPOSITORY_PATH}" STREQUAL "") @@ -144,14 +147,26 @@ function(git_pull) # store the current revision git_revision(REVISION REPOSITORY_PATH "${_fun_REPOSITORY_PATH}") + # skip the pull if the revision is the same + if(NOT "${_fun_TARGET_REVISION}" STREQUAL "" AND "${REVISION}" STREQUAL "${_fun_TARGET_REVISION}") + message(STATUS "Skipping pull of ${_fun_REPOSITORY_PATH} because it's already at ${REVISION}") + return() + else() + # pull and restore it after the pull + set(_fun_TARGET_REVISION "${REVISION}") + endif() + git_switch_back(REPOSITORY_PATH "${_fun_REPOSITORY_PATH}") message(STATUS "Updating ${_fun_REPOSITORY_PATH}") find_program(GIT_EXECUTABLE "git" REQUIRED) - execute_process(COMMAND "${GIT_EXECUTABLE}" "pull" WORKING_DIRECTORY "${_fun_REPOSITORY_PATH}") + execute_process( + COMMAND "${GIT_EXECUTABLE}" "pull" WORKING_DIRECTORY "${_fun_REPOSITORY_PATH}" + COMMAND_ERROR_IS_FATAL LAST + ) # restore the revision - git_checkout(REPOSITORY_PATH "${_fun_REPOSITORY_PATH}" REVISION "${REVISION}") + git_checkout(REPOSITORY_PATH "${_fun_REPOSITORY_PATH}" REVISION "${_fun_TARGET_REVISION}") endfunction() #[[.rst: @@ -192,6 +207,11 @@ function(git_checkout) message(FATAL_ERROR "REPOSITORY_PATH and REVISION are required") endif() + git_revision(REVISION REPOSITORY_PATH "${_fun_REPOSITORY_PATH}") + if("${REVISION}" STREQUAL "${_fun_REVISION}") + return() + endif() + find_program(GIT_EXECUTABLE "git" REQUIRED) execute_process( COMMAND "${GIT_EXECUTABLE}" "-c" "advice.detachedHead=false" "checkout" "${_fun_REVISION}" diff --git a/src/Vcpkg.cmake b/src/Vcpkg.cmake index 77ed309a..114c2f22 100644 --- a/src/Vcpkg.cmake +++ b/src/Vcpkg.cmake @@ -29,7 +29,7 @@ endmacro() macro(_update_vcpkg_repository) if(${_vcpkg_args_ENABLE_VCPKG_UPDATE}) - git_pull(REPOSITORY_PATH "${_vcpkg_args_VCPKG_DIR}") + git_pull(REPOSITORY_PATH "${_vcpkg_args_VCPKG_DIR}" TARGET_REVISION "${_vcpkg_args_VCPKG_REV}") endif() endmacro() @@ -94,7 +94,6 @@ endmacro() macro(_checkout_vcpkg_repository) if(NOT "${_vcpkg_args_VCPKG_REV}" STREQUAL "") - git_checkout(REPOSITORY_PATH "${_vcpkg_args_VCPKG_DIR}" REVISION "${_vcpkg_args_VCPKG_REV}") endif() endmacro() From 0652dee58e83379aebd8fe5ac817f5082a6a49f1 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 16 Jan 2024 22:03:55 -0800 Subject: [PATCH 05/20] fix: use git_wait for all write git operations to allow parallel builds --- src/Git.cmake | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Git.cmake b/src/Git.cmake index 7515e1f1..3bc66bf8 100644 --- a/src/Git.cmake +++ b/src/Git.cmake @@ -160,6 +160,10 @@ function(git_pull) message(STATUS "Updating ${_fun_REPOSITORY_PATH}") find_program(GIT_EXECUTABLE "git" REQUIRED) + + # wait for lock before pulling + git_wait(REPOSITORY_PATH "${_fun_REPOSITORY_PATH}") + execute_process( COMMAND "${GIT_EXECUTABLE}" "pull" WORKING_DIRECTORY "${_fun_REPOSITORY_PATH}" COMMAND_ERROR_IS_FATAL LAST @@ -212,6 +216,9 @@ function(git_checkout) return() endif() + # wait for lock before checking out + git_wait(REPOSITORY_PATH "${_fun_REPOSITORY_PATH}") + find_program(GIT_EXECUTABLE "git" REQUIRED) execute_process( COMMAND "${GIT_EXECUTABLE}" "-c" "advice.detachedHead=false" "checkout" "${_fun_REVISION}" @@ -376,7 +383,7 @@ function(git_revision REVISION) COMMAND "${GIT_EXECUTABLE}" "rev-parse" "HEAD" OUTPUT_VARIABLE _git_revision WORKING_DIRECTORY "${_fun_REPOSITORY_PATH}" - OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL LAST ) set(${REVISION} ${_git_revision} PARENT_SCOPE) endfunction() @@ -411,7 +418,7 @@ function(git_is_detached IS_DETACHED) COMMAND "${GIT_EXECUTABLE}" "rev-parse" "--abbrev-ref" "--symbolic-full-name" "HEAD" OUTPUT_VARIABLE _git_status WORKING_DIRECTORY "${_fun_REPOSITORY_PATH}" - OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL LAST ) if("${_git_status}" STREQUAL "HEAD") set(${IS_DETACHED} TRUE PARENT_SCOPE) @@ -444,8 +451,13 @@ function(git_switch_back) if(${IS_DETACHED}) message(STATUS "Switch back ${_fun_REPOSITORY_PATH}") + + # wait for lock before switching back + git_wait(REPOSITORY_PATH "${_fun_REPOSITORY_PATH}") + execute_process( COMMAND "${GIT_EXECUTABLE}" "switch" "-" WORKING_DIRECTORY "${_fun_REPOSITORY_PATH}" + COMMAND_ERROR_IS_FATAL LAST ) endif() endfunction() @@ -477,20 +489,17 @@ function(git_wait) set(counter 0) - message(STATUS "Waiting for git lock file...[${counter}/${_fun_TIMEOUT_COUNTER}]") - # wait until .git/index is present (in case a parallel clone is running) while(NOT EXISTS "${_fun_REPOSITORY_PATH}/.git/index" OR EXISTS "${_fun_REPOSITORY_PATH}/.git/index.lock" ) - execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 0.5) + message(STATUS "Waiting for git lock file...[${counter}/${_fun_TIMEOUT_COUNTER}]") + execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 0.5 COMMAND_ERROR_IS_FATAL LAST) math(EXPR counter "${counter} + 1") if(${counter} GREATER ${_fun_TIMEOUT_COUNTER}) message(STATUS "Timeout waiting for git lock file. Continuing...") return() - else() - message(STATUS "Waiting for git lock file...[${counter}/${_fun_TIMEOUT_COUNTER}]") endif() endwhile() endfunction() From dda0abfabef0801e6d5166de1aef723ad4e50d21 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 16 Jan 2024 22:09:40 -0800 Subject: [PATCH 06/20] fix: checkout to the previous branch if switch back fails --- src/Git.cmake | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Git.cmake b/src/Git.cmake index 3bc66bf8..5ba604d6 100644 --- a/src/Git.cmake +++ b/src/Git.cmake @@ -457,8 +457,17 @@ function(git_switch_back) execute_process( COMMAND "${GIT_EXECUTABLE}" "switch" "-" WORKING_DIRECTORY "${_fun_REPOSITORY_PATH}" - COMMAND_ERROR_IS_FATAL LAST + RESULT_VARIABLE _switch_back_result ) + + # if the switch back failed, try to checkout the previous branch + if(NOT ${_switch_back_result} EQUAL 0) + 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 + ) + endif() endif() endfunction() From 0e89e7bd6d14e76d8e96e947efc117273f6a855d Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 16 Jan 2024 22:24:15 -0800 Subject: [PATCH 07/20] chore: v0.33.1 [skip ci] --- README.md | 2 +- docs/src/project_options_example.md | 2 +- package.json | 2 +- src/DynamicProjectOptions.cmake | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a4acbdc3..3ef58dfe 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ endif() # Add project_options from https://github.com/aminya/project_options # Change the version in the following URL to update the package (watch the releases of the repository for future updates) -set(PROJECT_OPTIONS_VERSION "v0.33.0") +set(PROJECT_OPTIONS_VERSION "v0.33.1") FetchContent_Declare( _project_options URL https://github.com/aminya/project_options/archive/refs/tags/${PROJECT_OPTIONS_VERSION}.zip) diff --git a/docs/src/project_options_example.md b/docs/src/project_options_example.md index 4909d37d..1fe14ea0 100644 --- a/docs/src/project_options_example.md +++ b/docs/src/project_options_example.md @@ -20,7 +20,7 @@ endif() # Add project_options from https://github.com/aminya/project_options # Change the version in the following URL to update the package (watch the releases of the repository for future updates) -set(PROJECT_OPTIONS_VERSION "v0.33.0") +set(PROJECT_OPTIONS_VERSION "v0.33.1") FetchContent_Declare( _project_options URL https://github.com/aminya/project_options/archive/refs/tags/${PROJECT_OPTIONS_VERSION}.zip) diff --git a/package.json b/package.json index 58784423..0ade6d44 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { "name": "project_options", - "version": "0.33.0", + "version": "0.33.1", "homepage": "http://aminya.github.io/project_options" } diff --git a/src/DynamicProjectOptions.cmake b/src/DynamicProjectOptions.cmake index 22c0956d..0e37eb6c 100644 --- a/src/DynamicProjectOptions.cmake +++ b/src/DynamicProjectOptions.cmake @@ -55,7 +55,7 @@ Here is an example of how to use ``dynamic_project_options``: # Add project_options from https://github.com/aminya/project_options # Change the version in the following URL to update the package (watch the releases of the repository for future updates) - set(PROJECT_OPTIONS_VERSION "v0.33.0") + set(PROJECT_OPTIONS_VERSION "v0.33.1") FetchContent_Declare( _project_options URL https://github.com/aminya/project_options/archive/refs/tags/${PROJECT_OPTIONS_VERSION}.zip) From 98d8183384a968bf80afd5226e7f3fffd420f0d1 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 25 Jan 2024 12:37:21 -0800 Subject: [PATCH 08/20] feat: checkout to default branch in case of switch back failures --- src/Git.cmake | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) 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() From bd1c6c273c782a9bda7a88177529c91842fba545 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 25 Jan 2024 12:52:03 -0800 Subject: [PATCH 09/20] test: update vcpkg in the tests --- README.md | 2 +- docs/src/project_options_example.md | 2 +- src/Vcpkg.cmake | 2 +- tests/install/vcpkg.json | 8 ++++---- tests/myproj/vcpkg.json | 8 ++++---- tests/rpi4-vcpkg/vcpkg.json | 1 + 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 3ef58dfe..abce3787 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 "3b213864579b6fa686e38715508f7cd41a50900f" ) # Set the project name and language diff --git a/docs/src/project_options_example.md b/docs/src/project_options_example.md index 1fe14ea0..5eb138cf 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 "3b213864579b6fa686e38715508f7cd41a50900f" ENABLE_VCPKG_UPDATE ) diff --git a/src/Vcpkg.cmake b/src/Vcpkg.cmake index 114c2f22..b5403ff1 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 "3b213864579b6fa686e38715508f7cd41a50900f" ENABLE_VCPKG_UPDATE ) diff --git a/tests/install/vcpkg.json b/tests/install/vcpkg.json index 7c556b53..b6e41d6e 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": "3b213864579b6fa686e38715508f7cd41a50900f", "dependencies": [ { "name": "eigen3", - "version>=": "3.4.0" + "version>=": "3.4.0#2" }, { "name": "fmt", - "version>=": "8.1.1" + "version>=": "10.2.1" } ] } diff --git a/tests/myproj/vcpkg.json b/tests/myproj/vcpkg.json index 4c2f4ac3..5b881878 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": "3b213864579b6fa686e38715508f7cd41a50900f", "dependencies": [ { "name": "eigen3", - "version>=": "3.4.0" + "version>=": "3.4.0#2" }, { "name": "fmt", - "version>=": "8.1.1" + "version>=": "10.2.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": [ From 21270744e3b99a71f59d95bd0f9c0dfd5fc343e9 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 25 Jan 2024 22:36:39 -0800 Subject: [PATCH 10/20] fix: fix the vcpkg rev and baseline --- README.md | 2 +- docs/src/project_options_example.md | 2 +- src/Vcpkg.cmake | 2 +- tests/install/vcpkg.json | 4 ++-- tests/myproj/vcpkg.json | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index abce3787..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 "3b213864579b6fa686e38715508f7cd41a50900f" + 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 5eb138cf..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 "3b213864579b6fa686e38715508f7cd41a50900f" + VCPKG_REV "6a3dd0874f153f8b375ec26210ea6d41dee3bb26" ENABLE_VCPKG_UPDATE ) diff --git a/src/Vcpkg.cmake b/src/Vcpkg.cmake index b5403ff1..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 "3b213864579b6fa686e38715508f7cd41a50900f" + VCPKG_REV "6a3dd0874f153f8b375ec26210ea6d41dee3bb26" ENABLE_VCPKG_UPDATE ) diff --git a/tests/install/vcpkg.json b/tests/install/vcpkg.json index b6e41d6e..e04facb5 100644 --- a/tests/install/vcpkg.json +++ b/tests/install/vcpkg.json @@ -2,7 +2,7 @@ "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", "name": "another-project", "version-string": "0.1.0", - "builtin-baseline": "3b213864579b6fa686e38715508f7cd41a50900f", + "builtin-baseline": "6a3dd0874f153f8b375ec26210ea6d41dee3bb26", "dependencies": [ { "name": "eigen3", @@ -10,7 +10,7 @@ }, { "name": "fmt", - "version>=": "10.2.1" + "version>=": "9.1.0#1" } ] } diff --git a/tests/myproj/vcpkg.json b/tests/myproj/vcpkg.json index 5b881878..a2cddbdb 100644 --- a/tests/myproj/vcpkg.json +++ b/tests/myproj/vcpkg.json @@ -2,7 +2,7 @@ "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", "name": "myproject", "version-string": "0.1.0", - "builtin-baseline": "3b213864579b6fa686e38715508f7cd41a50900f", + "builtin-baseline": "6a3dd0874f153f8b375ec26210ea6d41dee3bb26", "dependencies": [ { "name": "eigen3", @@ -10,7 +10,7 @@ }, { "name": "fmt", - "version>=": "10.2.1" + "version>=": "9.1.0#1" } ] } From 42818f6545cbaf8c13d4a9fefae3b43258e0f0e6 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 25 Jan 2024 22:41:46 -0800 Subject: [PATCH 11/20] test: update Eigen/Fmt compilation errors --- tests/myproj/include/mylib/lib.hpp | 4 ++-- tests/myproj/src/main/main.cpp | 6 +++--- tests/myproj/src/mylib2/lib.cpp | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) 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; From 3a1efcbbda981497057444985484edfebc138398 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 31 Jan 2024 21:03:38 -0800 Subject: [PATCH 12/20] fix: update vcpkg rev to the latest version --- README.md | 2 +- docs/src/project_options_example.md | 2 +- src/Vcpkg.cmake | 2 +- tests/install/vcpkg.json | 2 +- tests/myproj/CMakeLists.txt | 2 +- tests/myproj/vcpkg.json | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0725cd70..4b31b492 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 "6a3dd0874f153f8b375ec26210ea6d41dee3bb26" + VCPKG_REV "10e052511428d6b0c7fcc63a139e8024bb146032" ) # Set the project name and language diff --git a/docs/src/project_options_example.md b/docs/src/project_options_example.md index 3e7f98d6..cfa6b9b2 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 "6a3dd0874f153f8b375ec26210ea6d41dee3bb26" + VCPKG_REV "10e052511428d6b0c7fcc63a139e8024bb146032" ENABLE_VCPKG_UPDATE ) diff --git a/src/Vcpkg.cmake b/src/Vcpkg.cmake index 8848cc45..8f2f7778 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 "6a3dd0874f153f8b375ec26210ea6d41dee3bb26" + VCPKG_REV "10e052511428d6b0c7fcc63a139e8024bb146032" ENABLE_VCPKG_UPDATE ) diff --git a/tests/install/vcpkg.json b/tests/install/vcpkg.json index e04facb5..c682f737 100644 --- a/tests/install/vcpkg.json +++ b/tests/install/vcpkg.json @@ -2,7 +2,7 @@ "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", "name": "another-project", "version-string": "0.1.0", - "builtin-baseline": "6a3dd0874f153f8b375ec26210ea6d41dee3bb26", + "builtin-baseline": "10e052511428d6b0c7fcc63a139e8024bb146032", "dependencies": [ { "name": "eigen3", diff --git a/tests/myproj/CMakeLists.txt b/tests/myproj/CMakeLists.txt index e9cb8592..d9e3e890 100644 --- a/tests/myproj/CMakeLists.txt +++ b/tests/myproj/CMakeLists.txt @@ -18,7 +18,7 @@ if(ENABLE_CROSS_COMPILING) endif() run_vcpkg(VCPKG_URL "https://github.com/microsoft/vcpkg.git" VCPKG_REV - "6a3dd0874f153f8b375ec26210ea6d41dee3bb26" ENABLE_VCPKG_UPDATE + "10e052511428d6b0c7fcc63a139e8024bb146032" ENABLE_VCPKG_UPDATE ) project(myproj VERSION 0.2.0 LANGUAGES CXX C) diff --git a/tests/myproj/vcpkg.json b/tests/myproj/vcpkg.json index a2cddbdb..c4cbbf8c 100644 --- a/tests/myproj/vcpkg.json +++ b/tests/myproj/vcpkg.json @@ -2,7 +2,7 @@ "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", "name": "myproject", "version-string": "0.1.0", - "builtin-baseline": "6a3dd0874f153f8b375ec26210ea6d41dee3bb26", + "builtin-baseline": "10e052511428d6b0c7fcc63a139e8024bb146032", "dependencies": [ { "name": "eigen3", From f56ab4f49726c9d99771bb5ce74696e0c162d533 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 1 Feb 2024 11:56:37 -0800 Subject: [PATCH 13/20] fix: handle edge cases of git_switch_back before a pull --- src/Git.cmake | 65 ++++++++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/src/Git.cmake b/src/Git.cmake index b494d8f3..66884bc6 100644 --- a/src/Git.cmake +++ b/src/Git.cmake @@ -432,7 +432,10 @@ endfunction() ``git_switch_back`` =================== -Detect if the head is detached, if so, switch back before calling git pull on a detached head +Detect if the head is detached, if so, switch/checkout back +If the switch/checkout back fails or goes to a detached state, try to checkout the default branch + +This is used before updating the repository in a pull Input variables: @@ -447,38 +450,42 @@ function(git_switch_back) message(FATAL_ERROR "REPOSITORY_PATH is required") endif() + # return if the head is not detached git_is_detached(IS_DETACHED REPOSITORY_PATH "${_fun_REPOSITORY_PATH}") + if(NOT ${IS_DETACHED}) + return() + endif() - if(${IS_DETACHED}) - message(STATUS "Switch back ${_fun_REPOSITORY_PATH}") - - # wait for lock before switching back - git_wait(REPOSITORY_PATH "${_fun_REPOSITORY_PATH}") - - execute_process( - COMMAND "${GIT_EXECUTABLE}" "switch" "-" WORKING_DIRECTORY "${_fun_REPOSITORY_PATH}" - RESULT_VARIABLE _switch_back_result - ) - - # if the switch back failed, try to checkout the previous branch - if(NOT ${_switch_back_result} EQUAL 0) - message(STATUS "Switch back failed. Trying to checkout previous branch") - execute_process( - COMMAND "${GIT_EXECUTABLE}" "checkout" "-" WORKING_DIRECTORY "${_fun_REPOSITORY_PATH}" - RESULT_VARIABLE _checkout_result - ) + # first try to switch back + message(STATUS "Switch back ${_fun_REPOSITORY_PATH}") + git_wait(REPOSITORY_PATH "${_fun_REPOSITORY_PATH}") + execute_process( + COMMAND "${GIT_EXECUTABLE}" "switch" "-" WORKING_DIRECTORY "${_fun_REPOSITORY_PATH}" + RESULT_VARIABLE _switch_back_result + ) + git_is_detached(IS_DETACHED REPOSITORY_PATH "${_fun_REPOSITORY_PATH}") + if(${_switch_back_result} EQUAL 0 AND NOT ${IS_DETACHED}) + return() + endif() - # 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() + # if the switch back failed, try to checkout the previous branch + message(STATUS "Switch back failed. Trying to checkout previous branch") + git_wait(REPOSITORY_PATH "${_fun_REPOSITORY_PATH}") + execute_process( + COMMAND "${GIT_EXECUTABLE}" "checkout" "-" WORKING_DIRECTORY "${_fun_REPOSITORY_PATH}" + RESULT_VARIABLE _checkout_result + ) + git_is_detached(IS_DETACHED REPOSITORY_PATH "${_fun_REPOSITORY_PATH}") + if(${_checkout_result} EQUAL 0 AND NOT ${IS_DETACHED}) + return() + endif() - endif() + # switch/checkout back went to a detached state or failed, try to checkout the default branch + git_is_detached(IS_DETACHED REPOSITORY_PATH "${_fun_REPOSITORY_PATH}") + if(${IS_DETACHED}) + message(STATUS "Trying to checkout default branch") + git_default_branch(default_branch REPOSITORY_PATH "${_fun_REPOSITORY_PATH}") + git_checkout(REPOSITORY_PATH "${_fun_REPOSITORY_PATH}" REVISION "${default_branch}") endif() endfunction() From 7373cb974dafb5a13c04ce86573924beef54c324 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 1 Feb 2024 12:02:55 -0800 Subject: [PATCH 14/20] ci: disable PCH due to build failures --- tests/myproj/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/myproj/CMakeLists.txt b/tests/myproj/CMakeLists.txt index d9e3e890..91db79dc 100644 --- a/tests/myproj/CMakeLists.txt +++ b/tests/myproj/CMakeLists.txt @@ -61,9 +61,9 @@ project_options( # ENABLE_INCLUDE_WHAT_YOU_USE # ENABLE_GCC_ANALYZER ENABLE_COVERAGE - ENABLE_PCH - PCH_HEADERS - ${PCH_HEADERS} + # ENABLE_PCH + # PCH_HEADERS + # ${PCH_HEADERS} ENABLE_DOXYGEN ENABLE_INTERPROCEDURAL_OPTIMIZATION ENABLE_NATIVE_OPTIMIZATION From 7fd59c48ff2ffdce6765bb9dd7731b37acc7e222 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 1 Feb 2024 14:46:00 -0800 Subject: [PATCH 15/20] ci: ignore macos graphviz failure [skip ci] --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7af9aa86..0632413f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ on: jobs: Test: - if: "!contains(github.event.head_commit.message, '[skip ci]')" + if: ${{ !contains(github.event.head_commit.message, '[skip ci]') }} runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -83,13 +83,14 @@ jobs: doxygen: true - name: Test + if: ${{ !cancelled() }} run: | task test env: CMAKE_GENERATOR: ${{ matrix.cmake_generator }} - name: Lint - if: ${{ matrix.os == 'ubuntu-20.04' && matrix.compiler == 'gcc' }} + if: ${{ !cancelled() && matrix.os == 'ubuntu-20.04' && matrix.compiler == 'gcc' }} run: | # TODO add to setup-cpp python3 -m pip install --user cmakelint cmake-format From 0b3e25a26d2c8726e7527773e1c3388938c24098 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 1 Feb 2024 14:53:24 -0800 Subject: [PATCH 16/20] ci: skip vcpkg updates based on the requested revision --- src/Vcpkg.cmake | 52 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/src/Vcpkg.cmake b/src/Vcpkg.cmake index 8f2f7778..c91b90f9 100644 --- a/src/Vcpkg.cmake +++ b/src/Vcpkg.cmake @@ -59,28 +59,44 @@ macro(_bootstrap_vcpkg) endmacro() macro(_is_vcpkg_outdated) - if("${_vcpkg_args_VCPKG_UPDATE_THRESHOLD}" STREQUAL "") - set(_vcpkg_args_VCPKG_UPDATE_THRESHOLD 3600) - endif() + # skip the update if the requested revision is the same as the current revision + git_revision(_REVISION REPOSITORY_PATH "${_vcpkg_args_VCPKG_DIR}") + if(NOT "${_vcpkg_args_VCPKG_REV}" STREQUAL "" AND "${_REVISION}" STREQUAL + "${_vcpkg_args_VCPKG_REV}" + ) + message(STATUS "Skipping vcpkg update as it's already at ${_REVISION}") + set(_vcpkg_args_ENABLE_VCPKG_UPDATE OFF) + elseif(NOT "${_vcpkg_args_VCPKG_REV}" STREQUAL "" AND NOT "${_REVISION}" STREQUAL + "${_vcpkg_args_VCPKG_REV}" + ) + # Requested revision is different from the current revision, so update + set(_vcpkg_args_ENABLE_VCPKG_UPDATE ON) + else() + # Requested revision is not specified, so update depending on the timestamp + # Check if the vcpkg registry is updated using the timestamp file that project_option generates + if("${_vcpkg_args_VCPKG_UPDATE_THRESHOLD}" STREQUAL "") + set(_vcpkg_args_VCPKG_UPDATE_THRESHOLD 3600) + endif() - if(${_vcpkg_args_ENABLE_VCPKG_UPDATE}) - set(_time_stamp_file "${VCPKG_PARENT_DIR}/.vcpkg_last_update") - - if(EXISTS "${_time_stamp_file}") - string(TIMESTAMP _current_time "%s") - file(TIMESTAMP "${_time_stamp_file}" _vcpkg_last_update "%s") - # if the last update was more than VCPKG_UPDATE_THRESHOLD - math(EXPR time_diff "${_current_time} - ${_vcpkg_last_update}") - if(${time_diff} GREATER ${_vcpkg_args_VCPKG_UPDATE_THRESHOLD}) + if(${_vcpkg_args_ENABLE_VCPKG_UPDATE}) + set(_time_stamp_file "${VCPKG_PARENT_DIR}/.vcpkg_last_update") + + if(EXISTS "${_time_stamp_file}") + string(TIMESTAMP _current_time "%s") + file(TIMESTAMP "${_time_stamp_file}" _vcpkg_last_update "%s") + # if the last update was more than VCPKG_UPDATE_THRESHOLD + math(EXPR time_diff "${_current_time} - ${_vcpkg_last_update}") + if(${time_diff} GREATER ${_vcpkg_args_VCPKG_UPDATE_THRESHOLD}) + set(_vcpkg_args_ENABLE_VCPKG_UPDATE ON) + file(TOUCH "${_time_stamp_file}") + else() + message(STATUS "vcpkg updated recently. Skipping update.") + set(_vcpkg_args_ENABLE_VCPKG_UPDATE OFF) + endif() + else() set(_vcpkg_args_ENABLE_VCPKG_UPDATE ON) file(TOUCH "${_time_stamp_file}") - else() - message(STATUS "vcpkg updated recently. Skipping update.") - set(_vcpkg_args_ENABLE_VCPKG_UPDATE OFF) endif() - else() - set(_vcpkg_args_ENABLE_VCPKG_UPDATE ON) - file(TOUCH "${_time_stamp_file}") endif() endif() endmacro() From 6e861771caf51007b5bb15c70634ba63142d9d47 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Fri, 2 Feb 2024 08:05:10 -0800 Subject: [PATCH 17/20] fix: gracefully warn if doxygen is not installed --- src/Doxygen.cmake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Doxygen.cmake b/src/Doxygen.cmake index 64c053db..d8eae523 100644 --- a/src/Doxygen.cmake +++ b/src/Doxygen.cmake @@ -79,7 +79,11 @@ function(enable_doxygen DOXYGEN_THEME) endif() # find doxygen and dot if available - find_package(Doxygen REQUIRED OPTIONAL_COMPONENTS dot) + find_package(Doxygen OPTIONAL_COMPONENTS dot) + if (NOT Doxygen_FOUND) + message(WARNING "Doxygen not found, install doxygen and try again. Documentation will not be generated.") + return() + endif() # add doxygen-docs target message(STATUS "Adding `doxygen-docs` target that builds the documentation.") From 6557d00bdc56749665ea64e09b829a97c565dbc5 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Fri, 2 Feb 2024 08:05:37 -0800 Subject: [PATCH 18/20] ci: skip doxygen installation on macos --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0632413f..6f935948 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -80,7 +80,7 @@ jobs: cppcheck: true clangtidy: true task: true - doxygen: true + doxygen: ${{ !contains(matrix.os, 'macos-11') }} - name: Test if: ${{ !cancelled() }} From ed78da516ec6e98847c55acb319991d090597c2b Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Fri, 2 Feb 2024 00:25:59 -0800 Subject: [PATCH 19/20] fix: update Windows toolchain to the latest version --- src/VCEnvironment.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/VCEnvironment.cmake b/src/VCEnvironment.cmake index 8fed3c00..6773e2a9 100644 --- a/src/VCEnvironment.cmake +++ b/src/VCEnvironment.cmake @@ -59,7 +59,8 @@ macro(msvc_toolchain) include(FetchContent) FetchContent_Declare( _msvc_toolchain - URL "https://github.com/MarkSchofield/WindowsToolchain/archive/refs/tags/v0.7.0.zip" + GIT_REPOSITORY "https://github.com/MarkSchofield/WindowsToolchain.git" + GIT_TAG "17c6d4ff6531ee268b9a22a8bcfbb3809e970e4e" ) FetchContent_MakeAvailable(_msvc_toolchain) include("${_msvc_toolchain_SOURCE_DIR}/Windows.MSVC.toolchain.cmake") From afef2591c14ce3956ddcb7f1e605b6932c080d9f Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Fri, 2 Feb 2024 00:48:40 -0800 Subject: [PATCH 20/20] chore: v0.34.0 [skip ci] --- README.md | 2 +- docs/src/project_options_example.md | 2 +- package.json | 2 +- src/DynamicProjectOptions.cmake | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4b31b492..f555dfa0 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ endif() # Add project_options from https://github.com/aminya/project_options # Change the version in the following URL to update the package (watch the releases of the repository for future updates) -set(PROJECT_OPTIONS_VERSION "v0.33.1") +set(PROJECT_OPTIONS_VERSION "v0.34.0") FetchContent_Declare( _project_options URL https://github.com/aminya/project_options/archive/refs/tags/${PROJECT_OPTIONS_VERSION}.zip) diff --git a/docs/src/project_options_example.md b/docs/src/project_options_example.md index cfa6b9b2..d52ee2f6 100644 --- a/docs/src/project_options_example.md +++ b/docs/src/project_options_example.md @@ -20,7 +20,7 @@ endif() # Add project_options from https://github.com/aminya/project_options # Change the version in the following URL to update the package (watch the releases of the repository for future updates) -set(PROJECT_OPTIONS_VERSION "v0.33.1") +set(PROJECT_OPTIONS_VERSION "v0.34.0") FetchContent_Declare( _project_options URL https://github.com/aminya/project_options/archive/refs/tags/${PROJECT_OPTIONS_VERSION}.zip) diff --git a/package.json b/package.json index 0ade6d44..6d4e06fd 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { "name": "project_options", - "version": "0.33.1", + "version": "0.34.0", "homepage": "http://aminya.github.io/project_options" } diff --git a/src/DynamicProjectOptions.cmake b/src/DynamicProjectOptions.cmake index 0e37eb6c..3e158e53 100644 --- a/src/DynamicProjectOptions.cmake +++ b/src/DynamicProjectOptions.cmake @@ -55,7 +55,7 @@ Here is an example of how to use ``dynamic_project_options``: # Add project_options from https://github.com/aminya/project_options # Change the version in the following URL to update the package (watch the releases of the repository for future updates) - set(PROJECT_OPTIONS_VERSION "v0.33.1") + set(PROJECT_OPTIONS_VERSION "v0.34.0") FetchContent_Declare( _project_options URL https://github.com/aminya/project_options/archive/refs/tags/${PROJECT_OPTIONS_VERSION}.zip)