Do not initialize config on spack compiler list (#28042)
When `spack compiler list` is run without being restricted to a particular scope, and no compilers are found, say that none are available, and hint that the use should run spack compiler find to auto detect compilers. * Improve docs * Check if stdin is a tty * add a test
This commit is contained in:
		@@ -271,9 +271,10 @@ Compiler configuration
 | 
				
			|||||||
----------------------
 | 
					----------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Spack has the ability to build packages with multiple compilers and
 | 
					Spack has the ability to build packages with multiple compilers and
 | 
				
			||||||
compiler versions. Spack searches for compilers on your machine
 | 
					compiler versions. Compilers can be made available to Spack by
 | 
				
			||||||
automatically the first time it is run. It does this by inspecting
 | 
					specifying them manually in ``compilers.yaml``, or automatically by
 | 
				
			||||||
your ``PATH``.
 | 
					running ``spack compiler find``, but for convenience Spack will
 | 
				
			||||||
 | 
					automatically detect compilers the first time it needs them.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.. _cmd-spack-compilers:
 | 
					.. _cmd-spack-compilers:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -281,7 +282,7 @@ your ``PATH``.
 | 
				
			|||||||
``spack compilers``
 | 
					``spack compilers``
 | 
				
			||||||
^^^^^^^^^^^^^^^^^^^
 | 
					^^^^^^^^^^^^^^^^^^^
 | 
				
			||||||
 | 
					
 | 
				
			||||||
You can see which compilers spack has found by running ``spack
 | 
					You can see which compilers are available to Spack by running ``spack
 | 
				
			||||||
compilers`` or ``spack compiler list``:
 | 
					compilers`` or ``spack compiler list``:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.. code-block:: console
 | 
					.. code-block:: console
 | 
				
			||||||
@@ -320,9 +321,10 @@ An alias for ``spack compiler find``.
 | 
				
			|||||||
``spack compiler find``
 | 
					``spack compiler find``
 | 
				
			||||||
^^^^^^^^^^^^^^^^^^^^^^^
 | 
					^^^^^^^^^^^^^^^^^^^^^^^
 | 
				
			||||||
 | 
					
 | 
				
			||||||
If you do not see a compiler in this list, but you want to use it with
 | 
					Lists the compilers currently available to Spack. If you do not see
 | 
				
			||||||
Spack, you can simply run ``spack compiler find`` with the path to
 | 
					a compiler in this list, but you want to use it with Spack, you can
 | 
				
			||||||
where the compiler is installed.  For example:
 | 
					simply run ``spack compiler find`` with the path to where the
 | 
				
			||||||
 | 
					compiler is installed.  For example:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.. code-block:: console
 | 
					.. code-block:: console
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -146,9 +146,22 @@ def compiler_info(args):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def compiler_list(args):
 | 
					def compiler_list(args):
 | 
				
			||||||
 | 
					    compilers = spack.compilers.all_compilers(scope=args.scope, init_config=False)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # If there are no compilers in any scope, and we're outputting to a tty, give a
 | 
				
			||||||
 | 
					    # hint to the user.
 | 
				
			||||||
 | 
					    if len(compilers) == 0:
 | 
				
			||||||
 | 
					        if not sys.stdout.isatty():
 | 
				
			||||||
 | 
					            return
 | 
				
			||||||
 | 
					        msg = "No compilers available"
 | 
				
			||||||
 | 
					        if args.scope is None:
 | 
				
			||||||
 | 
					            msg += ". Run `spack compiler find` to autodetect compilers"
 | 
				
			||||||
 | 
					        tty.msg(msg)
 | 
				
			||||||
 | 
					        return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    index = index_by(compilers, lambda c: (c.spec.name, c.operating_system, c.target))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    tty.msg("Available compilers")
 | 
					    tty.msg("Available compilers")
 | 
				
			||||||
    index = index_by(spack.compilers.all_compilers(scope=args.scope),
 | 
					 | 
				
			||||||
                     lambda c: (c.spec.name, c.operating_system, c.target))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # For a container, take each element which does not evaluate to false and
 | 
					    # For a container, take each element which does not evaluate to false and
 | 
				
			||||||
    # convert it to a string. For elements which evaluate to False (e.g. None)
 | 
					    # convert it to a string. For elements which evaluate to False (e.g. None)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -300,8 +300,8 @@ def find_specs_by_arch(compiler_spec, arch_spec, scope=None, init_config=True):
 | 
				
			|||||||
                                               init_config)]
 | 
					                                               init_config)]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def all_compilers(scope=None):
 | 
					def all_compilers(scope=None, init_config=True):
 | 
				
			||||||
    config = get_compiler_config(scope)
 | 
					    config = get_compiler_config(scope, init_config=init_config)
 | 
				
			||||||
    compilers = list()
 | 
					    compilers = list()
 | 
				
			||||||
    for items in config:
 | 
					    for items in config:
 | 
				
			||||||
        items = items['compiler']
 | 
					        items = items['compiler']
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,6 +10,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import llnl.util.filesystem
 | 
					import llnl.util.filesystem
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import spack.compilers
 | 
				
			||||||
import spack.main
 | 
					import spack.main
 | 
				
			||||||
import spack.version
 | 
					import spack.version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -271,3 +272,13 @@ def test_compiler_find_path_order(
 | 
				
			|||||||
        'f77': str(clangdir.join('first_in_path', 'gfortran-8')),
 | 
					        'f77': str(clangdir.join('first_in_path', 'gfortran-8')),
 | 
				
			||||||
        'fc': str(clangdir.join('first_in_path', 'gfortran-8')),
 | 
					        'fc': str(clangdir.join('first_in_path', 'gfortran-8')),
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def test_compiler_list_empty(no_compilers_yaml, working_env, clangdir):
 | 
				
			||||||
 | 
					    # Spack should not automatically search for compilers when listing them and none
 | 
				
			||||||
 | 
					    # are available. And when stdout is not a tty like in tests, there should be no
 | 
				
			||||||
 | 
					    # output and no error exit code.
 | 
				
			||||||
 | 
					    os.environ['PATH'] = str(clangdir)
 | 
				
			||||||
 | 
					    out = compiler('list')
 | 
				
			||||||
 | 
					    assert not out
 | 
				
			||||||
 | 
					    assert compiler.returncode == 0
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user