Skip to content

Commit

Permalink
unclutter project root dir: move .fips-gen.py to [cmake-binary-dir]/f…
Browse files Browse the repository at this point in the history
…ips-gen.py
  • Loading branch information
floooh committed Apr 13, 2018
1 parent 421f772 commit 3e3955e
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 28 deletions.
2 changes: 1 addition & 1 deletion cmake/fips_generators.cmake
Expand Up @@ -115,7 +115,7 @@ macro(fips_handle_generators target)
if (CurProjectHasCodeGen)
if (NOT TARGET ALL_GENERATE)
add_custom_target(ALL_GENERATE
COMMAND ${PYTHON} ${FIPS_PROJECT_DIR}/.fips-gen.py ${CMAKE_BINARY_DIR}/fips_codegen.yml
COMMAND ${PYTHON} ${CMAKE_BINARY_DIR}/fips-gen.py ${CMAKE_BINARY_DIR}/fips_codegen.yml
WORKING_DIRECTORY ${FIPS_PROJECT_DIR})
if (CurTargetDependencies)
add_dependencies(ALL_GENERATE ${CurTargetDependencies})
Expand Down
12 changes: 8 additions & 4 deletions mod/dep.py
Expand Up @@ -309,7 +309,7 @@ def gather_imports(fips_dir, proj_dir) :
return None

