CMake ExternalProject_Add URL 中的非 ASCII

Non-ASCII in URL in CMake ExternalProject_Add

我在我的 CMake 中有这个 ExternalProject_Add 调用:

set(SIM_URL https://teamcity.vh.com/guestAuth/rep/download/Sim_Feat/.lastSuccessful/vhnHilsimPlantModel-{build.number}.zip)
set(SIM_FILENAME vhnHilsimPlantModel-{build.number}.zip)

# Download and install
include(ExternalProject)
ExternalProject_Add(get_sim
  DOWNLOAD_NAME ${SIM_FILENAME}
  URL ${SIM_URL}
  CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
             -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
  BUILD_BYPRODUCTS <INSTALL_DIR>/lib/sim_lib.a
  STEP_TARGETS update)

它在 2017 版 TeamCity 上运行良好。然而,在我们的 DevOps 将 TeamCity 升级到 2019 版本后,这段代码开始失败:

  file='/home/user/sim/sim-prefix/src/vhnHilsimPlantModel-{build.number}.zip'
Old file will be removed and new file downloaded from URL.
-- Downloading...
   dst='/home/user/build/apps/sim/sim-prefix/src/vhnHilsimPlantModel-{build.number}.zip'
   timeout='none'
-- Using src='https://teamcity.vh.com/guestAuth/rep/download/Sim_Feat/.lastSuccessful/vhnHilsimPlantModel-{build.number}.zip'
-- Retrying...
-- Using src='https://teamcity.vh.com/guestAuth/rep/download/Sim_Feat/.lastSuccessful/vhnHilsimPlantModel-{build.number}.zip'
-- Retry after 5 seconds (attempt #2) ...
-- Using src='https://teamcity.vh.com/guestAuth/rep/download/Sim_Feat/.lastSuccessful/vhnHilsimPlantModel-{build.number}.zip'
-- Retry after 5 seconds (attempt #3) ...
-- Using src='https://teamcity.vh.com/guestAuth/rep/download/Sim_Feat/.lastSuccessful/vhnHilsimPlantModel-{build.number}.zip'
-- Retry after 15 seconds (attempt #4) ...
-- Using src='https://teamcity.vh.com/guestAuth/rep/download/Sim_Feat/.lastSuccessful/vhnHilsimPlantModel-{build.number}.zip'
-- Retry after 60 seconds (attempt #5) ...
-- Using src='https://teamcity.vh.com/guestAuth/rep/download/Sim_Feat/.lastSuccessful/vhnHilsimPlantModel-{build.number}.zip'
CMake Error at vahana_sim-stamp/download-vahana_sim.cmake:157 (message):
  Each download failed!

    error: downloading 'https://teamcity.vh.com/guestAuth/rep/download/Sim_Feat/.lastSuccessful/vhnHilsimPlantModel-{build.number}.zip' failed
         status_code: 22
         status_string: "HTTP response code said error"
         log:
         --- LOG BEGIN ---
           Trying 172.31.21.90...

修复它的唯一方法是将 {} 分别更改为 %7B%7D。从技术上讲,这应该首先完成,但它确实有效。有谁知道为什么必须进行此更改 and/or 为什么在指定 URL 时必须对非 ASCII 字符进行编码?

我正在使用 CMake 3.10.2。

TeamCity 9.X documentation for Obtaining Artifacts 确认可以在 URL 中使用大括号 {build.number}

ARTIFACT_PATH is a path to the artifact on the TeamCity server. This path can contain a {build.number} pattern which will be replaced with the build number of the build whose artifact is retrieved.

然而,这导致了一些问题(一个例子 here), as there are several reserved characters in the RFC's pertaining to URI/URL standards (in this case RFC 1738)。 RFC 1738 标准认为一组字符“不安全”(包括花括号),除了 URI 的 reserved 字符:

Other characters are unsafe because gateways and other transport agents are known to sometimes modify such characters. These characters are "{", "}", "|", "", "^", "~", "[", "]", and "`". [...] All unsafe characters must always be encoded within a URL.

因此,之后更新了 TeamCity 软件以支持大括号 encodingsObtaining Artifacts 的 TeamCity 10.X documentation 已更新以符合 URL 编码标准:

ARTIFACT_PATH is a path to the artifact on the TeamCity server. This path can contain a {build.number} pattern (%7Bbuild.number%7D) which will be replaced by TeamCity with the build number of the build whose artifact is retrieved.

似乎在 TeamCity 2019 版本中,URL 中对使用原始花括号的支持已完全符合标准,只有 encoded[=32] =] 版本是允许的。因此,您可以将 CMake 代码更新为如下内容:

set(SIM_FILENAME vhnHilsimPlantModel-%7Bbuild.number%7D.zip)
set(SIM_URL https://teamcity.vh.com/guestAuth/rep/download/Sim_Feat/.lastSuccessful/${SIM_FILENAME})