Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor new build system structure (nasa#1994) #142

Merged
merged 6 commits into from
May 30, 2023
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"deployment_name": "MyDeployment",
"path_to_fprime": "./fprime",
"__deployment_name_upper": "{{cookiecutter.deployment_name.upper()}}"
}
Original file line number Diff line number Diff line change
@@ -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()

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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 %}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Include project-wide components here

# add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/MyComponent")
Original file line number Diff line number Diff line change
@@ -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")
LeStarch marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[fprime]
project_root: .
framework_path: ./fprime

default_cmake_options: FPRIME_ENABLE_FRAMEWORK_UTS=OFF
FPRIME_ENABLE_AUTOCODER_UTS=OFF
10 changes: 3 additions & 7 deletions src/fprime/util/build_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
26 changes: 22 additions & 4 deletions src/fprime/util/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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](
Expand All @@ -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]:
Expand Down
2 changes: 1 addition & 1 deletion src/fprime/util/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
21 changes: 19 additions & 2 deletions src/fprime/util/cookiecutter_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,32 @@ 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__)
+ "/../cookiecutter_templates/cookiecutter-fprime-deployment"
)
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).",
Expand Down