Repository: spack/spack

Issue:
clingo bootstrap from source produces error on x86 Ubuntu Focal
### Steps to reproduce
This is with the `develop` branch.
```
spack bootstrap now
```


### Error message

```
==> [2023-04-05-11:39:52.259183] Creating stage lock spack-stage-clingo-bootstrap-spack-vscxqd5pky4bqeni3xigybhdo43nvofy
==> [2023-04-05-11:39:52.260752] Using cached archive: /home/n.a.romero/spack/var/spack/cache/_source-cache/git//potassco/clingo.git/2a025667090d71b2c9dce60fe924feb6bde8f667.tar.gz
==> [2023-04-05-11:39:52.260912] Warning: Fetching from mirror without a checksum!
  This package is normally checked out from a version control system, but it has been archived on a spack mirror.  This means we cannot know a checksum for the tarball in advance. Be sure that your connection to this mirror is secure!
==> [2023-04-05-11:39:52.261079] Already staged spack-stage-clingo-bootstrap-spack-vscxqd5pky4bqeni3xigybhdo43nvofy in /tmp/n.a.romero/spack-stage/spack-stage-clingo-bootstrap-spack-vscxqd5pky4bqeni3xigybhdo43nvofy
==> [2023-04-05-11:39:52.261250] Already patched clingo-bootstrap
==> [2023-04-05-11:39:52.261333] clingo-bootstrap: Building clingo-bootstrap-spack-vscxqd5pky4bqeni3xigybhdo43nvofy [CMakePackage]
==> [2023-04-05-11:39:52.263871] '/usr/bin/gcc' '-dumpversion'
==> [2023-04-05-11:39:52.271694] clingo-bootstrap: Executing phase: 'cmake'
==> [2023-04-05-11:39:52.292884] Error: NoLibrariesError: Unable to locate Unable to find python libraries with the following names: libraries in

/home/n.a.romero/spack/var/spack/repos/builtin/packages/python/package.py:940, in libs:
        937            if lib:
        938                return lib
        939
  >>    940        raise spack.error.NoLibrariesError(
        941            "Unable to find {} libraries with the following names:".format(self.name),
        942            "\n".join(candidates),
        943        )

See build log for details:
  /tmp/n.a.romero/spack-stage/spack-stage-clingo-bootstrap-spack-vscxqd5pky4bqeni3xigybhdo43nvofy/spack-build-out.txt

Traceback (most recent call last):
  File "/home/n.a.romero/spack/lib/spack/spack/build_environment.py", line 1050, in _setup_pkg_and_run
    return_value = function(pkg, kwargs)
  File "/home/n.a.romero/spack/lib/spack/spack/installer.py", line 2073, in build_process
    return installer.run()
  File "/home/n.a.romero/spack/lib/spack/spack/installer.py", line 1941, in run
    self._real_install()
  File "/home/n.a.romero/spack/lib/spack/spack/installer.py", line 2033, in _real_install
    phase_fn.execute()
  File "/home/n.a.romero/spack/lib/spack/spack/builder.py", line 430, in execute
    self.phase_fn(pkg, pkg.spec, pkg.prefix)
  File "/home/n.a.romero/spack/lib/spack/spack/builder.py", line 306, in _adapter
    return phase_fn(spec, prefix)
  File "/home/n.a.romero/spack/lib/spack/spack/builder.py", line 150, in __forward
    return self.__getattr__(fn_name)(*args, **kwargs)
  File "/home/n.a.romero/spack/lib/spack/spack/builder.py", line 72, in __call__
    return self.phase_fn(self.builder.pkg, spec, prefix)
  File "/home/n.a.romero/spack/lib/spack/spack/build_systems/cmake.py", line 420, in cmake
    options += self.cmake_args()
  File "/home/n.a.romero/spack/lib/spack/spack/builder.py", line 322, in _adapter
    return bind_method()
  File "/home/n.a.romero/spack/var/spack/repos/builtin/packages/clingo-bootstrap/package.py", line 54, in cmake_args
    args.extend(
  File "/home/n.a.romero/spack/var/spack/repos/builtin/packages/clingo/package.py", line 120, in cmake_args
    else:
  File "/home/n.a.romero/spack/var/spack/repos/builtin/packages/clingo/package.py", line 92, in cmake_python_hints
    # XCode command line tools on macOS has no python-config executable, and
  File "/home/n.a.romero/spack/lib/spack/spack/spec.py", line 1180, in __get__
    value = f()
  File "/home/n.a.romero/spack/lib/spack/spack/spec.py", line 1169, in <lambda>
    callbacks_chain.append(lambda: getattr(pkg, self.attribute_name))
  File "/home/n.a.romero/spack/var/spack/repos/builtin/packages/python/package.py", line 941, in libs
    "Unable to find {} libraries with the following names:".format(self.name),
spack.error.NoLibrariesError: Unable to locate Unable to find python libraries with the following names: libraries in
==> [2023-04-05-11:39:52.293604] Flagging clingo-bootstrap-spack-vscxqd5pky4bqeni3xigybhdo43nvofy as failed: NoLibrariesError: Unable to locate Unable to find python libraries with the following names: libraries in
==> [2023-04-05-11:39:52.302528] Creating stage lock spack-stage-clingo-bootstrap-spack-vscxqd5pky4bqeni3xigybhdo43nvofy
==> [2023-04-05-11:39:52.307487] Reading config from file /home/n.a.romero/spack/etc/spack/defaults/config.yaml
Traceback (most recent call last):
  File "/home/n.a.romero/spack/bin/spack", line 54, in <module>
    sys.exit(main())
  File "/home/n.a.romero/spack/lib/spack/spack_installable/main.py", line 37, in main
    sys.exit(spack.main.main(argv))
  File "/home/n.a.romero/spack/lib/spack/spack/main.py", line 1004, in main
    return _main(argv)
  File "/home/n.a.romero/spack/lib/spack/spack/main.py", line 959, in _main
    return finish_parse_and_run(parser, cmd_name, env_format_error)
  File "/home/n.a.romero/spack/lib/spack/spack/main.py", line 987, in finish_parse_and_run
    return _invoke_command(command, parser, args, unknown)
  File "/home/n.a.romero/spack/lib/spack/spack/main.py", line 636, in _invoke_command
    return_val = command(parser, args)
  File "/home/n.a.romero/spack/lib/spack/spack/cmd/bootstrap.py", line 468, in bootstrap
    callbacks[args.subcommand](args)
  File "/home/n.a.romero/spack/lib/spack/spack/cmd/bootstrap.py", line 450, in _now
    spack.bootstrap.ensure_core_dependencies()
  File "/home/n.a.romero/spack/lib/spack/spack/bootstrap/core.py", line 562, in ensure_core_dependencies
    ensure_clingo_importable_or_raise()
  File "/home/n.a.romero/spack/lib/spack/spack/bootstrap/core.py", line 497, in ensure_clingo_importable_or_raise
    ensure_module_importable_or_raise(module="clingo", abstract_spec=clingo_root_spec())
  File "/home/n.a.romero/spack/lib/spack/spack/bootstrap/core.py", line 403, in ensure_module_importable_or_raise
    raise ImportError(msg)
ImportError: cannot bootstrap the "clingo" Python module from spec "clingo-bootstrap@spack+python %gcc target=x86_64" due to the following failures:
github-actions-v0.4 raised ValueError: source is not trusted
  File "/home/n.a.romero/spack/lib/spack/spack/bootstrap/core.py", line 386, in ensure_module_importable_or_raise
    source_is_enabled_or_raise(current_config)
  File "/home/n.a.romero/spack/lib/spack/spack/bootstrap/core.py", line 355, in source_is_enabled_or_raise
    raise ValueError("source is not trusted")

github-actions-v0.3 raised ValueError: source is not trusted
  File "/home/n.a.romero/spack/lib/spack/spack/bootstrap/core.py", line 386, in ensure_module_importable_or_raise
    source_is_enabled_or_raise(current_config)
  File "/home/n.a.romero/spack/lib/spack/spack/bootstrap/core.py", line 355, in source_is_enabled_or_raise
    raise ValueError("source is not trusted")

spack-install raised InstallError: Terminating after first install failure: NoLibrariesError: Unable to locate Unable to find python libraries with the following names: libraries in
  File "/home/n.a.romero/spack/lib/spack/spack/bootstrap/core.py", line 388, in ensure_module_importable_or_raise
    if current_bootstrapper.try_import(module, abstract_spec):
  File "/home/n.a.romero/spack/lib/spack/spack/bootstrap/core.py", line 308, in try_import
    concrete_spec.package.do_install(fail_fast=True)
  File "/home/n.a.romero/spack/lib/spack/spack/package_base.py", line 1843, in do_install
    builder.install()
  File "/home/n.a.romero/spack/lib/spack/spack/installer.py", line 1788, in install
    raise InstallError("{0}: {1}".format(fail_fast_err, str(exc)), pkg=pkg
```

