Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
zingale committed Feb 1, 2023
2 parents dec21f5 + d681314 commit d388832
Show file tree
Hide file tree
Showing 67 changed files with 1,190 additions and 1,698 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/check-ifdefs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: check ifdefs

on:
push:
branches:
- development
- main
pull_request:
branches:
- development

jobs:
check-ifdefs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Cache pip
uses: actions/cache@v3
with:
# this path is specific to Ubuntu
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Run check-ifdefs
run: |
python .github/workflows/check_ifdefs.py .github/workflows/good_defines.txt
109 changes: 109 additions & 0 deletions .github/workflows/check_ifdefs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#!/bin/env python

import re
import sys

from pathlib import Path


def find_source_files():
p = Path("./")
files = list(p.glob(r"**/*.cpp"))
files += list(p.glob(r"**/*.H"))
return files

def check_file(filename):

# this is a general check to see if we should further examine a line
if_general_re = re.compile(r"^(?:#if|#elif)", re.IGNORECASE|re.DOTALL)

# this checks something of the form "#ifdef NAME"
ifdef_re = re.compile(r"^#if[n]*def\s+([a-z_0-9]+)", re.IGNORECASE|re.DOTALL)

# this checks something of the form
# #if (NAME == X)
if_re = re.compile(r"^(?:#if|#elif)\s+[\(]?([a-z_0-9]+)", re.IGNORECASE|re.DOTALL)

# together these check something of the form
# #if defined(NAME1) || !defined(NAME2)
if_defined_re1 = re.compile(r"^(?:#if|#elif)\s+[!]?(?:defined)", re.IGNORECASE|re.DOTALL)
if_defined_re2 = re.compile(r"[!]?(?:defined)\s*[\(]?([a-z_0-9]+)[\)]?", re.IGNORECASE|re.DOTALL)

ierr = 0
defines = []

with open(filename) as cf:
for line in cf:
if if_general_re.search(line):

# check each of the patterns
if if_defined_re1.search(line):
g = if_defined_re2.findall(line)
defines += g
continue

if g := ifdef_re.search(line):
defines.append(g.group(1))
continue

if g := if_re.search(line):
defines.append(g.group(1))
continue


# if we made it here, then we didn't handle things
ierr = 1
print(f"unhandled, file: {filename} | {line}")

return ierr, set(defines)

if __name__ == "__main__":

good_defines_file = sys.argv[1]

# read in the list of good defines

good_defines = []
with open(good_defines_file) as gd:
for line in gd:
good_defines.append(line.strip())

all_defines = []
total_errors = 0
for f in find_source_files():
if "tmp_build_dir" in f.parts:
# skip generated files
continue
ierr, defines = check_file(f)
all_defines += defines
total_errors += ierr

# remove any header guards

defines = []
for d in all_defines:
if d.endswith("_H") or d.endswith("_H_"):
continue
if len(d) == 1 and d.isdigit():
continue
defines.append(d)

defines = sorted(set(defines))

print("found defines:")
for d in defines:
print(d)

# now check to make sure that all the defines we found are okay

invalid = []
for d in defines:
if d not in good_defines:
invalid.append(d)

if invalid or total_errors > 0:
if invalid:
print("\ninvalid defines:")
for bad in invalid:
print(bad)
sys.exit(1)
46 changes: 46 additions & 0 deletions .github/workflows/good_defines.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
AMREX_DEBUG
AMREX_PARTICLES
AMREX_SPACEDIM
AMREX_USE_CUDA
AMREX_USE_GPU
AMREX_USE_OMP
AUX_THERMO
AUX_UPDATE
BL_FORT_USE_LOWERCASE
BL_FORT_USE_UNDERSCORE
BL_FORT_USE_UPPERCASE
BL_LANG_FORT
BL_LAZY
BL_USE_SETBUF
CXX_MODEL_PARSER
DIFFUSION
DO_PROBLEM_POST_INIT
DO_PROBLEM_POST_RESTART
DO_PROBLEM_POST_SIMULATION
DO_PROBLEM_POST_TIMESTEP
GRAVITY
GR_GRAV
HYBRID_MOMENTUM
INTEGRATOR
MAESTRO_INIT
MHD
NAUX_NET
NEW_NETWORK_IMPLEMENTATION
NGROUPS
NONAKA_PLOT
NSE
NSE_NET
NSE_TABLE
RADIATION
RAD_INTERP
REACTIONS
ROTATION
SCREENING
SHOCK_VAR
SIMPLIFIED_SDC
SPONGE
STRANG
TRUE_SDC
WIN32
_OPENMP
__cplusplus
6 changes: 3 additions & 3 deletions Diagnostics/Sedov/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ Blocs := .

CASTRO_HOME := ../..

INCLUDE_LOCATIONS += $(AMREX_HOME)/Src/Extern/amrdata
include $(AMREX_HOME)/Src/Extern/amrdata/Make.package
vpathdir += $(AMREX_HOME)/Src/Extern/amrdata
#INCLUDE_LOCATIONS += $(AMREX_HOME)/Src/Extern/amrdata
#include $(AMREX_HOME)/Src/Extern/amrdata/Make.package
#vpathdir += $(AMREX_HOME)/Src/Extern/amrdata

include $(CASTRO_HOME)/Exec/Make.Castro

Expand Down
2 changes: 0 additions & 2 deletions Diagnostics/Sedov/Make.package
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
ca_f90EXE_sources += sedov_util.f90
CEXE_headers += Sedov_F.H
78 changes: 0 additions & 78 deletions Diagnostics/Sedov/Sedov_F.H

This file was deleted.

Loading

0 comments on commit d388832

Please sign in to comment.