Implemented flags as lists for subsetting

This commit is contained in:
Gregory Becker 2016-01-12 15:22:15 -08:00
parent 2ac5ea42af
commit 528f9cd583
4 changed files with 72 additions and 44 deletions

39
lib/spack/env/cc vendored
View file

@ -91,41 +91,53 @@ case "$command" in
cc|gcc|c89|c99|clang|xlc)
command=("$SPACK_CC")
if [ "$SPACK_CFLAGS" ]; then
command+=("$SPACK_CFLAGS")
for flag in ${SPACK_CFLAGS[@]}; do
command+=("$flag");
done
fi
language="C"
;;
c++|CC|g++|clang++|xlC)
command=("$SPACK_CXX")
if [ "$SPACK_CXXFLAGS" ]; then
command+=("$SPACK_CXXFLAGS")
for flag in ${SPACK_CXXFLAGS[@]}; do
command+=("$flag");
done
fi
language="C++"
;;
f77|xlf)
command=("$SPACK_F77")
if [ "$SPACK_FFLAGS" ]; then
command+=("$SPACK_FFLAGS")
for flag in ${SPACK_FFLAGS[@]}; do
command+=("$flag");
done
fi
language="Fortran 77"
;;
fc|f90|f95|xlf90)
command="$SPACK_FC"
if [ "$SPACK_FFLAGS" ]; then
command+=("$SPACK_FFLAGS")
for flag in ${SPACK_FFLAGS[@]}; do
command+=("$flag");
done
fi
language="Fortran 90"
;;
cpp)
mode=cpp
if [ "$SPACK_CPPFLAGS" ]; then
command+=("$SPACK_CPPFLAGS")
for flag in ${SPACK_CPPFLAGS[@]}; do
command+=("$flag");
done
fi
;;
ld)
mode=ld
if [ "$SPACK_LDFLAGS" ]; then
command+=("$SPACK_LDFLAGS")
for flag in ${SPACK_LDFLAGS[@]}; do
command+=("$flag");
done
fi
;;
*)
@ -137,7 +149,9 @@ esac
if [ -z "$mode" ]; then
mode=ccld
if [ "$SPACK_LDFLAGS" ]; then
command+=("$SPACK_LDFLAGS")
for flag in ${SPACK_LDFLAGS[@]}; do
command+=("$flag");
done
fi
for arg in "$@"; do
if [ "$arg" = -v -o "$arg" = -V -o "$arg" = --version -o "$arg" = -dumpversion ]; then
@ -340,7 +354,6 @@ done
export PATH
full_command=("${command[@]}")
#full_command+=("$SPACK_CFLAGS")
full_command+=("${args[@]}")
#
@ -353,7 +366,11 @@ if [ "$SPACK_DEBUG" = "TRUE" ]; then
echo "$mode ${full_command[@]}" >> $output_log
fi
echo "---------------------------" > /g/g0/becker33/cflag_test
echo "${full_command[@]}" >> /g/g0/becker33/cflag_test
echo "---------------------------" >> /g/g0/becker33/cflag_test
#echo "---------------------------"
#echo "---------------------------"
#echo "---------------------------"
#echo "${full_command[@]}"
#echo "---------------------------"
#echo "---------------------------"
#echo "---------------------------"
exec "${full_command[@]}"

View file

@ -108,7 +108,7 @@ def set_compiler_environment_variables(pkg):
for flag in Compiler.valid_compiler_flags():
# Concreteness guarantees key safety here
if flags[flag] != '':
os.environ['SPACK_'+flag.upper()] = flags[flag]
os.environ['SPACK_'+flag.upper()] = ' '.join(f for f in flags[flag])
os.environ['SPACK_COMPILER_SPEC'] = str(pkg.spec.compiler)

View file