### Information on your system

```
(base) n.a.romero@sal-nplnpl04:~/spack$ spack debug report
* **Spack:** 0.20.0.dev0 (664c12c7be559ae71ccf8f810513c3746d340dd6)
* **Python:** 3.8.10
* **Platform:** linux-ubuntu20.04-cascadelake
* **Concretizer:** clingo
```

### General information

- [X] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [X] I have searched the issues of this repo and believe this is not a duplicate
- [X] I have run the failing commands in debug mode and reported the output


Discussion:
This looks very similar to the following issues:
https://github.com/spack/spack/issues/28183
https://github.com/spack/spack/issues/34770

Note that there are firewall issues at my current employer, so the Spack bootstrap fallbacks to source installation.
Running into this same issue

* **Spack:** 0.20.0.dev0 (4ace1e660a3ab60a2e510308d700e251126f8c0e)
* **Python:** 3.8.10
* **Platform:** linux-ubuntu20.04-broadwell
* **Concretizer:** clingo

Are there any work arounds?
Do you have any reproducer? Spack bootstraps correctly from binaries on `x86_64` (that is tested in CI on all PRs) so you might want to setup a local bootstrap buildcache like documented [here](https://spack.readthedocs.io/en/latest/bootstrapping.html#creating-a-mirror-for-air-gapped-systems).
I have managed to work around the issue since then, but can you try this with a fresh copy of develop.
- git clone develop branch
- spack bootstrap remove github-actions-v0.4
- spack bootstrap remove github-actions-v0.3
- spack bootstrap now



Resolving patch:
diff --git a/var/spack/repos/builtin/packages/python/package.py b/var/spack/repos/builtin/packages/python/package.py
--- a/var/spack/repos/builtin/packages/python/package.py
+++ b/var/spack/repos/builtin/packages/python/package.py
@@ -878,6 +878,9 @@ def config_vars(self):
                 "INCLUDEPY": self.prefix.include.join("python{}").format(version),
                 "LIBDEST": self.prefix.lib.join("python{}").format(version),
                 "LIBDIR": self.prefix.lib,
+                "LIBPL": self.prefix.lib.join("python{0}")
+                .join("config-{0}-{1}")
+                .format(version, sys.platform),
                 "LDLIBRARY": "{}python{}.{}".format(lib_prefix, version, dso_suffix),
                 "LIBRARY": "{}python{}.{}".format(lib_prefix, version, stat_suffix),
                 "LDSHARED": "cc",
@@ -947,6 +950,10 @@ def find_library(self, library):
         # in either lib or lib64, so we need to ask Python where its LIBDIR is.
         libdir = self.config_vars["LIBDIR"]
 
+        # Debian and derivatives use a triplet subdir under /usr/lib, LIBPL can be used
+        # to get the Python library directory
+        libpldir = self.config_vars["LIBPL"]
+
         # The system Python installation on macOS and Homebrew installations
         # install libraries into a Frameworks directory
         frameworkprefix = self.config_vars["PYTHONFRAMEWORKPREFIX"]
@@ -962,7 +969,14 @@ def find_library(self, library):
         win_bin_dir = self.config_vars["BINDIR"]
         win_root_dir = self.config_vars["prefix"]
 
-        directories = [libdir, frameworkprefix, macos_developerdir, win_bin_dir, win_root_dir]
+        directories = [
+            libdir,
+            libpldir,
+            frameworkprefix,
+            macos_developerdir,
+            win_bin_dir,
+            win_root_dir,
+        ]
 
         # The Python shipped with Xcode command line tools isn't in any of these locations
         for subdir in ["lib", "lib64"]:


Test patch: