Skip to content

Commit 0d98130

Browse files
authored
refactor: Separate hpp files for better scope of files + tests (#109)
The existing geoarrow.hpp was getting rather unwieldy, so we can split it up for better scope!
1 parent 5841fe4 commit 0d98130

12 files changed

+850
-768
lines changed

CMakeLists.txt

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -110,28 +110,39 @@ if(GEOARROW_BUNDLE)
110110
file(APPEND ${GEOARROW_C_TEMP} "${SRC_FILE_CONTENTS}")
111111
endforeach()
112112

113+
set(GEOARROW_HPP_TEMP ${CMAKE_BINARY_DIR}/amalgamation/geoarrow/geoarrow.hpp)
114+
file(WRITE ${GEOARROW_HPP_TEMP} "")
115+
foreach(SRC_FILE
116+
exception.hpp
117+
internal.hpp
118+
geometry_data_type.hpp
119+
array_reader.hpp
120+
array_writer.hpp)
121+
file(READ "src/geoarrow/hpp/${SRC_FILE}" SRC_FILE_CONTENTS)
122+
file(APPEND ${GEOARROW_HPP_TEMP} "${SRC_FILE_CONTENTS}")
123+
endforeach()
124+
113125
# Update includes for concatenated sources
114-
foreach(SRC_FILE ${GEOARROW_H_TEMP} ${GEOARROW_C_TEMP})
126+
foreach(SRC_FILE ${GEOARROW_HPP_TEMP} ${GEOARROW_H_TEMP} ${GEOARROW_C_TEMP})
115127
file(READ ${SRC_FILE} SRC_FILE_CONTENTS)
116128
string(REGEX REPLACE "#include \"[a-z_.]+\"" "" SRC_FILE_CONTENTS
117129
"${SRC_FILE_CONTENTS}")
130+
string(REGEX REPLACE "#include \"hpp/[a-z_.]+\"" "" SRC_FILE_CONTENTS
131+
"${SRC_FILE_CONTENTS}")
118132
file(WRITE ${SRC_FILE} "${SRC_FILE_CONTENTS}")
119133
endforeach()
120134

121-
# Make sure geoarrow.h is included from geoarrow.c
122-
file(READ ${GEOARROW_C_TEMP} SRC_FILE_CONTENTS)
123-
file(WRITE ${GEOARROW_C_TEMP} "#include \"geoarrow.h\"\n")
124-
file(APPEND ${GEOARROW_C_TEMP} "${SRC_FILE_CONTENTS}")
125-
126-
# Copy geoarrow.hpp
127-
file(COPY_FILE src/geoarrow/geoarrow.hpp
128-
${CMAKE_BINARY_DIR}/amalgamation/geoarrow/geoarrow.hpp)
129-
file(COPY_FILE src/geoarrow/geoarrow_arrow.hpp
130-
${CMAKE_BINARY_DIR}/amalgamation/geoarrow/geoarrow_arrow.hpp)
135+
# Make sure geoarrow.h is included from geoarrow.c and geoarrow.hpp
136+
foreach(SRC_FILE ${GEOARROW_HPP_TEMP} ${GEOARROW_C_TEMP})
137+
file(READ ${SRC_FILE} SRC_FILE_CONTENTS)
138+
file(WRITE ${SRC_FILE} "#include \"geoarrow.h\"\n")
139+
file(APPEND ${SRC_FILE} "${SRC_FILE_CONTENTS}")
140+
endforeach()
131141

132142
# "install" means copy the bundled sources to the specified dir. Just
133-
# geoarrow.c and geoarrow.h for now.
134-
install(FILES ${GEOARROW_H_TEMP} ${GEOARROW_C_TEMP} DESTINATION ".")
143+
# geoarrow.c, geoarrow.h, and geoarrow.hpp for now.
144+
install(FILES ${GEOARROW_HPP_TEMP} ${GEOARROW_H_TEMP} ${GEOARROW_C_TEMP}
145+
DESTINATION ".")
135146

136147
# If building tests, add the geoarrow target so we can test against it
137148
if(GEOARROW_BUILD_TESTS)
@@ -244,7 +255,6 @@ if(GEOARROW_BUILD_TESTS)
244255

245256
enable_testing()
246257

247-
add_executable(geoarrow_hpp_test src/geoarrow/geoarrow_hpp_test.cc)
248258
add_executable(geoarrow_type_inline_test src/geoarrow/geoarrow_type_inline_test.cc)
249259
add_executable(builder_test src/geoarrow/builder_test.cc)
250260
add_executable(array_view_test src/geoarrow/array_view_test.cc)
@@ -261,13 +271,12 @@ if(GEOARROW_BUILD_TESTS)
261271
add_executable(array_reader_test src/geoarrow/array_reader_test.cc)
262272
add_executable(array_writer_test src/geoarrow/array_writer_test.cc)
263273
add_executable(wkx_files_test src/geoarrow/wkx_files_test.cc)
264-
add_executable(geoarrow_arrow_test src/geoarrow/geoarrow_arrow_test.cc)
265274

266-
target_link_libraries(geoarrow_hpp_test
267-
geoarrow
268-
gtest_main
269-
gmock_main
270-
nanoarrow::nanoarrow)
275+
add_executable(hpp_array_writer_test src/geoarrow/hpp/array_writer_test.cc)
276+
add_executable(hpp_geometry_data_type_test src/geoarrow/hpp/geometry_data_type_test.cc)
277+
add_executable(hpp_arrow_extension_type_test
278+
src/geoarrow/hpp/arrow_extension_type_test.cc)
279+
271280
target_link_libraries(geoarrow_type_inline_test geoarrow gtest_main
272281
nanoarrow::nanoarrow)
273282
target_link_libraries(builder_test geoarrow gtest_main nanoarrow::nanoarrow)
@@ -285,10 +294,18 @@ if(GEOARROW_BUILD_TESTS)
285294
target_link_libraries(array_reader_test geoarrow gtest_main nanoarrow::nanoarrow)
286295
target_link_libraries(array_writer_test geoarrow gtest_main nanoarrow::nanoarrow)
287296
target_link_libraries(wkx_files_test geoarrow gtest_main nanoarrow::nanoarrow)
288-
target_link_libraries(geoarrow_arrow_test geoarrow ${GEOARROW_ARROW_TARGET} gtest_main)
297+
298+
target_link_libraries(hpp_array_writer_test
299+
geoarrow
300+
gtest_main
301+
gmock_main
302+
nanoarrow::nanoarrow)
303+
target_link_libraries(hpp_geometry_data_type_test geoarrow gtest_main
304+
nanoarrow::nanoarrow)
305+
target_link_libraries(hpp_arrow_extension_type_test geoarrow ${GEOARROW_ARROW_TARGET}
306+
gtest_main)
289307

290308
include(GoogleTest)
291-
gtest_discover_tests(geoarrow_hpp_test)
292309
gtest_discover_tests(geoarrow_type_inline_test)
293310
gtest_discover_tests(builder_test)
294311
gtest_discover_tests(array_view_test)
@@ -305,5 +322,8 @@ if(GEOARROW_BUILD_TESTS)
305322
gtest_discover_tests(array_reader_test)
306323
gtest_discover_tests(array_writer_test)
307324
gtest_discover_tests(wkx_files_test)
308-
gtest_discover_tests(geoarrow_arrow_test)
325+
326+
gtest_discover_tests(hpp_array_writer_test)
327+
gtest_discover_tests(hpp_geometry_data_type_test)
328+
gtest_discover_tests(hpp_arrow_extension_type_test)
309329
endif()

python/geoarrow-c/bootstrap.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@
3333
vendor_source_files += glob.glob(
3434
os.path.join(vendor_source_dir, "double_parse_fast_float.cc")
3535
)
36+
vendor_source_files += glob.glob(os.path.join(vendor_source_dir, "hpp/*.hpp"))
3637
vendor_source_files += glob.glob(os.path.join(vendor_source_dir, "ryu/*.h"))
3738
vendor_source_files += glob.glob(os.path.join(vendor_source_dir, "ryu/*.c"))
3839
vendor_source_files += glob.glob(os.path.join(vendor_source_dir, "nanoarrow/*.h"))
3940
vendor_source_files += glob.glob(os.path.join(vendor_source_dir, "nanoarrow/*.c"))
4041

4142
os.mkdir(vendor_dir)
43+
os.mkdir(os.path.join(vendor_dir, "hpp"))
4244
os.mkdir(os.path.join(vendor_dir, "ryu"))
4345
os.mkdir(os.path.join(vendor_dir, "nanoarrow"))
4446
for source_file in vendor_source_files:

0 commit comments

Comments
 (0)