@@ -43,6 +43,7 @@ def _search_duplicate_compilers(error_cls):
4343import inspect
4444import itertools
4545import os .path
46+ import pathlib
4647import pickle
4748import re
4849import tempfile
@@ -845,15 +846,21 @@ def _test_detection_by_executable(pkgs, error_cls):
845846
846847 errors , tmpdir = [], tempfile .mkdtemp ()
847848
848- def mock_executable (name , output , subdir = ("bin" ,)):
849- file_parts = list (subdir ) + [name ]
850- f = os .path .join (tmpdir , * file_parts )
851- llnl .util .filesystem .mkdirp (os .path .dirname (f ))
852- t = jinja2 .Template ("#!/bin/bash\n {{ output }}\n " )
853- with open (f , "w" ) as fs :
854- fs .write (t .render (output = output ))
855- llnl .util .filesystem .set_executable (f )
856- return f
849+ def create_executable_scripts (layout_entry ):
850+ relative_paths = layout_entry ["executables" ]
851+ script = layout_entry ["script" ]
852+ script_template = jinja2 .Template ("#!/bin/bash\n {{ script }}\n " )
853+ tmp_path = pathlib .Path (tmpdir )
854+
855+ result = []
856+ for mock_exe_path in relative_paths :
857+ rel_path = pathlib .Path (mock_exe_path )
858+ abs_path = tmp_path / rel_path
859+ abs_path .parent .mkdir (parents = True , exist_ok = True )
860+ abs_path .write_text (script_template .render (script = script ))
861+ llnl .util .filesystem .set_executable (abs_path )
862+ result .append (abs_path )
863+ return result
857864
858865 def detection_tests_for (pkg ):
859866 pkg_dir = os .path .dirname (spack .repo .PATH .filename_for_package_name (pkg ))
@@ -864,15 +871,17 @@ def detection_tests_for(pkg):
864871 @contextlib .contextmanager
865872 def setup_test_layout (layout ):
866873 hints , to_be_removed = set (), []
867- for binary in layout :
868- exe = mock_executable (binary ["name" ], binary ["output" ], subdir = binary ["subdir" ])
869- to_be_removed .append (exe )
870- hints .add (os .path .dirname (str (exe )))
874+ for entry in layout :
875+ exes = create_executable_scripts (entry )
876+ to_be_removed .extend (exes )
877+
878+ for mock_executable in exes :
879+ hints .add (str (mock_executable .parent ))
871880
872881 yield list (hints )
873882
874883 for exe in to_be_removed :
875- os .unlink (exe )
884+ exe .unlink ()
876885
877886 # Filter the packages and retain only the ones with detection tests
878887 pkgs_with_tests = packages_with_detection_tests ()
0 commit comments