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

Remove dependency to UI, use RAII to handle resources #1678

Merged
merged 7 commits into from
Oct 9, 2023
1 change: 1 addition & 0 deletions src/analyzer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ INSTALL(EXPORT antares-analyzer
target_link_libraries(antares-${ANTARES_PRG_VERSION}-analyzer
PRIVATE
yuni-static-core
Antares::args_helper
${CMAKE_THREADS_LIBS_INIT}
antares-core #local.h
PUBLIC
Expand Down
2 changes: 1 addition & 1 deletion src/analyzer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <yuni/yuni.h>
#include <antares/logs/logs.h>
#include <yuni/core/getopt.h>
#include "../ui/common/winmain.hxx"
#include <antares/args/args_to_utf8.h>
#include <antares/version.h>
#include "atsp/atsp.h"
#include <antares/logs/hostinfo.h>
Expand Down
1 change: 1 addition & 0 deletions src/libs/antares/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

OMESSAGE("Antares Core library")

add_subdirectory(args)
add_subdirectory(writer)
add_subdirectory(memory)

Expand Down
22 changes: 22 additions & 0 deletions src/libs/antares/args/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
set(SRC_ARGS_HELPER
include/antares/args/args_to_utf8.h
args_to_utf8.cpp
)

source_group("misc\\args_helper" FILES ${SRC_ARGS_HELPER})

add_library(args_helper
${SRC_ARGS_HELPER}
)

add_library(Antares::args_helper ALIAS args_helper)

target_link_libraries(args_helper
PRIVATE
yuni-static-core
)

target_include_directories(args_helper
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
)
51 changes: 51 additions & 0 deletions src/libs/antares/args/args_to_utf8.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

#include <yuni/yuni.h>
#include "antares/args/args_to_utf8.h"


#ifdef YUNI_OS_WINDOWS
#include <string.h>
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#endif
#include <windows.h>
#include <shellapi.h>
flomnes marked this conversation as resolved.
Show resolved Hide resolved
#include <stdlib.h>
#include <stdio.h>
flomnes marked this conversation as resolved.
Show resolved Hide resolved
#endif

#ifdef YUNI_OS_WINDOWS
char** AntaresGetUTF8Arguments(int argc, char**)
{
wchar_t** wargv = CommandLineToArgvW(GetCommandLineW(), &argc);
char** argvUTF8 = (char**)malloc(argc * sizeof(char*));
for (int i = 0; i != argc; ++i)
{
const uint len = (uint)wcslen(wargv[i]);
const uint newLen = WideCharToMultiByte(CP_UTF8, 0, wargv[i], len, NULL, 0, NULL, NULL);
argvUTF8[i] = (char*)malloc((newLen + 1) * sizeof(char));
memset(argvUTF8[i], 0, (newLen + 1) * sizeof(char));
WideCharToMultiByte(CP_UTF8, 0, wargv[i], len, argvUTF8[i], newLen, NULL, NULL);
flomnes marked this conversation as resolved.
Show resolved Hide resolved
argvUTF8[i][newLen] = '\0';
}
return argvUTF8;
}

void FreeUTF8Arguments(int argc, char** argv)
{
for (int i = 0; i != argc; ++i)
free(argv[i]);
free(argv);
}

#else

char** AntaresGetUTF8Arguments(int argc, char** argv)
{
return argv;
}

void FreeUTF8Arguments(int argc, char** argv)
{}

#endif
1 change: 1 addition & 0 deletions src/solver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ add_executable(antares-solver
set_target_properties(antares-solver PROPERTIES OUTPUT_NAME ${exec_name})

set(ANTARES_SOLVER_LIBS
Antares::args_helper
Antares::date
Antares::benchmarking
Antares::result_writer
Expand Down
2 changes: 1 addition & 1 deletion src/solver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#include <antares/logs/logs.h>
#include "application.h"
#include "../ui/common/winmain.hxx" //TODO: remove that reverse dependency to UI
#include <antares/args/args_to_utf8.h>

#include <antares/fatal-error.h>
#include <antares/memory/memory.h>
Expand Down
1 change: 1 addition & 0 deletions src/tools/batchrun/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ set(BATCHRUN_LIBS
antares-core #local.h
yuni-static-core
${CMAKE_THREADS_LIBS_INIT}
Antares::args_helper
Antares::study
)

Expand Down
2 changes: 1 addition & 1 deletion src/tools/batchrun/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include <yuni/core/string.h>
#include <yuni/core/getopt.h>
#include <antares/study/finder.h>
#include "../../ui/common/winmain.hxx"
#include <antares/args/args_to_utf8.h>
#include <antares/version.h>
#include <antares/locale.h>
#ifdef YUNI_OS_WINDOWS
Expand Down
1 change: 1 addition & 0 deletions src/tools/cleaner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ INSTALL(EXPORT antares-study-cleaner

set(CLEANER_LIBS
yuni-static-core
Antares::args_helper
Antares::study
Antares::sys
antares-core #version.h
Expand Down
2 changes: 1 addition & 1 deletion src/tools/cleaner/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <antares/logs/logs.h>
#include <antares/study/finder.h>
#include <yuni/core/getopt.h>
#include "../../ui/common/winmain.hxx"
#include <antares/args/args_to_utf8.h>
#include <antares/utils/utils.h>
#include <antares/study/cleaner.h>
#include <antares/version.h>
Expand Down
1 change: 1 addition & 0 deletions src/tools/config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ INSTALL(EXPORT antares-config

set(CONFIG_LIBS
yuni-static-core
Antares::args_helper
${CMAKE_THREADS_LIBS_INIT}
)

Expand Down
2 changes: 1 addition & 1 deletion src/tools/config/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <antares/resources/resources.h>
#include <iostream>
#include <yuni/core/getopt.h>
#include "../../ui/common/winmain.hxx"
#include <antares/args/args_to_utf8.h>
#include <antares/version.h>
#include <yuni/core/system/username.h>
#include <antares/locale.h>
Expand Down
1 change: 1 addition & 0 deletions src/tools/finder/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ INSTALL(EXPORT antares-study-finder
set(FINDER_LIBS
antares-core
yuni-static-core
Antares::args_helper
${CMAKE_THREADS_LIBS_INIT}
)

Expand Down
2 changes: 1 addition & 1 deletion src/tools/finder/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <antares/logs/logs.h>
#include <antares/study/finder.h>
#include <yuni/core/getopt.h>
#include "../../ui/common/winmain.hxx"
#include <antares/args/args_to_utf8.h>
#include <antares/utils/utils.h>
#include <antares/version.h>
#include <antares/locale.h>
Expand Down
1 change: 1 addition & 0 deletions src/tools/updater/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ INSTALL(EXPORT antares-study-updater

set(UPDATER_LIBS
yuni-static-core
Antares::args_helper
Antares::study
Antares::sys
antares-core #version.h
Expand Down
2 changes: 1 addition & 1 deletion src/tools/updater/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <antares/logs/logs.h>
#include <antares/study/finder.h>
#include <yuni/core/getopt.h>
#include "../../ui/common/winmain.hxx"
#include <antares/args/args_to_utf8.h>
#include <antares/utils/utils.h>
#include <antares/study/cleaner.h>
#include <antares/version.h>
Expand Down
1 change: 1 addition & 0 deletions src/tools/vacuum/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ set(VACUUM_LIBS
antares-fswalker
yuni-static-core
${CMAKE_THREADS_LIBS_INIT}
Antares::args_helper
Antares::study
)

Expand Down
2 changes: 1 addition & 1 deletion src/tools/vacuum/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include <antares/antares.h>
#include <fswalker/fswalker.h>
#include <antares/logs/logs.h>
#include "../../ui/common/winmain.hxx"
#include <antares/args/args_to_utf8.h>
#include <antares/version.h>
#include <antares/locale.h>
#include "modified-inode.h"
Expand Down
1 change: 1 addition & 0 deletions src/tools/yby-aggregator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ INSTALL(EXPORT antares-ybyaggregator

set(YBY_AGGREGATOR_LIBS
antares-core #version.h
Antares::args_helper
Antares::date
Antares::logs
yuni-static-core
Expand Down
2 changes: 1 addition & 1 deletion src/tools/yby-aggregator/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <yuni/yuni.h>
#include <antares/logs/logs.h>
#include <yuni/core/getopt.h>
#include "../../ui/common/winmain.hxx"
#include <antares/args/args_to_utf8.h>
#include <antares/utils/utils.h>
#include <antares/version.h>
#include <antares/sys/policy.h>
Expand Down
71 changes: 0 additions & 71 deletions src/ui/common/winmain.hxx

This file was deleted.

5 changes: 2 additions & 3 deletions src/ui/simulator/cmake/application.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ SET(SRC_APPLICATION
application/study.h
application/study.cpp

# The main
../common/winmain.hxx
main.cpp
)

Expand All @@ -72,7 +70,8 @@ target_link_libraries(antares-ui-application
PRIVATE
${wxWidgets_LIBRARIES}
antares-ui-common
antares-core
antares-core
Antares::args_helper
Antares::sys
Antares::study
)
Expand Down
2 changes: 1 addition & 1 deletion src/ui/simulator/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "application/application.h"
#include "application/main.h"
#include <yuni/core/getopt.h>
#include "../common/winmain.hxx"
#include <antares/args/args_to_utf8.h>
#include <antares/resources/resources.h>
#include <antares/sys/policy.h>
#include <antares/logs/logs.h>
Expand Down