Coverage for python/lsst/sconsUtils/state.py: 63%
297 statements
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-26 11:16 -0800
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-26 11:16 -0800
1# This file is part of sconsUtils.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
22"""Global state for sconsUtils.
24This module acts like a singleton, holding all global state for sconsUtils.
25This includes the primary Environment object (`lsst.sconsUtils.state.env`),
26the message log (`lsst.sconsUtils.state.log`), the command-line variables
27object (`lsst.sconsUtils.state.state.opts`), and a dictionary of command-line
28targets used to setup aliases, default targets, and dependencies
29(`lsst.sconsUtils.state.targets`). All four of these variables are aliased
30to the main `lsst.sconsUtils` scope, so there should be no need for users to
31deal with the state module directly.
33These are all initialized when the module is imported, but may be modified
34by other code (particularly `lsst.sconsUtils.dependencies.configure`).
35"""
37import os
38import re
39import shlex
40from configparser import ConfigParser
42import SCons.Conftest
43import SCons.Script
45from . import eupsForScons
46from .utils import conda_compilers, get_conda_prefix, use_conda_compilers
48SCons.Script.EnsureSConsVersion(2, 1, 0)
50"""A dictionary of SCons aliases and targets.
52These are used to setup aliases, default targets, and dependencies by
53`lsst.sconsUtils.scripts.BasicSConstruct.finish`.
54While one can still use env.Alias to setup aliases (and should for "install"),
55putting targets here will generally provide better build-time dependency
56handling (like ensuring everything is built before we try to install, and
57making sure SCons doesn't rebuild the world before installing).
59Users can add additional keys to the dictionary if desired.
61Targets should be added by calling extend() or using ``+=`` on the dict
62values, to keep the lists of targets from turning into lists-of-lists.
63"""
64targets = {
65 "doc": [],
66 "tests": [],
67 "lib": [],
68 "python": [],
69 "examples": [],
70 "include": [],
71 "version": [],
72 "shebang": [],
73 "pkginfo": [],
74 "scripts": [],
75}
77env = None
78log = None
79opts = None
82def _initOptions():
83 SCons.Script.AddOption(
84 "--filterWarn",
85 dest="filterWarn",
86 action="store_true",
87 default=False,
88 help="Filter out a class of warnings deemed irrelevant",
89 )
90 SCons.Script.AddOption(
91 "--force",
92 dest="force",
93 action="store_true",
94 default=False,
95 help="Set to force possibly dangerous behaviours",
96 )
97 SCons.Script.AddOption(
98 "--linkFarmDir",
99 dest="linkFarmDir",
100 action="store",
101 default=None,
102 help="The directory of symbolic links needed to build and use the package",
103 )
104 SCons.Script.AddOption(
105 "--prefix", dest="prefix", action="store", default=False, help="Specify the install destination"
106 )
107 SCons.Script.AddOption(
108 "--setenv",
109 dest="setenv",
110 action="store_true",
111 default=False,
112 help="Treat arguments such as Foo=bar as defining construction variables",
113 )
114 SCons.Script.AddOption(
115 "--tag", dest="tag", action="store", default=None, help="Declare product with this eups tag"
116 )
117 SCons.Script.AddOption(
118 "--verbose",
119 dest="verbose",
120 action="store_true",
121 default=False,
122 help="Print additional messages for debugging.",
123 )
124 SCons.Script.AddOption(
125 "--traceback",
126 dest="traceback",
127 action="store_true",
128 default=False,
129 help="Print full exception tracebacks when errors occur.",
130 )
131 SCons.Script.AddOption(
132 "--no-eups",
133 dest="no_eups",
134 action="store_true",
135 default=False,
136 help="Do not use EUPS for configuration",
137 )
138 SCons.Script.AddOption(
139 "--no-tests",
140 dest="no_tests",
141 action="store_true",
142 default=False,
143 help=(
144 "Do not build or run tests (by clearing the 'tests' target). "
145 "Library targets in the test directory may still be built."
146 ),
147 )
150def _initLog():
151 from . import utils
153 global log
154 log = utils.Log()
157def _get_macosx_deployment_target_default():
158 """Determine the default deployment target on macOS.
160 Returns
161 -------
162 target : `str`
163 The default target for this platform. Can be returned even
164 if not running on macOS.
165 """
166 uname = os.uname()
167 if uname.sysname == "Darwin" and uname.machine == "arm64": 167 ↛ 169line 167 didn't jump to line 169 because the condition on line 167 was always true
168 return "11.0"
169 return "10.9"
172def _initVariables():
173 files = []
174 if "optfile" in SCons.Script.ARGUMENTS: 174 ↛ 175line 174 didn't jump to line 175 because the condition on line 174 was never true
175 configfile = SCons.Script.ARGUMENTS["optfile"]
176 if configfile not in files:
177 files.append(configfile)
178 for file in files: 178 ↛ 179line 178 didn't jump to line 179 because the loop on line 178 never started
179 if not os.path.isfile(file):
180 log.warn(f"Warning: Will ignore non-existent options file, {file}")
181 if "optfile" not in SCons.Script.ARGUMENTS: 181 ↛ 184line 181 didn't jump to line 184 because the condition on line 181 was always true
182 files.append("buildOpts.py")
183 global opts
184 opts = SCons.Script.Variables(files)
185 opts.AddVariables(
186 ("archflags", "Extra architecture specification to add to CC/LINK flags (e.g. -m32)", ""),
187 ("cc", "Choose the compiler to use", ""),
188 SCons.Script.BoolVariable("debug", "Set to enable debugging flags (use --debug)", True),
189 ("eupsdb", "Specify which element of EUPS_PATH should be used", None),
190 ("flavor", "Set the build flavor", None),
191 SCons.Script.BoolVariable("force", "Set to force possibly dangerous behaviours", False),
192 ("optfile", "Specify a file to read default options from", None),
193 ("prefix", "Specify the install destination", None),
194 SCons.Script.EnumVariable(
195 "opt", "Set the optimisation level", 3, allowed_values=("g", "0", "1", "2", "3")
196 ),
197 SCons.Script.EnumVariable(
198 "profile", "Compile/link for profiler", 0, allowed_values=("0", "1", "pg", "gcov")
199 ),
200 ("version", "Specify the version to declare", None),
201 ("baseversion", "Specify the current base version", None),
202 ("optFiles", "Specify a list of files that SHOULD be optimized", None),
203 ("noOptFiles", "Specify a list of files that should NOT be optimized", None),
204 (
205 "macosx_deployment_target",
206 "Deployment target for Mac OS X",
207 _get_macosx_deployment_target_default(),
208 ),
209 )
212def _initEnvironment():
213 """Construction and basic setup of the state.env variable."""
215 ourEnv = {}
216 preserveVars = [
217 "DYLD_LIBRARY_PATH",
218 "EUPS_DIR",
219 "EUPS_LOCK_PID",
220 "EUPS_PATH",
221 "EUPS_SHELL",
222 "EUPS_USERDATA",
223 "LD_LIBRARY_PATH",
224 "PATH",
225 "SHELL",
226 "TEMP",
227 "TERM",
228 "TMP",
229 "TMPDIR",
230 "XPA_PORT",
231 "CONDA_BUILD_SYSROOT",
232 "SDKROOT",
233 "GCC_COLORS",
234 ]
236 codeCheckerVars = [
237 "LD_PRELOAD",
238 "CC_LOGGER_FILE",
239 "CC_LOGGER_GCC_LIKE",
240 "CC_LIB_DIR",
241 "CC_DATA_FILES_DIR",
242 "CC_LOGGER_BIN",
243 ]
245 # The list of implicit multithreading environment variables here
246 # is taken from lsst.utils.disable_implicit_threading(), but
247 # has to be put here for dependency ordering reasons, and
248 # to ensure these are set prior to any instantiation of pytest
249 # or any code that may implicitly spawn threads.
250 implicitMultithreadingVars = [
251 "OPENBLAS_NUM_THREADS",
252 "GOTO_NUM_THREADS",
253 "OMP_NUM_THREADS",
254 "MKL_NUM_THREADS",
255 "MKL_DOMAIN_NUM_THREADS",
256 "MPI_NUM_THREADS",
257 "NUMEXPR_NUM_THREADS",
258 "NUMEXPR_MAX_THREADS",
259 ]
261 for key in preserveVars:
262 if key in os.environ:
263 ourEnv[key] = os.environ[key]
265 # check if running in CodeChecker environment
266 if "CC_LOGGER_BIN" in os.environ: 266 ↛ 267line 266 didn't jump to line 267 because the condition on line 266 was never true
267 for key in codeCheckerVars:
268 if key in os.environ:
269 ourEnv[key] = os.environ[key]
271 # Turn off implicit multithreading.
272 for key in implicitMultithreadingVars:
273 ourEnv[key] = "1"
275 # Find and propagate EUPS environment variables.
276 cfgPath = []
277 for k in os.environ:
278 m = re.search(r"^(?P<name>\w+)_DIR(?P<extra>_EXTRA)?$", k)
279 if not m:
280 continue
281 cfgPath.append(os.path.join(os.environ[k], "ups"))
282 cfgPath.append(os.path.join(os.environ[k], "configs"))
283 if m.group("extra"): 283 ↛ 284line 283 didn't jump to line 284 because the condition on line 283 was never true
284 cfgPath.append(os.environ[k])
285 else:
286 cfgPath.append(os.path.join(os.environ[k], "ups"))
287 p = m.group("name")
288 varname = eupsForScons.utils.setupEnvNameFor(p)
289 if varname in os.environ: 289 ↛ 277line 289 didn't jump to line 277 because the condition on line 289 was always true
290 ourEnv[varname] = os.environ[varname]
291 ourEnv[k] = os.environ[k]
293 # add <build root>/ups directory to the configuration search path
294 # this allows the .cfg file for the package being built to be found without
295 # requiring <product name>_DIR to be in the env
296 cfgPath.append(os.path.join(SCons.Script.Dir("#").abspath, "ups"))
298 #
299 # Add any values marked as export=FOO=XXX[,GOO=YYY] to ourEnv
300 #
301 exportVal = SCons.Script.ARGUMENTS.pop("export", None)
302 if exportVal: 302 ↛ 303line 302 didn't jump to line 303 because the condition on line 302 was never true
303 for kv in exportVal.split(","):
304 k, v = kv.split("=")
305 ourEnv[k] = v
306 global env
307 sconsUtilsPath, thisFile = os.path.split(__file__)
308 toolPath = os.path.join(sconsUtilsPath, "tools")
309 env = SCons.Script.Environment(ENV=ourEnv, variables=opts, toolpath=[toolPath], tools=["default", "cuda"])
310 env.cfgPath = cfgPath
311 #
312 # We don't want "lib" inserted at the beginning of loadable module names;
313 # we'll import them under their given names.
314 #
315 env["LDMODULEPREFIX"] = ""
316 if env["PLATFORM"] == "darwin": 316 ↛ 339line 316 didn't jump to line 339 because the condition on line 316 was always true
317 env["LDMODULESUFFIX"] = ".so"
318 if not re.search(r"-install_name", str(env["SHLINKFLAGS"])): 318 ↛ 320line 318 didn't jump to line 320 because the condition on line 318 was always true
319 env.Append(SHLINKFLAGS=["-install_name", "${TARGET.file}"])
320 if not re.search(r"-headerpad_max_install_names", str(env["SHLINKFLAGS"])): 320 ↛ 325line 320 didn't jump to line 325 because the condition on line 320 was always true
321 env.Append(SHLINKFLAGS=["-Wl,-headerpad_max_install_names"])
322 #
323 # We want to be explicit about the OS X version we're targeting
324 #
325 env["ENV"]["MACOSX_DEPLOYMENT_TARGET"] = env["macosx_deployment_target"]
326 # This flag is required for std::variant and std::filesystem
327 # on deployment platforms < 10.13 and 10.15
328 for flag in ("-D_LIBCPP_DISABLE_AVAILABILITY=1",):
329 env["CFLAGS"].append(flag)
330 env["CXXFLAGS"].append(flag)
331 log.info("Setting OS X binary compatibility level: {}".format(env["ENV"]["MACOSX_DEPLOYMENT_TARGET"]))
332 #
333 # For XCode 7.3 we need to explicitly add a trailing slash to library
334 # paths. This does not hurt things on older XCodes. We can remove this
335 # once XCode is fixed. See Apple radar rdr://25313838
336 #
337 env["LIBDIRSUFFIX"] = "/"
339 if use_conda_compilers():
340 _conda_prefix = get_conda_prefix()
341 if "LDFLAGS" in os.environ: 341 ↛ 342line 341 didn't jump to line 342 because the condition on line 341 was never true
342 LDFLAGS = shlex.split(os.environ["LDFLAGS"]) # respects quoting!
343 LDFLAGS = [v for v in LDFLAGS if v[0:2] != "-L"]
344 # this one breaks some linking in the eups build
345 LDFLAGS = [v for v in LDFLAGS if v != "-Wl,-dead_strip_dylibs"]
346 env.Append(LIBPATH=[f"{_conda_prefix}/lib"])
347 env.Append(LINKFLAGS=LDFLAGS)
348 env.Append(SHLINKFLAGS=LDFLAGS)
350 if "CFLAGS" in os.environ: 350 ↛ 351line 350 didn't jump to line 351 because the condition on line 350 was never true
351 CFLAGS = shlex.split(os.environ["CFLAGS"]) # respects quoting!
352 CFLAGS = [v for v in CFLAGS if v[0:2] != "-I"]
353 env.Append(CCFLAGS=CFLAGS)
355 if "CXXFLAGS" in os.environ: 355 ↛ 356line 355 didn't jump to line 356 because the condition on line 355 was never true
356 CXXFLAGS = shlex.split(os.environ["CXXFLAGS"]) # respects quoting!
357 CXXFLAGS = [v for v in CXXFLAGS if v[0:2] != "-I"]
358 CXXFLAGS = [v for v in CXXFLAGS if v[0:5] != "-std="] # we let LSST set this
359 CXXFLAGS = [v for v in CXXFLAGS if v not in CFLAGS] # conda puts in duplicates
360 env.Append(CXXFLAGS=CXXFLAGS)
362 #
363 # Remove valid options from the arguments
364 #
365 # SCons Variables do not behave like dicts
366 for opt in opts.keys():
367 try:
368 del SCons.Script.ARGUMENTS[opt]
369 except KeyError:
370 pass
371 #
372 # Process those arguments
373 #
374 for k in ("force", "prefix"): # these may now be set as options instead of variables
375 if SCons.Script.GetOption(k): 375 ↛ 376line 375 didn't jump to line 376 because the condition on line 375 was never true
376 env[k] = SCons.Script.GetOption(k)
378 if env["debug"]: 378 ↛ 387line 378 didn't jump to line 387 because the condition on line 378 was always true
379 env.Append(CCFLAGS=["-g"])
381 #
382 # determine if EUPS is present
383 #
385 # --no-eups overides probing
386 # XXX is it possible to test python snippets as a scons action?
387 if SCons.Script.GetOption("no_eups"): 387 ↛ 388line 387 didn't jump to line 388 because the condition on line 387 was never true
388 env["no_eups"] = True
389 else:
390 env["no_eups"] = not eupsForScons.haveEups()
392 if not env.GetOption("no_progress"):
393 if env["no_eups"]: 393 ↛ 394line 393 didn't jump to line 394 because the condition on line 393 was never true
394 log.info("EUPS integration: disabled")
395 else:
396 log.info("EUPS integration: enabled")
398 #
399 # Find the eups path, replace 'flavor' in favor of 'PLATFORM' if needed.
400 #
401 eupsPath = None
402 try:
403 db = env["eupsdb"]
404 if "EUPS_PATH" not in os.environ:
405 raise RuntimeError("You can't use eupsdb=XXX without an EUPS_PATH set")
406 eupsPath = None
407 for d in os.environ["EUPS_PATH"].split(":"):
408 if re.search(rf"/{db}$|^{db}/|/{db}/", d):
409 eupsPath = d
410 break
411 if not eupsPath:
412 raise RuntimeError(f'I cannot find DB "{db}" in $EUPS_PATH')
413 except KeyError:
414 if "EUPS_PATH" in os.environ: 414 ↛ 416line 414 didn't jump to line 416 because the condition on line 414 was always true
415 eupsPath = os.environ["EUPS_PATH"].split(":")[0]
416 env["eupsPath"] = eupsPath
417 try:
418 env["PLATFORM"] = env["flavor"]
419 del env["flavor"]
420 except KeyError:
421 pass
422 #
423 # Check arguments
424 #
425 errorStr = ""
426 #
427 # Process otherwise unknown arguments. If setenv is true,
428 # set construction variables; otherwise generate an error
429 #
430 if SCons.Script.GetOption("setenv"): 430 ↛ 431line 430 didn't jump to line 431 because the condition on line 430 was never true
431 for key in SCons.Script.ARGUMENTS:
432 env[key] = SCons.Script.Split(SCons.Script.ARGUMENTS[key])
433 else:
434 for key in SCons.Script.ARGUMENTS: 434 ↛ 435line 434 didn't jump to line 435 because the loop on line 434 never started
435 errorStr += f" {key}={SCons.Script.ARGUMENTS[key]}"
436 if errorStr: 436 ↛ 437line 436 didn't jump to line 437 because the condition on line 436 was never true
437 log.fail(f"Unprocessed arguments:{errorStr}")
438 #
439 # We need a binary name, not just "Posix"
440 #
441 env["eupsFlavor"] = eupsForScons.flavor()
443 # Forward environment variables that should always be set to allow
444 # our code to run even outside of tests. Executables would normally
445 # pick up the linker environment variables via libraryLoaderEnvironment().
446 for envvar in ["PYTHONPATH", "HTTP_PROXY", "HTTPS_PROXY"]:
447 if envvar in os.environ:
448 env.AppendENVPath(envvar, os.environ[envvar])
451_configured = False
454def _configureCommon():
455 """Configuration checks for the compiler, platform, and standard
456 libraries."""
457 global _configured
458 if _configured: 458 ↛ 459line 458 didn't jump to line 459 because the condition on line 458 was never true
459 return
460 _configured = True
462 def ClassifyCc(context):
463 """Return a pair of string identifying the compiler in use.
465 Parameters
466 ----------
467 context : context
468 Context.
470 Returns
471 -------
472 compiler : `str`
473 Compiler to use, or "unknown".
474 version : `str`
475 Compiler version or "unknown".
476 """
477 versionNameList = (
478 (r"gcc(?:\-.+)? +\(.+\) +([0-9.a-zA-Z]+)", "gcc"),
479 (r"gnu-cc(?:\-.+)? +\(.+\) +([0-9.a-zA-Z]+)", "gcc"), # catch the conda-build compiler on linux
480 (r"\(GCC\) +([0-9.a-zA-Z]+) ", "gcc"),
481 (r"LLVM +version +([0-9.a-zA-Z]+) ", "clang"), # clang on Mac
482 (r"clang +version +([0-9.a-zA-Z]+) ", "clang"), # clang on linux or clang w/ conda on Mac
483 (r"\(ICC\) +([0-9.a-zA-Z]+) ", "icc"),
484 (r"cc \(Ubuntu +([0-9\~\-.a-zA-Z]+)\)", "gcc"), # gcc on Ubuntu (not always caught by #3 above)
485 )
487 context.Message("Checking who built the CC compiler...")
488 result = context.TryAction(SCons.Script.Action(r"$CC --version > $TARGET"))
489 ccVersDumpOK, ccVersDump = result[0:2]
490 if ccVersDumpOK: 490 ↛ 497line 490 didn't jump to line 497 because the condition on line 490 was always true
491 for reStr, compilerName in versionNameList:
492 match = re.search(reStr, ccVersDump)
493 if match:
494 compilerVersion = match.groups()[0]
495 context.Result(f"{compilerName}={compilerVersion}")
496 return (compilerName, compilerVersion)
497 context.Result("unknown")
498 return ("unknown", "unknown")
500 if env.GetOption("clean") or env.GetOption("no_exec") or env.GetOption("help"):
501 env.whichCc = "unknown" # who cares? We're cleaning/not execing, not building
502 else:
503 if use_conda_compilers():
504 # conda-build expects you to use the compilers as-is
505 env["CC"], env["CXX"] = conda_compilers()
507 conf = env.Configure(custom_tests={"ClassifyCc": ClassifyCc})
508 env.whichCc, env.ccVersion = conf.ClassifyCc()
509 if not env.GetOption("no_progress"): 509 ↛ 510line 509 didn't jump to line 510 because the condition on line 509 was never true
510 log.info(f"CC is **CONDA** {env.whichCc} version {env.ccVersion}")
511 conf.Finish()
512 else:
513 if env["cc"] != "": 513 ↛ 514line 513 didn't jump to line 514 because the condition on line 513 was never true
514 CC = CXX = None
515 if re.search(r"^gcc(-\d+(\.\d+)*)?( |$)", env["cc"]):
516 CC = env["cc"]
517 CXX = re.sub(r"^gcc", "g++", CC)
518 elif re.search(r"^icc( |$)", env["cc"]):
519 CC = env["cc"]
520 CXX = re.sub(r"^icc", "icpc", CC)
521 elif re.search(r"^clang( |$)", env["cc"]):
522 CC = env["cc"]
523 CXX = re.sub(r"^clang", "clang++", CC)
524 elif re.search(r"^cc( |$)", env["cc"]):
525 CC = env["cc"]
526 CXX = re.sub(r"^cc", "c++", CC)
527 else:
528 log.fail(f"Unrecognised compiler: {env['cc']}")
529 env0 = SCons.Script.Environment()
530 if CC and env["CC"] == env0["CC"]:
531 env["CC"] = CC
532 if CC and env["CXX"] == env0["CXX"]:
533 env["CXX"] = CXX
534 conf = env.Configure(custom_tests={"ClassifyCc": ClassifyCc})
535 env.whichCc, env.ccVersion = conf.ClassifyCc()
537 # If we have picked up a default compiler called gcc that is really
538 # clang, we call it clang to avoid confusion (gcc on macOS has
539 # subtly different options)
540 if not env["cc"] and env.whichCc == "clang" and env["CC"] == "gcc": 540 ↛ 541line 540 didn't jump to line 541 because the condition on line 540 was never true
541 env["CC"] = "clang"
542 env["CXX"] = "clang++"
544 if not env.GetOption("no_progress"): 544 ↛ 546line 544 didn't jump to line 546 because the condition on line 544 was always true
545 log.info(f"CC is {env.whichCc} version {env.ccVersion}")
546 conf.Finish()
548 #
549 # Compiler flags, including CCFLAGS for C and C++ and CXXFLAGS for C++ only
550 #
551 ARCHFLAGS = os.environ.get("ARCHFLAGS", env.get("archflags"))
552 if ARCHFLAGS: 552 ↛ 553line 552 didn't jump to line 553 because the condition on line 552 was never true
553 env.Append(CCFLAGS=ARCHFLAGS.split())
554 env.Append(LINKFLAGS=ARCHFLAGS.split())
555 # We'll add warning and optimisation options last
556 if env["profile"] == "1" or env["profile"] == "pg": 556 ↛ 557line 556 didn't jump to line 557 because the condition on line 556 was never true
557 env.Append(CCFLAGS=["-pg"])
558 env.Append(LINKFLAGS=["-pg"])
559 elif env["profile"] == "gcov": 559 ↛ 560line 559 didn't jump to line 560 because the condition on line 559 was never true
560 env.Append(CCFLAGS="--coverage")
561 env.Append(LINKFLAGS="--coverage")
563 #
564 # Enable C++20 support
565 #
566 if not (env.GetOption("clean") or env.GetOption("help") or env.GetOption("no_exec")):
567 if not env.GetOption("no_progress"):
568 log.info("Checking for C++20 support")
569 conf = env.Configure()
570 for cpp20Arg in (f"-std={val}" for val in ("c++20",)): 570 ↛ 579line 570 didn't jump to line 579 because the loop on line 570 didn't complete
571 conf.env = env.Clone()
572 conf.env.Append(CXXFLAGS=cpp20Arg)
573 if conf.CheckCXX(): 573 ↛ 570line 573 didn't jump to line 570 because the condition on line 573 was always true
574 env.Append(CXXFLAGS=cpp20Arg)
575 if not env.GetOption("no_progress"):
576 log.info(f"C++20 supported with {cpp20Arg!r}")
577 break
578 else:
579 log.fail(f"C++20 extensions could not be enabled for compiler {env.whichCc!r}")
580 conf.Finish()
582 #
583 # Byte order
584 #
585 import socket
587 if socket.htons(1) != 1: 587 ↛ 593line 587 didn't jump to line 593 because the condition on line 587 was always true
588 env.Append(CCFLAGS=["-DLSST_LITTLE_ENDIAN=1"])
589 #
590 # If we're linking to libraries that themselves linked to
591 # shareable libraries we need to do something special.
592 #
593 if re.search(r"^(Linux|Linux64)$", env["eupsFlavor"]) and "LD_LIBRARY_PATH" in os.environ: 593 ↛ 594line 593 didn't jump to line 594 because the condition on line 593 was never true
594 env.Append(LINKFLAGS=["-Wl,-rpath-link"])
595 env.Append(LINKFLAGS=[f"-Wl,{os.environ['LD_LIBRARY_PATH']}"])
596 #
597 # Set the optimization level.
598 #
599 if env["opt"]: 599 ↛ 605line 599 didn't jump to line 605 because the condition on line 599 was always true
600 env["CCFLAGS"] = [o for o in env["CCFLAGS"] if not re.search(r"^-O(\d|s|g|fast)$", o)]
601 env.MergeFlags(f"-O{env['opt']}")
602 #
603 # Set compiler-specific warning flags.
604 #
605 if env.whichCc == "clang": 605 ↛ 606line 605 didn't jump to line 606 because the condition on line 605 was never true
606 env.Append(CCFLAGS=["-Wall"])
607 env["CCFLAGS"] = [o for o in env["CCFLAGS"] if not re.search(r"^-mno-fused-madd$", o)]
609 ignoreWarnings = {
610 "unused-function": "boost::regex has functions in anon namespaces in headers",
611 }
612 filterWarnings = {
613 "attributes": "clang pretends to be g++, but complains about g++ attributes such as flatten",
614 "char-subscripts": "seems innocous enough, and is used by boost",
615 "constant-logical-operand": "Used by eigen 2.0.15. Should get this fixed",
616 "format-security": "format string is not a string literal",
617 "mismatched-tags": "mixed class and struct. Used by gcc 4.2 RTL and eigen 2.0.15",
618 "parentheses": "equality comparison with extraneous parentheses",
619 "shorten-64-to-32": "implicit conversion loses integer precision",
620 "self-assign": "x = x",
621 "unused-local-typedefs": "unused typedef", # lots from boost
622 "unknown-pragmas": "unknown pragma ignored",
623 "deprecated-register": "register is deprecated",
624 }
625 for k in ignoreWarnings:
626 env.Append(CCFLAGS=[f"-Wno-{k}"])
627 if env.GetOption("filterWarn"):
628 for k in filterWarnings:
629 env.Append(CCFLAGS=[f"-Wno-{k}"])
630 elif env.whichCc == "gcc":
631 env.Append(CCFLAGS=["-Wall"])
632 env.Append(CCFLAGS=["-Wno-unknown-pragmas"]) # we don't want complaints about icc/clang pragmas
633 env.Append(CCFLAGS=["-Wno-unused-local-typedefs"]) # boost generates a lot of these
634 elif env.whichCc == "icc": 634 ↛ 635line 634 didn't jump to line 635 because the condition on line 634 was never true
635 env.Append(CCFLAGS=["-Wall"])
636 filterWarnings = {
637 21: "type qualifiers are meaningless in this declaration",
638 68: "integer conversion resulted in a change of sign",
639 111: "statement is unreachable",
640 191: "type qualifier is meaningless on cast type",
641 193: 'zero used for undefined preprocessing identifier "SYMB"',
642 279: "controlling expression is constant",
643 304: 'access control not specified ("public" by default)', # comes from boost
644 383: "value copied to temporary, reference to temporary used",
645 # 424: 'Extra ";" ignored',
646 444: 'destructor for base class "CLASS" is not virtual',
647 981: "operands are evaluated in unspecified order",
648 1418: "external function definition with no prior declaration",
649 1419: "external declaration in primary source file",
650 1572: "floating-point equality and inequality comparisons are unreliable",
651 1720: 'function "FUNC" has no corresponding member operator delete'
652 "(to be called if an exception is thrown during initialization of an allocated object)",
653 2259: 'non-pointer conversion from "int" to "float" may lose significant bits',
654 }
655 if env.GetOption("filterWarn"):
656 env.Append(CCFLAGS=["-wd{}".format(",".join([str(k) for k in filterWarnings]))])
657 # Workaround intel bug; cf. RHL's intel bug report 580167
658 env.Append(LINKFLAGS=["-Wl,-no_compact_unwind", "-wd,11015"])
659 #
660 # Disable link-time-optimization on GCC, for compatibility with conda
661 # binaries
662 #
663 if env.whichCc == "gcc":
664 env.Append(CCFLAGS=["-fno-lto"])
665 env.Append(LINKFLAGS=["-fno-lto"])
668def _saveState():
669 """Save state such as optimization level used.
671 Notes
672 -----
673 The scons mailing lists were unable to tell RHL how to get this back
674 from ``.sconsign.dblite``.
675 """
677 if env.GetOption("clean"):
678 return
680 config = ConfigParser()
681 config.add_section("Build")
682 config.set("Build", "cc", env.whichCc)
683 if env["opt"]: 683 ↛ 686line 683 didn't jump to line 686 because the condition on line 683 was always true
684 config.set("Build", "opt", env["opt"])
686 try:
687 confFile = os.path.join(env.Dir(env["CONFIGUREDIR"]).abspath, "build.cfg")
688 with open(confFile, "w") as configfile:
689 config.write(configfile)
690 except Exception as e:
691 log.warn(f"Unexpected exception in _saveState: {e}")
694_initOptions()
695_initLog()
696_initVariables()
697_initEnvironment()