#-------------------------------------------------------------------------------
def write_imports(fips_dir, proj_dir, imported) :
def write_imports(fips_dir, proj_dir, cfg_name, imported) :
"""write the big imports map created with 'gather_imports'
to a .fips-imports.cmake file in the current project
Expand Down Expand Up @@ -421,14 +421,18 @@ def write_imports(fips_dir, proj_dir, imported) :
gen_dir = util.get_generators_dir(util.get_project_dir(fips_dir, imp_proj_name))
if gen_dir:
gen_search_paths += '"' + gen_dir + '",\n'
template.copy_template_file(fips_dir, proj_dir, '.fips-gen.py', { 'genpaths': gen_search_paths}, True)
proj_name = util.get_project_name_from_dir(proj_dir)
build_dir = util.get_build_dir(fips_dir, proj_name, cfg_name);
if not os.path.isdir(build_dir):
os.makedirs(build_dir)
template.copy_template_file(fips_dir, build_dir, 'fips-gen.py', { 'genpaths': gen_search_paths}, True)

#-------------------------------------------------------------------------------
def gather_and_write_imports(fips_dir, proj_dir) :
def gather_and_write_imports(fips_dir, proj_dir, cfg_name) :
"""first does and gather_imports, then a write_imports with the result"""
imports = gather_imports(fips_dir, proj_dir)
if imports is not None :
write_imports(fips_dir, proj_dir, imports)
write_imports(fips_dir, proj_dir, cfg_name, imports)
else :
log.error("project imports are incomplete, please run 'fips fetch'")

Expand Down
21 changes: 11 additions & 10 deletions mod/project.py
Expand Up @@ -62,7 +62,7 @@ def gen_project(fips_dir, proj_dir, cfg, force) :
"""private: generate build files for one config"""

proj_name = util.get_project_name_from_dir(proj_dir)
build_dir = util.get_build_dir(fips_dir, proj_name, cfg)
build_dir = util.get_build_dir(fips_dir, proj_name, cfg['name'])
defines = {}
defines['FIPS_USE_CCACHE'] = 'ON' if settings.get(proj_dir, 'ccache') else 'OFF'
defines['FIPS_AUTO_IMPORT'] = 'OFF' if dep.get_policy(proj_dir, 'no_auto_import') else 'ON'
Expand All @@ -73,6 +73,7 @@ def gen_project(fips_dir, proj_dir, cfg, force) :
do_it = force
if not os.path.isdir(build_dir) :
os.makedirs(build_dir)
if not os.path.isfile(build_dir + '/CMakeCache.txt'):
do_it = True
if do_it :
# if Ninja build tool and on Windows, need to copy
Expand Down Expand Up @@ -105,7 +106,7 @@ def gen(fips_dir, proj_dir, cfg_name) :
dep.fetch_imports(fips_dir, proj_dir)
proj_name = util.get_project_name_from_dir(proj_dir)
util.ensure_valid_project_dir(proj_dir)
dep.gather_and_write_imports(fips_dir, proj_dir)
dep.gather_and_write_imports(fips_dir, proj_dir, cfg_name)

# load the config(s)
configs = config.load(fips_dir, proj_dir, cfg_name)
Expand Down Expand Up @@ -143,7 +144,7 @@ def configure(fips_dir, proj_dir, cfg_name) :
dep.fetch_imports(fips_dir, proj_dir)
proj_name = util.get_project_name_from_dir(proj_dir)
util.ensure_valid_project_dir(proj_dir)
dep.gather_and_write_imports(fips_dir, proj_dir)
dep.gather_and_write_imports(fips_dir, proj_dir, cfg_name)

# load configs, if more then one, only use first one
configs = config.load(fips_dir, proj_dir, cfg_name)
Expand All @@ -156,7 +157,7 @@ def configure(fips_dir, proj_dir, cfg_name) :
log.error("Failed to generate '{}' of project '{}'".format(cfg['name'], proj_name))

# run ccmake or cmake-gui
build_dir = util.get_build_dir(fips_dir, proj_name, cfg)
build_dir = util.get_build_dir(fips_dir, proj_name, cfg['name'])
if ccmake.check_exists(fips_dir) :
ccmake.run(build_dir)
elif cmake_gui.check_exists(fips_dir) :
Expand Down Expand Up @@ -184,7 +185,7 @@ def make_clean(fips_dir, proj_dir, cfg_name) :
if config_valid :
log.colored(log.YELLOW, "=== cleaning: {}".format(cfg['name']))

build_dir = util.get_build_dir(fips_dir, proj_name, cfg)
build_dir = util.get_build_dir(fips_dir, proj_name, cfg['name'])
result = False
if cfg['build_tool'] == make.name :
result = make.run_clean(fips_dir, build_dir)
Expand Down Expand Up @@ -226,7 +227,7 @@ def build(fips_dir, proj_dir, cfg_name, target=None) :
dep.fetch_imports(fips_dir, proj_dir)
proj_name = util.get_project_name_from_dir(proj_dir)
util.ensure_valid_project_dir(proj_dir)
dep.gather_and_write_imports(fips_dir, proj_dir)
dep.gather_and_write_imports(fips_dir, proj_dir, cfg_name)

# load the config(s)
configs = config.load(fips_dir, proj_dir, cfg_name)
Expand All @@ -242,7 +243,7 @@ def build(fips_dir, proj_dir, cfg_name, target=None) :
log.error("Failed to generate '{}' of project '{}'".format(cfg['name'], proj_name))

# select and run build tool
build_dir = util.get_build_dir(fips_dir, proj_name, cfg)
build_dir = util.get_build_dir(fips_dir, proj_name, cfg['name'])
num_jobs = settings.get(proj_dir, 'jobs')
result = False
if cfg['build_tool'] == make.name :
Expand Down Expand Up @@ -293,7 +294,7 @@ def run(fips_dir, proj_dir, cfg_name, target_name, target_args, target_cwd) :
log.colored(log.YELLOW, "=== run '{}' (config: {}, project: {}):".format(target_name, cfg['name'], proj_name))

# find deploy dir where executables live
deploy_dir = util.get_deploy_dir(fips_dir, proj_name, cfg)
deploy_dir = util.get_deploy_dir(fips_dir, proj_name, cfg['name'])
if not target_cwd :
target_cwd = deploy_dir

Expand Down Expand Up @@ -372,12 +373,12 @@ def clean(fips_dir, proj_dir, cfg_name) :
for cfg in configs :
log.colored(log.YELLOW, "=== clean: {}".format(cfg['name']))

build_dir = util.get_build_dir(fips_dir, proj_name, cfg)
build_dir = util.get_build_dir(fips_dir, proj_name, cfg['name'])
if os.path.isdir(build_dir) :
shutil.rmtree(build_dir)
log.info(" deleted '{}'".format(build_dir))

deploy_dir = util.get_deploy_dir(fips_dir, proj_name, cfg)
deploy_dir = util.get_deploy_dir(fips_dir, proj_name, cfg['name'])
if os.path.isdir(deploy_dir) :
shutil.rmtree(deploy_dir)
log.info(" deleted '{}'".format(deploy_dir))
Expand Down
12 changes: 6 additions & 6 deletions mod/tools/vscode.py
Expand Up @@ -155,7 +155,7 @@ def get_vs_header_paths(fips_dir, proj_dir, cfg):

# next get the used active Visual Studio instance from the cmake cache
proj_name = util.get_project_name_from_dir(proj_dir)
build_dir = util.get_build_dir(fips_dir, proj_name, cfg)
build_dir = util.get_build_dir(fips_dir, proj_name, cfg['name'])
outp = subprocess.check_output(['cmake', '-LA', '.'], cwd=build_dir)
for line in outp.splitlines():
if line.startswith('CMAKE_LINKER:FILEPATH='):
Expand Down Expand Up @@ -213,8 +213,8 @@ def write_launch_json(fips_dir, proj_dir, vscode_dir, cfg):
'''write the .vscode/launch.json file'''
proj_name = util.get_project_name_from_dir(proj_dir)
exe_targets = read_cmake_targets(fips_dir, proj_dir, cfg, ['app'])
deploy_dir = util.get_deploy_dir(fips_dir, proj_name, cfg)
build_dir = util.get_build_dir(fips_dir, proj_name, cfg)
deploy_dir = util.get_deploy_dir(fips_dir, proj_name, cfg['name'])
build_dir = util.get_build_dir(fips_dir, proj_name, cfg['name'])

launch = {
'version': '0.2.0',
Expand Down Expand Up @@ -275,7 +275,7 @@ def write_launch_json(fips_dir, proj_dir, vscode_dir, cfg):
'request': 'launch',
'stopOnEntry': True,
'pythonPath': '${config:python.pythonPath}',
'program': proj_dir + '/.fips-gen.py',
'program': build_dir + '/fips-gen.py',
'args': [ build_dir + '/fips_codegen.yml' ],
"cwd": proj_dir,
"debugOptions": [
Expand Down Expand Up @@ -317,7 +317,7 @@ def write_c_cpp_properties_json(fips_dir, proj_dir, impex, cfg):
and all dependent projects
'''
proj_name = util.get_project_name_from_dir(proj_dir)
build_dir = util.get_build_dir(fips_dir, proj_name, cfg)
build_dir = util.get_build_dir(fips_dir, proj_name, cfg['name'])
inc_paths = read_cmake_headerdirs(fips_dir, proj_dir, cfg)
defines = read_cmake_defines(fips_dir, proj_dir, cfg)
props = {
Expand Down Expand Up @@ -368,7 +368,7 @@ def write_c_cpp_properties_json(fips_dir, proj_dir, impex, cfg):
def write_cmake_tools_settings(fips_dir, proj_dir, vscode_dir, cfg):
'''write a settings.json for CMakeTools plugin settings'''
proj_name = util.get_project_name_from_dir(proj_dir)
build_dir = util.get_build_dir(fips_dir, proj_name, cfg)
build_dir = util.get_build_dir(fips_dir, proj_name, cfg['name'])
settings = {
'cmake.buildDirectory': build_dir,
'cmake.configureSettings': {
Expand Down
10 changes: 6 additions & 4 deletions mod/util.py
Expand Up @@ -47,21 +47,23 @@ def get_build_dir(fips_dir, proj_name, cfg) :
:param fips_dir: absolute path of fips
:param proj_name: project name
:param cfg: config object
:param cfg: build config name (or config object for backward compatibility)
:returns: absolute path of build directory
"""
return '{}/fips-build/{}/{}'.format(get_workspace_dir(fips_dir), proj_name, cfg['name'])
cfg_name = cfg if type(cfg) == str else cfg['name']
return '{}/fips-build/{}/{}'.format(get_workspace_dir(fips_dir), proj_name, cfg_name)

