spack/lib/spack/env
Andrey Parfenov 7dc485d288
cc: Ensure that user-specified flags take precedence over others (#37376)
Spack flags supplied by users should supersede flags from package build systems and
other places in Spack.  However, Spack currently adds user-supplied flags to the 
beginning of the compile line, which means that in some cases build system flags will
supersede user-supplied ones.

The right place to add a flag to ensure it has highest precedence for the compiler really
depends on the type of flag.  For example, search paths like `-L` and `-I` are examined
in order, so adding them first is highest precedence.  Compilers take the *last* occurrence
of optimization flags like `-O2`, so those should be placed *after* other such flags.  Shim
libraries with `-l` should go *before* other libraries on the command line, so we want
user-supplied libs to go first, etc.

`lib/spack/env/cc` already knows how to split arguments into categories like `libs_list`,
`rpath_dirs_list`, etc., so we can leverage that functionality to merge user flags into
the arg list correctly.

The general rules for injected flags are:

1. All `-L`, `-I`, `-isystem`, `-l`, and `*-rpath` flags from `spack_flags_*` to appear
   before their regular counterparts.
2. All other flags ordered with the ones from flags after their regular counterparts,
   i.e. `other_flags` before `spack_flags_other_flags`

- [x] Generalize argument categorization into its own function in the `cc` shell script
- [x] Apply the same splitting logic to injected flags and flags from the original compile line.
- [x] Use the resulting flag lists to merge user- and build-system-supplied flags by category.
- [x] Add tests.

Signed-off-by: Andrey Parfenov <andrey.parfenov@intel.com>

Co-authored-by: iermolae <igor.ermolaev@intel.com>
2023-06-18 14:07:08 -07:00
..
aocc
arm
case-insensitive
cce Cray support: use linux platform for newer craype versions (#29392) 2022-11-04 14:52:11 -07:00
clang
fj
gcc
intel
nag
nvhpc
oneapi Support packages which need to explicitly refer to dpcpp by name (#27168) 2021-12-02 15:49:20 -08:00
pgi
rocmcc rocmcc compiler: initial commit based on aocc and clang (#28575) 2022-03-03 14:34:22 -07:00
xl
xl_r
c89
c99
c++
cc cc: Ensure that user-specified flags take precedence over others (#37376) 2023-06-18 14:07:08 -07:00
cpp
f77
f90
f95
fc
ftn
ld
ld.gold Add ld.gold and ld.lld compiler wrapper (#25626) 2021-08-27 13:16:26 +02:00
ld.lld Add ld.gold and ld.lld compiler wrapper (#25626) 2021-08-27 13:16:26 +02:00