Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support full paths in FC #276

Merged
merged 4 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions source/fab/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import sys
from pathlib import Path
from typing import Dict, Optional
import os

from fab.steps.analyse import analyse
from fab.steps.c_pragma_injector import c_pragma_injector
Expand All @@ -20,6 +21,7 @@
from fab.steps.grab.folder import grab_folder
from fab.steps.preprocess import preprocess_c, preprocess_fortran
from fab.util import common_arg_parser
from fab.tools import get_tool


def _generic_build_config(folder: Path, kwargs=None) -> BuildConfig:
Expand Down Expand Up @@ -61,15 +63,18 @@ def calc_linker_flags():
# todo: test this and get it running
# 'ifort': (..., [...])
}

try:
linker, linker_flags = linkers[fc]
except KeyError:
raise NotImplementedError(f"Fab's zero configuration mode does not yet work with compiler '{fc}'")
# Get linker from $LD
linker, linker_flags = get_tool(os.environ.get("LD", None))
except ValueError:
# Get linker from linkers, or else just use $FC
linker, linker_flags = linkers.get(os.path.basename(fc), (fc, []))

return linker, linker_flags


def cli_fab(folder: Path, kwargs: Optional[Dict] = None):
def cli_fab(folder: Path = None, kwargs: Optional[Dict] = None):
ScottWales marked this conversation as resolved.
Show resolved Hide resolved
"""
Running Fab from the command line will attempt to build the project in the current or given folder.
The following params are used for testing. When run normally any parameters will be caught
Expand Down
4 changes: 2 additions & 2 deletions source/fab/steps/compile_fortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def handle_compiler_args(common_flags=None, path_flags=None):

# Do we know this compiler? If so we can manage the flags a little, to avoid duplication or misconfiguration.
# todo: This has been raised for discussion - we might never want to modify incoming flags...
known_compiler = COMPILERS.get(compiler)
known_compiler = COMPILERS.get(os.path.basename(compiler))
if known_compiler:
common_flags = remove_managed_flags(compiler, common_flags)
else:
Expand Down Expand Up @@ -342,7 +342,7 @@ def compile_file(analysed_file, flags, output_fpath, mp_common_args):

# tool
command = [mp_common_args.compiler]
known_compiler = COMPILERS.get(mp_common_args.compiler)
known_compiler = COMPILERS.get(os.path.basename(mp_common_args.compiler))

# Compile flag.
# If it's an unknown compiler, we rely on the user config to specify this.
Expand Down
17 changes: 17 additions & 0 deletions tests/system_tests/zero_config/test_zero_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from pathlib import Path

from fab.cli import cli_fab
import shutil
import os
from unittest import mock


class TestZeroConfig(object):
Expand All @@ -25,3 +28,17 @@ def test_c_fortran_interop(self, tmp_path):
kwargs=kwargs)

assert (config.project_workspace / 'main').exists()

def test_fortran_explicit_gfortran(self, tmp_path):
# test the sample project in the fortran dependencies system test
kwargs = {'project_label': 'fortran explicit gfortran', 'fab_workspace': tmp_path, 'multiprocessing': False}

cc = shutil.which('gcc')
fc = shutil.which('gfortran')

with mock.patch.dict(os.environ, CC=cc, FC=fc, LD=fc):
config = cli_fab(
folder=Path(__file__).parent.parent / 'CFortranInterop',
kwargs=kwargs)

assert (config.project_workspace / 'main').exists()