def test_compiler_get_real_version_fails(working_env, monkeypatch, tmpdir): # Test variables test_version = '2.2.2' # Create compiler gcc = str(tmpdir.join('gcc')) with open(gcc, 'w') as f: f.write("""#!/bin/bash if [[ $CMP_ON == "1" ]]; then echo "$CMP_VER" fi """) fs.set_executable(gcc) # Add compiler to config compiler_info = { 'spec': 'gcc@foo', 'paths': { 'cc': gcc, 'cxx': None, 'f77': None, 'fc': None, }, 'flags': {}, 'operating_system': 'fake', 'target': 'fake', 'modules': ['turn_on'], 'environment': { 'set': {'CMP_VER': test_version}, }, 'extra_rpaths': [], } compiler_dict = {'compiler': compiler_info} # Set module load to turn compiler on def module(*args): if args[0] == 'show': return '' elif args[0] == 'load': os.environ['SPACK_TEST_CMP_ON'] = "1" monkeypatch.setattr(spack.util.module_cmd, 'module', module) # Make compiler fail when getting implicit rpaths def _call(*args, **kwargs): raise ProcessError("Failed intentionally") monkeypatch.setattr(spack.util.executable.Executable, '__call__', _call) # Run and no change to environment compilers = spack.compilers.get_compilers([compiler_dict]) assert len(compilers) == 1 compiler = compilers[0] try: _ = compiler.get_real_version() assert False except ProcessError: # Confirm environment does not change after failed call assert 'SPACK_TEST_CMP_ON' not in os.environ
def test_compiler_get_real_version(working_env, monkeypatch, tmpdir): # Test variables test_version = '2.2.2' # Create compiler gcc = str(tmpdir.join('gcc')) with open(gcc, 'w') as f: f.write("""#!/bin/bash if [[ $CMP_ON == "1" ]]; then echo "$CMP_VER" fi """) fs.set_executable(gcc) # Add compiler to config compiler_info = { 'spec': 'gcc@foo', 'paths': { 'cc': gcc, 'cxx': None, 'f77': None, 'fc': None, }, 'flags': {}, 'operating_system': 'fake', 'target': 'fake', 'modules': ['turn_on'], 'environment': { 'set': { 'CMP_VER': test_version }, }, 'extra_rpaths': [], } compiler_dict = {'compiler': compiler_info} # Set module load to turn compiler on def module(*args): if args[0] == 'show': return '' elif args[0] == 'load': os.environ['CMP_ON'] = "1" monkeypatch.setattr(spack.util.module_cmd, 'module', module) # Run and confirm output compilers = spack.compilers.get_compilers([compiler_dict]) assert len(compilers) == 1 compiler = compilers[0] version = compiler.get_real_version() assert version == test_version
def optimization_flags(self, compiler): """Returns the flags needed to optimize for this target using the compiler passed as argument. Args: compiler (CompilerSpec or Compiler): object that contains both the name and the version of the compiler we want to use """ # Mixed toolchains are not supported yet import spack.compilers if isinstance(compiler, spack.compiler.Compiler): if spack.compilers.is_mixed_toolchain(compiler): msg = ('microarchitecture specific optimizations are not ' 'supported yet on mixed compiler toolchains [check' ' {0.name}@{0.version} for further details]') warnings.warn(msg.format(compiler)) return '' # Try to check if the current compiler comes with a version number or # has an unexpected suffix. If so, treat it as a compiler with a # custom spec. compiler_version = compiler.version version_number, suffix = cpu.version_components(compiler.version) if not version_number or suffix not in ('', 'apple'): # Try to deduce the underlying version of the compiler, regardless # of its name in compilers.yaml. Depending on where this function # is called we might get either a CompilerSpec or a fully fledged # compiler object. import spack.spec if isinstance(compiler, spack.spec.CompilerSpec): compiler = spack.compilers.compilers_for_spec(compiler).pop() try: compiler_version = compiler.get_real_version() except spack.util.executable.ProcessError as e: # log this and just return compiler.version instead tty.debug(str(e)) return self.microarchitecture.optimization_flags( compiler.name, str(compiler_version) )