Skip to content

Commit

Permalink
Keep only the existing format of 'compilers.yaml' and extend it.
Browse files Browse the repository at this point in the history
  • Loading branch information
skosukhin committed Aug 31, 2018
1 parent 6b0e0c9 commit e355f12
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 204 deletions.
25 changes: 20 additions & 5 deletions lib/spack/docs/basic_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ In the exceptional case a compiler requires setting special environment
variables, like an explicit library load path. These can bet set in an
extra section in the compiler configuration (the supported environment
modification commands are: ``set``, ``unset``, ``append-path``, and
``prepend-path``). The user can also specify additional ``RPATHs`` that the
``prepend-path``). The user can also specify additional ``RPATHs`` that the
compiler will add to all executables generated by that compiler. This is
useful for forcing certain compilers to RPATH their own runtime libraries, so
that executables will run without the need to set ``LD_LIBRARY_PATH``.
Expand All @@ -702,14 +702,29 @@ that executables will run without the need to set ``LD_LIBRARY_PATH``.
f77: /opt/gcc/bin/gfortran
fc: /opt/gcc/bin/gfortran
environment:
- [unset, BAD_VARIABLE]
- [set, GOOD_VARIABLE, 1]
- [prepend-path, PATH, /path/to/binutils]
- [append-path, LD_LIBRARY_PATH, /opt/gcc/lib]
unset:
BAD_VARIABLE: # The colon is required but the value must be empty
set:
GOOD_VARIABLE_NUM: 1
GOOD_VARIABLE_STR: good
prepend-path:
PATH: /path/to/binutils
append-path:
LD_LIBRARY_PATH: /opt/gcc/lib
extra_rpaths:
- /path/to/some/compiler/runtime/directory
- /path/to/some/other/compiler/runtime/directory
.. note::

The section `environment` is interpreted as an ordered dictionary, which
means two things. First, environment modification are applied in the order
they are specified in the configuration file. Second, you cannot express
environment modifications that require mixing different commands, i.e. you
cannot `set` one variable, than `prepend-path` to another one, and than
again `set` a third one.

^^^^^^^^^^^^^^^^^^^^^^^
Architecture specifiers
^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
12 changes: 0 additions & 12 deletions lib/spack/env/cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,6 @@ if [[ -z $command ]]; then
die "ERROR: Compiler '$SPACK_COMPILER_SPEC' does not support compiling $language programs."
fi

#
# Set paths as defined in the 'environment' section of the compiler config
# names are stored in SPACK_ENV_TO_SET
# values are stored in SPACK_ENV_SET_<varname>
#
IFS=':' read -ra env_set_varnames <<< "$SPACK_ENV_TO_SET"
for varname in "${env_set_varnames[@]}"; do
spack_varname="SPACK_ENV_SET_$varname"
export "$varname"="${!spack_varname}"
unset "$spack_varname"
done

#
# Filter '.' and Spack environment directories out of PATH so that
# this script doesn't just call itself
Expand Down
35 changes: 13 additions & 22 deletions lib/spack/spack/build_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,28 +293,19 @@ def set_build_environment_variables(pkg, env, dirty):
compiler = pkg.compiler
environment = compiler.environment

if issubclass(type(environment), dict):
# For backward compatibility
if 'set' in environment:
env_to_set = environment['set']
for key, value in iteritems(env_to_set):
env.set('SPACK_ENV_SET_%s' % key, value)
env.set('%s' % key, value)
# Let shell know which variables to set
env_variables = ":".join(env_to_set.keys())
env.set('SPACK_ENV_TO_SET', env_variables)
elif issubclass(type(environment), list):
for modification in environment:
env_cmd = modification[0]
env_cmd_args = modification[1:]
if env_cmd == 'set' and len(env_cmd_args) == 2:
env.set(*env_cmd_args)
elif env_cmd == 'unset' and len(env_cmd_args) == 1:
env.unset(*env_cmd_args)
elif env_cmd == 'prepend-path' and len(env_cmd_args) == 2:
env.prepend_path(*env_cmd_args)
elif env_cmd == 'append-path' and len(env_cmd_args) == 2:
env.append_path(*env_cmd_args)
for command, variable in iteritems(environment):
if command == 'set':
for name, value in iteritems(variable):
env.set(name, value)
elif command == 'unset':
for name, _ in iteritems(variable):
env.unset(name)
elif command == 'prepend-path':
for name, value in iteritems(variable):
env.prepend_path(name, value)
elif command == 'append-path':
for name, value in iteritems(variable):
env.append_path(name, value)

