<commit_before># Configure functions for the sprokit project
# The following functions are defined:
#
#   sprokit_configure_file
#   sprokit_configure_directory
#
# The following variables may be used to control the behavior of the functions:
#
#   sprokit_configure_extra_dests
#     A list of other paths to configure the file into.
#
# Their syntax is:
#
#   sprokit_configure_file(name source dest [variable ...])
#     The first argument is the name of the file being configured. The
#     next two parameters are the source and destination paths of the file to
#     be configured. Any variables that need to be replaced in the file
#     should be passed as extra arguments. The file will be added to the
#     list of files to be cleaned.
#
#   sprokit_configure_directory(name sourcedir destdir)
#     Configures an entire directory from ${sourcedir} into ${destdir}. Add
#     a dependency on the configure-${name} to ensure that it is complete
#     before another target.

add_custom_target(configure ALL)

function (_sprokit_configure_file name source dest)
  file(WRITE "${configure_script}"
    "# Configure script for \"${source}\" -> \"${dest}\"\n")

  foreach (arg ${ARGN})
    file(APPEND "${configure_script}"
      "set(${arg} \"${${arg}}\")\n")
  endforeach ()

  file(APPEND "${configure_script}" "${configure_code}")

  file(APPEND "${configure_script}" "
configure_file(
  \"${source}\"
  \"${configured_path}\"
  @ONLY)\n")

  file(APPEND "${configure_script}" "
configure_file(
  \"${configured_path}\"
  \"${dest}\"
  COPYONLY)\n")

  foreach (extra_dest IN LISTS sprokit_configure_extra_dests)
    file(APPEND "${configure_script}" "
configure_file(
  \"${configured_path}\"
  \"${extra_dest}\"
  COPYONLY)\n")
  endforeach ()

  set(clean_files
    "${dest}"
    ${sprokit_configure_extra_dests}
    "${configured_path}"
    "${configure_script}")

  set_directory_properties(
    PROPERTIES
      ADDITIONAL_MAKE_CLEAN_FILES "${clean_files}")
endfunction ()

function (sprokit_configure_file name source dest)
  set(configure_script
    "${CMAKE_CURRENT_BINARY_DIR}/configure.${name}.cmake")
  set(configured_path
    "${configure_script}.output")

  _sprokit_configure_file(${name} "${source}" "${dest}" ${ARGN})

  add_custom_command(
    OUTPUT  "${dest}"
            ${extra_output}
    COMMAND "${CMAKE_COMMAND}"
            -P "${configure_script}"
    MAIN_DEPENDENCY
            "${source}"
    DEPENDS "${source}"
            "${configure_script}"
    WORKING_DIRECTORY
            "${CMAKE_CURRENT_BINARY_DIR}"
    COMMENT "Configuring ${name} file \"${source}\" -> \"${dest}\"")
  if (NOT no_configure_target)
    add_custom_target(configure-${name} ${all}
      DEPENDS "${dest}"
      SOURCES "${source}")
    source_group("Configured Files"
      FILES "${source}")
    add_dependencies(configure
      configure-${name})
  endif ()
endfunction ()

function (sprokit_configure_file_always name source dest)
  set(extra_output
    "${dest}.noexist")

  sprokit_configure_file(${name} "${source}" "${dest}" ${ARGN})<commit_msg>Allow extra arguments for configure targets<commit_after># Configure functions for the sprokit project
# The following functions are defined:
#
#   sprokit_configure_file
#   sprokit_configure_directory
#
# The following variables may be used to control the behavior of the functions:
#
#   sprokit_configure_extra_dests
#     A list of other paths to configure the file into.
#
#   sprokit_configure_cmake_args
#     Extra arguments to pass to CMake when running the generated script.
#
# Their syntax is:
#
#   sprokit_configure_file(name source dest [variable ...])
#     The first argument is the name of the file being configured. The
#     next two parameters are the source and destination paths of the file to
#     be configured. Any variables that need to be replaced in the file
#     should be passed as extra arguments. The file will be added to the
#     list of files to be cleaned.
#
#   sprokit_configure_directory(name sourcedir destdir)
#     Configures an entire directory from ${sourcedir} into ${destdir}. Add
#     a dependency on the configure-${name} to ensure that it is complete
#     before another target.

add_custom_target(configure ALL)

function (_sprokit_configure_file name source dest)
  file(WRITE "${configure_script}"
    "# Configure script for \"${source}\" -> \"${dest}\"\n")

  foreach (arg ${ARGN})
    file(APPEND "${configure_script}"
      "set(${arg} \"${${arg}}\")\n")
  endforeach ()

  file(APPEND "${configure_script}" "${configure_code}")

  file(APPEND "${configure_script}" "
configure_file(
  \"${source}\"
  \"${configured_path}\"
  @ONLY)\n")

  file(APPEND "${configure_script}" "
configure_file(
  \"${configured_path}\"
  \"${dest}\"
  COPYONLY)\n")

  foreach (extra_dest IN LISTS sprokit_configure_extra_dests)
    file(APPEND "${configure_script}" "
configure_file(
  \"${configured_path}\"
  \"${extra_dest}\"
  COPYONLY)\n")
  endforeach ()

  set(clean_files
    "${dest}"
    ${sprokit_configure_extra_dests}
    "${configured_path}"
    "${configure_script}")

  set_directory_properties(
    PROPERTIES
      ADDITIONAL_MAKE_CLEAN_FILES "${clean_files}")
endfunction ()

function (sprokit_configure_file name source dest)
  set(configure_script
    "${CMAKE_CURRENT_BINARY_DIR}/configure.${name}.cmake")
  set(configured_path
    "${configure_script}.output")

  _sprokit_configure_file(${name} "${source}" "${dest}" ${ARGN})

  add_custom_command(
    OUTPUT  "${dest}"
            ${extra_output}
    COMMAND "${CMAKE_COMMAND}"
            ${sprokit_configure_cmake_args}
            -P "${configure_script}"
    MAIN_DEPENDENCY
            "${source}"
    DEPENDS "${source}"
            "${configure_script}"
    WORKING_DIRECTORY
            "${CMAKE_CURRENT_BINARY_DIR}"
    COMMENT "Configuring ${name} file \"${source}\" -> \"${dest}\"")
  if (NOT no_configure_target)
    add_custom_target(configure-${name} ${all}
      DEPENDS "${dest}"
      SOURCES "${source}")
    source_group("Configured Files"
      FILES "${source}")
    add_dependencies(configure
      configure-${name})
  endif ()
endfunction ()

function (sprokit_configure_file_always name source dest)
  set(extra_output
    "${dest}.noexist")

  sprokit_configure_file(${name} "${source}" "${dest}" ${ARGN})
{'fraction_non_alphanumeric': 0.13205756761031157, 'fraction_numerical': 0.0, 'mean_word_length': 3.9290724863600937, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2535932', 'n_tokens_mistral': 1971, 'n_tokens_neox': 1950, 'n_words': 513}