Skip to content

Commit

Permalink
[BUGFIX] a-b-c: actually set compiler, improved default (#2051)
Browse files Browse the repository at this point in the history
* Actually set the compiler to the user provided `--cxx` or the scripts default.
* Have a fallback to `c++` in case `arbor.config()['CXX']` does not exist (typically true for pip installed wheels).
* Verbose mode for `a-b-c`
  • Loading branch information
brenthuisman authored Dec 6, 2022
1 parent 1627302 commit 86b62b7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
4 changes: 2 additions & 2 deletions doc/contrib/coding-style.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ run the following commands to apply it:
# Install the formatter if not present
pip install black
# Automatically apply style. If unsure what this does read on.
black . scripts/build-catalogue.in
# Automatically apply style to a certain file. If unsure what this does read on.
black . scripts/arbor/build-catalogue.in
The formatter can also be run with ``--check`` to list offending files and
``--diff`` to preview changes. Most editors can `integrate with black
Expand Down
50 changes: 39 additions & 11 deletions scripts/arbor-build-catalogue
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,47 @@ import re


config = A.config()
prefix = Path(config['prefix'])
prefix = Path(config["prefix"])
CXX = Path(config["CXX"])
if not prefix.exists():
try:
# Example <>/lib/python3.10/site-packages/arbor
altern = Path(A.__path__[0]).parent.parent.parent.parent
print(f"Warning: prefix '{prefix}' does not exist, falling back to '{altern}'.", file=sys.stderr)
print(
f"Warning: prefix '{prefix}' does not exist, falling back to '{altern}'.",
file=sys.stderr,
)
prefix = altern
except:
print(f"Error: Neither prefix '{prefix}' nor fallback '{altern}' exist; giving up.", file=sys.stderr)
print(
f"Error: Neither prefix '{prefix}' nor fallback '{altern}' exist. Please specify the prefix where you keep your Python libraries with --prefix.",
file=sys.stderr,
)
exit(-1)
if not CXX.exists():
try:
# Example <>/lib/python3.10/site-packages/arbor
altern = "c++"
print(
f"Warning: prefix '{CXX}' does not exist, falling back to '{altern}'.",
file=sys.stderr,
)
CXX = altern
except:
print(
f"Error: Neither prefix '{CXX}' nor fallback '{altern}' exist. Please provide a path to a C++ compiler with --cxx",
file=sys.stderr,
)
exit(-1)


def parse_arguments():
parser = argparse.ArgumentParser(
description="Generate dynamic catalogue and build it into a shared object.",
usage="%(prog)s catalogue_name mod_source_dir",
add_help=False,
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)

parser.add_argument("name", metavar="name", type=str, help="Catalogue name.")

Expand All @@ -54,9 +78,7 @@ enabled) must be present in the target directory.""",

parser.add_argument("-q", "--quiet", action="store_true", help="Less output.")

parser.add_argument("--cpu",
default=True,
help="Enable CPU support.")
parser.add_argument("--cpu", default=True, help="Enable CPU support.")

parser.add_argument(
"--debug",
Expand All @@ -65,7 +87,7 @@ enabled) must be present in the target directory.""",
const=True,
default=None,
help="Don't clean up the generated temp cpp code."
+" Can be a target path for the generated code.",
+ " Can be a target path for the generated code.",
)

parser.add_argument(
Expand All @@ -79,8 +101,8 @@ enabled) must be present in the target directory.""",
parser.add_argument(
"--cxx",
metavar="cxx",
default=config["CXX"],
help='Use this C++ compiler.',
default=CXX,
help="Use this C++ compiler.",
)

parser.add_argument(
Expand Down Expand Up @@ -126,6 +148,12 @@ mod_dir = pwd / Path(args["modpfx"])
mods = [f[:-4] for f in os.listdir(mod_dir) if f.endswith(".mod")]
quiet = args["quiet"]
verbose = args["verbose"] and not quiet
if verbose:
print("=" * 80)
print(f"{os.path.basename(__file__)} called with the following arguments:")
for k, v in args.items():
print(k, v)
print("=" * 80)
debug = args["debug"]
raw = args["raw"]
gpu = args["gpu"]
Expand Down Expand Up @@ -191,7 +219,7 @@ set(arbor_DIR {pakdir})
find_package(arbor REQUIRED)
{gpu_support}
set(CMAKE_BUILD_TYPE release)
set(CMAKE_CXX_COMPILER ${{ARB_CXX}})
set(CMAKE_CXX_COMPILER {args["cxx"]})
set(CMAKE_CXX_FLAGS ${{ARB_CXX_FLAGS}})
include(BuildModules.cmake)
Expand Down

0 comments on commit 86b62b7

Please sign in to comment.