Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSazonov committed Jul 15, 2024
1 parent 27b3055 commit c8bd251
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 62 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ jobs:
shell: bash
run: scripts/print_build_variables.sh # bash -x scripts/print_build_variables.sh for printing commands

- name: Create CFML and pyCFML directories
- name: Create scripts, CFML and pyCFML directories
shell: bash
run: |
scripts/create_scripts_dir.sh
scripts/create_cfml_repo_dir.sh
scripts/create_cfml_build_dir.sh
scripts/create_cfml_dist_dir.sh
Expand Down
46 changes: 33 additions & 13 deletions scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def _compiler_options():
compiler = _compiler_name()
mode = _compiling_mode()
options = ''
for build in CONFIG['build-objs']:
for build in CONFIG['build-configs']:
if _platform() in build['platforms'] and compiler in build['compilers']:
options = f"{build['modes']['base']}"
if build['modes'][mode]:
Expand All @@ -162,7 +162,7 @@ def _compiler_options():
def _obj_ext():
compiler = _compiler_name()
ext = ''
for build in CONFIG['build-objs']:
for build in CONFIG['build-configs']:
if _platform() in build['platforms'] and compiler in build['compilers']:
ext = build['obj-ext']
break
Expand All @@ -171,7 +171,7 @@ def _obj_ext():
def _compiler_build_shared_template():
compiler = _compiler_name()
template = ''
for build in CONFIG['build-objs']:
for build in CONFIG['build-configs']:
if _platform() in build['platforms'] and compiler in build['compilers']:
template = build['build-shared']
break
Expand All @@ -180,7 +180,7 @@ def _compiler_build_shared_template():
def _compiler_build_exe_template():
compiler = _compiler_name()
template = ''
for build in CONFIG['build-objs']:
for build in CONFIG['build-configs']:
if _platform() in build['platforms'] and compiler in build['compilers']:
template = build['build-exe']
break
Expand All @@ -189,7 +189,7 @@ def _compiler_build_exe_template():
def _compiler_obj_ext():
compiler = _compiler_name()
obj_ext = ''
for build in CONFIG['build-objs']:
for build in CONFIG['build-configs']:
if _platform() in build['platforms'] and compiler in build['compilers']:
obj_ext = build['obj-ext']
break
Expand Down Expand Up @@ -386,16 +386,19 @@ def loaded_config(name: str):
with open(path, 'rb') as f:
config = tomllib.load(f)
if _bash_syntax():
for idx, build in enumerate(config['build-objs']):
config['build-objs'][idx]['build-shared'] = build['build-shared'].replace('/', '-')
config['build-objs'][idx]['build-exe'] = build['build-exe'].replace('/', '-')
config['build-objs'][idx]['modes']['base'] = build['modes']['base'].replace('/', '-')
config['build-objs'][idx]['modes']['debug'] = build['modes']['debug'].replace('/', '-')
config['build-objs'][idx]['modes']['release'] = build['modes']['release'].replace('/', '-')
for idx, build in enumerate(config['build-configs']):
config['build-configs'][idx]['build-shared'] = build['build-shared'].replace('/', '-')
config['build-configs'][idx]['build-exe'] = build['build-exe'].replace('/', '-')
config['build-configs'][idx]['modes']['base'] = build['modes']['base'].replace('/', '-')
config['build-configs'][idx]['modes']['debug'] = build['modes']['debug'].replace('/', '-')
config['build-configs'][idx]['modes']['release'] = build['modes']['release'].replace('/', '-')
return config

def clear_main_script():
path = _main_script_path()
if not os.path.isfile(path):
file = Path(path)
file.parent.mkdir(exist_ok=True, parents=True)
with open(path, 'w') as file:
pass

Expand Down Expand Up @@ -440,6 +443,22 @@ def print_build_variables():
_write_lines_to_file(lines, script_name)
append_to_main_script(lines)

def create_scripts_dir():
scripts_dir = CONFIG['project']['dir']['scripts']
scripts_path = os.path.join(_project_path(), scripts_dir)
lines = []
msg = _echo_msg(f"Deleting build dir '{scripts_dir}'")
lines.append(msg)
cmd = f'rm -rf {scripts_path}'
lines.append(cmd)
msg = _echo_msg(f"Creating build dir '{scripts_dir}'")
lines.append(msg)
cmd = f'mkdir -p {scripts_path}'
lines.append(cmd)
script_name = f'{sys._getframe().f_code.co_name}.sh'
_write_lines_to_file(lines, script_name)
append_to_main_script(lines)