if compiler.extra_rpaths:
extra_rpaths = ':'.join(compiler.extra_rpaths)
Expand Down
210 changes: 95 additions & 115 deletions lib/spack/spack/schema/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,129 +34,109 @@
'title': 'Spack compiler configuration file schema',
'type': 'object',
'additionalProperties': False,
'patternProperties': {
'properties': {
'compilers': {
'type': 'array',
'items': {
'compiler': {
'type': 'object',
'additionalProperties': False,
'required': [
'paths', 'spec', 'modules', 'operating_system'],
'properties': {
'paths': {
'type': 'object',
'required': ['cc', 'cxx', 'f77', 'fc'],
'additionalProperties': False,
'properties': {
'cc': {'anyOf': [{'type': 'string'},
{'type': 'null'}]},
'cxx': {'anyOf': [{'type': 'string'},
{'type': 'null'}]},
'f77': {'anyOf': [{'type': 'string'},
{'type': 'null'}]},
'fc': {'anyOf': [{'type': 'string'},
{'type': 'null'}]}}},
'flags': {
'type': 'object',
'additionalProperties': False,
'properties': {
'cflags': {'anyOf': [{'type': 'string'},
{'type': 'null'}]},
'cxxflags': {'anyOf': [{'type': 'string'},
{'type': 'null'}]},
'fflags': {'anyOf': [{'type': 'string'},
{'type': 'null'}]},
'cppflags': {'anyOf': [{'type': 'string'},
{'type': 'null'}]},
'ldflags': {'anyOf': [{'type': 'string'},
'type': 'object',
'additionalProperties': False,
'properties': {
'compiler': {
'type': 'object',
'additionalProperties': False,
'required': [
'paths', 'spec', 'modules', 'operating_system'],
'properties': {
'paths': {
'type': 'object',
'required': ['cc', 'cxx', 'f77', 'fc'],
'additionalProperties': False,
'properties': {
'cc': {'anyOf': [{'type': 'string'},
{'type': 'null'}]},
'ldlibs': {'anyOf': [{'type': 'string'},
{'type': 'null'}]}}},
'spec': {'type': 'string'},
'operating_system': {'type': 'string'},
'alias': {'anyOf': [{'type': 'string'},
{'type': 'null'}]},
'modules': {'anyOf': [{'type': 'string'},
{'type': 'null'},
{'type': 'array'}]},
'environment': {
'oneOf': [
{
'type': 'object',
'default': {},
'additionalProperties': False,
'properties': {
'set': {
'type': 'object',
'patternProperties': {
r'\w[\w-]*': { # variable name
'type': 'string'
}
'cxx': {'anyOf': [{'type': 'string'},
{'type': 'null'}]},
'f77': {'anyOf': [{'type': 'string'},
{'type': 'null'}]},
'fc': {'anyOf': [{'type': 'string'},
{'type': 'null'}]}}},
'flags': {
'type': 'object',
'additionalProperties': False,
'properties': {
'cflags': {'anyOf': [{'type': 'string'},
{'type': 'null'}]},
'cxxflags': {'anyOf': [{'type': 'string'},
{'type': 'null'}]},
'fflags': {'anyOf': [{'type': 'string'},
{'type': 'null'}]},
'cppflags': {'anyOf': [{'type': 'string'},
{'type': 'null'}]},
'ldflags': {'anyOf': [{'type': 'string'},
{'type': 'null'}]},
'ldlibs': {'anyOf': [{'type': 'string'},
{'type': 'null'}]}}},
'spec': {'type': 'string'},
'operating_system': {'type': 'string'},
'target': {'type': 'string'},
'alias': {'anyOf': [{'type': 'string'},
{'type': 'null'}]},
'modules': {'anyOf': [{'type': 'string'},
{'type': 'null'},
{'type': 'array'}]},
'environment': {
'type': 'object',
'default': {},
'additionalProperties': False,
'properties': {
'set': {
'type': 'object',
'patternProperties': {
# Variable name
r'\w[\w-]*': {
'anyOf': [{'type': 'string'},
{'type': 'number'}]
}
}
}
},
{
'type': 'array',
'default': [],
'items': {
'anyOf': [
{
# Commands with 2 arguments
'type': 'array',
'additionalItems': False,
'minItems': 3,
'items': [
{
'type': 'string',
'enum': [
'set',
'append-path',
'prepend-path']
},
{
# Variable name
'type': 'string'
},
{
# Variable value
'anyOf': [
{'type': 'string'},
{'type': 'number'}
]
}
]
},
{
# Commands with 1 argument
'type': 'array',
'additionalItems': False,
'minItems': 2,
'items': [
{
'type': 'string',
'enum': ['unset']
},
{
# Variable name
'type': 'string'
}
]
},
'unset': {
'type': 'object',
'patternProperties': {
# Variable name
r'\w[\w-]*': {'type': 'null'}
}
},
'prepend-path': {
'type': 'object',
'patternProperties': {
# Variable name
r'\w[\w-]*': {
'anyOf': [{'type': 'string'},
{'type': 'number'}]
}
]
}
},
'append-path': {
'type': 'object',
'patternProperties': {
# Variable name
r'\w[\w-]*': {
'anyOf': [{'type': 'string'},
{'type': 'number'}]
}
}
}
}
]
},
'extra_rpaths': {
'type': 'array',
'default': [],
'items': {'type': 'string'}
},
'extra_rpaths': {
'type': 'array',
'default': [],
'items': {'type': 'string'}
}
}
},
},
},
},
},
}
}
}
}
}
}
Loading

0 comments on commit e355f12

Please sign in to comment.