1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-07-22 18:57:39 +02:00
trexio/tools/build_trexio.sh
Evgeny Posenitskiy 29d927675e
Major refactoring of the generator script (#47)
* minor cleaning

* create functions for dictionary parsers in the external file

* remove files_exclude since post-processing does the job

* no need to have group_group_dset when propagatin dsets

* oneliner for paths to templates

* add dset_per_group dict

* add function to iteratively populate string based on triggers list

* added recursive replacer for numbers

* add recursive replaces for datasets

* add function for text groups  [iterative+recursive upd]

* do not define triggers in the master script

* transition to helper dictionaries

* cleaning

* comment main code blocks

* rearrange parameters

* add documentation strings to the functions

* minor cleaning and changes

* adapt build_trexio script

* add consisteny check for dimensioning variables
2021-05-26 19:11:46 +02:00

97 lines
2.3 KiB
Bash
Executable File

#!/bin/bash
# Check that script is executed from tools directory
if [[ $(basename $PWD) != "tools" ]] ; then
echo "This script should run in the tools directory"
exit -1
fi
TREXIO_ROOT=$(dirname "${PWD}../")
# First define readonly global variables.
readonly SRC=${TREXIO_ROOT}/src
readonly TOOLS=${TREXIO_ROOT}/tools
# Function to produce TREXIO source files from org-mode files
function tangle()
{
local command="(org-babel-tangle-file \"$1\")"
emacs --batch \
--eval "(require 'org)" \
--eval "(org-babel-do-load-languages 'org-babel-load-languages '((python . t)))" \
--eval "(setq org-confirm-babel-evaluate nil)" \
--eval "$command"
}
# Create trex.json file
cd ${TREXIO_ROOT}
tangle trex.org
# Go to src directory
cd ${SRC}
# We want the script to crash on the 1st error:
set -e
# Create directories for templates
echo "create populated directories"
mkdir -p templates_front/populated
mkdir -p templates_text/populated
mkdir -p templates_hdf5/populated
# It is important to ad '--' to rm because it tells rm that what follows are
# not options. It is safer.
# Cleaning of existing data
echo "remove existing templates"
rm -f -- templates_front/*.{c,h,f90}
rm -f -- templates_text/*.{c,h}
rm -f -- templates_hdf5/*.{c,h}
echo "clean populated directories"
rm -f -- templates_front/populated/*
rm -f -- templates_text/populated/*
rm -f -- templates_hdf5/populated/*
# Produce source files for front end
echo "tangle org files to generate templates"
cd templates_front
tangle templator_front.org
cd ..
# Produce source files for TEXT back end
cd templates_text
tangle templator_text.org
cd ..
# Produce source files for HDF5 back end
cd templates_hdf5
tangle templator_hdf5.org
cd ..
# Populate templates with TREXIO structure according to trex.json file
echo "run generator script to populate templates"
cp ${TOOLS}/generator.py ${TOOLS}/generator_tools.py ${SRC}
python3 generator.py
rm -f -- ${SRC}/generator.py ${SRC}/generator_tools.py
rm -f -r -- ${SRC}/__pycache__/
# Put pieces of source files together
echo "compile populated files in the lib source files "
cd templates_front
source build.sh
cp trexio* ../
cd ..
mv trexio.h trexio_f.f90 ../include
cd templates_text
source build.sh
cp trexio* ../
cd ..
cd templates_hdf5
source build.sh
cp trexio* ../
cd ..