From a0bd6c8817bbd2839c3fe1e41e627bfabf3c052f Mon Sep 17 00:00:00 2001
From: Tom Scogland <scogland1@llnl.gov>
Date: Wed, 16 Feb 2022 23:45:24 -0800
Subject: binutils: add external detection (#29022)

---
 var/spack/repos/builtin/packages/binutils/package.py | 9 +++++++++
 1 file changed, 9 insertions(+)

(limited to 'var')

diff --git a/var/spack/repos/builtin/packages/binutils/package.py b/var/spack/repos/builtin/packages/binutils/package.py
index 1ea2765197..8d4a4ad692 100644
--- a/var/spack/repos/builtin/packages/binutils/package.py
+++ b/var/spack/repos/builtin/packages/binutils/package.py
@@ -2,6 +2,7 @@
 # Spack Project Developers. See the top-level COPYRIGHT file for details.
 #
 # SPDX-License-Identifier: (Apache-2.0 OR MIT)
+import re
 
 
 class Binutils(AutotoolsPackage, GNUMirrorPackage):
@@ -12,6 +13,8 @@ class Binutils(AutotoolsPackage, GNUMirrorPackage):
 
     maintainers = ['alalazo']
 
+    executables = ['^nm$', '^readelf$']
+
     version('2.37', sha256='67fc1a4030d08ee877a4867d3dcab35828148f87e1fd05da6db585ed5a166bd4')
     version('2.36.1', sha256='5b4bd2e79e30ce8db0abd76dd2c2eae14a94ce212cfc59d3c37d23e24bc6d7a3')
     version('2.35.2', sha256='cfa7644dbecf4591e136eb407c1c1da16578bd2b03f0c2e8acdceba194bb9d61')
@@ -80,6 +83,12 @@ class Binutils(AutotoolsPackage, GNUMirrorPackage):
     # --disable-ld flag
     conflicts('~ld', '+gold')
 
+    @classmethod
+    def determine_version(cls, exe):
+        output = Executable(exe)('--version', output=str, error=str)
+        match = re.search(r'GNU Binutils.*\) (\S+)', output)
+        return match.group(1) if match else None
+
     def setup_build_environment(self, env):
 
         if self.spec.satisfies('%cce'):
-- 
cgit v1.2.3-70-g09d2