Skip to content

Commit 81f596d

Browse files
committed
reapi: simplify build entries for go tests
Problem: the Go test links against unnecessary libraries such as Fluxion resource, reapi_module, and flux::core. Furthermore, the options are a long, unwrapped string which is hard to read. Remove the unnecessary entries in the CGO_LIBRARY_FLAGS and make the presentation more readable. Update GolangSimple.cmake to remove string replacement of " " with ";" which causes the list expansion to fail.
1 parent 7825191 commit 81f596d

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

cmake/GolangSimple.cmake

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@ function(BUILD_GO_PROGRAM NAME MAIN_SRC CGO_CFLAGS CGO_LIBRARY_FLAGS)
1111
get_filename_component(MAIN_SRC_ABS ${MAIN_SRC} ABSOLUTE)
1212
add_custom_target(${NAME})
1313

14-
# IMPORTANT: the trick to getting *spaces* to render in COMMAND is to convert them to ";"
15-
# string(REPLACE <match-string> <replace-string> <out-var> <input>...)
16-
STRING(REPLACE " " ";" CGO_LIBRARY_FLAGS ${CGO_LIBRARY_FLAGS})
1714
add_custom_command(TARGET ${NAME}
18-
COMMAND GOPATH=${GOPATH}:${CUSTOM_GO_PATH} GOOS=linux G0111MODULE=off CGO_CFLAGS="${CGO_CFLAGS}" CGO_LDFLAGS='${CGO_LIBRARY_FLAGS}' go build -ldflags '-w'
15+
COMMAND GOPATH=${GOPATH}:${CUSTOM_GO_PATH} GOOS=linux G0111MODULE=off CGO_CFLAGS="${CGO_CFLAGS}" CGO_LDFLAGS="${CGO_LIBRARY_FLAGS}" go build -ldflags '-w'
1916
-o "${CMAKE_CURRENT_SOURCE_DIR}/${NAME}"
2017
${CMAKE_GO_FLAGS} ${MAIN_SRC}
2118
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}

resource/reapi/bindings/go/src/test/CMakeLists.txt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,24 @@ set(SRCS main.go)
33
set(CGO_CFLAGS "-I${CMAKE_BINARY_DIR}/resource/reapi/bindings/c")
44

55
# This is currently passed but not used because when passed into add_custom_command the spaces are escaped
6-
set(CGO_LIBRARY_FLAGS "-Wl,-R ${CMAKE_BINARY_DIR}/resource -L${CMAKE_BINARY_DIR}/resource/reapi/bindings -L${CMAKE_BINARY_DIR}/resource/libjobspec -ljobspec_conv -lreapi_cli -L${CMAKE_BINARY_DIR}/resource -lresource -L${CMAKE_BINARY_DIR}/resource/planner/c -lplanner -L${CMAKE_BINARY_DIR}/resource/planner/c++ -lplanner_cxx -lflux-idset -lstdc++ -lczmq -ljansson -lhwloc -lboost_system -lflux-hostlist -lboost_graph -lyaml-cpp")
6+
set(CGO_LIBRARY_FLAGS -Wl,-R
7+
-lflux-idset
8+
-lstdc++
9+
-lczmq
10+
-ljansson
11+
-lhwloc
12+
-lboost_system
13+
-lflux-hostlist
14+
-lboost_graph
15+
-lyaml-cpp
16+
-L${CMAKE_BINARY_DIR}/resource/reapi/bindings -lreapi_cli
17+
)
718

819
# This ensures the main binary is cleaned up
920
set_directory_properties(
1021
PROPERTIES
11-
ADDITIONAL_CLEAN_FILES "${CMAKE_CURRENT_BINARY_DIR}/main"
22+
ADDITIONAL_CLEAN_FILES "${CMAKE_CURRENT_BINARY_DIR}/main"
1223
)
1324

14-
# GO_GET(go_redis github.com/hoisie/redis)
15-
# main main.go
1625
# We add the dependencies at the end so the build can run in parallel and we don't try to build this before they are ready!
17-
BUILD_GO_PROGRAM(${TARGET} ${SRCS} "${CGO_CFLAGS}" "${CGO_LIBRARY_FLAGS}" jobspec_conv reapi_module reapi_cli resource flux::core)
26+
BUILD_GO_PROGRAM(${TARGET} ${SRCS} "${CGO_CFLAGS}" "${CGO_LIBRARY_FLAGS}" reapi_cli)

0 commit comments

Comments
 (0)