@ -183,24 +183,47 @@ def concretize_compiler_flags(self, spec):
"""
ret = False
for flag in Compiler.valid_compiler_flags():
if flag in spec.compiler_flags:
continue
# if flag in spec.compiler_flags:
# continue
try:
nearest = next(p for p in spec.traverse(direction='parents')
if ((p.compiler == spec.compiler and p is not spec)
and flag in p.compiler_flags))
if ((not flag in spec.compiler_flags) or
spec.compiler_flags[flag] != nearest.compiler_flags[flag]):
spec.compiler_flags[flag] = nearest.compiler_flags[flag]
sorted(spec.compiler_flags[flag]) != sorted(nearest.compiler_flags[flag])):
if flag in spec.compiler_flags:
spec.compiler_flags[flag] = list(set(spec.compiler_flags[flag]) |
set(nearest.compiler_flags[flag]))
else:
spec.compielr_flags[flag] = nearest.compiler_flags[flag]
ret = True
except StopIteration:
if (flag in spec.root.compiler_flags and ((not flag in spec.compiler_flags) or
spec.compiler_flags[flag] != spec.root.compiler_flags[flag])):
spec.compiler_flags[flag] = spec.root.compiler_flags[flag]
sorted(spec.compiler_flags[flag]) != sorted(spec.root.compiler_flags[flag]))):
if flag in spec.compiler_flags:
spec.compiler_flags[flag] = list(set(spec.compiler_flags[flag]) |
set(spec.root.compiler_flags[flag]))
else:
spec.compiler_flags[flag] = spec.root.compiler_flags[flag]
ret = True
else:
spec.compiler_flags[flag] = ''
if not flag in spec.compiler_flags:
spec.compiler_flags[flag] = []
# Include the compiler flag defaults from the config files
# This ensures that spack will detect conflicts that stem from a change
# in default compiler flags.
compiler = spack.compilers.compiler_for_spec(spec.compiler)
for flag in compiler.flags:
if flag not in spec.compiler_flags or spec.compiler_flags[flag] == []:
spec.compiler_flags[flag] = compiler.flags[flag]
ret = True
else:
if (sorted(spec.compiler_flags[flag]) != sorted(compiler.flags[flag])) and (not set(spec.compiler_flags[flag]) >= set(compiler.flags[flag])):
ret = True
spec.compiler_flags[flag] = list(set(spec.compiler_flags[flag]) |
set(compiler.flags[flag]))
return ret

View file

@ -381,11 +381,11 @@ def __init__(self, spec):
def satisfies(self, other, strict=False):
#"strict" makes no sense if this works, but it matches how we need it. Maybe
if strict:
return all(k in self and self[k] == other[k]
for k in other if other[k] != "")
return all(f in self and set(self[f]) == set(other[f])
for f in other if other[f] != [])
else:
return all(k in self and self[k] == other[k]
for k in other)
return all(f in self and set(self[f]) >= set(other[f])
for f in other)
def constrain(self, other):
@ -396,13 +396,11 @@ def constrain(self, other):
changed = False
# Others_set removes flags set to '' from the comparison
others_set = (k for k in other if other[k] != '')
others_set = (k for k in other if other[k] != [])
for k in others_set:
if k in self and self[k] != '':
if self[k] != other[k]:
# This will not recognize incompatible flags, merely concatenates
self[k] += ' ' + other[k]
changed = True
if k in self and self[k] != other[k]:
self[k] = list(set(self[k]) | set(other[k]))
changed = True
else:
self[k] = other[k]
changed = True
@ -422,13 +420,13 @@ def copy(self):
def _cmp_key(self):
return ''.join(str(key)+str(value) for key, value in sorted(self.items()))
return ''.join(str(key) + ' '.join(str(v) for v in value) for key, value in sorted(self.items()))
def __str__(self):
sorted_keys = filter(lambda flag: self[flag] != "", sorted(self.keys()))
sorted_keys = filter(lambda flag: self[flag] != [], sorted(self.keys()))
cond_symbol = '+' if len(sorted_keys)>0 else ''
return cond_symbol + '+'.join(str(key) + '=\"' + str(self[key]) + '\"' for key in sorted_keys)
return cond_symbol + '+'.join(str(key) + '=\"' + ' '.join(str(f) for f in self[key]) + '\"' for key in sorted_keys)
class DependencyMap(HashableMap):
@ -516,7 +514,7 @@ def _add_flag(self, name, value):
self._set_architecture(value)
elif name in valid_flags:
assert(self.compiler_flags is not None)
self.compiler_flags[name] = value
self.compiler_flags[name] = value.split()
else:
self._add_variant(self,name,value)
@ -816,6 +814,7 @@ def _concretize_helper(self, presets=None, visited=None):
concretized, they're added to the presets, and ancestors
will prefer the settings of their children.
"""
if presets is None: presets = {}
if visited is None: visited = set()
@ -929,16 +928,6 @@ def concretize(self):
changed = any(changes)
force=True
# Include the compiler flag defaults from the config files
# This ensures that spack will detect conflicts that stemp from a change
# in default compiler flags.
pkg = spack.db.get(self)
for flag in pkg.compiler.flags:
if self.compiler_flags[flag] == '':
self.compiler_flags[flag] += pkg.compiler.flags[flag]
else:
self.compiler_flags[flag] += ' ' + pkg.compiler.flags[flag]
self._concrete = True
@ -1907,7 +1896,6 @@ def spec(self, name, check_valid_token = False):
self.token.value = self.token.value[1:-1]
else:
self.expect(ID)
print "about to add", option, "=", self.token.value
spec._add_flag(option,self.token.value)
else:
spec._add_variant(self.variant(option),True)