Get TSP files from remote git location with sparse checkout (#6081)

* Get TSP files from remote git location with sparce checkout

* PR comments

* spell

* use SHA
This commit is contained in:
gearama 2024-10-08 22:44:41 -07:00 committed by GitHub
parent 0e48f058d4
commit 97fe310d51
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,42 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
find_package(Git)
macro(DownloadTSPFiles TSP_REPO TSP_SHA TSP_REPO_PATH TSP_DESTINATION)
message ("Downloading TSP files using the following params TSP_REPO=${TSP_REPO} TSP_SHA=${TSP_SHA} TSP_REPO_PATH=${TSP_REPO_PATH} TSP_DESTINATION=${TSP_DESTINATION}")
if(Git_FOUND)
message("Git found: ${GIT_EXECUTABLE}")
else()
message(FATAL_ERROR "Git not found")
endif()
set(DOWNLOAD_FOLDER ${CMAKE_SOURCE_DIR}/build/${TSP_DESTINATION})
#cleanup folder
file(REMOVE_RECURSE ${DOWNLOAD_FOLDER})
make_directory(${DOWNLOAD_FOLDER})
#init git in folder
execute_process(COMMAND ${GIT_EXECUTABLE} init
WORKING_DIRECTORY ${DOWNLOAD_FOLDER})
#add remote
execute_process(COMMAND ${GIT_EXECUTABLE} remote add origin ${TSP_REPO}
WORKING_DIRECTORY ${DOWNLOAD_FOLDER})
#set sparse-checkout
execute_process(COMMAND ${GIT_EXECUTABLE} sparse-checkout init --cone
WORKING_DIRECTORY ${DOWNLOAD_FOLDER})
#set sparse-checkout folder
execute_process(COMMAND ${GIT_EXECUTABLE} sparse-checkout set ${TSP_REPO_PATH}
WORKING_DIRECTORY ${DOWNLOAD_FOLDER})
#fetch
execute_process(COMMAND ${GIT_EXECUTABLE} fetch
WORKING_DIRECTORY ${DOWNLOAD_FOLDER})
#switch branch
execute_process(COMMAND ${GIT_EXECUTABLE} checkout ${TSP_SHA}
WORKING_DIRECTORY ${DOWNLOAD_FOLDER})
if (NOT ${STATUS_CODE} EQUAL 0)
message(FATAL_ERROR "TSP download failed (Link: ${TSP_FULL_PATH}).")
endif()
endmacro()

View File

@ -31,6 +31,18 @@ include(AzureConfigRTTI)
include(AzureBuildTargetForCI)
# Add create_map_file function
include(CreateMapFile)
option(TSP_GEN "Generate from TypeSpec" OFF)
if(TSP_GEN)
include(TSPCompile)
set(TSP_DESTINATION "keyvault_secrets")
set(TSP_REPO "https://github.com/Azure/azure-rest-api-specs.git")
set(TSP_SHA "1da5a85c4dc4f4f1caa47fff691e85960ef4bf20")
set(TSP_REPO_PATH "specification/keyvault/data-plane/Security.KeyVault.Secrets/")
DownloadTSPFiles(${TSP_REPO} ${TSP_SHA} ${TSP_REPO_PATH} ${TSP_DESTINATION})
endif()
if(FETCH_SOURCE_DEPS)
GetFolderList(SECRETS)