nmodl icon indicating copy to clipboard operation
nmodl copied to clipboard

Broken build-system for copying Python files.

Open 1uc opened this issue 1 year ago • 0 comments

We use:

file(
  GLOB NMODL_PYTHON_FILES
  RELATIVE "${NMODL_PROJECT_SOURCE_DIR}/python/nmodl/"
  CONFIGURE_DEPENDS "${NMODL_PROJECT_SOURCE_DIR}/python/nmodl/*.py")

foreach(file IN LISTS NMODL_PYTHON_FILES)
  cpp_cc_build_time_copy(INPUT ${NMODL_PROJECT_SOURCE_DIR}/python/nmodl/${file} OUTPUT
                         ${CMAKE_BINARY_DIR}/lib/nmodl/${file})
  list(APPEND nmodl_python_binary_dir_files "${CMAKE_BINARY_DIR}/lib/nmodl/${file}")
endforeach()

with

function(cpp_cc_build_time_copy)
  cmake_parse_arguments(opt "NO_TARGET" "INPUT;OUTPUT" "" ${ARGN})
  add_custom_command(
    OUTPUT "${opt_OUTPUT}"
    DEPENDS "${opt_INPUT}"
    COMMAND ${CMAKE_COMMAND} -E copy "${opt_INPUT}" "${opt_OUTPUT}")
  if(NOT opt_NO_TARGET)
    string(SHA256 target_name "${opt_INPUT};${opt_OUTPUT}")
    set(target_name "build-time-copy-${target_name}")
    if(NOT TARGET "${target_name}")
      add_custom_target(${target_name} ALL DEPENDS "${opt_OUTPUT}")
    endif()
  endif()

to copy the Python files into a subdirectory of lib. Unfortunately, it now occasionally happens that the copying fails when building in parallel:

[  1%] Generating ../../lib/nmodl/ode.py
...
[  2%] Generating ../../lib/nmodl/ode.py
...
Error copying file "/home/lucg/git/bbp/nmodl/python/nmodl/ode.py" to "/home/lucg/git/bbp/nmodl/build-debug/lib/nmodl/ode.py".

Note that lib/nmodl/ode.py is generated twice.

1uc avatar Oct 07 '24 13:10 1uc