Skip to content

Commit 88faf52

Browse files
committed
[feat] cli: integrate cli in main executable
1 parent 6fbafdc commit 88faf52

File tree

8 files changed

+88
-105
lines changed

8 files changed

+88
-105
lines changed

.github/workflows/build_linux.yml

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,11 @@ jobs:
4343
wget https://github.com/bgallois/SoBundle/releases/download/continuous/so_bundle
4444
chmod +x so_bundle
4545
./so_bundle --exec ./bin/fasttrack --qt ${{ github.workspace }}/Qt/${{ env.QT_VERSION }}/gcc_64/ --bundle
46-
- name: build_run_cli
47-
run: |
48-
cd build
49-
./so_bundle --exec ./bin/fasttrack-cli --qt ${{ github.workspace }}/Qt/${{ env.QT_VERSION }}/gcc_64/ --bundle
5046
- name: upload_artefact
5147
uses: actions/upload-artifact@v4
5248
with:
5349
name: FastTrack
5450
path: ./build/bin/fasttrack.run
55-
- name: upload_artefact
56-
uses: actions/upload-artifact@v4
57-
with:
58-
name: FastTrack-Cli
59-
path: ./build/bin/fasttrack-cli.run
6051

6152
test_bundle:
6253
runs-on: ubuntu-latest
@@ -65,11 +56,11 @@ jobs:
6556
- name: download artifact
6657
uses: actions/download-artifact@v4
6758
with:
68-
name: FastTrack-Cli
69-
path: FastTrack-Cli
59+
name: FastTrack
60+
path: FastTrack
7061

7162
- name: Run FastTrack executable
7263
run: |
73-
cd FastTrack-Cli
74-
chmod +x fasttrack-cli.run
75-
./fasttrack-cli.run -- --help
64+
cd FastTrack
65+
chmod +x fasttrack.run
66+
./fasttrack.run -- --cli --help

.github/workflows/build_mac.yml

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -118,33 +118,6 @@ jobs:
118118
with:
119119
name: FastTrack.dmg
120120
path: ./build/bin/FastTrack.dmg
121-
- name: build_ft_cli
122-
run: |
123-
cd build/bin
124-
APP=FastTrack-Cli.app
125-
APP_BINARY=$APP/Contents/MacOS/FastTrack-Cli
126-
mv fasttrack-cli.app "$APP"
127-
macdeployqt "$APP" \
128-
-always-overwrite \
129-
-verbose=2
130-
find / -name "libutf8_validity.dylib" -exec cp {} $APP/Contents/Frameworks/ \; 2> >(tee /dev/stderr) || true
131-
find / -name "libgcc_s.1.1.dylib" -exec cp {} $APP/Contents/Frameworks/ \; 2> >(tee /dev/stderr) || true
132-
find / -name "libsharpyuv.0.dylib" -exec cp {} $APP/Contents/Frameworks/ \; 2> >(tee /dev/stderr) || true
133-
find / -name "libjxl_cms.0.11.dylib" -exec cp {} $APP/Contents/Frameworks/ \; 2> >(tee /dev/stderr) || true
134-
find / -name "libvtk*.dylib" -exec cp {} $APP/Contents/Frameworks/ \; 2> >(tee /dev/stderr) || true
135-
find / -name "libsqlite3*.dylib" -exec cp {} $APP/Contents/Frameworks/ \; 2> >(tee /dev/stderr) || true
136-
find / -name "libhpdf*.dylib" -exec cp {} $APP/Contents/Frameworks/ \; 2> >(tee /dev/stderr) || true
137-
cp -v /opt/homebrew/opt/little-cms2/lib/lib*.dylib $APP/Contents/Frameworks/ || true
138-
cp -v /opt/homebrew/opt/jpeg-xl/lib/lib*.dylib $APP/Contents/Frameworks/ || true
139-
find "$APP/Contents/Frameworks" -type f -name "*.dylib" -exec codesign --remove-signature {} \; 2>/dev/null || true
140-
find "$APP/Contents/Frameworks" -type f -name "*.dylib" -exec codesign --force --sign - {} \;
141-
python macdeployqtfix.py fasttrack-cli.app/contents/macos/fasttrack-cli ../../Qt/${{ env.QT_VERSION }}/
142-
hdiutil create -volname FastTrack-Cli -srcfolder $APP -ov -format UDZO FastTrack-Cli.dmg
143-
- name: upload_artefact_cli
144-
uses: actions/upload-artifact@v4
145-
with:
146-
name: FastTrack-Cli.dmg
147-
path: ./build/bin/FastTrack-Cli.dmg
148121

