PackageBase.detect_dev_src_change: speed up (#48618)
This commit is contained in:
parent
31a1b2fd6c
commit
70df460fa7
@ -75,7 +75,6 @@
|
|||||||
"install_tree",
|
"install_tree",
|
||||||
"is_exe",
|
"is_exe",
|
||||||
"join_path",
|
"join_path",
|
||||||
"last_modification_time_recursive",
|
|
||||||
"library_extensions",
|
"library_extensions",
|
||||||
"mkdirp",
|
"mkdirp",
|
||||||
"partition_path",
|
"partition_path",
|
||||||
@ -1470,15 +1469,36 @@ def set_executable(path):
|
|||||||
|
|
||||||
|
|
||||||
@system_path_filter
|
@system_path_filter
|
||||||
def last_modification_time_recursive(path):
|
def recursive_mtime_greater_than(path: str, time: float) -> bool:
|
||||||
path = os.path.abspath(path)
|
"""Returns true if any file or dir recursively under `path` has mtime greater than `time`."""
|
||||||
times = [os.stat(path).st_mtime]
|
# use bfs order to increase likelihood of early return
|
||||||
times.extend(
|
queue: Deque[str] = collections.deque()
|
||||||
os.lstat(os.path.join(root, name)).st_mtime
|
|
||||||
for root, dirs, files in os.walk(path)
|
if os.stat(path).st_mtime > time:
|
||||||
for name in dirs + files
|
return True
|
||||||
)
|
|
||||||
return max(times)
|
while queue:
|
||||||
|
current = queue.popleft()
|
||||||
|
|
||||||
|
try:
|
||||||
|
entries = os.scandir(current)
|
||||||
|
except OSError:
|
||||||
|
continue
|
||||||
|
|
||||||
|
with entries:
|
||||||
|
for entry in entries:
|
||||||
|
try:
|
||||||
|
st = entry.stat(follow_symlinks=False)
|
||||||
|
except OSError:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if st.st_mtime > time:
|
||||||
|
return True
|
||||||
|
|
||||||
|
if entry.is_dir(follow_symlinks=False):
|
||||||
|
queue.append(entry.path)
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
@system_path_filter
|
@system_path_filter
|
||||||
|
@ -1099,14 +1099,14 @@ def update_external_dependencies(self, extendee_spec=None):
|
|||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def detect_dev_src_change(self):
|
def detect_dev_src_change(self) -> bool:
|
||||||
"""
|
"""
|
||||||
Method for checking for source code changes to trigger rebuild/reinstall
|
Method for checking for source code changes to trigger rebuild/reinstall
|
||||||
"""
|
"""
|
||||||
dev_path_var = self.spec.variants.get("dev_path", None)
|
dev_path_var = self.spec.variants.get("dev_path", None)
|
||||||
_, record = spack.store.STORE.db.query_by_spec_hash(self.spec.dag_hash())
|
_, record = spack.store.STORE.db.query_by_spec_hash(self.spec.dag_hash())
|
||||||
mtime = fsys.last_modification_time_recursive(dev_path_var.value)
|
assert dev_path_var and record, "dev_path variant and record must be present"
|
||||||
return mtime > record.installation_time
|
return fsys.recursive_mtime_greater_than(dev_path_var.value, record.installation_time)
|
||||||
|
|
||||||
def all_urls_for_version(self, version: StandardVersion) -> List[str]:
|
def all_urls_for_version(self, version: StandardVersion) -> List[str]:
|
||||||
"""Return all URLs derived from version_urls(), url, urls, and
|
"""Return all URLs derived from version_urls(), url, urls, and
|
||||||
|
Loading…
Reference in New Issue
Block a user