From b51e8e3a0c6597d56dcc99b19b69d00546719e8b Mon Sep 17 00:00:00 2001 From: Unai Martinez-Corral Date: Thu, 26 May 2022 11:51:51 +0200 Subject: [PATCH 1/3] f4pga/wrappers/sh: do not require F4PGA_ENV_* envvars as long as F4PGA_INSTALL_DIR is defined Create them and pass a custom env to run_sh Signed-off-by: Unai Martinez-Corral --- f4pga/wrappers/sh/__init__.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/f4pga/wrappers/sh/__init__.py b/f4pga/wrappers/sh/__init__.py index ada659f..ab8a99a 100644 --- a/f4pga/wrappers/sh/__init__.py +++ b/f4pga/wrappers/sh/__init__.py @@ -24,15 +24,24 @@ from pathlib import Path from subprocess import check_call +f4pga_environ = environ.copy() + ROOT = Path(__file__).resolve().parent -F4PGA_FAM = environ.get('F4PGA_FAM', 'xc7') -SH_SUBDIR = 'quicklogic' if F4PGA_FAM == 'eos-s3' else F4PGA_FAM +F4PGA_FAM = f4pga_environ.get('F4PGA_FAM', 'xc7') +isQuickLogic = F4PGA_FAM == 'eos-s3' +SH_SUBDIR = 'quicklogic' if isQuickLogic else F4PGA_FAM + +F4PGA_INSTALL_DIR = Path(f4pga_environ.get('F4PGA_INSTALL_DIR')) +f4pga_environ['F4PGA_ENV_BIN'] = f4pga_environ.get('F4PGA_ENV_BIN', str(F4PGA_INSTALL_DIR / F4PGA_FAM / 'conda/bin')) +f4pga_environ['F4PGA_ENV_SHARE'] = f4pga_environ.get('F4PGA_ENV_SHARE', str(F4PGA_INSTALL_DIR / F4PGA_FAM / ( + 'share' if isQuickLogic else 'install/share/symbiflow' +))) def run_sh(script): stdout.flush() stderr.flush() - check_call([str(script)]+sys_argv[1:]) + check_call([str(script)]+sys_argv[1:], env=f4pga_environ) def generate_constraints(): From e3bc36fa1d73456485d59c50fdf07c7ea58f2155 Mon Sep 17 00:00:00 2001 From: Unai Martinez-Corral Date: Mon, 30 May 2022 23:37:40 +0200 Subject: [PATCH 2/3] f4pga/wrappers/sh: raise exception if F4PGA_INSTALL_DIR is undefined Signed-off-by: Unai Martinez-Corral --- f4pga/wrappers/sh/__init__.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/f4pga/wrappers/sh/__init__.py b/f4pga/wrappers/sh/__init__.py index ab8a99a..3d96618 100644 --- a/f4pga/wrappers/sh/__init__.py +++ b/f4pga/wrappers/sh/__init__.py @@ -31,9 +31,13 @@ F4PGA_FAM = f4pga_environ.get('F4PGA_FAM', 'xc7') isQuickLogic = F4PGA_FAM == 'eos-s3' SH_SUBDIR = 'quicklogic' if isQuickLogic else F4PGA_FAM -F4PGA_INSTALL_DIR = Path(f4pga_environ.get('F4PGA_INSTALL_DIR')) -f4pga_environ['F4PGA_ENV_BIN'] = f4pga_environ.get('F4PGA_ENV_BIN', str(F4PGA_INSTALL_DIR / F4PGA_FAM / 'conda/bin')) -f4pga_environ['F4PGA_ENV_SHARE'] = f4pga_environ.get('F4PGA_ENV_SHARE', str(F4PGA_INSTALL_DIR / F4PGA_FAM / ( +F4PGA_INSTALL_DIR = f4pga_environ.get('F4PGA_INSTALL_DIR') +if F4PGA_INSTALL_DIR is None: + raise(Exception("Required environment variable F4PGA_INSTALL_DIR is undefined!")) +F4PGA_INSTALL_DIR_PATH = Path(F4PGA_INSTALL_DIR) + +f4pga_environ['F4PGA_ENV_BIN'] = f4pga_environ.get('F4PGA_ENV_BIN', str(F4PGA_INSTALL_DIR_PATH / F4PGA_FAM / 'conda/bin')) +f4pga_environ['F4PGA_ENV_SHARE'] = f4pga_environ.get('F4PGA_ENV_SHARE', str(F4PGA_INSTALL_DIR_PATH / F4PGA_FAM / ( 'share' if isQuickLogic else 'install/share/symbiflow' ))) From a7d5a284865c5ea67d6f6d93f03db17d8aab4732 Mon Sep 17 00:00:00 2001 From: Unai Martinez-Corral Date: Mon, 30 May 2022 16:21:52 +0200 Subject: [PATCH 3/3] test: wrappers without F4PGA_INSTALL_DIR (exception expected) Signed-off-by: Unai Martinez-Corral --- test/test_wrappers.py | 52 ++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/test/test_wrappers.py b/test/test_wrappers.py index 069c1b9..d6ce1bb 100644 --- a/test/test_wrappers.py +++ b/test/test_wrappers.py @@ -1,28 +1,31 @@ +from os import environ from pytest import mark from sys import stdout, stderr from subprocess import check_call +wrappers = [ + 'symbiflow_generate_constraints', + 'symbiflow_pack', + 'symbiflow_place', + 'symbiflow_route', + 'symbiflow_synth', + 'symbiflow_write_bitstream', + 'symbiflow_write_fasm', + 'symbiflow_write_xml_rr_graph', + 'vpr_common', + 'symbiflow_analysis', + 'symbiflow_repack', + 'symbiflow_generate_bitstream', + 'symbiflow_generate_libfile', + 'ql_symbiflow' +] + @mark.xfail @mark.parametrize( "wrapper", - [ - 'symbiflow_generate_constraints', - 'symbiflow_pack', - 'symbiflow_place', - 'symbiflow_route', - 'symbiflow_synth', - 'symbiflow_write_bitstream', - 'symbiflow_write_fasm', - 'symbiflow_write_xml_rr_graph', - 'vpr_common', - 'symbiflow_analysis', - 'symbiflow_repack', - 'symbiflow_generate_bitstream', - 'symbiflow_generate_libfile', - 'ql_symbiflow' - ] + wrappers ) def test_shell_wrapper(wrapper): print(f"\n::group::Test {wrapper}") @@ -32,3 +35,20 @@ def test_shell_wrapper(wrapper): check_call(f"{wrapper}") finally: print("\n::endgroup::") + +@mark.xfail +@mark.parametrize( + "wrapper", + wrappers +) +def test_shell_wrapper_without_F4PGA_INSTALL_DIR(wrapper): + test_environ = environ.copy() + del test_environ['F4PGA_INSTALL_DIR'] + + print(f"\n::group::Test {wrapper}") + stdout.flush() + stderr.flush() + try: + check_call(f"{wrapper}", env=test_environ) + finally: + print("\n::endgroup::")