Skip to content

Commit

Permalink
Auto-detect everest project dirs (eg. everest-core) from CMakeCache.t…
Browse files Browse the repository at this point in the history
…xt (#169)

* Auto-detect everest project dirs (eg. everest-core) from CMakeCache.txt

Signed-off-by: Kai-Uwe Hermann <[email protected]>

* Refactor everest-framework schemas detection to use new helper function

Signed-off-by: Kai-Uwe Hermann <[email protected]>

* Bump version of ev-cli to 0.4.4

Signed-off-by: Kai-Uwe Hermann <[email protected]>

---------

Signed-off-by: Kai-Uwe Hermann <[email protected]>
  • Loading branch information
hikinggrass authored Nov 29, 2024
1 parent de49492 commit 9ce7f00
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 18 deletions.
2 changes: 1 addition & 1 deletion ev-dev-tools/src/ev_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""EVerest command line utility."""
__version__ = '0.4.3'
__version__ = '0.4.4'
33 changes: 16 additions & 17 deletions ev-dev-tools/src/ev_cli/ev.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,10 @@ def generate_interface_headers(interface, all_interfaces_flag, output_dir):
def module_create(args):
create_strategy = 'force-create' if args.force else 'create'

detected_projects = helpers.detect_everest_projects(args.everest_projects, args.build_dir)
if detected_projects:
helpers.everest_dirs.extend(detected_projects)

mod_files = generate_module_files(args.module, False, args.licenses)

if args.only == 'which':
Expand All @@ -559,6 +563,10 @@ def module_create(args):


def module_update(args):
detected_projects = helpers.detect_everest_projects(args.everest_projects, args.build_dir)
if detected_projects:
helpers.everest_dirs.extend(detected_projects)

# Always generate type info before updating module
for type_with_namespace in list_types_with_namespace():
_tmpl_data, _last_mtime = TypeParser.generate_type_info(type_with_namespace, all_types=True)
Expand Down Expand Up @@ -748,7 +756,11 @@ def main():
common_parser.add_argument('--work-dir', '-wd', type=str,
help='work directory containing the manifest definitions (default: .)', default=str(Path.cwd()))
common_parser.add_argument('--everest-dir', '-ed', nargs='*',
help='everest directory containing the interface definitions (default: .)', default=[str(Path.cwd())])
help='everest directory containing the interface definitions (default: .)',
default=[str(Path.cwd()), str(Path.cwd() / '../everest-core')])
common_parser.add_argument('--everest-projects', '-ep', nargs='*',
help='everest project names. used in auto detection of their directories to get eg. interface defintions (default: everest-core)',
default=['everest-core'])
common_parser.add_argument('--schemas-dir', '-sd', type=str,
help='everest framework directory containing the schema definitions (default: ../everest-framework/schemas)',
default=str(Path.cwd() / '../everest-framework/schemas'))
Expand Down Expand Up @@ -872,23 +884,10 @@ def main():
' doesn\'t exist.\n'
f'dir: {schemas_dir}')
cmake_cache_path = Path(args.build_dir) / 'CMakeCache.txt'
print(f'Searching for everest-framework in: {cmake_cache_path}')
print('You can either provide the schemas directory with --schemas-dir or influence the'
' automatic search path by setting --build-dir (default: ./build)')
if not cmake_cache_path.exists():
print(f'CMakeCache.txt does not exist: {cmake_cache_path}')
found_dir = helpers.get_path_from_cmake_cache('everest-framework', cmake_cache_path, '--schemas-dir')
if not found_dir:
exit(1)
with open(cmake_cache_path, 'r') as cmake_cache_file:
search = 'everest-framework_SOURCE_DIR:STATIC='
for line in cmake_cache_file:
if line.startswith(search):
found_schemas_dir = Path(line.replace(search, '', 1).strip(' \t\n\r')) / 'schemas'
if found_schemas_dir.exists():
print(f'Found everest-framework schemas directory: {found_schemas_dir}')
user_choice = input('Do you want to use this? [Y/n] ').lower()
if user_choice == 'y' or not user_choice:
schemas_dir = found_schemas_dir
break
schemas_dir = found_dir / 'schemas'
if not schemas_dir.exists():
exit(1)

Expand Down
40 changes: 40 additions & 0 deletions ev-dev-tools/src/ev_cli/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,3 +775,43 @@ def get_license_header(license_dirs, license_url):
return None
with open(license_path, 'r') as custom_license_file:
return custom_license_file.read().strip()


def get_path_from_cmake_cache(variable_prefix, cmake_cache_path, option_name):
print(f'Searching for {variable_prefix} in: {cmake_cache_path}')
print(f'You can either provide the {variable_prefix} directory with {option_name} or influence the'
' automatic search path by setting --build-dir (default: ./build)')
if not cmake_cache_path.exists():
print(f'CMakeCache.txt does not exist: {cmake_cache_path}')
return None
with open(cmake_cache_path, 'r') as cmake_cache_file:
search = f'{variable_prefix}_SOURCE_DIR:STATIC='
for line in cmake_cache_file:
if line.startswith(search):
found_dir = Path(line.replace(search, '', 1).strip(' \t\n\r'))
if found_dir.exists():
print(f'Found {variable_prefix} directory: {found_dir}')
user_choice = input('Do you want to use this? [Y/n] ').lower()
if user_choice == 'y' or not user_choice:
return found_dir
break
return None


def detect_everest_projects(everest_projects, build_dir):
detected_everest_project = False
for everest_dir in everest_dirs:
if everest_dir.exists() and everest_dir.name in everest_projects:
detected_everest_project = True

found_dirs = []

if not detected_everest_project:
print('Could not detect ' + ", ".join(everest_projects) + ' path in --everest-dir')
cmake_cache_path = Path(build_dir) / 'CMakeCache.txt'
for everest_project in everest_projects:
found_dir = get_path_from_cmake_cache(everest_project, cmake_cache_path, '--everest-dir')
if found_dir:
found_dirs.append(found_dir)

return found_dirs

0 comments on commit 9ce7f00

Please sign in to comment.