-
Notifications
You must be signed in to change notification settings - Fork 117
Creates hashes for different compliers/setups #981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
sbryngelson
wants to merge
7
commits into
MFlowCode:master
Choose a base branch
from
sbryngelson:fix-hashes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
04ae726
better hashes
sbryngelson 4952826
fix lint
sbryngelson 524fd70
Update toolchain/mfc/build.py
sbryngelson 004dd1e
Update toolchain/mfc/build.py
sbryngelson d42a0f7
Update toolchain/mfc/build.py
sbryngelson a7e7d19
Update toolchain/mfc/build.py
sbryngelson 4a57558
Update .pr_agent.toml
sbryngelson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,4 +1,8 @@ | ||||||
import os, typing, hashlib, dataclasses | ||||||
import os, typing, dataclasses | ||||||
import re | ||||||
import pathlib | ||||||
import subprocess | ||||||
import tempfile | ||||||
|
||||||
from .case import Case | ||||||
from .printer import cons | ||||||
|
@@ -32,19 +36,82 @@ def compute(self) -> typing.Set: | |||||
def __hash__(self) -> int: | ||||||
return hash(self.name) | ||||||
|
||||||
def get_compiler_info(self) -> str: | ||||||
compiler = "unknown" | ||||||
with tempfile.TemporaryDirectory() as build_dir: | ||||||
try: | ||||||
subprocess.run( | ||||||
["cmake", "-B", build_dir, "-S", ".", "-DCMAKE_VERBOSE_MAKEFILE=ON"], | ||||||
check=True, | ||||||
stdout=subprocess.DEVNULL, | ||||||
stderr=subprocess.DEVNULL, | ||||||
) | ||||||
except (subprocess.CalledProcessError, FileNotFoundError): | ||||||
return "unknown" | ||||||
|
||||||
cache = pathlib.Path(build_dir) / "CMakeCache.txt" | ||||||
if not cache.exists(): | ||||||
return "unknown" | ||||||
|
||||||
pat = re.compile(r"CMAKE_.*_COMPILER:FILEPATH=(.+)", re.IGNORECASE) | ||||||
compiler_name = "" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The regex pattern is compiled inside the method on every call. Consider moving this to module level or class level as a constant to avoid recompilation.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
|
||||||
for line in cache.read_text(errors="ignore").splitlines(): | ||||||
if "fortran" in line.lower(): | ||||||
sbryngelson marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
m = pat.search(line) | ||||||
if m: | ||||||
compiler_name = pathlib.Path(m.group(1).strip()).name | ||||||
break | ||||||
|
||||||
name = compiler_name.lower() | ||||||
if "gfortran" in name: | ||||||
compiler = "gnu" | ||||||
elif "ifort" in name or "ifx" in name: | ||||||
compiler = "intel" | ||||||
elif "nvfortran" in name: | ||||||
compiler = "nvhpc" | ||||||
elif name == "ftn" or "cray" in name: | ||||||
compiler = "cray" | ||||||
elif "pgfortran" in name: | ||||||
compiler = "pgi" | ||||||
elif "clang" in name: | ||||||
compiler = "clang" | ||||||
elif "flang" in name: | ||||||
compiler = "flang" | ||||||
return compiler | ||||||
|
||||||
def get_slug(self, case: Case ) -> str: | ||||||
if self.isDependency: | ||||||
return self.name | ||||||
|
||||||
m = hashlib.sha256() | ||||||
m.update(self.name.encode()) | ||||||
m.update(CFG().make_slug().encode()) | ||||||
m.update(case.get_fpp(self, False).encode()) | ||||||
# Start with target name | ||||||
parts = [self.name] | ||||||
|
||||||
# Add active configuration options | ||||||
cfg = CFG() | ||||||
cfg_parts = [] | ||||||
for key, value in sorted(cfg.items()): | ||||||
if value: # Only include enabled options | ||||||
cfg_parts.append(key) | ||||||
sbryngelson marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
if cfg_parts: | ||||||
parts.append('-'.join(cfg_parts)) | ||||||
|
||||||
# Add chemistry info if enabled | ||||||
if case.params.get('chemistry', 'F') == 'T': | ||||||
m.update(case.get_cantera_solution().name.encode()) | ||||||
parts.append(f"chem-{case.get_cantera_solution().name}") | ||||||
|
||||||
# Add case optimization if enabled | ||||||
if case.params.get('case_optimization', False): | ||||||
parts.append('opt') | ||||||
|
||||||
# Add compiler identifier | ||||||
compiler_id = self.get_compiler_info() | ||||||
if compiler_id: | ||||||
sbryngelson marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
parts.append(f"fc-{compiler_id}") | ||||||
|
||||||
return m.hexdigest()[:10] | ||||||
# Join all parts with underscores | ||||||
return '_'.join(parts) | ||||||
|
||||||
# Get path to directory that will store the build files | ||||||
def get_staging_dirpath(self, case: Case ) -> str: | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.