Yaml spec parsing corner case (#17101)

* Catch yaml filename corner case in spec parser

* improved regex and remove redundant error checking

Co-authored-by: Gregory Becker <becker33@llnl.gov>
This commit is contained in:
psakievich 2020-06-16 12:27:33 -06:00 committed by GitHub
parent e816b66c94
commit dc31afe67d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 7 deletions

View File

@ -3945,7 +3945,8 @@ def __init__(self):
# Filenames match before identifiers, so no initial filename
# component is parsed as a spec (e.g., in subdir/spec.yaml)
(r'[/\w.-]+\.yaml[^\b]*', lambda scanner, v: self.token(FILE, v)),
(r'[/\w.-]*/[/\w/-]+\.yaml[^\b]*',
lambda scanner, v: self.token(FILE, v)),
# Hash match after filename. No valid filename can be a hash
# (files end w/.yaml), but a hash can match a filename prefix.
@ -4096,11 +4097,6 @@ def spec_from_file(self):
"""
path = self.token.value
# don't treat builtin.yaml, builtin.yaml-cpp, etc. as filenames
if re.match(spec_id_re + '$', path):
self.push_tokens([spack.parse.Token(ID, self.token.value)])
return None
# Special case where someone omits a space after a filename. Consider:
#
# libdwarf^/some/path/to/libelf.yamllibdwarf ^../../libelf.yaml
@ -4112,7 +4108,6 @@ def spec_from_file(self):
raise SpecFilenameError(
"Spec filename must end in .yaml: '{0}'".format(path))
# if we get here, we're *finally* interpreting path as a filename
if not os.path.exists(path):
raise NoSuchSpecFileError("No such spec file: '{0}'".format(path))

View File

@ -188,6 +188,32 @@ def test_full_specs(self):
" ^_openmpi@1.2:1.4,1.6%intel@12.1~qt_4 debug=2"
" ^stackwalker@8.1_1e arch=test-redhat6-x86")
def test_yaml_specs(self):
self.check_parse(
"yaml-cpp@0.1.8%intel@12.1"
" ^boost@3.1.4")
tempspec = r"builtin.yaml-cpp%gcc"
self.check_parse(
tempspec.strip("builtin."),
spec=tempspec)
tempspec = r"testrepo.yaml-cpp%gcc"
self.check_parse(
tempspec.strip("testrepo."),
spec=tempspec)
tempspec = r"builtin.yaml-cpp@0.1.8%gcc"
self.check_parse(
tempspec.strip("builtin."),
spec=tempspec)
tempspec = r"builtin.yaml-cpp@0.1.8%gcc@7.2.0"
self.check_parse(
tempspec.strip("builtin."),
spec=tempspec)
tempspec = r"builtin.yaml-cpp@0.1.8%gcc@7.2.0" \
r" ^boost@3.1.4"
self.check_parse(
tempspec.strip("builtin."),
spec=tempspec)
def test_canonicalize(self):
self.check_parse(
"mvapich_foo"