(rule
 (alias frama-c-configure)
 (deps (universe)
  (alias ../frama-c-configure-tests))
 (action
  (progn
   (echo "  - Crowbar Tests:" %{read:tests-crowbar-deps-available} "\n")
   (echo "    - FC_FUZZING env var:" %{env:FC_FUZZING=false} "\n")
   (echo "    - Crowbar: " %{lib-available:crowbar} "\n")
   (echo "    - Crowbar Utils:" %{lib-available:crowbar_utils} "\n")
   (echo "    - Inout:" %{lib-available:frama-c-inout.core} "\n")
   (echo "    - Eva:" %{lib-available:frama-c-eva.core} "\n")
   ; If you add some dependencies here, do not forget to add them to the
   ; crowbar_fake_lib library to update tests-crowbar-deps-available
   (echo "  - Other Fuzzing Tests:" %{read:tests-fuzzing-deps-available} "\n")
   (echo "    - FC_FUZZING env var:" %{env:FC_FUZZING=false} "\n")
   (echo "    - Python:" %{read:../../python-3.10-available} "\n")
   ; If you add some dependencies here, do not forget to update tests_configurator.ml
  ))
)

; The following library and two rules are printing to a file
; tests-crowbar-deps-available "true" or "false" depending on the
; availability of the dependencies for the test.
(library
  (name crowbar_deps_fake_lib)
  (enabled_if
    (and
      (<> %{env:FC_FUZZING=false} "false")
      %{lib-available:crowbar}
      %{lib-available:crowbar_utils}
      %{lib-available:frama-c-inout.core}
      %{lib-available:frama-c-eva.core}))
  (modules))
(rule
 (deps (universe))
 (enabled_if %{lib-available:crowbar_deps_fake_lib})
 (action (with-stdout-to "tests-crowbar-deps-available"
  (echo "true"))))
(rule
 (deps (universe))
 (enabled_if (not %{lib-available:crowbar_deps_fake_lib}))
 (action (with-stdout-to "tests-crowbar-deps-available"
  (echo "false (Crowbar tests are disabled)"))))

(rule
 (deps (universe))
 (enabled_if (and (<> %{env:FC_FUZZING=false} "false") (<> %{read:../../tests-fuzzing-deps-available} "true")))
 (action (with-stdout-to "tests-fuzzing-deps-available"
  (echo "true"))))
(rule
 (deps (universe))
 (enabled_if (not (and (<> %{env:FC_FUZZING=false} "false") (<> %{read:../../tests-fuzzing-deps-available} "true"))))
 (action (with-stdout-to "tests-fuzzing-deps-available"
  (echo "false (Fuzzing tests are disabled)"))))

(cram
 (enabled_if (<> %{env:FC_FUZZING=false} "false"))
 (deps (package frama-c))
)

(cram
 (applies_to * \ bitfield frama-smith)
 (deps (package crowbar_utils))
)

(cram
 (applies_to constfold)
 (deps
  (package frama-c-eva)
  (package frama-c-inout))
)

(cram
 (applies_to bitfield)
 (enabled_if %{read:../../python-3.10-available})
 (deps (env_var "NB_TESTS") (env_var "NB_CORES"))
)

(cram
 (applies_to frama-smith)
 (deps
   %{project_root}/dev/frama-smith.py
   %{project_root}/dev/minimize-crash-cmdline.py
   %{project_root}/dev/frama-smith-templates.json)
)
