Skip to content

Commit 1d354e3

Browse files
mergify[bot]cferreiragonzJavgilavi
authored
Fix Discovery CLI Tool in Windows (No privileges) (backport #5493) (#5510)
* Fix Discovery CLI Tool in Windows (#5493) * Refs #22463: Add test to check proper link between python and cpp files Signed-off-by: cferreiragonz <[email protected]> * Refs #22463: Remove .bat.in and call .exe from python Signed-off-by: cferreiragonz <[email protected]> * Refs #22463: Apply suggestions Signed-off-by: cferreiragonz <[email protected]> --------- Signed-off-by: cferreiragonz <[email protected]> (cherry picked from commit 2cdc2d9) # Conflicts: # tools/fastdds/discovery/parser.py * Fix conflicts Signed-off-by: Javier Gil Aviles <[email protected]> --------- Signed-off-by: Javier Gil Aviles <[email protected]> Co-authored-by: Carlos Ferreira González <[email protected]> Co-authored-by: Javier Gil Aviles <[email protected]>
1 parent 42b67a0 commit 1d354e3

File tree

8 files changed

+63
-22
lines changed

8 files changed

+63
-22
lines changed

.github/workflows/reusable-mac-ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ jobs:
7777
- name: Install Python dependencies
7878
uses: eProsima/eProsima-CI/multiplatform/install_python_packages@v0
7979
with:
80-
packages: vcstool xmlschema
80+
packages: vcstool xmlschema psutil
8181
upgrade: false
8282

8383
- name: Setup CCache

.github/workflows/reusable-ubuntu-ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ jobs:
200200
- name: Install Python dependencies
201201
uses: eProsima/eProsima-CI/ubuntu/install_python_packages@v0
202202
with:
203-
packages: vcstool xmlschema
203+
packages: vcstool xmlschema psutil
204204

205205
- name: Setup CCache
206206
uses: eProsima/eProsima-CI/external/setup-ccache-action@v0

.github/workflows/reusable-windows-ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ jobs:
8888
- name: Install Python dependencies
8989
uses: eProsima/eProsima-CI/windows/install_python_packages@v0
9090
with:
91-
packages: vcstool xmlschema
91+
packages: vcstool xmlschema psutil
9292

9393
- name: Update known hosts file for DNS resolver testing
9494
if: ${{ !contains(github.event.pull_request.labels.*.name, 'no-test') }}

test/system/tools/fastdds/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ if(Python3_Interpreter_FOUND)
2727
set(TESTS
2828
test_fastdds_installed
2929
test_fastdds_discovery
30+
test_fastdds_discovery_run
3031
test_ros_discovery
3132
test_fastdds_shm
3233
test_fastdds_xml_validate

test/system/tools/fastdds/tests.py

+44
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,28 @@
2626
Available tests:
2727
2828
test_fastdds_installed
29+
test_fastdds_version
2930
test_fastdds_discovery
31+
test_fastdds_discovery_run
3032
test_fastdds_shm
33+
test_fastdds_xml_validate
34+
test_ros_discovery
3135
3236
"""
3337

3438
import argparse
3539
import os
3640
import subprocess
41+
import signal
3742
import sys
3843
from pathlib import Path
44+
try: # Try catch for new python dependency
45+
import psutil
46+
except ImportError:
47+
print(
48+
'psutil module not found. '
49+
'Try to install running "pip install psutil"')
50+
sys.exit(1)
3951

4052

4153
def setup_script_name():
@@ -121,6 +133,36 @@ def test_fastdds_discovery(install_path, setup_script_path):
121133
sys.exit(ret)
122134

123135

136+
def test_fastdds_discovery_run(install_path, setup_script_path):
137+
"""Test that discovery command runs."""
138+
args = ' discovery -l 127.0.0.1'
139+
try:
140+
test_timeout = 10
141+
process = subprocess.Popen(
142+
cmd(install_path=install_path,
143+
setup_script_path=setup_script_path,
144+
args=args),
145+
shell=True)
146+
ret = process.wait(timeout=test_timeout)
147+
# Manually set the error return code because we need the process to timeout
148+
ret = 3
149+
except subprocess.TimeoutExpired:
150+
print(f'Timeout {test_timeout} expired. Test successful')
151+
try:
152+
# Need to kill all child processes to properly end the test
153+
parent = psutil.Process(process.pid)
154+
for child in parent.children(recursive=True):
155+
child.terminate()
156+
parent.terminate()
157+
ret = 0
158+
except Exception as e:
159+
print(f"Error while ending child processes: {e}")
160+
161+
if 0 != ret:
162+
print('test_fastdds_discovery_run FAILED')
163+
sys.exit(ret)
164+
165+
124166
def test_ros_discovery(install_path, setup_script_path):
125167
"""Test that discovery command runs."""
126168
args = ' -h'
@@ -200,6 +242,8 @@ def get_paths(install_path):
200242
lambda: test_fastdds_installed(fastdds_tool_path),
201243
'test_fastdds_discovery': lambda: test_fastdds_discovery(
202244
fastdds_tool_path, setup_script_path),
245+
'test_fastdds_discovery_run': lambda: test_fastdds_discovery_run(
246+
fastdds_tool_path, setup_script_path),
203247
'test_ros_discovery':
204248
lambda: test_ros_discovery(ros_disc_tool_path, setup_script_path),
205249
'test_fastdds_shm': lambda: test_fastdds_shm(fastdds_tool_path),

tools/fastdds/discovery/parser.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ def __init__(self, argv):
5454
(len(argv) == 1 and argv[0] == '--help')
5555
):
5656
print(self.__edit_tool_help(result.stdout))
57+
elif (
58+
(len(argv) == 1 and argv[0] == '-v') or
59+
(len(argv) == 1 and argv[0] == '--version')
60+
):
61+
result = subprocess.run([tool_path, '-v'])
62+
if result.returncode != 0:
63+
sys.exit(result.returncode)
5764
else:
5865
# Call the tool
5966
result = subprocess.run([tool_path] + argv)
@@ -87,9 +94,13 @@ def __find_tool_path(self):
8794
elif os.name == 'nt':
8895
ret = tool_path / 'fast-discovery-server.exe'
8996
if not os.path.exists(ret):
90-
ret = tool_path / 'fast-discovery-server.bat'
91-
if not os.path.exists(ret):
92-
print('fast-discovery-server tool not installed')
97+
exe_files = [f for f in tool_path.glob('*.exe') if re.match(r'fast-discovery-server.*\.exe$', f.name)]
98+
if len(exe_files) == 0:
99+
print("Unable to find fast-discovery-server tool. Check installation")
100+
elif len(exe_files) == 1:
101+
ret = exe_files[0]
102+
else:
103+
print('Multiple candidates for fast-discovery-server.exe. Check installation')
93104
sys.exit(1)
94105
else:
95106
print(f'{os.name} not supported')

tools/fds/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ install(EXPORT ${PROJECT_NAME}-targets
107107
if( WIN32 )
108108
# Use powershell to generate the link
109109
install(
110-
CODE "execute_process( COMMAND PowerShell -Command \"if( test-path ${PROJECT_NAME}.exe -PathType Leaf ) { rm ${PROJECT_NAME}.exe } ; New-Item -ItemType SymbolicLink -Target $<TARGET_FILE_NAME:${PROJECT_NAME}> -Path ${PROJECT_NAME}.exe \" ERROR_QUIET RESULTS_VARIABLE SYMLINK_FAILED WORKING_DIRECTORY \"${CMAKE_INSTALL_PREFIX}/${BIN_INSTALL_DIR}\") \n if( SYMLINK_FAILED ) \n message(STATUS \"Windows requires admin installation rights to create symlinks. A bat script will be provided instead.\") \n set(FAST_SERVER_BINARY_NAME $<TARGET_FILE_NAME:${PROJECT_NAME}>) \n configure_file(${CMAKE_CURRENT_LIST_DIR}/fast-discovery-server.bat.in ${CMAKE_INSTALL_PREFIX}/${BIN_INSTALL_DIR}${MSVCARCH_DIR_EXTENSION}/${PROJECT_NAME}.bat @ONLY) \n endif()"
110+
CODE "execute_process( COMMAND PowerShell -Command \"if( test-path ${PROJECT_NAME}.exe -PathType Leaf ) { rm ${PROJECT_NAME}.exe } ; New-Item -ItemType SymbolicLink -Target $<TARGET_FILE_NAME:${PROJECT_NAME}> -Path ${PROJECT_NAME}.exe \" ERROR_QUIET RESULTS_VARIABLE SYMLINK_FAILED WORKING_DIRECTORY \"${CMAKE_INSTALL_PREFIX}/${BIN_INSTALL_DIR}\") \n if( SYMLINK_FAILED ) \n message(STATUS \"Windows requires admin installation rights to create symlinks. Build again with privileges to create symlink. Tool will try to find executable if no symlink is found.\") \n endif()"
111111
COMPONENT discovery)
112112
else()
113113
# Use ln to create the symbolic link. We remove the version from the file name but keep the debug suffix

tools/fds/fast-discovery-server.bat.in

-15
This file was deleted.

0 commit comments

Comments
 (0)