Got rid of init_config flag since we don't need it. Instead we update the cache config if there are any changes

This commit is contained in:
Mario Melara 2016-06-18 00:48:08 -07:00
parent fe5eec5230
commit c703bfb54d

View File

@ -52,6 +52,7 @@
_imported_compilers_module = 'spack.compilers'
_path_instance_vars = ['cc', 'cxx', 'f77', 'fc']
_other_instance_vars = ['modules', 'operating_system']
_cache_config_file = []
# TODO: customize order in config file
if platform.system() == 'Darwin':
@ -82,7 +83,7 @@ def _to_dict(compiler):
return {'compiler': d}
def get_compiler_config(scope=None, init_config=True):
def get_compiler_config(scope=None):
"""Return the compiler configuration for the specified architecture.
"""
def init_compiler_config():
@ -97,9 +98,7 @@ def init_compiler_config():
# Update the configuration if there are currently no compilers
# configured. Avoid updating automatically if there ARE site
# compilers configured but no user ones.
# if (isinstance(arch, basestring) or arch == my_arch) and arch not in config:
empty_config = []
if not config and init_config:
if not config:
if scope is None:
# We know no compilers were configured in any scope.
init_compiler_config()
@ -112,11 +111,13 @@ def init_compiler_config():
init_compiler_config()
config = spack.config.get_config('compilers', scope=scope)
return config
elif config:
return config
else:
return empty_config
return [] # Return empty list which we will later append to.
def add_compilers_to_config(compilers, scope=None, init_config=True):
def add_compilers_to_config(compilers, scope=None):
"""Add compilers to the config for the specified architecture.
Arguments:
@ -124,10 +125,10 @@ def add_compilers_to_config(compilers, scope=None, init_config=True):
- scope: configuration scope to modify.
"""
compiler_config = get_compiler_config(scope, init_config)
print compiler_config
for compiler in compilers:
compiler_config.append(_to_dict(compiler))
global _cache_config_file
_cache_config_file = compiler_config
spack.config.update_config('compilers', compiler_config, scope)
@ -140,32 +141,35 @@ def remove_compiler_from_config(compiler_spec, scope=None):
- scope: configuration scope to modify.
"""
compiler_config = get_compiler_config(scope)
matches = [(a,c) for (a,c) in compiler_config.items() if c['spec'] == compiler_spec]
if len(matches) == 1:
del compiler_config[matches[0][0]]
else:
config_length = len(compiler_config)
filtered_compiler_config = [comp for comp in compiler_config
if spack.spec.CompilerSpec(comp['compiler']['spec']) != compiler_spec]
# Need a better way for this
global _cache_config_file
_cache_config_file = filtered_compiler_config # Update the cache for changes
if len(filtered_compiler_config) == config_length: # No items removed
CompilerSpecInsufficientlySpecificError(compiler_spec)
spack.config.update_config('compilers', filtered_compiler_config, scope)
spack.config.update_config('compilers', compiler_config, scope)
_cache_config_file = {}
def all_compilers_config(scope=None, init_config=True):
def all_compilers_config(scope=None):
"""Return a set of specs for all the compiler versions currently
available to build with. These are instances of CompilerSpec.
"""
# Get compilers for this architecture.
global _cache_config_file #Create a cache of the config file so we don't load all the time.
if not _cache_config_file:
_cache_config_file = get_compiler_config(scope, init_config)
_cache_config_file = get_compiler_config(scope)
return _cache_config_file
else:
return _cache_config_file
def all_compilers(scope=None, init_config=True):
def all_compilers(scope=None):
# Return compiler specs from the merged config.
return [spack.spec.CompilerSpec(s['compiler']['spec'])
for s in all_compilers_config(scope, init_config)]
for s in all_compilers_config(scope)]
def default_compiler():