def create_cfml_repo_dir():
repo_dir = CONFIG['cfml']['dir']['repo']
repo_path = os.path.join(_project_path(), repo_dir)
Expand Down Expand Up @@ -1218,7 +1237,8 @@ def run_powder_mod_main():
append_header_to_main_script(f"Print some build-specific variables")
print_build_variables()

append_header_to_main_script(f"Create {cfml_project_name} and {pycfml_project_name} directories")
append_header_to_main_script(f"Create scripts, {cfml_project_name} and {pycfml_project_name} directories")
create_scripts_dir()
create_cfml_repo_dir()
create_cfml_build_dir()
create_cfml_dist_dir()
Expand Down Expand Up @@ -1257,7 +1277,7 @@ def run_powder_mod_main():

append_header_to_main_script(f"Make {pycfml_project_name} distribution")
copy_built_to_pycfml_dist()
#change_runpath_for_built_pycfml()
change_runpath_for_built_pycfml()
copy_extra_libs_to_pycfml_dist()
copy_py_api_files_to_pycfml_dist()
copy_init_file_to_pycfml_dist()
Expand Down
95 changes: 47 additions & 48 deletions scripts.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[project.dir]
scripts = 'build/scripts'

##############################
# CrysFML Fortran 2008 Library
##############################
Expand Down Expand Up @@ -48,9 +51,6 @@ dist-wheel = 'dist/pyCFML/wheel' # for Python wheel
# Generic build template commands and related parameters
########################################################

[project.dir]
scripts = 'scripts'

[template]
clone-repo = 'git clone --single-branch --branch {BRANCH} {URL} {OUT_PATH}'
build-obj = '{COMPILER} {OPTIONS} -c {PATH} -I {INCLUDE}'
Expand All @@ -72,8 +72,51 @@ run-benchmarks.base = 'pytest {PATH} --color=yes --benchmark-only --benchmark-st
run-benchmarks.master-branch = '--benchmark-autosave'
run-benchmarks.non-master-branch = '--benchmark-compare --benchmark-compare-fail=median:25%'

######################
# Build configurations
######################

[[build-configs]]
platforms = ['macos', 'linux', 'windows']
compilers = ['gfortran']
obj-ext = 'o'
build-shared = '{COMPILER} -shared CFML_Wraps.{OBJ_EXT} Wraps_*.{OBJ_EXT} {PATH}.{OBJ_EXT} -o {PATH}.{EXT} -L{CFML_LIB_PATH} -l{CFML_LIB_NAME} {PYTHON_LIB}'
build-exe = '{COMPILER} {OPTIONS} -o {EXE_NAME} {SOURCE_PATH} -I {CFML_INCLUDE_PATH} -L{CFML_LIB_DIR} -l{CFML_LIB_NAME}'
modes.base = '-cpp -fdec-math -fPIC -fno-stack-arrays -ffree-line-length-none'
modes.debug = ''
modes.release = ''

[[build-configs]]
platforms = ['macos']
compilers = ['nagfor']
obj-ext = 'o'
build-shared = '{COMPILER} -Wl,-shared CFML_Wraps.{OBJ_EXT} Wraps_*.{OBJ_EXT} {PATH}.{OBJ_EXT} -o {PATH}.{EXT} -L{CFML_LIB_PATH} -l{CFML_LIB_NAME} {PYTHON_LIB}'
build-exe = '{COMPILER} {OPTIONS} -o {EXE_NAME} {SOURCE_PATH} -I {CFML_INCLUDE_PATH} -L{CFML_LIB_DIR} -l{CFML_LIB_NAME}'
modes.base = '-f2008 -fpp -PIC -quiet -w=all -colour'
modes.debug = ''
modes.release = ''

[[build-configs]]
platforms = ['linux', 'macos']
compilers = ['ifort', 'ifx']
obj-ext = 'o'
build-shared = "{COMPILER} -shared CFML_Wraps.{OBJ_EXT} Wraps_*.{OBJ_EXT} {PATH}.{OBJ_EXT} -o {PATH}.{EXT} -L{CFML_LIB_PATH} -l{CFML_LIB_NAME} {IFPORT_LIB} {PYTHON_LIB}"
build-exe = '{COMPILER} {OPTIONS} -o {EXE_NAME} {SOURCE_PATH} -I {CFML_INCLUDE_PATH} -L{CFML_LIB_DIR} -l{CFML_LIB_NAME}'
modes.base = '-w -fpp -fPIC -heap-arrays -nologo'
modes.debug = '' # -g3
modes.release = '' # -O3

