fprime.fbuild.cmake

fprime.fbuild.cmake:

File to contain basic wrappers for the CMake. This will enable basic CMake commands in order to detect the properties of the build. This should not be imported in-person, but rather should be included by the build package. This can be the receiver of these delegated functions.

@author mstarch

Module Contents

Classes

CMakeHandler()

CMake handler interacts with an F prime CMake-based system. This will help us interact with CMake in refined ways.

class fprime.fbuild.cmake.CMakeHandler[source]

CMake handler interacts with an F prime CMake-based system. This will help us interact with CMake in refined ways.

CMAKE_LOCATION_FIELDS = ['FPRIME_PROJECT_ROOT', 'FPRIME_LIBRARY_LOCATIONS', 'FPRIME_FRAMEWORK_PATH'][source]
set_verbose(self, verbose)[source]

Sets verbosity

execute_known_target(self, target, build_dir, path, cmake_args=None, make_args=None, top_target=False)[source]

Executes a known target for a given build_dir. Path will default to a known path.

Parameters
  • build_dir – build_dir to use to run this.

  • target – target to execute at the path, using above build_dir

  • path – path to run target against. (default) current working directory

  • cmake_args – cmake args input

  • top_target – top-level target. Do not append path name

Returns

return code from CMake

get_include_locations(self, cmake_dir)[source]

Gets the locations that can be used as the root of an include tree. Common directories are placed in these include locations. These include standard builds, configs, etc.

Parameters

cmake_dir – directory of a CMake build, or directory containing a CMake project

Returns

[] List of include locations. Order: project, lib, lib, …, F prime core

get_include_info(self, path, cmake_dir)[source]

Calculates the include root of the given path. The include root is defined as the following based on the other two values supplied. First, the following two path values are established: - Location of the project’s root. This is defined in the project_dir’s CMakeList.txt, or in the CMake Cache. - Location of the project’s F prime checkout. This is defined in the same places. From there, the include root of the supplied path is whichever of those two paths is your parent. In cases where both are parents, it will take the outer-most parent

Parameters
  • path – path to calculate looking for include-root

  • cmake_dir – directory of a CMake build, or directory containing a CMake project

Returns

(relative include path, include root for the given path)

get_fprime_configuration(self, fields, cmake_dir=None)[source]

Gets fprime configuration for the given field(s). This will return a list of fields for the set of input fields. The user may supply a string for a single value returned as list of one, or a list of fields for list of values.

Parameters
  • fields – name of field, or list of names of fields

  • cmake_dir – a cmake directory (project or build) to used. default: None, use existing temp cached build.

Returns

list of values, or Nones

generate_build(self, source_dir, build_dir, args=None, ignore_output=False)[source]

Generate a build directory for purposes of the build.

Parameters
  • source_dir – source directory to generate from

  • build_dir – build directory to generate to

  • args – arguments to hand to CMake.

  • ignore_output – do not print the output where the user can see it

get_cmake_module(self, path, build_dir)[source]

Gets the CMake module

CMake modules are constructed from a path relative to some project root (fprime, deployment, or library roots). This relative path is then converted to use “_” instead of “/”

Parameters
  • path – path to contextualize. May be None to use os.getcwd().

  • build_dir – build directory to use

Returns

CMake module name in format x_y_z

get_project_relative_path(self, path, build_dir)[source]

Gets the path relative to the cmake setup, or raises CMakeOrphanException

Parameters
  • path – path to contextualize. May be None to use os.getcwd().

  • build_dir – build directory to use

Returns

path string that is relative to some root of the project. i.e. used for target suffix names

get_available_targets(self, build_dir, path)[source]

Gets a list of available CMake targets in the current directory

Parameters
  • build_dir – build directory to use for detecting targets

  • path – contextual path. None for “cwd”

Note

This code might not work on non-GNU makefile variants of CMake as it depends on the “help” target

Returns

list of CMake make targets

