Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 101 additions & 18 deletions BA_PACKAGE.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ FIND_PACKAGE(CMLIB COMPONENTS CMUTIL CMDEF)
#
# OUTPUT_PATH_VAR - name of the variable where the absolute path of the package root will be stored.
#
# Wrapper around BA_PACKAGE
# - adds package path to CMAKE_PREFIX_PATH
# - propagates output variables
# - manage prefixes and suffixes
#
# <function>(
# <package_name>
# <version_tag>
Expand All @@ -45,7 +50,7 @@ FUNCTION(BA_PACKAGE_LIBRARY package_name version_tag)
SET(suffix "d")
ENDIF()

_BRINGAUTO_PACKAGE(${package_name} ${version_tag} "lib" "${suffix}-dev" output_var
BA_PACKAGE(${package_name} ${version_tag} "lib" "${suffix}-dev" output_var
CACHE_ONLY ${__CACHE_ONLY}
NO_DEBUG ${__NO_DEBUG}
)
Expand All @@ -64,7 +69,20 @@ ENDFUNCTION()

##
#
# Download, cache and populate Executable package
# Download, cache and populate Executable package.
#
# CACHE_ONLY - if specified no download is performed. The package
# must be cached by a previous call to BA_PACKAGE_EXECUTABLE() without CACHE_ONLY switch.
#
# NO_DEBUG - use release, not debug version of the package (can be used if release and debug
# variant are equal)
#
# OUTPUT_PATH_VAR - name of the variable where the absolute path of the package root will be stored.
#
# Wrapper around BA_PACKAGE
# - adds package path to CMAKE_PREFIX_PATH
# - propagates output variables
# - manage prefixes and suffixes
#
# <function>(
# <package_name>
Expand All @@ -90,7 +108,7 @@ FUNCTION(BA_PACKAGE_EXECUTABLE package_name version_tag)
SET(suffix "d")
ENDIF()

_BRINGAUTO_PACKAGE(${package_name} ${version_tag} "" "${suffix}" output_var
BA_PACKAGE(${package_name} ${version_tag} "" "${suffix}" output_var
CACHE_ONLY ${__CACHE_ONLY}
NO_DEBUG ${__NO_DEBUG}
)
Expand All @@ -107,7 +125,7 @@ ENDFUNCTION()



## Helper
##
#
# Download, cache and populate package represented by 'package_name'
# and concretized by 'prefix' and 'suffix'.
Expand All @@ -120,7 +138,7 @@ ENDFUNCTION()
# [NO_DEBUG {ON|OFF}]
# )
#
FUNCTION(_BRINGAUTO_PACKAGE package_name version_tag prefix suffix output_var)
FUNCTION(BA_PACKAGE package_name version_tag prefix suffix output_var)
CMLIB_PARSE_ARGUMENTS(
OPTIONS
CACHE_ONLY
Expand All @@ -141,28 +159,51 @@ FUNCTION(_BRINGAUTO_PACKAGE package_name version_tag prefix suffix output_var)
SET(package_string "${package_name_expanded}_${version_tag}_${platform_string}.zip")

BA_PACKAGE_VARS_GET(REVISION revision_var)
SET(git_path "${CMDEF_DISTRO_ID}/${CMDEF_DISTRO_VERSION_ID}/${machine}")

_BA_PACKAGE_URL_ENCODE_IF_ENABLED("${revision_var}" revision_var_norm)
_BA_PACKAGE_URL_ENCODE_IF_ENABLED("${git_path}" git_path_norm)
_BA_PACKAGE_URL_ENCODE_IF_ENABLED("${package_string}" package_string_norm)
_BA_PACKAGE_URL_ENCODE_IF_ENABLED("${package_name}" package_name_norm)

SET(revision_arg)
IF(revision_var)
SET(revision_arg REVISION "${revision_var}")
IF(revision_var_norm)
SET(revision_arg REVISION "${revision_var_norm}")
ENDIF()
SET(git_path "${CMDEF_DISTRO_ID}/${CMDEF_DISTRO_VERSION_ID}/${machine}")

BA_PACKAGE_VARS_GET(URI_TEMPLATE template_var)
CMLIB_STORAGE_TEMPLATE_INSTANCE(remote_file template_var
${revision_arg}
GIT_PATH "${git_path}"
ARCHIVE_NAME "${package_string}"
PACKAGE_GROUP_NAME "${package_name}"
GIT_PATH "${git_path_norm}"
ARCHIVE_NAME "${package_string_norm}"
PACKAGE_GROUP_NAME "${package_name_norm}"
)

SET(git_archive_path_arg)
SET(git_revision_arg)
BA_PACKAGE_VARS_GET(GIT_PATH_TEMPLATE git_path_template_var)
IF(git_path_template_var)
CMLIB_STORAGE_TEMPLATE_INSTANCE(git_archive_path git_path_template_var
${revision_arg}
GIT_PATH "${git_path_norm}"
ARCHIVE_NAME "${package_string_norm}"
PACKAGE_GROUP_NAME "${package_name_norm}"
)
SET(git_revision_arg GIT_REVISION "${revision_var}")
Comment thread
koudis marked this conversation as resolved.
SET(git_archive_path_arg GIT_PATH "${git_archive_path}")
ENDIF()

STRING(TOUPPER "${package_name}" package_name_upper_orig)
STRING(REGEX REPLACE "[^A-Z0-9]" "" package_name_upper "${package_name_upper_orig}")
STRING(REGEX REPLACE "[\\-]" "" package_name_upper_wodash "${package_name_upper_orig}")
STRING(REGEX REPLACE "[^A-Z0-9]" "" package_name_upper "${package_name_upper_orig}")
IF(NOT package_name_upper)
MESSAGE(FATAL_ERROR "Invalid package name: ${package_name}")
ENDIF()
IF(NOT (package_name_upper STREQUAL package_name_upper_wodash))
MESSAGE(WARNING "Package name ${package_name} contains invalid characters. It was normalized to form a proper CMLIB cache keyword: ${package_name} --> ${package_name_upper}")
ENDIF()

# Not sure if this is useful? In production it feels weird.
Comment thread
koudis marked this conversation as resolved.
# The only reason is to not have accidental collisions....
#IF(NOT (package_name_upper STREQUAL package_name_upper_orig))
# MESSAGE(WARNING "Package name ${package_name} contains invalid characters. It was normalized to form a proper CMLIB cache keyword: ${package_name} --> ${package_name_upper}")
Comment thread
koudis marked this conversation as resolved.
#ENDIF()

SET(keywords BACPACK ${package_name_upper})

Expand All @@ -186,7 +227,10 @@ FUNCTION(_BRINGAUTO_PACKAGE package_name version_tag prefix suffix output_var)
CMLIB_DEPENDENCY(
KEYWORDS ${keywords}
TYPE ARCHIVE
ARCHIVE_TYPE ZIP
URI "${remote_file}"
${git_revision_arg}
${git_archive_path_arg}
OUTPUT_PATH_VAR cache_path
)
ENDIF()
Expand All @@ -198,7 +242,46 @@ ENDFUNCTION()

## Helper
#
# Print preformatted message
# Percent-encode characters that are not allowed in URI components.
# Encoding is only performed when ESCAPE_TEMPLATE_ARGS is ON/True.
#
# <function>(
# <input> <output_var>
# )
#
FUNCTION(_BA_PACKAGE_URL_ENCODE_IF_ENABLED input output)
BA_PACKAGE_VARS_GET(ESCAPE_TEMPLATE_ARGS _escape_enabled)
IF(NOT _escape_enabled)
SET(${output} "${input}" PARENT_SCOPE)
RETURN()
ENDIF()
SET(result "${input}")
STRING(REPLACE "%" "%25" result "${result}")
STRING(REPLACE " " "%20" result "${result}")
STRING(REPLACE "!" "%21" result "${result}")
STRING(REPLACE "#" "%23" result "${result}")
STRING(REPLACE "$" "%24" result "${result}")
STRING(REPLACE "&" "%26" result "${result}")
STRING(REPLACE "'" "%27" result "${result}")
STRING(REPLACE "(" "%28" result "${result}")
STRING(REPLACE ")" "%29" result "${result}")
STRING(REPLACE "*" "%2A" result "${result}")
STRING(REPLACE "+" "%2B" result "${result}")
STRING(REPLACE "," "%2C" result "${result}")
STRING(REPLACE "/" "%2F" result "${result}")
STRING(REPLACE ":" "%3A" result "${result}")
STRING(REPLACE ";" "%3B" result "${result}")
STRING(REPLACE "=" "%3D" result "${result}")
STRING(REPLACE "?" "%3F" result "${result}")
STRING(REPLACE "@" "%40" result "${result}")
SET(${output} "${result}" PARENT_SCOPE)
ENDFUNCTION()



## Helper
#
# Print reformatted message
#
# <function>(
# <action> <message>
Expand All @@ -211,4 +294,4 @@ FUNCTION(_BA_PACKAGE_MESSAGE action message)
MESSAGE(FATAL_ERROR "BA_PACKAGE: Cannot print unknown action ${action}")
ENDIF()
MESSAGE(STATUS "BA_PACKAGE [${action}]: ${message}")
ENDFUNCTION()
ENDFUNCTION()
17 changes: 16 additions & 1 deletion BA_PACKAGE_VARS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# be stored as INTERNAL cache variable.
# - Every variable is stored as a CMake cache variable with name BA_PACKAGE_VARS__<var_name>.
# Double _ is chosen to avoid defining reserved variable names SET and GET.
# - Every variable shall be set/get by a SetterGetter function.
# - Every variable shall be set/get by a Setter-Getter function.
#
# Mechanism of Setter/Getter was chosen in order to simplify
# future maintenance and "configuration" (in backward compatibility manner)
Expand All @@ -27,6 +27,21 @@ SET(BA_PACKAGE_VARS__URI_TEMPLATE "NonExistentPath"
"Storage URI template used to construct the package download URI"
)

SET(BA_PACKAGE_VARS__GIT_PATH_TEMPLATE "NonExistentPath"
Comment thread
koudis marked this conversation as resolved.
CACHE INTERNAL
"Git path template to use. If non empty the URI_TEMPLATE represents remote Git repository. Takes same template params as URI_TEMPLATE."
)
Comment thread
coderabbitai[bot] marked this conversation as resolved.

SET(BA_PACKAGE_VARS__HTTP_HEADER "NonExistentHTTPHEADER"
Comment thread
koudis marked this conversation as resolved.
CACHE INTERNAL
"HTTP header to use when accessing Package Repository over HTTP."
)

SET(BA_PACKAGE_VARS__ESCAPE_TEMPLATE_ARGS OFF
CACHE INTERNAL
"Escape template arguments when constructing the package download URI"
)



##
Expand Down
29 changes: 21 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Setting variable values are highly affected by [CMCONF Global Config].
- `<GIT_PATH>` - path to Packages in the repository for a given system. Set to `${CMDEF_DISTRO_ID}/${CMDEF_DISTRO_VERSION_ID}/${CMDEF_ARCHITECTURE}`,
- `<PACKAGE_GROUP_NAME>` - package group name as stated in [BringAuto Packager Context]
- `<ARCHIVE_NAME>` - full name of the Package. Set to ${package_group_name}_${version_tag}_${platform_string}.zip. The platform string is derived from CMDEF variables: `CMDEF_ARCHITECTURE`, `CMDEF_DISTRO_ID`, `CMDEF_DISTRO_VERSION_ID`.
- `GIT_PATH_TEMPLATE` - [CMake-lib] template to construct path to the package in the repository. If set `URI_TEMPLATE` shall represent a remote Git repository. It takes the same template params as `URI_TEMPLATE`.

```cmake
# Set REVISION to deps_update
Expand All @@ -70,29 +71,41 @@ BA_PACKAGE_VARS_SET(REVISION deps_update)
BA_PACKAGE_LIBRARY(nlohmann-json v3.10.5)
```

## Tests

- [cmake_tests/] — unit tests for CMake module logic using mocks, no network or build required.
- [test/] — integration tests that build a real application, install dependencies, and verify installed file structure.
Comment thread
koudis marked this conversation as resolved.


## FAQ

### Q: I want to migrate to newest version of Package tracker

- see [doc/MigrationGuide_0_to_1.md]
- see [doc/MigrationGuide_1_to_2.md]


### Q: Package not found even if it exists in the repository

- Ensure the package was built for your platform (CMDEF_DISTRO_ID, CMDEF_DISTRO_VERSION_ID, CMDEF_ARCHITECTURE).
- Verify REVISION and URI_TEMPLATE (see CMCONF Global Config) point to the right Package Repository and branch.
- If using a local Package Repository, confirm BA_PACKAGE_LOCAL_PATH points to the correct directory and that the expected package archive exists.

### Q: Package conflict if I want to build my project by second build type
### Q: Package conflict if I want to build my project by another build type

If you want to use the same cache path for Release and Debug build types
you must ensure that the package differs between Debug/Release build configs
If the same cache path is used for Release and Debug build types,
it must be ensured that the package differs between Debug/Release build configs
and does not have files with the same paths.

If you have a package that has the same content for Debug and Release you need to
use `NO_DEBUG ON` in `BA_PACKAGE_LIBRARY`; otherwise the conflict will occur.
If the package has the same content for Debug and Release
`NO_DEBUG ON` flag shall be used in `BA_PACKAGE_LIBRARY`; otherwise the conflict will occur.

(Look at [example/] for quick overview)



[BringAuto Packager]: https://github.com/bacpack-system/packager
[CMCONF Global Config]: ./doc/GlobalConfiguration.md
[CMake-lib]: https://github.com/cmakelib/cmakelib
[BringAuto Packager Context]: https://github.com/bacpack-system/packager/blob/master/doc/ContextStructure.md
[example/]: example/
[example/]: example/
[cmake_tests/]: cmake_tests/
[test/]: test/
33 changes: 17 additions & 16 deletions STORAGE.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,27 @@ SET(BA_PACKAGE_CMCONF_USE TRUE
CACHE BOOL
"Switch on for CMCONF use; off for testing purposes. Do not alter this setting unless you know what you are doing."
)
INCLUDE("${CMAKE_CURRENT_LIST_DIR}/BA_PACKAGE_VARS.cmake")
INCLUDE("${CMAKE_CURRENT_LIST_DIR}/BA_PACKAGE.cmake")
INCLUDE("${CMAKE_CURRENT_LIST_DIR}/BA_PACKAGE_DEPS.cmake")

IF(BA_PACKAGE_CMCONF_USE)
BA_PACKAGE_PREREQ_CMCONF_INIT(template revision)
BA_PACKAGE_PREREQ_CMCONF_INIT(template revision git_archive_path_template http_header template_args_uri_escape)
BA_PACKAGE_VARS_SET(REVISION "${revision}")
BA_PACKAGE_VARS_SET(URI_TEMPLATE "${template}")
BA_PACKAGE_VARS_SET(GIT_PATH_TEMPLATE "${git_archive_path_template}")
BA_PACKAGE_VARS_SET(ESCAPE_TEMPLATE_ARGS "${template_args_uri_escape}")
BA_PACKAGE_VARS_SET(HTTP_HEADER "${http_header}")
ENDIF()

IF(BA_PACKAGE_HTTP_AUTHORIZATION_HEADER)
IF(CMLIB_FILE_DOWNLOAD_AUTHORIZATION_HEADER)
MESSAGE(WARNING "HTTP Authorization header is defined but CMLIB_FILE_DOWNLOAD_AUTHORIZATION_HEADER is already set. Using BA_PACKAGE_HTTP_AUTHORIZATION_HEADER.")
BA_PACKAGE_VARS_GET(HTTP_HEADER http_header)
IF(http_header)
IF(CMLIB_FILE_DOWNLOAD_HTTP_HEADER AND (NOT CMLIB_FILE_DOWNLOAD_HTTP_HEADER STREQUAL http_header))
MESSAGE(WARNING "BA_PACKAGE_HTTP_HEADER is defined but CMLIB_FILE_DOWNLOAD_HTTP_HEADER is already set. Using BA_PACKAGE_HTTP_HEADER.")
ENDIF()
SET(CMLIB_FILE_DOWNLOAD_AUTHORIZATION_HEADER "Authorization: ${BA_PACKAGE_HTTP_AUTHORIZATION_HEADER}"
SET(CMLIB_FILE_DOWNLOAD_HTTP_HEADER "${http_header}"
CACHE STRING
"HTTP Authorization header set by Package Tracker to access the private repository"
"HTTP header set by Package Tracker to access the private repository"
FORCE
)
ENDIF()



INCLUDE("${CMAKE_CURRENT_LIST_DIR}/BA_PACKAGE_VARS.cmake")
INCLUDE("${CMAKE_CURRENT_LIST_DIR}/BA_PACKAGE.cmake")
INCLUDE("${CMAKE_CURRENT_LIST_DIR}/BA_PACKAGE_DEPS.cmake")

BA_PACKAGE_VARS_SET(REVISION "${revision}")
BA_PACKAGE_VARS_SET(URI_TEMPLATE "${template}")
ENDIF()
4 changes: 3 additions & 1 deletion doc/GlobalConfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ to [CMake User Package Registry]. [CMCONF Example] can be found in [CMCONF] repo
| BA_PACKAGE_LOCAL_PATH | Absolute Path to the local Package Repository. Used if BA_PACKAGE_LOCAL_USE is set to ON. If ENV variable BA_PACKAGE_LOCAL_PATH is set it is used instead of this CMCONF setting. Resulting value is passed to URI_TEMPLATE setting variable as "file://<local_path>/package/<GIT_PATH>/<PACKAGE_GROUP_NAME>/<ARCHIVE_NAME>" |
| BA_PACKAGE_URI_REVISION | Git revision to use when accessing Package Repository. Used if BA_PACKAGE_LOCAL_USE is set to OFF. |
| BA_PACKAGE_URI_TEMPLATE_REMOTE | [CMake-lib] template to construct URI to download package from remote Package Repository. Passed to URI_TEMPLATE setting variable. Used if BA_PACKAGE_LOCAL_USE is set to OFF. |
| BA_PACKAGE_HTTP_AUTHORIZATION_HEADER | HTTP Authorization header to use when accessing Package Repository. Used if BA_PACKAGE_LOCAL_USE is set to OFF. |
| BA_PACKAGE_GIT_ARCHIVE_PATH_TEMPLATE | When set the BA_PACKAGE_URI_TEMPLATE_REMOTE represents a Git repository URI which forces `git clone --archive` to be used to download depdencies instead of HTTP download. It is [CMake-lib] template to construct the git archive path. Passed to GIT_PATH_TEMPLATE setting variable. If set the BA_PACKAGE_URI_TEMPLATE_REMOTE shall point to the Git repository and BA_PACKAGE_URI_REVISION is used as Git revision. Used if BA_PACKAGE_LOCAL_USE is set to OFF. |
| BA_PACKAGE_HTTP_HEADER | HTTP header to use when accessing Package Repository. Used if BA_PACKAGE_LOCAL_USE is set to OFF. |
| BA_PACKAGE_TEMPLATE_ARGS_URI_ESCAPE | If set to ON, template argument values (REVISION, GIT_PATH, PACKAGE_GROUP_NAME, ARCHIVE_NAME) are percent-encoded before URI template expansion. Used if BA_PACKAGE_LOCAL_USE is set to OFF. |

## Environment Variables

Expand Down
File renamed without changes.
Loading