Repository: spack/spack

Issue:
Cannot concretize when specifying `platform=` in externals
### Steps to reproduce

This environment fails to concretize:
```yaml
spack:
  specs:
  - hwloc
  view: false
  concretizer:
    unify: true
  packages:
    hwloc:
      externals:
      - spec: hwloc@2.2.0 platform=linux
        prefix: /usr
      buildable: False
```

The behavior regressed in https://github.com/spack/spack/pull/42253

<details>

<summary>Original report</summary>

I have a `package.yaml` defined like this (minimal reproducer):
```yaml
packages:
  hwloc:
    externals:
      - spec: hwloc@2.2.0 # arch=None-None-None works as well
        prefix: /usr
    buildable: False
```
If i concretize:
```console 
$ spack spec hwloc
Input spec
--------------------------------
 -   hwloc

Concretized
--------------------------------
[e]  hwloc@2.2.0%gcc@12.3.0~cairo~cuda~gl~libudev+libxml2~netloc~nvml~oneapi-level-zero~opencl+pci~rocm build_system=autotools libs=shared,static arch=linux-rocky8-zen2
```
All good.
Now if I add anything specific to the `arch=` spec, like this for example:
```yaml
packages:
  hwloc:
    externals:
      - spec: hwloc@2.2.0 arch=linux-None-None # added platform
        prefix: /usr
    buildable: False
```
And try to concretize:
```console 
$ spack spec hwloc
==> Error: concretization failed for the following reasons:

   1. Attempted to use external for 'hwloc' which does not satisfy any configured external spec version
   2. Attempted to use external for 'hwloc' which does not satisfy any configured external spec
   3. Attempted to build package hwloc which is not buildable and does not have a satisfying external
        attr('node_version_satisfies', 'hwloc', '=2.2.0') is an external constraint for hwloc which was not satisfied
```
The error message complains about the version but it's actually fake, as if i add more specific constraints it will complain about something else:
```yaml
packages:
  hwloc:
    externals:
      - spec: hwloc@2.2.0 arch=linux-rocky8-None # added OS
        prefix: /usr
    buildable: False
```
```console 
$ spack spec hwloc
==> Error: concretization failed for the following reasons:

   1. Cannot select a single "node_os" for package "hwloc"
   2. Attempted to use external for 'hwloc' which does not satisfy any configured external spec
   3. Attempted to build package hwloc which is not buildable and does not have a satisfying external
        attr('node_os', 'hwloc', 'rocky8') is an external constraint for hwloc which was not satisfied
```
Specifying variants works fine.

I'm executing this with the latest develop branch but this error is present also in 0.21.2. 
0.21.1 works fine.
</details>

### Error message

```console
==> Error: concretization failed for the following reasons:

   1. Attempted to use external for 'hwloc' which does not satisfy any configured external spec version
   2. Attempted to use external for 'hwloc' which does not satisfy any configured external spec
   3. Attempted to build package hwloc which is not buildable and does not have a satisfying external
        attr('node_version_satisfies', 'hwloc', '=2.2.0') is an external constraint for hwloc which was not satisfied
```

### Information on your system

* **Spack:** 0.22.0.dev0 (32deca2a4ce0f05b44d67a09887434fc8057a5fa)
* **Python:** 3.6.8
* **Platform:** linux-rocky8-zen2
* **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:
@becker33 @alalazo could it be this commit here?
https://github.com/spack/spack/commit/9963e2a20ca1b381ff5e6a3d316c200e01dd0766
@becker33 @scheibelp @alalazo 
I believe that this is the same bug that I am hitting.
The issue is specific to `platform=` specification. Minimal reproducer is:
```yaml
spack:
  specs:
  - hwloc
  view: false
  concretizer:
    unify: true
  packages:
    hwloc:
      externals:
      - spec: hwloc@2.2.0 platform=linux
        prefix: /usr
      buildable: False

```
While I look for a fix, note that the issue comes from the least useful part of the `arch=` (at least for an external). I would suggest, as a workaround and as a best practice, to always use the disjoint form and write `os=` and `target=` explicitly.
Bisection says this regressed in https://github.com/spack/spack/pull/42253
Edited the description, kept the original report in  a `<details>` section.

Resolving patch:
diff --git a/lib/spack/spack/solver/asp.py b/lib/spack/spack/solver/asp.py
--- a/lib/spack/spack/solver/asp.py
+++ b/lib/spack/spack/solver/asp.py
@@ -1610,6 +1610,7 @@ def external_imposition(input_spec, requirements):
                 self.gen.newline()
 
             self.trigger_rules()
+            self.effect_rules()
 
     def preferred_variants(self, pkg_name):
         """Facts on concretization preferences, as read from packages.yaml"""


Test patch:
diff --git a/lib/spack/spack/test/concretize.py b/lib/spack/spack/test/concretize.py
--- a/lib/spack/spack/test/concretize.py
+++ b/lib/spack/spack/test/concretize.py
@@ -2398,6 +2398,19 @@ def test_reuse_specs_from_non_available_compilers(self, mutable_config, mutable_
         for s in root.traverse(root=False):
             assert s.satisfies("%gcc@10.2.1")
 
+    @pytest.mark.regression("43406")
+    def test_externals_with_platform_explicitly_set(self, tmp_path):
+        """Tests that users can specify platform=xxx in an external spec"""
+        external_conf = {
+            "mpich": {
+                "buildable": False,
+                "externals": [{"spec": "mpich@=2.0.0 platform=test", "prefix": str(tmp_path)}],
+            }
+        }
+        spack.config.set("packages", external_conf)
+        s = Spec("mpich").concretized()
+        assert s.external
+
 
 @pytest.fixture()
 def duplicates_test_repository():