static purge(build_dir)[source]

Reusable purge functionality, so the user may purge or the system may cleanup itself

Parameters

build_dir – build dir specified to purge

_read_values_from_cache(self, keys, build_dir)[source]

Reads set values from cache into an output tuple.

Parameters
  • keys – keys to read in iterable

  • build_dir – build directory containing cache file

Returns

a tuple of keys, None if not part of cache

_read_cache(self, build_dir)[source]

Reads the cache from the associated build_dir. This will return a dictionary of cache variable name to its value. This will not update internal state.

Parameters

build_dir – build directory to harvest for cache variables

Returns

{<cmake cache variable>: <cmake cache value>}

static _cmake_validate_source_dir(source_dir)[source]

Raises an exception if the source dir is not a valid CMake source directory. This means a CMakeLists.txt exists and defines within it a project call.

Parameters

source_dir – source directory to validate

static _cmake_validate_build_dir(build_dir)[source]

Raises an exception if the build dir is not a valid CMake build directory

Parameters

build_dir – build_dir to validate

_cmake_referesh_cache(self, build_dir)[source]

Runs the cmake target required to refresh the cmake cache. This will allow for unknown targets to be searched for before the utility gives up and produces.

Parameters

build_dir – directory to build in

_run_cmake(self, arguments, workdir=None, print_output=True, write_override=False, environment=None)[source]

Will run the cmake system supplying the given arguments. Assumes that the CMake executable is somewhere on the path in order for this to run.

Parameters
  • arguments – arguments to supply to CMake.

  • workdir – work directory to run in

  • print_output – print_output to the screen. Default: True

  • write_override – allows for non-read-only commands

  • environment – environment to write into

Returns

(stdout, stderr)

static _communicate(proc, stdout, stderr, print_output=True)[source]

Communicates with a process while assuring that output is captured and optionally printed. This will buffer lines for the standard out file handle when not none, and will always buffer standard error so that it can be provided when needed. This effectively replaces the .communicate method of the proc itself, while still preventing deadlocks. The output is returned for each stream as a list of lines.

Parameters
  • proc – Popen process constructed with the above pairs to the submitted file handles

  • stdout – standard output file handle. Paired with the FH provided to the Popen stdout argument

  • stderr – standard error file handle. Paired with the FH provided to the Popen stderr argument

  • print_output – print output to the screen. If False, output is masked. Default: True, print to screen.

:return return code, stdout as list of lines, stderr as list of lines

exception fprime.fbuild.cmake.CMakeException[source]

Bases: fprime.common.error.FprimeException

Error occurred within this CMake package

exception fprime.fbuild.cmake.CMakeInconsistencyException(project_cmake, build_dir)[source]

Bases: fprime.fbuild.cmake.CMakeException

Project CMakeLists.txt is inconsistent with build dir

exception fprime.fbuild.cmake.CMakeOrphanException(file_dir)[source]

Bases: fprime.fbuild.cmake.CMakeException

File is not managed by CMake project

exception fprime.fbuild.cmake.CMakeProjectException(project_dir, error)[source]

Bases: fprime.fbuild.cmake.CMakeException

Invalid project directory

exception fprime.fbuild.cmake.CMakeInvalidBuildException(build_dir)[source]

Bases: fprime.fbuild.cmake.CMakeException

The supplied build directory was not setup as a CMake value

exception fprime.fbuild.cmake.CMakeExecutionException(message, stderr, printed)[source]

Bases: fprime.fbuild.cmake.CMakeException

Pass up a CMake Error as an Exception

get_errors(self)[source]

Returns the error stream data to the caller :return: stderr of CMake as supplied into this Exception

need_print(self)[source]

Returns if the errors need to be printed :return: need print

exception fprime.fbuild.cmake.CMakeNoSuchTargetException(build_dir, target)[source]

Bases: fprime.fbuild.cmake.CMakeException

The target does not exist.

Build: 1.4.1