From f8e0f65b48160101c470620b91b785ee09e4ee7b Mon Sep 17 00:00:00 2001 From: Unai Martinez-Corral Date: Thu, 18 Aug 2022 19:19:26 +0200 Subject: [PATCH] f4pga: F4PGA_INSTALL_DIR is optional Signed-off-by: Unai Martinez-Corral --- f4pga/context.py | 17 +++++++++++++---- f4pga/flows/common.py | 7 ++----- f4pga/wrappers/sh/__init__.py | 4 ++-- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/f4pga/context.py b/f4pga/context.py index 0a18ddc..0140346 100644 --- a/f4pga/context.py +++ b/f4pga/context.py @@ -25,7 +25,16 @@ FPGA_FAM = environ.get('FPGA_FAM', 'xc7') if FPGA_FAM not in ['xc7', 'eos-s3', 'qlf_k4n8']: raise(Exception(f"Unsupported FPGA_FAM <{FPGA_FAM}>!")) -F4PGA_INSTALL_DIR = 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_DEBUG = environ.get('F4PGA_DEBUG') + +install_dir = environ.get('F4PGA_INSTALL_DIR') +if install_dir is None: + default_install_dir = Path('/usr/local') + if F4PGA_DEBUG is not None: + print("Environment variable F4PGA_INSTALL_DIR is undefined!") + print(f"Using default {default_install_dir}") + F4PGA_INSTALL_DIR = default_install_dir +else: + F4PGA_INSTALL_DIR = Path(install_dir) + +F4PGA_SHARE_DIR = Path(environ.get('F4PGA_SHARE_DIR', F4PGA_INSTALL_DIR / FPGA_FAM / 'share/f4pga')) diff --git a/f4pga/flows/common.py b/f4pga/flows/common.py index 2dfe2e2..0b660f9 100644 --- a/f4pga/flows/common.py +++ b/f4pga/flows/common.py @@ -25,14 +25,11 @@ from shutil import move as sh_mv from subprocess import run from re import match as re_match, finditer as re_finditer -from f4pga.context import FPGA_FAM +from f4pga.context import FPGA_FAM, F4PGA_SHARE_DIR -install_dir = environ.get("F4PGA_INSTALL_DIR", "/usr/local") bin_dir_path = str(Path(sys_argv[0]).resolve().parent.parent) -share_dir_path = \ - environ.get('F4PGA_SHARE_DIR', - str(Path(f'{install_dir}/{FPGA_FAM}/share/f4pga').resolve())) +share_dir_path = str(F4PGA_SHARE_DIR) class F4PGAException(Exception): diff --git a/f4pga/wrappers/sh/__init__.py b/f4pga/wrappers/sh/__init__.py index e5cd0b3..7378eb6 100644 --- a/f4pga/wrappers/sh/__init__.py +++ b/f4pga/wrappers/sh/__init__.py @@ -25,7 +25,7 @@ from pathlib import Path from shutil import which from subprocess import check_call -from f4pga.context import FPGA_FAM, F4PGA_INSTALL_DIR_PATH +from f4pga.context import FPGA_FAM, F4PGA_SHARE_DIR python3 = which('python3') @@ -35,7 +35,7 @@ isQuickLogic = FPGA_FAM != 'xc7' SH_SUBDIR = 'quicklogic' if isQuickLogic else FPGA_FAM f4pga_environ = environ.copy() -f4pga_environ['F4PGA_SHARE_DIR'] = f4pga_environ.get('F4PGA_SHARE_DIR', str(F4PGA_INSTALL_DIR_PATH / FPGA_FAM / 'share/f4pga')) +f4pga_environ['F4PGA_SHARE_DIR'] = f4pga_environ.get('F4PGA_SHARE_DIR', F4PGA_SHARE_DIR) # Helper functions