149122
test_bundle:
150123
runs-on: macos-latest
@@ -153,11 +126,11 @@ jobs:
153126
- name: download artifact
154127
uses: actions/download-artifact@v4
155128
with:
156-
name: FastTrack-Cli.dmg
157-
path: FastTrack-Cli
129+
name: FastTrack.dmg
130+
path: FastTrack
158131

159132
- name: Run FastTrack executable
160133
run: |
161-
cd FastTrack-Cli
162-
hdiutil attach FastTrack-Cli.dmg -mountpoint /Volumes/FastTrackApp
163-
/Volumes/FastTrackApp/FastTrack-Cli.app/Contents/MacOS/FastTrack-Cli --help
134+
cd FastTrack
135+
hdiutil attach FastTrack.dmg -mountpoint /Volumes/FastTrackApp
136+
/Volumes/FastTrackApp/FastTrack.app/Contents/MacOS/FastTrack --cli --help

.github/workflows/build_win.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ jobs:
3636
cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DSKIP_TEST=ON ../
3737
mingw32-make
3838
mv bin/fasttrack.exe bin/FastTrack.exe
39-
mv bin/fasttrack-cli.exe bin/FastTrack-Cli.exe
4039
mv bin FastTrack
4140
windeployqt FastTrack/FastTrack.exe --no-translations # https://bugreports.qt.io/browse/QTBUG-62103?jql=status%20%3D%20Open%20AND%20text%20~%20%22windeployqt%20platform%22 and https://bugreports.qt.io/browse/QTBUG-112204
4241
cp ${{ github.workspace }}/src/assets/icon.ico FastTrack
@@ -63,4 +62,4 @@ jobs:
6362
- name: Run FastTrack executable
6463
run: |
6564
cd FastTrack
66-
./FastTrack-Cli.exe --help
65+
./FastTrack.exe --cli --help

src/CMakeLists.txt

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ add_executable(fasttrack
2323
timeline.cpp
2424
autolevel.cpp
2525
imageviewer.cpp
26+
cli.cpp
2627

2728
updater.h
2829
mainwindow.h
@@ -38,6 +39,7 @@ add_executable(fasttrack
3839
timeline.h
3940
autolevel.h
4041
imageviewer.h
42+
cli.h
4143

4244
mainwindow.ui
4345
replay.ui
@@ -58,19 +60,6 @@ add_custom_target(translations ALL DEPENDS ${QM_FILES})
5860

5961
target_compile_definitions(fasttrack PRIVATE APP_VERSION="${PROJECT_VERSION}")
6062

61-
add_executable(fasttrack-cli
62-
fasttrack-cli.cpp
63-
tracking.cpp
64-
videoreader.cpp
65-
Hungarian.cpp
66-
67-
tracking.h
68-
videoreader.h
69-
Hungarian.h
70-
)
71-
72-
target_compile_definitions(fasttrack-cli PRIVATE APP_VERSION="${PROJECT_VERSION}")
73-
7463
function(configure_target target_name)
7564
if(UNIX AND NOT APPLE)
7665
target_compile_options(${target_name} PRIVATE -O3)
@@ -116,7 +105,6 @@ function(configure_target target_name)
116105
endfunction()
117106

118107
configure_target(fasttrack)
119-
configure_target(fasttrack-cli)
120108

121109
if(UNIX AND NOT APPLE)
122110
install(TARGETS fasttrack DESTINATION /usr/bin)
@@ -132,5 +120,4 @@ if(UNIX AND NOT APPLE)
132120
DESTINATION share/licenses/fasttrack)
133121
endif()
134122

135-
install(TARGETS fasttrack-cli DESTINATION /usr/bin)
136123
install(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION /usr/share/licenses/fasttrack)

src/fasttrack-cli.cpp renamed to src/cli.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,7 @@ This file is part of Fast Track.
1515
along with FastTrack. If not, see <https://www.gnu.org/licenses/>.
1616
*/
1717

18-
#include <getopt.h>
19-
#include <stdio.h>
20-
#include <stdlib.h>
21-
#include <tracking.h>
22-
#include <QCoreApplication>
23-
#include <QHash>
24-
#include <QHashIterator>
25-
#include <QObject>
26-
#include <QString>
27-
#include <QStringList>
28-
#include <QTextStream>
29-
30-
using namespace std;
18+
#include "cli.h"
3119

3220
void loadConfig(const QString &path, QHash<QString, QString> &parameters) {
3321
QFile parameterFile(path);
@@ -100,10 +88,7 @@ All arguments are mandatory except --backPath and --cfg. Loading a configuration
10088
stdout);
10189
}
10290

