Skip to content

Commit

Permalink
Install ev-cli locally and depend on templates files for generation
Browse files Browse the repository at this point in the history
Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
  • Loading branch information
hikinggrass authored and Pietfried committed Oct 11, 2024
1 parent 9e315b5 commit 04559b2
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ ev_setup_python_executable(
PYTHON_VENV_PATH ${${PROJECT_NAME}_PYTHON_VENV_PATH}
)

set(EVEREST_SCRIPTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/scripts")

# Already include CTest here to allow it to find tests defined in subdirectories like lib and modules
if(EVEREST_CORE_BUILD_TESTING)
include(CTest)
Expand Down
32 changes: 22 additions & 10 deletions cmake/ev-cli.cmake
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
macro(setup_ev_cli)
if(NOT TARGET ev-cli)
add_custom_target(ev-cli)
endif()
if(${EV_CLI})
message(FATAL_ERROR "EV_CLI is already defined.")
return()
endif()
if(NOT ${${PROJECT_NAME}_USE_PYTHON_VENV})
find_program(EV_CLI ev-cli REQUIRED)
else()
Expand All @@ -15,9 +8,28 @@ macro(setup_ev_cli)
if(NOT ${IS_PYTHON_VENV_ACTIVE})
message(FATAL_ERROR "Python venv is not active. Please activate the python venv before running this command.")
endif()
set(EV_CLI "${${PROJECT_NAME}_PYTHON_VENV_PATH}/bin/ev-cli")
add_dependencies(ev-cli
ev-dev-tools_pip_install_dist
find_program(EV_CLI ev-cli REQUIRED)

find_program(EV_GET_PACKAGE_LOCATION
NAMES get_package_location.py
PATHS "${EVEREST_SCRIPTS_DIR}"
NO_DEFAULT_PATH
)
execute_process(
COMMAND ${EV_GET_PACKAGE_LOCATION} --package-name ev-dev-tools
OUTPUT_VARIABLE EV_CLI_PACKAGE_LOCATION
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE
EV_GET_PACKAGE_LOCATION_RESULT
)
if(EV_GET_PACKAGE_LOCATION_RESULT AND NOT EV_GET_PACKAGE_LOCATION_RESULT EQUAL 0)
# TODO: this probably does not have to be a FATAL_ERROR
message(FATAL_ERROR "Could not get ev-dev-tools package location")
endif()
message(STATUS "Using ev-cli package: ${EV_CLI_PACKAGE_LOCATION}")
set_property(
GLOBAL
PROPERTY EV_CLI_TEMPLATES_DIR "${EV_CLI_PACKAGE_LOCATION}/src/ev_cli/templates"
)
endif()
endmacro()
Expand Down
21 changes: 18 additions & 3 deletions cmake/everest-generate.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,18 @@ function (_ev_add_interfaces)
# FIXME (aw): check for duplicates here!
get_target_property(GENERATED_OUTPUT_DIR generate_cpp_files EVEREST_GENERATED_OUTPUT_DIR)
set(CHECK_DONE_FILE "${GENERATED_OUTPUT_DIR}/.interfaces_generated_${EVEREST_PROJECT_NAME}")
get_property(EV_CLI_TEMPLATES_DIR
GLOBAL
PROPERTY EV_CLI_TEMPLATES_DIR
)

add_custom_command(
OUTPUT
"${CHECK_DONE_FILE}"
DEPENDS
${ARGV}
ev-cli
${EV_CLI_TEMPLATES_DIR}/interface-Base.hpp.j2
${EV_CLI_TEMPLATES_DIR}/interface-Exports.hpp.j2
COMMENT
"Generating/updating interface files ..."
VERBATIM
Expand Down Expand Up @@ -346,13 +351,17 @@ function (_ev_add_types)
# FIXME (aw): check for duplicates here!
get_target_property(GENERATED_OUTPUT_DIR generate_cpp_files EVEREST_GENERATED_OUTPUT_DIR)
set(CHECK_DONE_FILE "${GENERATED_OUTPUT_DIR}/.types_generated_${EVEREST_PROJECT_NAME}")
get_property(EV_CLI_TEMPLATES_DIR
GLOBAL
PROPERTY EV_CLI_TEMPLATES_DIR
)

add_custom_command(
OUTPUT
"${CHECK_DONE_FILE}"
DEPENDS
${ARGV}
ev-cli
${EV_CLI_TEMPLATES_DIR}/types.hpp.j2
COMMENT
"Generating/updating type files ..."
VERBATIM
Expand Down Expand Up @@ -484,6 +493,11 @@ function (ev_add_cpp_module MODULE_NAME)
set(GENERATED_MODULE_DIR "${GENERATED_OUTPUT_DIR}/modules")
set(MODULE_LOADER_DIR ${GENERATED_MODULE_DIR}/${MODULE_NAME})

get_property(EV_CLI_TEMPLATES_DIR
GLOBAL
PROPERTY EV_CLI_TEMPLATES_DIR
)

add_custom_command(
OUTPUT
${MODULE_LOADER_DIR}/ld-ev.hpp
Expand All @@ -496,7 +510,8 @@ function (ev_add_cpp_module MODULE_NAME)
${RELATIVE_MODULE_DIR}
DEPENDS
${MODULE_PATH}/manifest.yaml
ev-cli
${EV_CLI_TEMPLATES_DIR}/ld-ev.cpp.j2
${EV_CLI_TEMPLATES_DIR}/ld-ev.hpp.j2
WORKING_DIRECTORY
${PROJECT_SOURCE_DIR}
COMMENT
Expand Down
54 changes: 54 additions & 0 deletions scripts/get_package_location.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env -S python3 -tt
# -*- coding: utf-8 -*-
#
# SPDX-License-Identifier: Apache-2.0
# Copyright Pionix GmbH and Contributors to EVerest
#
"""
author: kai-uwe.hermann@pionix.de
"""

import argparse
from importlib.metadata import Distribution, PackageNotFoundError
import json


__version__ = '0.1.0'


class EVerestParsingException(SystemExit):
pass


def main():
parser = argparse.ArgumentParser(
description='EVerest get package location')
parser.add_argument('--version', action='version',
version=f'%(prog)s {__version__}')
parser.add_argument('--package-name', type=str,
help='Name of the package that the location should be retrieved from', default=None)
args = parser.parse_args()

if not 'package_name' in args or not args.package_name:
raise EVerestParsingException('Please provide a valid package name')

direct_url = ""
try:
direct_url = Distribution.from_name(
args.package_name).read_text('direct_url.json')
except PackageNotFoundError as e:
raise EVerestParsingException(e)
url = json.loads(direct_url).get('url', None)

if url and url.startswith('file://'):
url = url.replace('file://', '')
print(f'{url}')
else:
raise EVerestParsingException()


if __name__ == '__main__':
try:
main()
except EVerestParsingException as e:
raise SystemExit(e)

0 comments on commit 04559b2

Please sign in to comment.