diff --git a/src/fprime/cookiecutter_templates/cookiecutter-fprime-deployment/cookiecutter.json b/src/fprime/cookiecutter_templates/cookiecutter-fprime-deployment/cookiecutter.json index ac1896ee..fba79559 100644 --- a/src/fprime/cookiecutter_templates/cookiecutter-fprime-deployment/cookiecutter.json +++ b/src/fprime/cookiecutter_templates/cookiecutter-fprime-deployment/cookiecutter.json @@ -1,5 +1,4 @@ { "deployment_name": "MyDeployment", - "path_to_fprime": "./fprime", "__deployment_name_upper": "{{cookiecutter.deployment_name.upper()}}" } diff --git a/src/fprime/cookiecutter_templates/cookiecutter-fprime-deployment/{{cookiecutter.deployment_name}}/CMakeLists.txt b/src/fprime/cookiecutter_templates/cookiecutter-fprime-deployment/{{cookiecutter.deployment_name}}/CMakeLists.txt index 24b83275..6a67dcb7 100644 --- a/src/fprime/cookiecutter_templates/cookiecutter-fprime-deployment/{{cookiecutter.deployment_name}}/CMakeLists.txt +++ b/src/fprime/cookiecutter_templates/cookiecutter-fprime-deployment/{{cookiecutter.deployment_name}}/CMakeLists.txt @@ -1,32 +1,22 @@ ##### # '{{cookiecutter.deployment_name}}' Deployment: # -# This sets up the build for the '{{cookiecutter.deployment_name}}' Application, including custom -# components. In addition, it imports FPrime.cmake, which includes the core F Prime components. +# This registers the '{{cookiecutter.deployment_name}}' deployment to the build system. +# Custom components that have not been added at the project-level should be added to +# the list below. # ##### ### -# Basic Project Setup +# Topology and Components ### -cmake_minimum_required(VERSION 3.13) -cmake_policy(SET CMP0048 NEW) -project({{cookiecutter.deployment_name}} VERSION 1.0.0 LANGUAGES C CXX) +add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Top/") -### -# F' Core Setup -# This includes all of the F prime core components, and imports the make-system. -### -include("${FPRIME_FRAMEWORK_PATH}/cmake/FPrime.cmake") -# NOTE: register custom targets between these two lines -include("${FPRIME_FRAMEWORK_PATH}/cmake/FPrime-Code.cmake") +# Add custom components to this specific deployment here +# add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/MyComponent/") -### -# Components and Topology -### -add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Top/") set(SOURCE_FILES "${CMAKE_CURRENT_LIST_DIR}/Main.cpp") -set(MOD_DEPS ${PROJECT_NAME}/Top) +set(MOD_DEPS ${FPRIME_CURRENT_MODULE}/Top) register_fprime_deployment() diff --git a/src/fprime/cookiecutter_templates/cookiecutter-fprime-deployment/{{cookiecutter.deployment_name}}/settings.ini b/src/fprime/cookiecutter_templates/cookiecutter-fprime-deployment/{{cookiecutter.deployment_name}}/settings.ini deleted file mode 100644 index c85d6a57..00000000 --- a/src/fprime/cookiecutter_templates/cookiecutter-fprime-deployment/{{cookiecutter.deployment_name}}/settings.ini +++ /dev/null @@ -1,7 +0,0 @@ -; For more information: https://nasa.github.io/fprime/UsersGuide/user/settings.html -[fprime] -project_root: ../ -framework_path: ../{{ cookiecutter.path_to_fprime.lstrip('./') }} - -default_cmake_options: FPRIME_ENABLE_FRAMEWORK_UTS=OFF - FPRIME_ENABLE_AUTOCODER_UTS=OFF \ No newline at end of file diff --git a/src/fprime/cookiecutter_templates/cookiecutter-fprime-project/cookiecutter.json b/src/fprime/cookiecutter_templates/cookiecutter-fprime-project/cookiecutter.json index e454ab2e..abc3ce56 100644 --- a/src/fprime/cookiecutter_templates/cookiecutter-fprime-project/cookiecutter.json +++ b/src/fprime/cookiecutter_templates/cookiecutter-fprime-project/cookiecutter.json @@ -1,6 +1,7 @@ { + "__default_branch": "devel", "project_name": "MyProject", - "fprime_branch_or_tag": "master", + "fprime_branch_or_tag": "{{ cookiecutter.__default_branch }}", "install_venv": ["yes", "no"], "venv_install_path": "{% if cookiecutter.install_venv == 'yes' %}./venv{% else %}None{% endif %}" } diff --git a/src/fprime/cookiecutter_templates/cookiecutter-fprime-project/hooks/post_gen_project.py b/src/fprime/cookiecutter_templates/cookiecutter-fprime-project/hooks/post_gen_project.py index 04328cc3..59a6046e 100644 --- a/src/fprime/cookiecutter_templates/cookiecutter-fprime-project/hooks/post_gen_project.py +++ b/src/fprime/cookiecutter_templates/cookiecutter-fprime-project/hooks/post_gen_project.py @@ -12,7 +12,8 @@ import subprocess import sys -DEFAULT_BRANCH = "master" +# Fail-safe in case user input is invalid branch/tag +DEFAULT_BRANCH = "{{ cookiecutter.__default_branch }}" # Add F' as a submodule subprocess.run(["git", "init"]) diff --git a/src/fprime/cookiecutter_templates/cookiecutter-fprime-project/{{cookiecutter.project_name}}/CMakeLists.txt b/src/fprime/cookiecutter_templates/cookiecutter-fprime-project/{{cookiecutter.project_name}}/CMakeLists.txt index f59e45de..34cbb633 100644 --- a/src/fprime/cookiecutter_templates/cookiecutter-fprime-project/{{cookiecutter.project_name}}/CMakeLists.txt +++ b/src/fprime/cookiecutter_templates/cookiecutter-fprime-project/{{cookiecutter.project_name}}/CMakeLists.txt @@ -1,6 +1,8 @@ #### -# +# This sets up the build system for the '{{cookiecutter.project_name}}' project, including +# components and deployments from project.cmake. In addition, it imports the core F Prime components. #### + cmake_minimum_required(VERSION 3.13) project({{cookiecutter.project_name}} C CXX) diff --git a/src/fprime/cookiecutter_templates/cookiecutter-fprime-project/{{cookiecutter.project_name}}/Components/CMakeLists.txt b/src/fprime/cookiecutter_templates/cookiecutter-fprime-project/{{cookiecutter.project_name}}/Components/CMakeLists.txt new file mode 100644 index 00000000..5fa1a86d --- /dev/null +++ b/src/fprime/cookiecutter_templates/cookiecutter-fprime-project/{{cookiecutter.project_name}}/Components/CMakeLists.txt @@ -0,0 +1,3 @@ +# Include project-wide components here + +# add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/MyComponent") diff --git a/src/fprime/cookiecutter_templates/cookiecutter-fprime-project/{{cookiecutter.project_name}}/project.cmake b/src/fprime/cookiecutter_templates/cookiecutter-fprime-project/{{cookiecutter.project_name}}/project.cmake index 763e9972..ba74208c 100644 --- a/src/fprime/cookiecutter_templates/cookiecutter-fprime-project/{{cookiecutter.project_name}}/project.cmake +++ b/src/fprime/cookiecutter_templates/cookiecutter-fprime-project/{{cookiecutter.project_name}}/project.cmake @@ -1,2 +1,4 @@ -# This CMake file is intended to register project-wide objects so they can be -# reused easily between deployments, but also by other projects. +# This CMake file is intended to register project-wide objects. +# This allows for reuse between deployments, or other projects. + +add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Components") diff --git a/src/fprime/cookiecutter_templates/cookiecutter-fprime-project/{{cookiecutter.project_name}}/settings.ini b/src/fprime/cookiecutter_templates/cookiecutter-fprime-project/{{cookiecutter.project_name}}/settings.ini index 0d1d215c..7b336233 100644 --- a/src/fprime/cookiecutter_templates/cookiecutter-fprime-project/{{cookiecutter.project_name}}/settings.ini +++ b/src/fprime/cookiecutter_templates/cookiecutter-fprime-project/{{cookiecutter.project_name}}/settings.ini @@ -1,3 +1,6 @@ [fprime] project_root: . framework_path: ./fprime + +default_cmake_options: FPRIME_ENABLE_FRAMEWORK_UTS=OFF + FPRIME_ENABLE_AUTOCODER_UTS=OFF \ No newline at end of file diff --git a/src/fprime/util/build_helper.py b/src/fprime/util/build_helper.py index 177e32ae..af571b92 100644 --- a/src/fprime/util/build_helper.py +++ b/src/fprime/util/build_helper.py @@ -80,7 +80,7 @@ def validate_tools_from_requirements(build: Build): print(message) -def load_build(parsed): +def load_build(parsed, skip_validation=False): """ Loads Build object and returns it to the caller. Additionally, this will validate the installed tool versions (such as fpp and other F' utilities) against the requirements.txt @@ -110,15 +110,11 @@ def load_build(parsed): if parsed.command == "generate": build.invent(parsed.platform, build_dir=parsed.build_cache) else: - does_not_need_cache_directory = parsed.command in [ - "purge", - "info", - "format", - ] + build.load( parsed.platform, parsed.build_cache, - skip_validation=does_not_need_cache_directory, + skip_validation=skip_validation, ) validate_tools_from_requirements(build) return build diff --git a/src/fprime/util/cli.py b/src/fprime/util/cli.py index e688c19f..eceb5f8d 100644 --- a/src/fprime/util/cli.py +++ b/src/fprime/util/cli.py @@ -25,7 +25,11 @@ def utility_entry(args): parsed, cmake_args, make_args, parser, runners = parse_args(args) try: - build = None if skip_build_loading(parsed) else load_build(parsed) + build = ( + None + if skip_build_loading(parsed) + else load_build(parsed, skip_build_cache_validation(parsed)) + ) # runners is a Dict[str, Callable] of {command_name: handler_functions} pairs return runners[parsed.command]( @@ -46,14 +50,28 @@ def utility_entry(args): def skip_build_loading(parsed): """Determines if the build load step should be skipped. Commands that do not require a build object - should manually be added here by the developer.""" - if parsed.command == "new" and parsed.new_deployment: - return True + should manually be added here by the developer. + """ if parsed.command == "new" and parsed.new_project: return True return False +def skip_build_cache_validation(parsed): + """Determines if the build cache validation step should be skipped. Commands that do not require a + build **cache** should manually be added here by the developer. + """ + if parsed.command in [ + "purge", + "info", + "format", + ]: + return True + if parsed.command == "new" and parsed.new_deployment: + return True + return False + + def add_special_parsers( subparsers, common: argparse.ArgumentParser, help_text: "HelpText" ) -> Dict[str, Callable]: diff --git a/src/fprime/util/commands.py b/src/fprime/util/commands.py index c1f3ed61..0245ee49 100644 --- a/src/fprime/util/commands.py +++ b/src/fprime/util/commands.py @@ -128,7 +128,7 @@ def run_new( if parsed.new_component: return new_component(build) if parsed.new_deployment: - return new_deployment(parsed) + return new_deployment(build, parsed) if parsed.new_project: return new_project(parsed) raise NotImplementedError( diff --git a/src/fprime/util/cookiecutter_wrapper.py b/src/fprime/util/cookiecutter_wrapper.py index 277df589..24620c1e 100644 --- a/src/fprime/util/cookiecutter_wrapper.py +++ b/src/fprime/util/cookiecutter_wrapper.py @@ -217,7 +217,7 @@ def new_component(build: Build): return 1 -def new_deployment(parsed_args): +def new_deployment(build: Build, parsed_args): """Creates a new deployment using cookiecutter""" source = ( os.path.dirname(__file__) @@ -225,7 +225,24 @@ def new_deployment(parsed_args): ) print("[INFO] Cookiecutter: using builtin template for new deployment") try: - gen_path = cookiecutter(source, overwrite_if_exists=parsed_args.overwrite) + gen_path = Path( + cookiecutter(source, overwrite_if_exists=parsed_args.overwrite) + ).resolve() + + proj_root = build.get_settings("project_root", None) + # Attempt to register to CMakeLists.txt or project.cmake + proj_root = Path(proj_root) + cmake_file = find_nearest_cmake_file(gen_path, build.deployment, proj_root) + if cmake_file is None or not add_to_cmake( + cmake_file, + gen_path.relative_to(cmake_file.parent), + proj_root, + ): + print( + f"[INFO] Could not register {gen_path} with build system. Please add it manually." + ) + return 0 + except OutputDirExistsException as out_directory_error: print( f"{out_directory_error}. Use --overwrite to overwrite (will not delete non-generated files).",