@@ -87,6 +87,35 @@ def restore_cmake_versions
8787 end
8888end
8989
90+ def patch_cmake_jemalloc
91+ cmake_file = 'odgi/CMakeLists.txt'
92+ return unless File . exist? ( cmake_file )
93+
94+ jemalloc_backup = "#{ cmake_file } .jemalloc_backup"
95+ return if File . exist? ( jemalloc_backup )
96+
97+ content = File . read ( cmake_file )
98+
99+ # Remove or comment out the JEMALLOC_LINK_LIBRARIES setting
100+ patched = content . gsub ( /^(\s *set\s *\( \s *JEMALLOC_LINK_LIBRARIES\s +"jemalloc"\s *\) )/ , '# \1 # Patched by Rakefile' )
101+
102+ if content != patched
103+ File . write ( jemalloc_backup , content )
104+ File . write ( cmake_file , patched )
105+ puts "Patched jemalloc linking in: #{ cmake_file } "
106+ end
107+ end
108+
109+ def restore_cmake_jemalloc
110+ cmake_file = 'odgi/CMakeLists.txt'
111+ jemalloc_backup = "#{ cmake_file } .jemalloc_backup"
112+ return unless File . exist? ( jemalloc_backup )
113+
114+ File . write ( cmake_file , File . read ( jemalloc_backup ) )
115+ File . delete ( jemalloc_backup )
116+ puts "Restored jemalloc linking in: #{ cmake_file } "
117+ end
118+
90119def patch_sdsl_lite
91120 # Patch louds_tree.hpp after sdsl-lite build
92121 louds_tree_files = Dir . glob ( 'odgi/build/sdsl-lite-prefix/src/sdsl-lite*/include/sdsl/louds_tree.hpp' )
@@ -131,6 +160,7 @@ odgi_vendor_lib = File.join(VENDOR_LIB_DIR, "libodgi.#{shared_lib_ext}")
131160# Build odgi using vendor jemalloc and move to vendor
132161file odgi_vendor_lib => [ jemalloc_vendor_lib ] do
133162 patch_cmake_versions
163+ patch_cmake_jemalloc
134164
135165 # Use vendor jemalloc
136166 jemalloc_include_dir = File . expand_path ( 'jemalloc/include' , __dir__ )
@@ -161,6 +191,14 @@ namespace :odgi do
161191 restore_cmake_versions
162192 end
163193
194+ task :patch_jemalloc do
195+ patch_cmake_jemalloc
196+ end
197+
198+ task :restore_jemalloc do
199+ restore_cmake_jemalloc
200+ end
201+
164202 task :patch_sdsl do
165203 patch_sdsl_lite
166204 end
177215namespace :vendor do
178216 desc 'Clean vendor directory'
179217 task :clean do
218+ # Restore patches before cleaning
219+ restore_cmake_versions
220+ restore_cmake_jemalloc
221+ restore_sdsl_lite
222+
180223 if Dir . exist? ( VENDOR_DIR )
181224 FileUtils . rm_rf ( VENDOR_DIR )
182225 puts "Cleaned vendor directory: #{ VENDOR_DIR } "
0 commit comments