summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2020-01-28 21:41:35 -0800
committerTodd Gamblin <tgamblin@llnl.gov>2020-01-29 21:15:58 -0800
commit3519a176245d9cc6b5f6802aad3b1bb1c2d6ec47 (patch)
treeae6c2141ca1a620dd7d762c50331f5e90e300063 /lib
parenta2f8a2321d94a89ad1cb13e0dccca20e5f5aa325 (diff)
downloadspack-3519a176245d9cc6b5f6802aad3b1bb1c2d6ec47.tar.gz
spack-3519a176245d9cc6b5f6802aad3b1bb1c2d6ec47.tar.bz2
spack-3519a176245d9cc6b5f6802aad3b1bb1c2d6ec47.tar.xz
spack-3519a176245d9cc6b5f6802aad3b1bb1c2d6ec47.zip
specs: avoid traversing specs when parsing
The Spec parser currently calls `spec.traverse()` after every parse, in order to set the platform if it's not set. We don't need to do a full traverse -- we can just check the platforrm as new specs are parsed. This takes about a second off the time required to import all packages in Spack (from 8s to 7s). - [x] simplify platform-setting logic in `SpecParser`.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/spec.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py
index 3bee81c0d4..4b6bd67b6d 100644
--- a/lib/spack/spack/spec.py
+++ b/lib/spack/spack/spec.py
@@ -1117,6 +1117,18 @@ class Spec(object):
self._dependencies[spec.name] = dspec
spec._dependents[self.name] = dspec
+ def _add_default_platform(self):
+ """If a spec has an os or a target and no platform, give it
+ the default platform.
+
+ This is private because it is used by the parser -- it's not
+ expected to be used outside of ``spec.py``.
+
+ """
+ arch = self.architecture
+ if arch and not arch.platform and (arch.os or arch.target):
+ self._set_architecture(platform=spack.architecture.platform().name)
+
#
# Public interface
#
@@ -4053,14 +4065,6 @@ class SpecParser(spack.parse.Parser):
except spack.parse.ParseError as e:
raise SpecParseError(e)
- # If the spec has an os or a target and no platform, give it
- # the default platform
- platform_default = spack.architecture.platform().name
- for spec in specs:
- for s in spec.traverse():
- if s.architecture and not s.architecture.platform and \
- (s.architecture.os or s.architecture.target):
- s._set_architecture(platform=platform_default)
return specs
def spec_from_file(self):
@@ -4192,6 +4196,7 @@ class SpecParser(spack.parse.Parser):
else:
break
+ spec._add_default_platform()
return spec
def variant(self, name=None):