103-
int main(int argc, char **argv) {
104-
QCoreApplication app(argc, argv);
105-
char env[] = "OPENCV_OPENCL_DEVICE=disabled";
106-
putenv(env); // disable OpenCL to fix windows memory leaks and increase performance
91+
int cli(int argc, char **argv) {
10792
static struct option long_options[] =
10893
{
10994
{"maxArea", required_argument, 0, 'a'},

src/cli.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
This file is part of Fast Track.
3+
4+
FastTrack is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
FastTrack is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with FastTrack. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
#ifndef CLI_H
19+
#define CLI_H
20+
#include <getopt.h>
21+
#include <stdio.h>
22+
#include <stdlib.h>
23+
#include <tracking.h>
24+
#include <QCoreApplication>
25+
#include <QHash>
26+
#include <QHashIterator>
27+
#include <QObject>
28+
#include <QString>
29+
#include <QStringList>
30+
#include <QTextStream>
31+
32+
using namespace std;
33+
34+
void loadConfig(const QString &path, QHash<QString, QString> &parameters);
35+
void help();
36+
int cli(int argc, char **argv);
37+
38+
#endif

src/main.cpp

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ This file is part of Fast Track.
2424
#include <QScopedPointer>
2525
#include <QSplashScreen>
2626
#include <QString>
27+
#include "cli.h"
2728
#include "mainwindow.h"
2829

2930
QScopedPointer<QFile> logFile;
@@ -35,27 +36,36 @@ void messageHandler(QtMsgType type, const QMessageLogContext &context, const QSt
3536
}
3637

3738
int main(int argc, char *argv[]) {
38-
char env[] = "OPENCV_OPENCL_DEVICE=disabled";
39-
putenv(env); // disable OpenCL to fix windows memory leaks and increase performance
40-
QApplication a(argc, argv);
41-
QPixmap pixmap(QStringLiteral(":/assets/icon.png"));
42-
QSplashScreen splash(pixmap);
43-
splash.show();
44-
a.setApplicationName(QStringLiteral("FastTrack"));
45-
a.setApplicationVersion(APP_VERSION); // clazy:exclude=qstring-allocations
46-
a.setOrganizationName(QStringLiteral("FastTrackOrg"));
47-
a.setOrganizationDomain(QStringLiteral("www.fasttrack.sh"));
48-
logFile.reset(new QFile(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/fasttrack.log"));
49-
QDir().mkpath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation));
50-
logFile.data()->open(QFile::Append | QFile::Text);
39+
qputenv("OPENCV_OPENCL_DEVICE", "disabled"); // disable OpenCL to fix windows memory leaks and increase performance
40+
if (qstrcmp(argv[1], "--cli")) {
41+
QApplication a(argc, argv);
42+
QPixmap pixmap(QStringLiteral(":/assets/icon.png"));
43+
QSplashScreen splash(pixmap);
44+
splash.show();
45+
a.setApplicationName(QStringLiteral("FastTrack"));
46+
a.setApplicationVersion(APP_VERSION); // clazy:exclude=qstring-allocations
47+
a.setOrganizationName(QStringLiteral("FastTrackOrg"));
48+
a.setOrganizationDomain(QStringLiteral("www.fasttrack.sh"));
49+
logFile.reset(new QFile(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/fasttrack.log"));
50+
QDir().mkpath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation));
51+
logFile.data()->open(QFile::Append | QFile::Text);
5152
#ifdef QT_NO_DEBUG
52-
qInstallMessageHandler(messageHandler);
53+
qInstallMessageHandler(messageHandler);
5354
#endif
54-
MainWindow w;
55-
w.setWindowIcon(QIcon(":/assets/icon.png"));
56-
QFontDatabase::addApplicationFont(QStringLiteral(":/assets/Font.ttf"));
57-
w.setStyleSheet(QStringLiteral("QWidget {font-family: 'Lato', sans-serif;}"));
58-
w.show();
59-
splash.finish(&w);
60-
a.exec();
55+
MainWindow w;
56+
w.setWindowIcon(QIcon(":/assets/icon.png"));
57+
QFontDatabase::addApplicationFont(QStringLiteral(":/assets/Font.ttf"));
58+
w.setStyleSheet(QStringLiteral("QWidget {font-family: 'Lato', sans-serif;}"));
59+
w.show();
60+
splash.finish(&w);
61+
a.exec();
62+
}
63+
else {
64+
std::vector<char *> args(argv, argv + argc);
65+
args.erase(args.begin() + 1);
66+
argc = static_cast<int>(args.size());
67+
argv = args.data();
68+
QCoreApplication a(argc, argv);
69+
return cli(argc, argv);
70+
}
6171
}

test/accuracyTest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,16 @@ def tracking(path, imagePath, normDist=None, normAngle=None, maxDist=None, maxTi
159159
morphType = str(int(groundParameter.loc["morphType"][1]))
160160

161161
if platform.system() == "Windows":
162-
executable = "FastTrack-Cli.exe"
162+
executable = "FastTrack.exe"
163163
prefix = ""
164164
elif platform.system() == "Linux":
165-
executable = "fasttrack-cli"
165+
executable = "fasttrack"
166166
prefix = ""
167167
elif platform.system() == "Darwin":
168-
executable = "fasttrack-cli.app --args"
168+
executable = "fasttrack.app --args"
169169
prefix = "open -W "
170170

171-
cmd = prefix + os.path.abspath("../build/bin/" + executable) + " --maxArea " + maxArea + " --minArea " + minArea + " --lightBack "+ lightBack + " --thresh "+ thresh + " --reg " + reg + " --spot "+ spot + " --nBack "+ nBack + " --regBack "+ regBack + " --methBack " + methBack+ " --xTop "+ xTop + " --yTop "+ yTop + " --xBottom " + xBottom + " --yBottom " + yBottom+ " --morph " + morph + " --morphSize " + morphSize+ " --morphType " + morphType +" --normArea " +str(normArea) + " --normPerim "+ str(normPerim) + " --normDist " + str(normDist) + " --normAngle " + str(normAngle) + " --maxDist " + str(maxDist) + " --maxTime " + str(maxTime) + " --path "+ os.path.abspath(path + imagePath) + " --backPath " + os.path.abspath("dataSet/images/Groundtruth/Tracking_Result/background.pgm") #+ " > /dev/null 2>&1"
171+
cmd = prefix + os.path.abspath("../build/bin/" + executable) + " --cli" + " --maxArea " + maxArea + " --minArea " + minArea + " --lightBack "+ lightBack + " --thresh "+ thresh + " --reg " + reg + " --spot "+ spot + " --nBack "+ nBack + " --regBack "+ regBack + " --methBack " + methBack+ " --xTop "+ xTop + " --yTop "+ yTop + " --xBottom " + xBottom + " --yBottom " + yBottom+ " --morph " + morph + " --morphSize " + morphSize+ " --morphType " + morphType +" --normArea " +str(normArea) + " --normPerim "+ str(normPerim) + " --normDist " + str(normDist) + " --normAngle " + str(normAngle) + " --maxDist " + str(maxDist) + " --maxTime " + str(maxTime) + " --path "+ os.path.abspath(path + imagePath) + " --backPath " + os.path.abspath("dataSet/images/Groundtruth/Tracking_Result/background.pgm") #+ " > /dev/null 2>&1"
172172
print(cmd)
173173
out = os.system(cmd)
174174

0 commit comments

Comments
 (0)