Skip to content

Commit

Permalink
ci(msvs): workflow to verify msvs project files are complete (#1365)
Browse files Browse the repository at this point in the history
* ci(msvs): workflow to verify msvs project files are complete

* add check for srcbmi and cleanup

* fix renamed reference

* implement suggested change, run black and isort
  • Loading branch information
langevin-usgs authored Sep 24, 2023
1 parent 48eb172 commit 2bcbd48
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
68 changes: 68 additions & 0 deletions .github/common/msvs_vfproj_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import xml.etree.ElementTree as ET
from pathlib import Path


def get_source_files(src_folder):
p = Path(".")
src_files = []
print(f"Processing {src_folder} folder")
ftypes = ("*.[fF]9[05]", "*.inc")
src_files = []
for ft in ftypes:
src_files.extend(p.glob(f"{src_folder}/**/{ft}"))
return src_files


def get_msvs_files(vfproj_file):
print(f"Processing {vfproj_file}")
tree = ET.parse(vfproj_file)
root = tree.getroot()
msvs_files = []
for f in root.iter("File"):
s = f.attrib["RelativePath"]
s = s.replace("\\", "/")
s = s.replace("../", "")
fpath = Path(s)
msvs_files.append(fpath)
return msvs_files


def check_files(name, src_files, msvs_files):
print(
f"Verifying {name} files referenced in msvs project files are in src folder..."
)
s, m = set(src_files), set(msvs_files)
diff = s ^ m
from pprint import pformat

assert not any(diff), (
f"{name} src files don't match msvs project file\n"
f"=> symmetric difference:\n{pformat(diff)}\n"
f"=> src - msvs:\n{pformat(s - m)}\n"
f"=> msvs - src:\n{pformat(m - s)}\n"
"Check to make sure msvs project file is consistent with source files."
)


def check_mf6():
# get list of source files and files referenced in msvs project files
src_files = get_source_files("src")
msvs_files = []
for vfproj in ["./msvs/mf6core.vfproj", "./msvs/mf6.vfproj"]:
msvs_files.extend(get_msvs_files(vfproj))
check_files("MF6", src_files, msvs_files)


def check_bmi():
# get list of source files and files referenced in msvs project files
src_files = get_source_files("srcbmi")
msvs_files = []
for vfproj in ["./msvs/mf6bmi.vfproj"]:
msvs_files.extend(get_msvs_files(vfproj))
check_files("BMI", src_files, msvs_files)


if __name__ == "__main__":
check_mf6()
check_bmi()
print("msvs project (vfproj) files appear up-to-date...")
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ jobs:
- name: Check Fortran source formatting
run: python .github/common/fortran_format_check.py

- name: Check msvs project files
run: python .github/common/msvs_vfproj_check.py

build:
name: Build
runs-on: ubuntu-22.04
Expand Down
2 changes: 1 addition & 1 deletion msvs/mf6core.vfproj
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
<File RelativePath="..\src\Model\ModelUtilities\Xt3dAlgorithm.f90"/>
<File RelativePath="..\src\Model\ModelUtilities\Xt3dInterface.f90"/></Filter>
<Filter Name="TransportModel">
<File RelativePath="..\src\Model\tsp1.f90"/></Filter>
<File RelativePath="..\src\Model\TransportModel\tsp1.f90"/></Filter>
<File RelativePath="..\src\Model\BaseModel.f90"/>
<File RelativePath="..\src\Model\ExplicitModel.f90"/>
<File RelativePath="..\src\Model\NumericalModel.f90"/>
Expand Down

0 comments on commit 2bcbd48

Please sign in to comment.