Skip to content

Commit

Permalink
fixup! Use the same patching script and command for all repos
Browse files Browse the repository at this point in the history
  • Loading branch information
dcandler committed Nov 29, 2024
1 parent 591aeb8 commit 88c5d02
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 31 deletions.
16 changes: 5 additions & 11 deletions cmake/fetch_llvm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,24 @@
# top level to any library builds to prevent repeated checkouts.

include(FetchContent)
include(${CMAKE_CURRENT_LIST_DIR}/patch_repo.cmake)

if(NOT VERSIONS_JSON)
include(${CMAKE_CURRENT_LIST_DIR}/read_versions.cmake)
endif()
read_repo_version(llvmproject llvm-project)

set(patch_script ${CMAKE_CURRENT_LIST_DIR}/patch_repo.py)
if(GIT_PATCH_METHOD STREQUAL "am")
set(patch_script_args --method am)
elseif(GIT_PATCH_METHOD STREQUAL "apply")
set(patch_script_args --method apply)
endif()
set(patch_dir ${CMAKE_CURRENT_LIST_DIR}/../patches)
set(LLVM_PATCH_COMMAND ${Python3_EXECUTABLE} ${patch_script} ${patch_script_args} ${patch_dir}/llvm-project)
get_patch_command(llvm-project llvm_patch_command)
if(APPLY_LLVM_PERFORMANCE_PATCHES)
set(LLVM_PATCH_COMMAND ${LLVM_PATCH_COMMAND} && ${Python3_EXECUTABLE} ${patch_script} ${patch_script_args} ${patch_dir}/llvm-project-perf)
get_patch_command(llvm-project-perf llvm_perf_patch_command)
set(llvm_patch_command ${llvm_patch_command} && ${llvm_perf_patch_command} )
endif()

FetchContent_Declare(llvmproject
GIT_REPOSITORY https://github.com/llvm/llvm-project.git
GIT_TAG "${llvmproject_TAG}"
GIT_SHALLOW "${llvmproject_SHALLOW}"
GIT_PROGRESS TRUE
PATCH_COMMAND ${LLVM_PATCH_COMMAND}
PATCH_COMMAND ${llvm_patch_command}
# Add the llvm subdirectory later to ensure that
# LLVMEmbeddedToolchainForArm is the first project declared.
# Otherwise CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT
Expand Down
13 changes: 3 additions & 10 deletions cmake/fetch_newlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,20 @@
# top level to any library builss to prevent repeated checkouts.

include(FetchContent)
include(${CMAKE_CURRENT_LIST_DIR}/patch_repo.cmake)

if(NOT VERSIONS_JSON)
include(${CMAKE_CURRENT_LIST_DIR}/read_versions.cmake)
endif()
read_repo_version(newlib newlib)

set(patch_script ${CMAKE_CURRENT_LIST_DIR}/patch_repo.py)
if(GIT_PATCH_METHOD STREQUAL "am")
set(patch_script_args --method am)
elseif(GIT_PATCH_METHOD STREQUAL "apply")
set(patch_script_args --method apply)
endif()
set(patch_dir ${CMAKE_CURRENT_LIST_DIR}/../patches)
set(NEWLIB_PATCH_COMMAND ${Python3_EXECUTABLE} ${patch_script} ${patch_script_args} ${patch_dir}/newlib)
get_patch_command(newlib newlib_patch_command)

FetchContent_Declare(newlib
GIT_REPOSITORY https://sourceware.org/git/newlib-cygwin.git
GIT_TAG "${newlib_TAG}"
GIT_SHALLOW "${newlib_SHALLOW}"
GIT_PROGRESS TRUE
PATCH_COMMAND ${NEWLIB_PATCH_COMMAND}
PATCH_COMMAND ${newlib_patch_command}
# Similarly to picolibc, we don't do the configuration here.
SOURCE_SUBDIR do_not_add_newlib_subdir
)
Expand Down
13 changes: 3 additions & 10 deletions cmake/fetch_picolibc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,20 @@
# top level to any library builss to prevent repeated checkouts.

include(FetchContent)
include(${CMAKE_CURRENT_LIST_DIR}/patch_repo.cmake)

if(NOT VERSIONS_JSON)
include(${CMAKE_CURRENT_LIST_DIR}/read_versions.cmake)
endif()
read_repo_version(picolibc picolibc)

set(patch_script ${CMAKE_CURRENT_LIST_DIR}/patch_repo.py)
if(GIT_PATCH_METHOD STREQUAL "am")
set(patch_script_args --method am)
elseif(GIT_PATCH_METHOD STREQUAL "apply")
set(patch_script_args --method apply)
endif()
set(patch_dir ${CMAKE_CURRENT_LIST_DIR}/../patches)
set(PICOLIBC_PATCH_COMMAND ${Python3_EXECUTABLE} ${patch_script} ${patch_script_args} ${patch_dir}/picolibc)
get_patch_command(picolibc picolibc_patch_command)

FetchContent_Declare(picolibc
GIT_REPOSITORY https://github.com/picolibc/picolibc.git
GIT_TAG "${picolibc_TAG}"
GIT_SHALLOW "${picolibc_SHALLOW}"
GIT_PROGRESS TRUE
PATCH_COMMAND ${PICOLIBC_PATCH_COMMAND}
PATCH_COMMAND ${picolibc_patch_command}
# We only want to download the content, not configure it at this
# stage. picolibc will be built in many configurations using
# ExternalProject_Add using the sources that are checked out here.
Expand Down
16 changes: 16 additions & 0 deletions cmake/patch_repo.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

# Function to generate a PATCH_COMMAND, calling the
# patch_repo.py script using a target set of patches.

function(get_patch_command patch_dir patch_command_out)
set(patch_script ${CMAKE_CURRENT_LIST_DIR}/patch_repo.py)
list(APPEND patch_script_args ${Python3_EXECUTABLE} ${patch_script})
if(GIT_PATCH_METHOD STREQUAL "am")
list(APPEND patch_script_args "--method" "am")
elseif(GIT_PATCH_METHOD STREQUAL "apply")
list(APPEND patch_script_args "--method" "apply")
endif()
list(APPEND patch_script_args ${CMAKE_CURRENT_LIST_DIR}/../patches/${patch_dir})

set(${patch_command_out} ${patch_script_args} PARENT_SCOPE)
endfunction()

0 comments on commit 88c5d02

Please sign in to comment.