Skip to content

Commit

Permalink
Recognize proper keywords in FetchContent_Declare
Browse files Browse the repository at this point in the history
  • Loading branch information
BlankSpruce committed Jan 10, 2025
1 parent da593a7 commit 572c0eb
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .gersemirc.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/BlankSpruce/gersemi/0.18.0-rc1/gersemi/configuration.schema.json
# yaml-language-server: $schema=https://raw.githubusercontent.com/BlankSpruce/gersemi/0.18.0/gersemi/configuration.schema.json

definitions: []
disable_formatting: false
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Changelog
## [0.18.0] 2025-XX-XX
## [0.18.0] 2025-01-10
### Added
- Add support for extensions and provide example extension as a template.

### Fixed
- Recognize `unquoted_legacy` rule of CMake language. (#49)
- Cut down excessive memory usage when used on a project with big number of files.
- Correctly recognize keywords from download, upload and patch steps of `ExternalProject_Add` in `FetchContent_Declare`. (#50)

## [0.17.1] 2024-11-29
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion gersemi/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
__license__ = "MPL 2.0"
__title__ = "gersemi"
__url__ = "https://github.com/BlankSpruce/gersemi"
__version__ = "0.18.0-rc1"
__version__ = "0.18.0"
154 changes: 75 additions & 79 deletions gersemi/builtin_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,61 @@
"one_value_keywords": ["debug", "optimized", "general"]
}

_ExternalProject_Add_DownloadStep = {
"one_value_keywords": {
# Described in "Directory Options"
"DOWNLOAD_DIR",
#
"URL_HASH",
"URL_MD5",
"DOWNLOAD_NAME",
"DOWNLOAD_EXTRACT_TIMESTAMP",
"DOWNLOAD_NO_EXTRACT",
"DOWNLOAD_NO_PROGRESS",
"TIMEOUT",
"INACTIVITY_TIMEOUT",
"HTTP_USERNAME",
"HTTP_PASSWORD",
"TLS_VERSION",
"TLS_VERIFY",
"TLS_CAINFO",
"NETRC",
"NETRC_FILE",
"GIT_REPOSITORY",
"GIT_TAG",
"GIT_REMOTE_NAME",
"GIT_SUBMODULES_RECURSE",
"GIT_SHALLOW",
"GIT_PROGRESS",
"GIT_REMOTE_UPDATE_STRATEGY",
"SVN_REPOSITORY",
"SVN_REVISION",
"SVN_USERNAME",
"SVN_PASSWORD",
"SVN_TRUST_CERT",
"HG_REPOSITORY",
"HG_TAG",
"CVS_REPOSITORY",
"CVS_MODULE",
"CVS_TAG",
},
"multi_value_keywords": {
"DOWNLOAD_COMMAND",
"URL",
"HTTP_HEADER",
"GIT_SUBMODULES",
"GIT_CONFIG",
},
}
_ExternalProject_Add_UpdateStep = {
"one_value_keywords": ["UPDATE_DISCONNECTED"],
"multi_value_keywords": ["UPDATE_COMMAND"],
}
_ExternalProject_Add_PatchStep = {
"one_value_keywords": [],
"multi_value_keywords": ["PATCH_COMMAND"],
}


builtin_commands_impl = {
#### Legend
Expand Down Expand Up @@ -2148,38 +2203,11 @@
"BINARY_DIR",
"INSTALL_DIR",
# Download Step
"URL_HASH",
"URL_MD5",
"DOWNLOAD_NAME",
"DOWNLOAD_NO_EXTRACT",
"TIMEOUT",
"HTTP_USERNAME",
"HTTP_PASSWORD",
"TLS_VERIFY",
"TLS_CAINFO",
"NETRC",
"NETRC_FILE",
"GIT_REPOSITORY",
"GIT_TAG",
"GIT_REMOTE_NAME",
"GIT_SUBMODULES_RECURSE",
"GIT_SHALLOW",
"GIT_PROGRESS",
"GIT_REMOTE_UPDATE_STRATEGY",
"SVN_REPOSITORY",
"SVN_REVISION",
"SVN_USERNAME",
"SVN_PASSWORD",
"SVN_TRUST_CERT",
"HG_REPOSITORY",
"HG_TAG",
"CVS_REPOSITORY",
"CVS_MODULE",
"CVS_TAG",
"DOWNLOAD_EXTRACT_TIMESTAMP",
"TLS_VERSION",
# Update/Patch Step
"UPDATE_DISCONNECTED",
*_ExternalProject_Add_DownloadStep["one_value_keywords"],
# Update Step
*_ExternalProject_Add_UpdateStep["one_value_keywords"],
# Patch Step
*_ExternalProject_Add_PatchStep["one_value_keywords"],
# Configure Step
"CMAKE_COMMAND",
"CMAKE_GENERATOR",
Expand Down Expand Up @@ -2222,14 +2250,11 @@
],
"multi_value_keywords": [
# Download Step
"DOWNLOAD_COMMAND",
"URL",
"HTTP_HEADER",
"GIT_SUBMODULES",
"GIT_CONFIG",
# Update/Patch Step
"UPDATE_COMMAND",
"PATCH_COMMAND",
*_ExternalProject_Add_DownloadStep["multi_value_keywords"],
# Update Step
*_ExternalProject_Add_UpdateStep["multi_value_keywords"],
# Patch Step
*_ExternalProject_Add_PatchStep["multi_value_keywords"],
# Configure Step
"CONFIGURE_COMMAND",
"CMAKE_ARGS",
Expand Down Expand Up @@ -2318,49 +2343,20 @@
"options": ["SYSTEM", "OVERRIDE_FIND_PACKAGE", "EXCLUDE_FROM_ALL"],
"one_value_keywords": [
# Download Step
"URL_HASH",
"URL_MD5",
"DOWNLOAD_NAME",
"DOWNLOAD_NO_EXTRACT",
"TIMEOUT",
"HTTP_USERNAME",
"HTTP_PASSWORD",
"TLS_VERIFY",
"TLS_CAINFO",
"NETRC",
"NETRC_FILE",
"GIT_REPOSITORY",
"GIT_TAG",
"GIT_REMOTE_NAME",
"GIT_SUBMODULES_RECURSE",
"GIT_SHALLOW",
"GIT_PROGRESS",
"GIT_REMOTE_UPDATE_STRATEGY",
"SVN_REPOSITORY",
"SVN_REVISION",
"SVN_USERNAME",
"SVN_PASSWORD",
"SVN_TRUST_CERT",
"HG_REPOSITORY",
"HG_TAG",
"CVS_REPOSITORY",
"CVS_MODULE",
"CVS_TAG",
"SOURCE_SUBDIR",
# Update/Patch Step
"UPDATE_DISCONNECTED",
*_ExternalProject_Add_DownloadStep["one_value_keywords"],
# Update Step
*_ExternalProject_Add_UpdateStep["one_value_keywords"],
# Patch Step
*_ExternalProject_Add_PatchStep["one_value_keywords"],
],
"multi_value_keywords": [
"FIND_PACKAGE_ARGS",
# Download Step
"DOWNLOAD_COMMAND",
"URL",
"HTTP_HEADER",
"GIT_SUBMODULES",
"GIT_CONFIG",
# Update/Patch Step
"UPDATE_COMMAND",
"PATCH_COMMAND",
*_ExternalProject_Add_DownloadStep["multi_value_keywords"],
# Update Step
*_ExternalProject_Add_UpdateStep["multi_value_keywords"],
# Patch Step
*_ExternalProject_Add_PatchStep["multi_value_keywords"],
],
"keyword_kinds": {
key: KeywordKind.CommandLine
Expand Down
19 changes: 19 additions & 0 deletions tests/formatter/issue_0050_fetchcontent_declare.in.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### {list_expansion: favour-expansion}
# https://cmake.org/cmake/help/latest/module/FetchContent.html#commands
#
# The <contentOptions> can be any of the download, update, or patch
# options that the ExternalProject_Add() command understands.

FetchContent_Declare(
${fetchcontent_target}
HTTP_USERNAME
"$ENV{USERNAME}"
HTTP_PASSWORD "$ENV{PASSWORD}"
URL
"${src_url}"
DOWNLOAD_NO_EXTRACT TRUE
URL_HASH SHA256=${exp_hash}
DOWNLOAD_DIR
${dst_folder}
DOWNLOAD_NAME ${download_name}
)
16 changes: 16 additions & 0 deletions tests/formatter/issue_0050_fetchcontent_declare.out.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# https://cmake.org/cmake/help/latest/module/FetchContent.html#commands
#
# The <contentOptions> can be any of the download, update, or patch
# options that the ExternalProject_Add() command understands.

FetchContent_Declare(
${fetchcontent_target}
HTTP_USERNAME "$ENV{USERNAME}"
HTTP_PASSWORD "$ENV{PASSWORD}"
URL
"${src_url}"
DOWNLOAD_NO_EXTRACT TRUE
URL_HASH SHA256=${exp_hash}
DOWNLOAD_DIR ${dst_folder}
DOWNLOAD_NAME ${download_name}
)

0 comments on commit 572c0eb

Please sign in to comment.