[[build-configs]]
platforms = ['windows']
compilers = ['ifort', 'ifx']
obj-ext = 'obj'
build-shared = 'link CFML_Wraps.{OBJ_EXT} Wraps_*.{OBJ_EXT} {PATH}.{OBJ_EXT} /out:"{PATH}.{EXT}" /libpath:{CFML_LIB_PATH} /dll {CFML_LIB_NAME}.lib {PYTHON_LIB}'
build-exe = '{COMPILER} {OPTIONS} /exe:{EXE_NAME} {SOURCE_PATH} -I {CFML_INCLUDE_PATH} {CFML_LIB_DIR}\{CFML_LIB_NAME}.{LIB_EXT}'
modes.base = '/w /fpp /heap-arrays /nologo -DWIN32=ON'
modes.debug = ''
modes.release = ''

[build]
#src-ext = { cfml = 'f90', pycfml = 'F90' }
src-ext = 'f90'
static-lib-prefix = { macos = 'lib', linux = 'lib', windows = '' }
static-lib-ext = { macos = 'a', linux = 'a', windows = 'lib' }
Expand Down Expand Up @@ -192,50 +235,6 @@ dependent-libs.macos.arm.gfortran = [
#site-packages.linux = '/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages'
#site-packages.windows = 'c:\hostedtoolcache\windows\Python\3.11.9\x64\lib\site-packages'

######################
# Build configurations
######################

[[build-objs]]
platforms = ['macos', 'linux', 'windows']
compilers = ['gfortran']
obj-ext = 'o'
build-shared = '{COMPILER} -shared CFML_Wraps.{OBJ_EXT} Wraps_*.{OBJ_EXT} {PATH}.{OBJ_EXT} -o {PATH}.{EXT} -L{CFML_LIB_PATH} -l{CFML_LIB_NAME} {PYTHON_LIB}'
build-exe = '{COMPILER} {OPTIONS} -o {EXE_NAME} {SOURCE_PATH} -I {CFML_INCLUDE_PATH} -L{CFML_LIB_DIR} -l{CFML_LIB_NAME}'
modes.base = '-cpp -fdec-math -fPIC -fno-stack-arrays -ffree-line-length-none'
modes.debug = ''
modes.release = ''

[[build-objs]]
platforms = ['macos']
compilers = ['nagfor']
obj-ext = 'o'
build-shared = '{COMPILER} -Wl,-shared CFML_Wraps.{OBJ_EXT} Wraps_*.{OBJ_EXT} {PATH}.{OBJ_EXT} -o {PATH}.{EXT} -L{CFML_LIB_PATH} -l{CFML_LIB_NAME} {PYTHON_LIB}'
build-exe = '{COMPILER} {OPTIONS} -o {EXE_NAME} {SOURCE_PATH} -I {CFML_INCLUDE_PATH} -L{CFML_LIB_DIR} -l{CFML_LIB_NAME}'
modes.base = '-f2008 -fpp -PIC -quiet -w=all -colour'
modes.debug = ''
modes.release = ''

[[build-objs]]
platforms = ['linux', 'macos']
compilers = ['ifort', 'ifx']
obj-ext = 'o'
build-shared = "{COMPILER} -shared CFML_Wraps.{OBJ_EXT} Wraps_*.{OBJ_EXT} {PATH}.{OBJ_EXT} -o {PATH}.{EXT} -L{CFML_LIB_PATH} -l{CFML_LIB_NAME} {IFPORT_LIB} {PYTHON_LIB}"
build-exe = '{COMPILER} {OPTIONS} -o {EXE_NAME} {SOURCE_PATH} -I {CFML_INCLUDE_PATH} -L{CFML_LIB_DIR} -l{CFML_LIB_NAME}'
modes.base = '-w -fpp -fPIC -heap-arrays -nologo'
modes.debug = '' # -g3
modes.release = '' # -O3

[[build-objs]]
platforms = ['windows']
compilers = ['ifort', 'ifx']
obj-ext = 'obj'
build-shared = 'link CFML_Wraps.{OBJ_EXT} Wraps_*.{OBJ_EXT} {PATH}.{OBJ_EXT} /out:"{PATH}.{EXT}" /libpath:{CFML_LIB_PATH} /dll {CFML_LIB_NAME}.lib {PYTHON_LIB}'
build-exe = '{COMPILER} {OPTIONS} /exe:{EXE_NAME} {SOURCE_PATH} -I {CFML_INCLUDE_PATH} {CFML_LIB_DIR}\{CFML_LIB_NAME}.{LIB_EXT}'
modes.base = '/w /fpp /heap-arrays /nologo -DWIN32=ON'
modes.debug = ''
modes.release = ''

##############################
# CrysFML fortran source files
##############################
Expand Down
Empty file removed scripts/empty.txt
Empty file.

0 comments on commit c8bd251

Please sign in to comment.