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
5 changes: 2 additions & 3 deletions cmake/ccpp_capgen.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ function(ccpp_capgen)
list(APPEND CCPP_CAPGEN_CMD_LIST "--output-root" "${arg_OUTPUT_ROOT}")
endif()
if(DEFINED arg_VERBOSITY)
string(REPEAT "--verbose" ${arg_VERBOSITY} VERBOSE_PARAMS_SEPERATED)
separate_arguments(VERBOSE_PARAMS UNIX_COMMAND "${VERBOSE_PARAMS_SEPERATED}")
string(REPEAT "--verbose " ${arg_VERBOSITY} VERBOSE_PARAMS_SEPARATED)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for fixing this!

separate_arguments(VERBOSE_PARAMS UNIX_COMMAND "${VERBOSE_PARAMS_SEPARATED}")
list(APPEND CCPP_CAPGEN_CMD_LIST ${VERBOSE_PARAMS})
endif()

Expand Down Expand Up @@ -126,4 +126,3 @@ function(ccpp_datafile)
string(REPLACE "," ";" CCPP_CAPS_LIST ${CCPP_CAPS}) # Convert "," separated list from python back to ";" separated list for CMake.
set(CCPP_CAPS_LIST "${CCPP_CAPS_LIST}" PARENT_SCOPE)
endfunction()

23 changes: 14 additions & 9 deletions scripts/ccpp_capgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,26 +93,29 @@ def delete_pathnames_from_file(capfile, logger):
# end if

###############################################################################
def find_associated_fortran_file(filename):
def find_associated_fortran_file(filename, fortran_source_path):
###############################################################################
"Find the Fortran file associated with metadata file, <filename>"
"""Find the Fortran file associated with metadata file, <filename>.
Fortran files should be in <fortran_source_path>.
"""
fort_filename = None
lastdot = filename.rfind('.')
##XXgoldyXX: Should we check to make sure <filename> ends in '.meta.'?
if lastdot < 0:
base = filename + '.'
base = os.path.basename(filename + '.')
else:
base = filename[0:lastdot+1]
base = os.path.basename(filename[0:lastdot+1])
# end if
for extension in _FORTRAN_FILENAME_EXTENSIONS:
test_name = base + extension
test_name = os.path.join(fortran_source_path, base + extension)
if os.path.exists(test_name):
fort_filename = test_name
break
# end if
# end for
if fort_filename is None:
raise CCPPError("Cannot find Fortran file associated with {}".format(filename))
emsg = f"Cannot find Fortran file associated with '{filename}'."
emsg += f"\nfortran_src_path = '{fortran_source_path}'"
raise CCPPError(emsg)
# end if
return fort_filename

