Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/capgen_unit_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@ jobs:

- name: Run Fortran to metadata test
run: cd test && ./test_fortran_to_metadata.sh

- name: Run offline metadata parser test
run: cd test && ./test_offline_metadata_checker.sh
5 changes: 3 additions & 2 deletions scripts/ccpp_capgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ def parse_host_model_files(host_filenames, host_name, run_env,

###############################################################################
def parse_scheme_files(scheme_filenames, run_env, skip_ddt_check=False,
known_ddts=list()):
known_ddts=list(), relative_source_path=False):
###############################################################################
"""
Gather information from scheme files (e.g., init, run, and finalize
Expand All @@ -553,7 +553,8 @@ def parse_scheme_files(scheme_filenames, run_env, skip_ddt_check=False,
logger.info('Reading CCPP schemes from {}'.format(filename))
# parse metadata file
mtables = parse_metadata_file(filename, known_ddts, run_env,
skip_ddt_check=skip_ddt_check)
skip_ddt_check=skip_ddt_check,
relative_source_path=relative_source_path)
fortran_source_path = mtables[0].fortran_source_path
fort_file = find_associated_fortran_file(filename, fortran_source_path)
ftables, additional_routines = parse_fortran_file(fort_file, run_env)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def compare_fortran_and_metadata(scheme_directory, run_env):
## Check for files
metadata_files = find_files_to_compare(scheme_directory)
# Perform checks
parse_scheme_files(metadata_files, run_env, skip_ddt_check=True)
parse_scheme_files(metadata_files, run_env, skip_ddt_check=True, relative_source_path=True)

def parse_command_line(arguments, description):
"""Parse command-line arguments"""
Expand Down
11 changes: 7 additions & 4 deletions scripts/metadata_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def _parse_config_line(line, context):

########################################################################

def parse_metadata_file(filename, known_ddts, run_env, skip_ddt_check=False):
def parse_metadata_file(filename, known_ddts, run_env, skip_ddt_check=False, relative_source_path=False):
"""Parse <filename> and return list of parsed metadata tables"""
# Read all lines of the file at once
meta_tables = []
Expand All @@ -200,7 +200,8 @@ def parse_metadata_file(filename, known_ddts, run_env, skip_ddt_check=False):
if MetadataTable.table_start(curr_line):
new_table = MetadataTable(run_env, parse_object=parse_obj,
known_ddts=known_ddts,
skip_ddt_check=skip_ddt_check)
skip_ddt_check=skip_ddt_check,
relative_source_path=relative_source_path)
ntitle = new_table.table_name
if ntitle not in table_titles:
meta_tables.append(new_table)
Expand Down Expand Up @@ -360,7 +361,7 @@ class MetadataTable():
def __init__(self, run_env, table_name_in=None, table_type_in=None,
dependencies=None, dependencies_path=None, source_path=None,
known_ddts=None, var_dict=None, module=None, parse_object=None,
skip_ddt_check=False):
skip_ddt_check=False, relative_source_path=False):
"""Initialize a MetadataTable, either with a name, <table_name_in>, and
type, <table_type_in>, or with information from a file (<parse_object>).
if <parse_object> is None, <dependencies>, <dependencies_path>, and
Expand Down Expand Up @@ -448,7 +449,9 @@ def __init__(self, run_env, table_name_in=None, table_type_in=None,
self.__dependencies[ind] = os.path.abspath(os.path.join(path, dep))
# end for
if self.__fortran_src_path:
self.__fortran_src_path = os.path.join(path, self.__fortran_src_path)
if not relative_source_path:
self.__fortran_src_path = os.path.join(path, self.__fortran_src_path)
# end if
# end if
# end if

Expand Down
35 changes: 35 additions & 0 deletions test/test_offline_metadata_checker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#! /bin/bash

## Relevant directories and file paths
root_dir="$(cd $(dirname ${0}); pwd -P)"
script_dir="$(dirname ${root_dir})/scripts/fortran_tools"
test_dir="$(dirname ${root_dir})/test/advection_test"
offline_script="${script_dir}/offline_check_fortran_vs_metadata.py"
relative_path="capgen_test"

# Run the script
${offline_script} --directory ${test_dir}
res=$?

retval=0
if [ ${res} -ne 0 ]; then
echo "FAIL: offline_check_fortran_vs_metadata.py exited with error ${res} while checking ${test_dir}"
retval=${res}
exit ${retval}
else
echo "PASS"
fi

# Run the script again with a relative path
cd ${root_dir}
${offline_script} --directory ${relative_path}
res=$?

retval=0
if [ ${res} -ne 0 ]; then
echo "FAIL: offline_check_fortran_vs_metadata.py exited with error ${res} while checking ${relative_path}"
retval=${res}
else
echo "PASS"
fi
exit ${retval}