[SCons] Fix cleanup of -isysroot flags in package builds

Also filter out paths referring to conda build environment
This commit is contained in:
Ray Speth 2023-08-20 17:42:41 -04:00 committed by Ingmar Schoegl
parent d564130fc5
commit 2820749d0f
4 changed files with 42 additions and 20 deletions

View File

@ -51,8 +51,8 @@ if localenv["package_build"]:
# compatible with the SDK used for building.
excludes = (
"-isysroot", "-mmacosx", "-march", "-mtune", "-fdebug-prefix-map")
localenv["CCFLAGS"] = compiler_flag_list(localenv["CCFLAGS"], excludes)
localenv["CXXFLAGS"] = compiler_flag_list(localenv["CXXFLAGS"], excludes)
localenv["CCFLAGS"] = compiler_flag_list(localenv["CCFLAGS"], env["CC"], excludes)
localenv["CXXFLAGS"] = compiler_flag_list(localenv["CXXFLAGS"], env["CC"], excludes)
# Generate cantera.pc for use with pkg-config
localenv["pc_prefix"] = localenv["prefix"]

View File

@ -52,7 +52,7 @@ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}
# Note: These CMakeLists.txt and SConstruct files are automatically installed
# by the "RecursiveInstall" that grabs everything in the cxx directory.
flag_excludes = ["$(", "/TP", "$)", "/nologo"]
flag_excludes = [r"\$\(", "/TP", r"\$\)", "/nologo"]
incdirs = [localenv["ct_incroot"]]
libdirs = [localenv["ct_libdir"]]
if localenv["package_build"]:
@ -60,8 +60,8 @@ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}
# conda package for now.
# Users should compile against their local SDKs, which should be backwards
# compatible with the SDK used for building.
flag_excludes.extend(["-isysroot", "-mmacosx", "-march", "-mtune"
"-fdebug-prefix-map"])
flag_excludes.extend(["-isysroot", "-mmacosx", "-march", "-mtune",
"-fdebug-prefix-map", ".*/_build_env/"])
else:
incdirs.extend([localenv["sundials_include"], localenv["boost_inc_dir"]])
incdirs.append(localenv["hdf_include"])
@ -78,7 +78,8 @@ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}
for d in libdirs])
cc_flags = compiler_flag_list(localenv["CCFLAGS"] + localenv["CXXFLAGS"],
flag_excludes)
env["CC"], flag_excludes)
link_flags = compiler_flag_list(localenv["LINKFLAGS"], env["CC"], flag_excludes)
localenv["tmpl_compiler_flags"] = repr(cc_flags)
localenv['tmpl_cantera_frameworks'] = repr(localenv['FRAMEWORKS'])
localenv['tmpl_cantera_incdirs'] = repr([x for x in incdirs if x])
@ -90,7 +91,7 @@ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}
localenv['cmake_cantera_incdirs'] += ' "/usr/local/include"'
localenv['tmpl_cantera_libdirs'] = repr([x for x in libdirs if x])
localenv['cmake_cantera_libdirs'] = ' '.join(quoted(x) for x in libdirs if x)
localenv['tmpl_cantera_linkflags'] = repr(localenv['LINKFLAGS'])
localenv['tmpl_cantera_linkflags'] = repr(link_flags)
localenv['tmpl_progname'] = name
localenv['tmpl_sourcename'] = name + '.cpp'
env_args = []

View File

@ -24,7 +24,7 @@ for program_name, fortran_sources in samples:
# Generate SConstruct file to be installed
linkflags = ["-g", localenv["thread_flags"]]
flag_excludes = ["$(", "/TP", "$)", "/nologo"]
flag_excludes = [r"\$\(", "/TP", r"\$\)", "/nologo"]
incdirs = [localenv["ct_incroot"]]
libdirs = [localenv["ct_libdir"]]
if localenv["package_build"]:
@ -32,8 +32,8 @@ if localenv["package_build"]:
# conda package for now.
# Users should compile against their local SDKs, which should be backwards
# compatible with the SDK used for building.
flag_excludes.extend(["-isysroot", "-mmacosx", "-march", "-mtune",
"-fdebug-prefix-map"])
flag_excludes.extend(["-mmacosx", "-march", "-mtune", "-fdebug-prefix-map",
"-isysroot", ".*/_build_env/"])
else:
linkflags.append(f"-Wl,-rpath,{localenv['ct_shlibdir']}")
@ -50,7 +50,7 @@ else:
libs = ["cantera_fortran"] + localenv["cantera_libs"] + localenv["cxx_stdlib"]
cc_flags = compiler_flag_list(localenv["CCFLAGS"] + localenv["CXXFLAGS"],
flag_excludes)
env["CC"], flag_excludes)
localenv["tmpl_compiler_flags"] = repr(cc_flags)
localenv['tmpl_cantera_incdirs'] = repr([x for x in incdirs if x])
localenv['tmpl_cantera_libs'] = repr(libs)

View File

@ -1098,24 +1098,45 @@ def add_RegressionTest(env: "SCEnvironment") -> None:
def compiler_flag_list(
flags: "Union[str, Iterable]",
excludes: "Optional[Iterable]" = []
compiler: str,
excludes: "Optional[Iterable]" = (),
) -> "List[str]":
"""
Separate concatenated compiler flags in ``flags``.
Entries listed in ``excludes`` are omitted.
``compiler`` is either ``"cl"`` for MSVC or anything else for a different
compiler.
Entries starting with the regular expression patterns in ``excludes`` are omitted.
"""
if not isinstance(flags, str):
flags = " ".join(flags)
# split concatenated entries. Options can start with "-", "/", or "$"
flags = re.findall(r"""(?:^|\ +) # start of string or leading whitespace
([-/\$].+?) # capture start of option
if compiler == "cl":
# Options can start with "/", or "$"
expr = r"""(?:^|\ +) # start of string or leading whitespace
([/\$].+?) # capture start of option
(?=\ +[-/\$]|\ *$) # start of next option or end of string
""", flags, re.VERBOSE)
cc_flags = []
"""
else:
# Options can start with "-"
expr = r"""(?:^|\ +) # start of string or leading whitespace
(-.+?) # capture start of option
(?=\ +-|\ *$) # start of next option or end of string
"""
# split concatenated entries
flags = re.findall(expr, flags, re.VERBOSE)
# Remove duplicates and excluded items
excludes = tuple(excludes)
cc_flags = []
for flag in flags:
if not flag.startswith(excludes) and flag not in cc_flags:
if flag in cc_flags:
continue
if not any(re.match(exclude, flag) for exclude in excludes):
cc_flags.append(flag)
return cc_flags