Expand Down Expand Up @@ -493,7 +496,8 @@ def parse_host_model_files(host_filenames, host_name, run_env,
logger.info('Reading host model data from {}'.format(filename))
# parse metadata file
mtables = parse_metadata_file(filename, known_ddts, run_env)
fort_file = find_associated_fortran_file(filename)
fortran_source_path = mtables[0].fortran_source_path
fort_file = find_associated_fortran_file(filename, fortran_source_path)
ftables, _ = parse_fortran_file(fort_file, run_env)
# Check Fortran against metadata (will raise an exception on error)
mheaders = list()
Expand Down Expand Up @@ -550,7 +554,8 @@ def parse_scheme_files(scheme_filenames, run_env, skip_ddt_check=False,
# parse metadata file
mtables = parse_metadata_file(filename, known_ddts, run_env,
skip_ddt_check=skip_ddt_check)
fort_file = find_associated_fortran_file(filename)
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)
# Check Fortran against metadata (will raise an exception on error)
mheaders = list()
Expand Down
24 changes: 21 additions & 3 deletions scripts/metadata_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
relative_path = <relative path>
dependencies = <dependencies>
module = <module name> # only needed if module name differs from filename
source_path = <relative source directory of Fortran source (if different)>
dynamic_constituent_routine = <routine name>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops! I know this is unrelated to your changes, but can you remove this residual dynamic constituents line left by me?


[ccpp-arg-table]
Expand Down Expand Up @@ -357,19 +358,20 @@ class MetadataTable():
__table_start = re.compile(r"(?i)\s*\[\s*ccpp-table-properties\s*\]")

def __init__(self, run_env, table_name_in=None, table_type_in=None,
dependencies=None, relative_path=None,
dependencies=None, relative_path=None, source_path=None,
known_ddts=None, var_dict=None, module=None, parse_object=None,
skip_ddt_check=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> and <relative_path> are
also stored.
if <parse_object> is None, <dependencies>, <relative_path>, and
are <source_path> are also stored.
If <var_dict> and / or module are passed (not allowed with
<parse_object), then a single MetadataSection is added with
that information.
"""
self.__pobj = parse_object
self.__dependencies = dependencies
self.__fortran_src_path = source_path
self.__module_name = module
self.__relative_path = relative_path
self.__sections = []
Expand Down Expand Up @@ -428,6 +430,10 @@ def __init__(self, run_env, table_name_in=None, table_type_in=None,
perr = "module not allowed as argument when reading file"
raise ParseInternalError(perr)
# end if
if source_path is not None:
perr = "source_path not allowed as argument when reading file"
raise ParseInternalError(perr)
# end if
if known_ddts is None:
known_ddts = []
# end if
Expand All @@ -441,6 +447,9 @@ def __init__(self, run_env, table_name_in=None, table_type_in=None,
for ind, dep in enumerate(self.__dependencies):
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)
# end if
# end if

def __init_from_file(self, known_ddts, run_env, skip_ddt_check=False):
Expand All @@ -451,6 +460,8 @@ def __init_from_file(self, known_ddts, run_env, skip_ddt_check=False):
skip_rest_of_section = False
self.__dependencies = [] # Default is no dependencies
self.__module_name = self.__pobj.default_module_name()
my_dirname = os.path.dirname(self.__pobj.filename)
self.__fortran_src_path = my_dirname
# Process lines until the end of the file or start of the next table.
while ((curr_line is not None) and
(not MetadataTable.table_start(curr_line))):
Expand Down Expand Up @@ -496,6 +507,8 @@ def __init_from_file(self, known_ddts, run_env, skip_ddt_check=False):
self.__module_name = value
elif key == 'relative_path':
self.__relative_path = value
elif key == 'source_path':
self.__fortran_src_path = os.path.join(my_dirname, value)
else:
tok_type = "metadata table start property"
self.__pobj.add_syntax_err(tok_type, token=key)
Expand Down Expand Up @@ -583,6 +596,11 @@ def relative_path(self):
"""Return the relative path for the table's dependencies"""
return self.__relative_path

@property
def fortran_source_path(self):
"""Return the Fortran source path for this table"""
return self.__fortran_src_path

@property
def run_env(self):
"""Return this table's CCPPFrameworkEnv object"""
Expand Down
21 changes: 19 additions & 2 deletions test/capgen_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,26 @@ set(HOST "test_host")
set(CCPP_CAP_FILES "${CMAKE_CURRENT_BINARY_DIR}/ccpp")

# Create lists for Fortran and meta data files from file names
list(TRANSFORM SCHEME_FILES APPEND ".F90" OUTPUT_VARIABLE SCHEME_FORTRAN_FILES)
# Fortran files are not all in one directory
set(SCHEME_FORTRAN_FILES "")
foreach(sfile ${SCHEME_FILES})
find_file(fort_file "${sfile}.F90" NO_CACHE
HINTS ${CMAKE_CURRENT_SOURCE_DIR}
HINTS ${CMAKE_CURRENT_SOURCE_DIR}/source_dir1
HINTS ${CMAKE_CURRENT_SOURCE_DIR}/source_dir2)
list(APPEND SCHEME_FORTRAN_FILES ${fort_file})
unset(fort_file)
endforeach()
list(TRANSFORM SCHEME_FILES APPEND ".meta" OUTPUT_VARIABLE SCHEME_META_FILES)
list(TRANSFORM SUITE_SCHEME_FILES APPEND ".F90" OUTPUT_VARIABLE SUITE_SCHEME_FORTRAN_FILES)
set(SUITE_SCHEME_FORTRAN_FILES "")
foreach(sfile ${SUITE_SCHEME_FILES})
find_file(fort_file "${sfile}.F90" NO_CACHE
HINTS ${CMAKE_CURRENT_SOURCE_DIR}
HINTS ${CMAKE_CURRENT_SOURCE_DIR}/source_dir1
HINTS ${CMAKE_CURRENT_SOURCE_DIR}/source_dir2)
list(APPEND SUITE_SCHEME_FORTRAN_FILES ${fort_file})
unset(fort_file)
endforeach()
list(TRANSFORM SUITE_SCHEME_FILES APPEND ".meta" OUTPUT_VARIABLE SUITE_SCHEME_META_FILES)
list(TRANSFORM HOST_FILES APPEND ".F90" OUTPUT_VARIABLE CAPGEN_HOST_FORTRAN_FILES)
list(TRANSFORM HOST_FILES APPEND ".meta" OUTPUT_VARIABLE CAPGEN_HOST_METADATA_FILES)
Expand Down
1 change: 1 addition & 0 deletions test/capgen_test/environ_conditions.meta
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[ccpp-table-properties]
name = environ_conditions
type = scheme
source_path = source_dir1
[ccpp-arg-table]
name = environ_conditions_run
type = scheme
Expand Down
1 change: 1 addition & 0 deletions test/capgen_test/temp_set.meta
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[ccpp-table-properties]
name = temp_set
type = scheme
source_path = source_dir2
[ccpp-arg-table]
name = temp_set_run
type = scheme
Expand Down