6363# DB version. This is stuck in the DB file to track changes in format.
6464# Increment by one when the database format changes.
6565# Versions before 5 were not integers.
66- _db_version = Version ("6 " )
66+ _db_version = Version ("7 " )
6767
6868# For any version combinations here, skip reindex when upgrading.
6969# Reindexing can take considerable time and is not always necessary.
7575 # version is saved to disk the first time the DB is written.
7676 (Version ("0.9.3" ), Version ("5" )),
7777 (Version ("5" ), Version ("6" )),
78+ (Version ("6" ), Version ("7" )),
7879]
7980
8081# Default timeout for spack database locks in seconds or None (no timeout).
107108]
108109
109110
111+ def reader (version ):
112+ reader_cls = {
113+ Version ("5" ): spack .spec .SpecfileV1 ,
114+ Version ("6" ): spack .spec .SpecfileV3 ,
115+ Version ("7" ): spack .spec .SpecfileV4 ,
116+ }
117+ return reader_cls [version ]
118+
119+
110120def _now ():
111121 """Returns the time since the epoch"""
112122 return time .time ()
@@ -674,7 +684,7 @@ def _write_to_file(self, stream):
674684 except (TypeError , ValueError ) as e :
675685 raise sjson .SpackJSONError ("error writing JSON database:" , str (e ))
676686
677- def _read_spec_from_dict (self , hash_key , installs , hash = ht .dag_hash ):
687+ def _read_spec_from_dict (self , spec_reader , hash_key , installs , hash = ht .dag_hash ):
678688 """Recursively construct a spec from a hash in a YAML database.
679689
680690 Does not do any locking.
@@ -692,7 +702,7 @@ def _read_spec_from_dict(self, hash_key, installs, hash=ht.dag_hash):
692702 spec_dict [hash .name ] = hash_key
693703
694704 # Build spec from dict first.
695- spec = spack . spec . Spec .from_node_dict (spec_dict )
705+ spec = spec_reader .from_node_dict (spec_dict )
696706 return spec
697707
698708 def db_for_spec_hash (self , hash_key ):
@@ -732,7 +742,7 @@ def query_local_by_spec_hash(self, hash_key):
732742 with self .read_transaction ():
733743 return self ._data .get (hash_key , None )
734744
735- def _assign_dependencies (self , hash_key , installs , data ):
745+ def _assign_dependencies (self , spec_reader , hash_key , installs , data ):
736746 # Add dependencies from other records in the install DB to
737747 # form a full spec.
738748 spec = data [hash_key ].spec
@@ -742,7 +752,7 @@ def _assign_dependencies(self, hash_key, installs, data):
742752 spec_node_dict = spec_node_dict [spec .name ]
743753 if "dependencies" in spec_node_dict :
744754 yaml_deps = spec_node_dict ["dependencies" ]
745- for dname , dhash , dtypes , _ , virtuals in spack . spec . Spec . read_yaml_dep_specs (
755+ for dname , dhash , dtypes , _ , virtuals in spec_reader . read_specfile_dep_specs (
746756 yaml_deps
747757 ):
748758 # It is important that we always check upstream installations
@@ -799,6 +809,7 @@ def check(cond, msg):
799809
800810 # TODO: better version checking semantics.
801811 version = Version (db ["version" ])
812+ spec_reader = reader (version )
802813 if version > _db_version :
803814 raise InvalidDatabaseVersionError (_db_version , version )
804815 elif version < _db_version :
@@ -834,7 +845,7 @@ def invalid_record(hash_key, error):
834845 for hash_key , rec in installs .items ():
835846 try :
836847 # This constructs a spec DAG from the list of all installs
837- spec = self ._read_spec_from_dict (hash_key , installs )
848+ spec = self ._read_spec_from_dict (spec_reader , hash_key , installs )
838849
839850 # Insert the brand new spec in the database. Each
840851 # spec has its own copies of its dependency specs.
@@ -850,7 +861,7 @@ def invalid_record(hash_key, error):
850861 # Pass 2: Assign dependencies once all specs are created.
851862 for hash_key in data :
852863 try :
853- self ._assign_dependencies (hash_key , installs , data )
864+ self ._assign_dependencies (spec_reader , hash_key , installs , data )
854865 except MissingDependenciesError :
855866 raise
856867 except Exception as e :
0 commit comments