#-------------------------------------------------------------------------------
def get_deploy_dir(fips_dir, proj_name, cfg) :
"""get absolute path to deploy directory in same workspace as fips
:param fips_dir: absolute path of fips
:param proj_name: project name
:param cfg: config object
:param cfg: build config name (or config object for backward compatibility)
:returns: absolute path of deploy directory
"""
return '{}/fips-deploy/{}/{}'.format(get_workspace_dir(fips_dir), proj_name, cfg['name'])
cfg_name = cfg if type(cfg) == str else cfg['name']
return '{}/fips-deploy/{}/{}'.format(get_workspace_dir(fips_dir), proj_name, cfg_name)

#-------------------------------------------------------------------------------
def get_fips_dir(proj_dir, name):
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion verbs/gdb.py
Expand Up @@ -24,7 +24,7 @@ def gdb(fips_dir, proj_dir, cfg_name, target=None, target_args=None) :
# check if config is valid
config_valid, _ = config.check_config_valid(fips_dir, proj_dir, cfg, print_errors = True)
if config_valid :
deploy_dir = util.get_deploy_dir(fips_dir, proj_name, cfg)
deploy_dir = util.get_deploy_dir(fips_dir, proj_name, cfg['name'])
log.colored(log.YELLOW, "=== gdb: {}".format(cfg['name']))
cmdLine = ['gdb', "-ex", "run", "--args", target]
if target_args :
Expand Down
2 changes: 1 addition & 1 deletion verbs/open.py
Expand Up @@ -31,7 +31,7 @@ def run(fips_dir, proj_dir, args) :
cfg = configs[0]

# find build dir, if it doesn't exist, generate it
build_dir = util.get_build_dir(fips_dir, proj_name, cfg)
build_dir = util.get_build_dir(fips_dir, proj_name, cfg['name'])
if not os.path.isdir(build_dir) :
log.warn("build dir not found, generating...")
project.gen(fips_dir, proj_dir, cfg['name'])
Expand Down
2 changes: 1 addition & 1 deletion verbs/valgrind.py
Expand Up @@ -24,7 +24,7 @@ def valgrind(fips_dir, proj_dir, cfg_name, target, target_args) :
# check if config is valid
config_valid, _ = config.check_config_valid(fips_dir, proj_dir, cfg, print_errors = True)
if config_valid :
deploy_dir = util.get_deploy_dir(fips_dir, proj_name, cfg)
deploy_dir = util.get_deploy_dir(fips_dir, proj_name, cfg['name'])
valgrind_bin = settings.get(proj_dir, 'valgrind')
if not valgrind_bin :
valgrind_bin = 'valgrind'
Expand Down

0 comments on commit 3e3955e

Please sign in to comment.