Skip to content

Commit fb2e6ea

Browse files
committed
Make metadata generation shell script more portable
1 parent 991cd23 commit fb2e6ea

2 files changed

Lines changed: 34 additions & 19 deletions

File tree

detectors/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ if(NOT "${DETRAY_GENERATE_METADATA}" STREQUAL "")
4747
OUTPUT "${GENERATED_HEADER}"
4848
COMMAND
4949
${CMAKE_CURRENT_SOURCE_DIR}/generate_metadata.sh -m
50-
${GENERATOR_SCRIPT} -o ${OUTPUT_DIR} -b ${CMAKE_BINARY_DIR}
50+
${GENERATOR_SCRIPT} -o ${OUTPUT_DIR} -p ${CMAKE_BINARY_DIR}
5151
DEPENDS
5252
"${GENERATOR_SCRIPT}"
5353
"${PROJECT_SOURCE_DIR}/detectors/generate_metadata.sh"

detectors/generate_metadata.sh

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#
55
# Mozilla Public License Version 2.0
66

7+
#!/bin/sh
8+
79
# Print help message
810
print_help()
911
{
@@ -23,8 +25,8 @@ print_help()
2325
log_lvl=0
2426

2527
# Parse options
26-
while getopts ":hvb:vv:m:o:" opt; do
27-
case $opt in
28+
while getopts ":hvp:vv:m:o:" opt; do
29+
case ${opt} in
2830
h)
2931
echo "Generate custom detray Detector Metadata"
3032
echo
@@ -34,27 +36,40 @@ while getopts ":hvb:vv:m:o:" opt; do
3436
v)
3537
((log_lvl++))
3638
;;
37-
b)
38-
build_dir=$OPTARG
39+
p)
40+
python_dir=${OPTARG}
3941
;;
4042
m)
41-
metadata_generator=$OPTARG
43+
metadata_generator=${OPTARG}
4244
;;
4345
o)
44-
out_dir=$OPTARG
46+
out_dir=${OPTARG}
4547
;;
4648
\?)
4749
echo
48-
echo "ERROR: Invalid option $opt! Usage:"
50+
echo "ERROR: Invalid option ${opt}! Usage:"
4951
echo
5052
print_help
5153
exit;;
5254
esac
5355
done
5456

55-
python_command="python $metadata_generator"
57+
# Check how to invoke the python interpreter
58+
python_command="python3"
59+
if [ ! type {$python_command} > /dev/null ]; then
60+
# Try again
61+
python_command="python"
62+
if [ ! type {$python_command} > /dev/null ]; then
63+
echo
64+
echo "ERROR: No python command found: exiting"
65+
echo
66+
exit
67+
fi
68+
fi
69+
70+
generator_command="${python_command} ${metadata_generator}"
5671

57-
if [[ -z "$metadata_generator" ]];then
72+
if [ -z "${metadata_generator}" ];then
5873
echo
5974
echo "ERROR: No detector metadata scrip supplied! Usage:"
6075
echo
@@ -63,19 +78,19 @@ if [[ -z "$metadata_generator" ]];then
6378
fi
6479

6580
# Configure verbosity
66-
if [[ $log_lvl == 1 ]]; then
67-
python_command="$python_command -v"
68-
elif [[ $log_lvl == 2 ]]; then
69-
python_command="$python_command -vv"
81+
if [ ${log_lvl} -eq 1 ]; then
82+
generator_command="${generator_command} -v"
83+
elif [ ${log_lvl} -eq 2 ]; then
84+
generator_command="${generator_command} -vv"
7085
fi
7186

7287
# Add the option for the custom output location
73-
if [[ ! -z "$out_dir" ]]; then
74-
python_command="$python_command -o $out_dir"
88+
if [ ! -z "${out_dir}" ]; then
89+
generator_command="${generator_command} -o ${out_dir}"
7590
fi
7691

77-
# Set uo the detray python package
78-
source $build_dir/python/setup.sh
92+
# Set up the detray python package
93+
export PYTHONPATH="${python_dir}/python":$PYTHONPATH
7994

8095
# Run the generation of the requested metadata
81-
eval $python_command
96+
eval ${generator_command}

0 commit comments

Comments
 (0)