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

Generation of VS Code debug configuration #302

Merged
merged 3 commits into from
Aug 9, 2023
Merged
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -15,5 +15,8 @@ www/
.project
.settings

# VSCode auto-generated files
.vscode

# CMake default directories
build/
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ enable_testing()
find_package(OmnetPP 5.5.1 MODULE REQUIRED)
include(AddOppRun)
include(AddOppTarget)
include(AddVSCode)
include(CheckGitSubmodule)
include(GenerateOppMessage)
include(GNUInstallDirs)
40 changes: 40 additions & 0 deletions cmake/AddVSCode.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
function(generate_vscode)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A doc-comment explaining the purpose of this function would be beneficial and appreciated 😃

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!

set(one_value_args "TARGET;FILE")
cmake_parse_arguments(args "${option_args}" "${one_value_args}" "" ${ARGN})

if(args_UNPARSED_ARGUMENTS)
message(SEND_ERROR "generate_vscode called with invalid arguments: ${args_UNPARSED_ARGUMENTS}")
endif()

if(NOT args_TARGET)
message(SEND_ERROR "generate_vscode: TARGET argument is missing")
endif()

if(NOT args_FILE)
message(SEND_ERROR "generate_vscode: FILE argument is missing")
endif()

# backup existing launch.json
if(EXISTS ${args_FILE})
string(TIMESTAMP t)
file(COPY_FILE ${args_FILE} ${args_FILE}.${t})
endif()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this does overwrite the file, then custom values get lost, am I right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a launch.json is found, it is moved to a new file and suffixed with the current time. This way, you would still have access to custom values, however, you would need to transfer them to newly written launch configuration again manually.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the biggest drawback especially for people with additional custom Configuration in their launch.json.


# collect all NED folders for given target
get_ned_folders(${args_TARGET} opp_run_ned_folders)
set(opp_run_ned_folders "\"-n$<JOIN:${opp_run_ned_folders},:>\"")

# collect libraries for opp_run
set(opp_run_libraries "")
_get_opp_run_dependencies(${args_TARGET} opp_run_dependencies)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the OmnetC++ dependencies am I right?
Do they change frequently?

Copy link
Contributor Author

@awillecke awillecke Jul 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the libraries of Artery (e.g. libartery_core.so, libtraci.so, ...). These might change when building Artery with other flags (e.g. libartery_envmod.so when WITH_ENVMOD is ON) or when you extend Artery with custom functionalities. Basically, they could change with every (re)generation of the build system.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if one includes all the libs all the time in the launch.json? Will this work?

foreach(opp_run_dependency IN LISTS opp_run_dependencies)
list(APPEND opp_run_libraries "\"-l$<TARGET_FILE:${opp_run_dependency}>\"")
endforeach()
set(opp_run_libraries "$<JOIN:${opp_run_libraries},,>")

set(opp_run_executable ${OMNETPP_RUN_DEBUG})

# substitute variables first, then generator expressions
configure_file(${PROJECT_SOURCE_DIR}/cmake/launch.json.in ${args_FILE} @ONLY)
file(GENERATE OUTPUT ${args_FILE} INPUT ${args_FILE})
endfunction()
76 changes: 76 additions & 0 deletions cmake/launch.json.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Artery in Debugger",
"type": "cppdbg",
"request": "launch",

// Set path to OMNet++ debug runner
"program": "@opp_run_executable@",

// Set working directory to scenario
"cwd": "${workspaceFolder}/scenarios/${input:scenario}",

"args": [
// Paths to NED files
@opp_run_ned_folders@,

// Libraries used for Artery
@opp_run_libraries@

// .ini file to of the scenario
"omnetpp.ini",

// OMNet++ config to run
"-c${input:config}",
// Run number
"-r${input:runId}",

// OMNet++ interface can either be Qtenv or Cmdenv
// "-uQtenv",
"-uCmdenv"
Comment on lines +34 to +36
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
I was wondering, is not QTenv the default graphical environment and CMDenv is deprecated afaik.
I notice this on the website as well.
So should not it be the other way around, QTenv commented in and CMDenv commented out?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that Cmdenv is deprecated but Tkenv. Of course, Cmdenv is not a graphical environment at all but it is very useful for automated/headless simulation runs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I mixed that up. Thank you for the clarification.

],
"stopAtEntry": false,
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Enable all-exceptions",
"text": "catch throw",
"ignoreFailures": true
}
],
// "preLaunchTask": "C/C++: clang++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
],
"inputs": [
{
"id": "scenario",
"type": "promptString",
"default": "artery",
"description": "Scenario folder to launch (provide the folder in ./scenarios/)"
},
{
"id": "config",
"type": "promptString",
"default": "inet",
"description": "OMNeT++ config to launch"
},
{
"id": "runId",
"type": "promptString",
"default": "0",
"description": "Run ID of the config to launch"
}
]
}
4 changes: 4 additions & 0 deletions src/artery/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -182,4 +182,8 @@ if(NOT is_multi_config)
install(
PROGRAMS ${PROJECT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/run_artery.sh.install
DESTINATION ${CMAKE_INSTALL_BINDIR} RENAME run_artery.sh)

if(NOT CMAKE_BUILD_TYPE OR "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
riebl marked this conversation as resolved.
Show resolved Hide resolved
generate_vscode(TARGET artery FILE ${PROJECT_SOURCE_DIR}/.vscode/launch.json)
endif()
endif()