Skip to content

Commit

Permalink
Merge pull request #242 from climbfuji/default_builddir_from_config
Browse files Browse the repository at this point in the history
dtc/develop: update logic around builddir (ccpp_prebuild.py) / basedir (metadata2html.py)
  • Loading branch information
climbfuji committed Nov 27, 2019
2 parents 6da7808 + b9ff247 commit f7ae56d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
9 changes: 8 additions & 1 deletion scripts/ccpp_prebuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
parser.add_argument('--debug', action='store_true', help='enable debugging output', default=False)
parser.add_argument('--static', action='store_true', help='enable a static build for a given suite definition file', default=False)
parser.add_argument('--suites', action='store', help='suite definition files to use (comma-separated, for static build only, without path)', default='')
parser.add_argument('--builddir', action='store', help='relative path to CCPP build directory', required=False, default='.')
parser.add_argument('--builddir', action='store', help='relative path to CCPP build directory', required=False, default=None)

# BASEDIR is the current directory where this script is executed
BASEDIR = os.getcwd()
Expand Down Expand Up @@ -71,6 +71,13 @@ def import_config(configfile, builddir):
sys.path.append(configpath)
ccpp_prebuild_config = importlib.import_module(configmodule)

# If the build directory for running ccpp_prebuild.py is not
# specified as command line argument, use value from config
if not builddir:
builddir = os.path.join(BASEDIR, ccpp_prebuild_config.DEFAULT_BUILD_DIR)
logging.info('Build directory not specified on command line, ' + \
'use "{}" from CCPP prebuild config'.format(ccpp_prebuild_config.DEFAULT_BUILD_DIR))

# Definitions in host-model dependent CCPP prebuild config script
config['variable_definition_files'] = ccpp_prebuild_config.VARIABLE_DEFINITION_FILES
config['scheme_files'] = ccpp_prebuild_config.SCHEME_FILES
Expand Down
18 changes: 10 additions & 8 deletions scripts/metadata2html.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
help='path to CCPP prebuild configuration file')
method.add_argument('--metafile', '-m', action='store',
help='name of metadata file to convert (requires -o)')
parser.add_argument('--basedir', '-b', action='store',
help='relative path to CCPP directory',
required=False, default='.')
parser.add_argument('--outputdir', '-o', action='store',
help='directory where to write the html files',
required='--metafile' in sys.argv or '-m' in sys.argv)
Expand All @@ -41,11 +38,10 @@ def parse_arguments():
args = parser.parse_args()
config = args.config
filename = args.metafile
basedir = args.basedir
outdir = args.outputdir
return (config, filename, outdir, basedir)
return (config, filename, outdir)

def import_config(configfile, basedir, logger):
def import_config(configfile, logger):
"""Import the configuration from a given configuration file"""

if not os.path.isfile(configfile):
Expand All @@ -58,6 +54,12 @@ def import_config(configfile, basedir, logger):
sys.path.append(configpath)
ccpp_prebuild_config = importlib.import_module(configmodule)

# Get the base directory for running metadata2html.py from
# the default build directory value in the CCPP prebuild config
basedir = os.path.join(os.getcwd(), ccpp_prebuild_config.DEFAULT_BUILD_DIR)
logger.info('Relative path to CCPP directory from CCPP prebuild config: {}'.format(
ccpp_prebuild_config.DEFAULT_BUILD_DIR))

config = {}
# Definitions in host-model dependent CCPP prebuild config script
config['variable_definition_files'] = ccpp_prebuild_config.VARIABLE_DEFINITION_FILES
Expand Down Expand Up @@ -106,9 +108,9 @@ def main():
logger = init_log('metadata2html')
set_log_level(logger, logging.INFO)
# Convert metadata file
(configfile, filename, outdir, basedir) = parse_arguments()
(configfile, filename, outdir) = parse_arguments()
if configfile:
config = import_config(configfile, basedir, logger)
config = import_config(configfile, logger)
filenames = get_metadata_files_from_config(config, logger)
outdir = get_output_directory_from_config(config, logger)
for filename in filenames:
Expand Down

0 comments on commit f7ae56d

Please sign in to comment.