diff options
-rw-r--r-- | etc/spack/defaults/config.yaml | 3 | ||||
-rw-r--r-- | lib/spack/spack/spec.py | 23 | ||||
-rw-r--r-- | lib/spack/spack/test/directory_layout.py | 8 | ||||
-rw-r--r-- | lib/spack/spack/test/spec_semantics.py | 42 |
4 files changed, 70 insertions, 6 deletions
diff --git a/etc/spack/defaults/config.yaml b/etc/spack/defaults/config.yaml index b6a09a7738..c7dfeb58b3 100644 --- a/etc/spack/defaults/config.yaml +++ b/etc/spack/defaults/config.yaml @@ -22,6 +22,9 @@ config: template_dirs: - $spack/templates + # default directory layout + directory_layout: "${ARCHITECTURE}/${COMPILERNAME}-${COMPILERVER}/${PACKAGE}-${VERSION}-${HASH}" + # Locations where different types of modules should be installed. module_roots: tcl: $spack/share/spack/modules diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py index 35ab59f76a..a88cb3f62a 100644 --- a/lib/spack/spack/spec.py +++ b/lib/spack/spack/spec.py @@ -2905,6 +2905,9 @@ class Spec(object): ${COMPILERFLAGS} Compiler flags ${OPTIONS} Options ${ARCHITECTURE} Architecture + ${PLATFORM} Platform + ${OS} Operating System + ${TARGET} Target ${SHA1} Dependencies 8-char sha1 prefix ${HASH:len} DAG hash with optional length specifier @@ -3062,12 +3065,22 @@ class Spec(object): elif named_str == 'OPTIONS': if self.variants: write(fmt % token_transform(str(self.variants)), '+') - elif named_str == 'ARCHITECTURE': + elif named_str in ["ARCHITECTURE", "PLATFORM", "TARGET", "OS"]: if self.architecture and str(self.architecture): - write( - fmt % token_transform(str(self.architecture)), - '=' - ) + if named_str == "ARCHITECTURE": + write( + fmt % token_transform(str(self.architecture)), + '=' + ) + elif named_str == "PLATFORM": + platform = str(self.architecture.platform) + write(fmt % token_transform(platform), '=') + elif named_str == "OS": + operating_sys = str(self.architecture.platform_os) + write(fmt % token_transform(operating_sys), '=') + elif named_str == "TARGET": + target = str(self.architecture.target) + write(fmt % token_transform(target), '=') elif named_str == 'SHA1': if self.dependencies: out.write(fmt % token_transform(str(self.dag_hash(7)))) diff --git a/lib/spack/spack/test/directory_layout.py b/lib/spack/spack/test/directory_layout.py index b166ea4eac..e5fb8c7a29 100644 --- a/lib/spack/spack/test/directory_layout.py +++ b/lib/spack/spack/test/directory_layout.py @@ -74,13 +74,19 @@ def test_yaml_directory_layout_parameters( # Test path_scheme arch, compiler, package7 = path_7.split('/') scheme_package7 = "${PACKAGE}-${VERSION}-${HASH:7}" - layout_package7 = YamlDirectoryLayout(str(tmpdir), path_scheme=scheme_package7) path_package7 = layout_package7.relative_path_for_spec(spec) assert(package7 == path_package7) + # Test separation of architecture + arch_scheme_package = "${PLATFORM}/${TARGET}/${OS}/${PACKAGE}/${VERSION}/${HASH:7}" # NOQA: ignore=E501 + layout_arch_package = YamlDirectoryLayout(str(tmpdir), + path_scheme=arch_scheme_package) + arch_path_package = layout_arch_package.relative_path_for_spec(spec) + assert(arch_path_package == spec.format(arch_scheme_package)) + # Ensure conflicting parameters caught with pytest.raises(InvalidDirectoryLayoutParametersError): YamlDirectoryLayout(str(tmpdir), diff --git a/lib/spack/spack/test/spec_semantics.py b/lib/spack/spack/test/spec_semantics.py index 03f77992c5..4ffb458765 100644 --- a/lib/spack/spack/test/spec_semantics.py +++ b/lib/spack/spack/test/spec_semantics.py @@ -720,3 +720,45 @@ class TestSpecSematics(object): with pytest.raises(ValueError): Spec('libelf foo') + + def test_spec_formatting(self): + spec = Spec("libelf cflags=-O2") + spec.concretize() + + # Since the default is the full spec see if the string rep of + # spec is the same as the output of spec.format() + # ignoring whitespace (though should we?) + assert str(spec) == spec.format().strip() + + # Testing named strings ie ${STRING} and whether we get + # the correct component + package_segments = [("${PACKAGE}", "name"), + ("${VERSION}", "versions"), + ("${COMPILER}", "compiler"), + ("${COMPILERFLAGS}", "compiler_flags"), + ("${OPTIONS}", "variants"), + ("${ARCHITECTURE}", "architecture")] + + compiler_segments = [("${COMPILERNAME}", "name"), + ("${COMPILERVER}", "versions")] + + architecture_segments = [("${PLATFORM}", "platform"), + ("${OS}", "platform_os"), + ("${TARGET}", "target")] + + for named_str, prop in package_segments: + expected = getattr(spec, prop, "") + actual = spec.format(named_str) + assert str(expected) == actual + + compiler = spec.compiler + for named_str, prop in compiler_segments: + expected = getattr(compiler, prop, "") + actual = spec.format(named_str) + assert str(expected) == actual + + arch = spec.architecture + for named_str, prop in architecture_segments: + expected = getattr(arch, prop, "") + actual = spec.format(named_str) + assert str(expected) == actual |