Skip to content

Commit 161acab

Browse files
committed
Improve CLI + Added CI & Style
- Added clang-tidy - Added CI Script to build FileShare on different platforms - Building CLI or GUI is now optional - CLI now supports custom config file, as well as many commands in interactive mode (Config edit, peer management, send/list/receive file)
1 parent 3fd7ccb commit 161acab

10 files changed

Lines changed: 1145 additions & 128 deletions

File tree

.clang-tidy

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
Checks: '
2+
*,
3+
-llvmlibc-*,
4+
-android-*,
5+
-altera-*,
6+
-fuchsia*,
7+
-google-readability-todo,
8+
-cppcoreguidelines-init-variables,
9+
-cppcoreguidelines-pro-type-reinterpret-cast,
10+
-llvm-namespace-comment,
11+
-readability-implicit-bool-conversion,
12+
-google-explicit-constructor,
13+
-abseil-string-find-str-contains,
14+
-readability-avoid-return-with-void-value,
15+
-readability-convert-member-functions-to-static,
16+
17+
-google-readability-braces-around-statements,
18+
-google-readability-namespace-comments,
19+
-hicpp-special-member-functions,
20+
-hicpp-braces-around-statements,
21+
-hicpp-explicit-conversions
22+
'
23+
24+
WarningsAsErrors: 'bugprone-exception-escape'
25+
FormatStyle: 'none' # TODO: Replace with 'file' once we have a proper .clang-format file
26+
InheritParentConfig: true
27+
CheckOptions:
28+
misc-include-cleaner.MissingIncludes: 'false'
29+
misc-include-cleaner.IgnoreHeaders: 'CppSockets/OSDetection.*;.*Version.hpp'
30+
31+
bugprone-argument-comment.StrictMode: 1
32+
33+
# Readability
34+
readability-braces-around-statements.ShortStatementLines: 2
35+
36+
readability-identifier-naming.NamespaceCase: CamelCase
37+
38+
readability-identifier-length.IgnoredVariableNames: "^(fd|nb|n|ss|ec|is|os|_.*)$"
39+
readability-identifier-length.IgnoredParameterNames: "^(fd|n|is|os|_.*)$"
40+
41+
cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor: true
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
name: "Code Scanning"
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
# The branches below must be a subset of the branches above
8+
branches: [ "master" ]
9+
schedule:
10+
- cron: '20 3 * * 0'
11+
12+
jobs:
13+
codeql:
14+
name: CodeQL
15+
# Runner size impacts CodeQL analysis time. To learn more, please see:
16+
# - https://gh.io/recommended-hardware-resources-for-running-codeql
17+
# - https://gh.io/supported-runners-and-hardware-resources
18+
# - https://gh.io/using-larger-runners
19+
# Consider using larger runners for possible analysis time improvements.
20+
runs-on: ubuntu-latest
21+
timeout-minutes: 360
22+
permissions:
23+
actions: read
24+
contents: read
25+
security-events: write
26+
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v3
30+
31+
# Initializes the CodeQL tools for scanning.
32+
- name: Initialize CodeQL
33+
uses: github/codeql-action/init@v3
34+
with:
35+
languages: 'c-cpp'
36+
# If you wish to specify custom queries, you can do so here or in a config file.
37+
# By default, queries listed here will override any specified in a config file.
38+
# Prefix the list here with "+" to use these queries and those in the config file.
39+
40+
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
41+
# queries: security-extended,security-and-quality
42+
43+
44+
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
45+
# If this step fails, then you should remove it and run the build manually (see below)
46+
- name: Autobuild
47+
uses: github/codeql-action/autobuild@v3
48+
49+
- name: Perform CodeQL Analysis
50+
uses: github/codeql-action/analyze@v3
51+
with:
52+
category: "/language:c-cpp"
53+
54+
flawfinder:
55+
name: Flawfinder
56+
runs-on: ubuntu-latest
57+
permissions:
58+
actions: read
59+
contents: read
60+
security-events: write
61+
steps:
62+
- name: Checkout code
63+
uses: actions/checkout@v3
64+
65+
- name: flawfinder_scan
66+
uses: david-a-wheeler/flawfinder@2.0.19
67+
with:
68+
arguments: '--sarif ./'
69+
output: 'flawfinder_results.sarif'
70+
71+
- name: Upload analysis results to GitHub Security tab
72+
uses: github/codeql-action/upload-sarif@v3
73+
with:
74+
sarif_file: ${{github.workspace}}/flawfinder_results.sarif
75+
76+
microsoft-analyze:
77+
permissions:
78+
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
79+
contents: read # for actions/checkout to fetch code
80+
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
81+
name: Microsoft Analyze
82+
runs-on: windows-latest
83+
84+
env:
85+
# Path to the CMake build directory.
86+
build: '${{ github.workspace }}/build'
87+
config: 'Debug'
88+
89+
steps:
90+
- name: Checkout repository
91+
uses: actions/checkout@v3
92+
93+
- name: VCPKG Install (Windows)
94+
uses: ./.github/workflows/windows-vcpkg
95+
with:
96+
key: ${{ runner.os }}-${{ env.config }}
97+
98+
- name: Configure CMake
99+
run: cmake -B ${{ env.build }} -DCMAKE_BUILD_TYPE=${{ env.config }}
100+
101+
# Build is not required unless generated source files are used
102+
# - name: Build CMake
103+
# run: cmake --build ${{ env.build }} --config ${{ env.config }}
104+
105+
- name: Run MSVC Code Analysis
106+
uses: microsoft/msvc-code-analysis-action@v0.1.1
107+
# Provide a unique ID to access the sarif output path
108+
id: run-analysis
109+
with:
110+
cmakeBuildDirectory: ${{ env.build }}
111+
buildConfiguration: ${{ env.config }}
112+
# Ruleset file that will determine what checks will be run
113+
ruleset: NativeRecommendedRules.ruleset
114+
# Paths to ignore analysis of CMake targets and includes
115+
# ignoredPaths: ${{ github.workspace }}/dependencies;${{ github.workspace }}/test
116+
117+
# Upload SARIF file to GitHub Code Scanning Alerts
118+
- name: Upload SARIF to GitHub
119+
uses: github/codeql-action/upload-sarif@v3
120+
with:
121+
sarif_file: ${{ steps.run-analysis.outputs.sarif }}
122+
123+
# # Upload SARIF file as an Artifact to download and view
124+
# - name: Upload SARIF as an Artifact
125+
# uses: actions/upload-artifact@v4
126+
# with:
127+
# name: sarif-file
128+
# path: ${{ steps.run-analysis.outputs.sarif }}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Windows VCPKG
2+
3+
inputs:
4+
key:
5+
required: true
6+
type: string
7+
8+
runs:
9+
using: "composite"
10+
steps:
11+
- name: Set Env
12+
shell: powershell
13+
run: |
14+
echo "VCPKG_ROOT=${env:VCPKG_INSTALLATION_ROOT}" | Out-File -FilePath $env:GITHUB_ENV -Append
15+
echo "VCPKG_CACHE=${env:LOCALAPPDATA}\vcpkg\archives" | Out-File -FilePath $env:GITHUB_ENV -Append
16+
17+
- name: Fetch VCPKG Cache (Windows)
18+
id: fetch-vcpkg-cache
19+
if: runner.os == 'Windows'
20+
uses: actions/cache/restore@v4
21+
with:
22+
key: ${{ inputs.key }}-vcpkg-${{ hashFiles('vcpkg.json') }}
23+
path: ${{ env.VCPKG_CACHE }}
24+
25+
- name: VCPKG Install (Windows)
26+
if: runner.os == 'Windows'
27+
shell: powershell
28+
run: |
29+
echo "CMAKE_TOOLCHAIN_FILE=${env:VCPKG_ROOT}\scripts\buildsystems\vcpkg.cmake" | Out-File -FilePath $env:GITHUB_ENV -Append
30+
vcpkg install
31+
32+
- name: Always Save VCPKG Cache (Windows)
33+
if: always() && runner.os == 'Windows' && steps.fetch-vcpkg-cache.outputs.cache-hit != 'true'
34+
uses: actions/cache/save@v4
35+
with:
36+
key: ${{ steps.fetch-vcpkg-cache.outputs.cache-primary-key }}
37+
path: ${{ env.VCPKG_CACHE }}

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ compile_commands.json
66

77
*.tmp
88
*.gch
9+
*.pch
910
vgcore.*
1011

11-
.vscode
12+
.vscode/
13+
.cache/

CMakeLists.txt

Lines changed: 53 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
## Author Francois Michaut
55
##
66
## Started on Sat Jan 15 01:19:13 2022 Francois Michaut
7-
## Last update Fri Nov 24 10:00:00 2023 Francois Michaut
7+
## Last update Sun Aug 24 18:52:09 2025 Francois Michaut
88
##
99
## CMakeLists.txt : Top level CMake
1010
##
@@ -14,17 +14,17 @@ set(CMAKE_CXX_STANDARD 20)
1414
set(CMAKE_CXX_STANDARD_REQUIRED True)
1515
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
1616

17-
include(ExternalProject)
1817
include(FetchContent)
1918

20-
# TODO: This currently breaks Apple/Windows builds: find another solution
21-
# set_property(GLOBAL PROPERTY ALLOW_DUPLICATE_CUSTOM_TARGETS 1)
2219
set(MAKEFLAGS "--no-print-directory")
2320

21+
option(BUILD_CLI "Build the FileShare CLI" ON)
22+
option(BUILD_GUI "Build the FileShare GUI" ON)
23+
2424
if (!WIN32)
2525
set(CMAKE_CXX_FLAGS_DEBUG_INIT "-O0 -DDEBUG -g3")
2626
set(CMAKE_CXX_FLAGS_RELEASE_INIT "-O3")
27-
add_compile_definitions(_GNU_SOURCE)
27+
add_compile_definitions(_GNU_SOURCE _FILE_OFFSET_BITS=64 _TIME_BITS=64)
2828
endif()
2929

3030
project(FileShare VERSION 0.1.0 LANGUAGES C CXX)
@@ -33,74 +33,70 @@ configure_file(include/FileShareVersion.hpp.in FileShareVersion.hpp)
3333
add_subdirectory(dependencies)
3434

3535
include_directories(
36-
"${CMAKE_CURRENT_BINARY_DIR}"
37-
"${CMAKE_CURRENT_SOURCE_DIR}/include"
36+
"${CMAKE_CURRENT_BINARY_DIR}" # For the configured Version file
37+
"${CMAKE_CURRENT_SOURCE_DIR}/include" # For the regular includes
3838
)
3939

40-
set(executables "")
41-
42-
function(add_mvc_source)
43-
set(local_executables ${executables})
40+
set(mvc_sources "")
41+
function(add_mvc_sources)
42+
set(local_sources ${mvc_sources})
4443

4544
foreach(name IN LISTS ARGN)
46-
set(new_executables
45+
set(new_sources
4746
"source/${name}/View.cpp"
4847
"source/${name}/Model.cpp"
4948
"source/${name}/Controller.cpp"
5049
)
5150

52-
set(local_executables ${local_executables} ${new_executables})
51+
set(local_sources ${local_sources} ${new_sources})
5352
endforeach()
5453

55-
set(executables ${local_executables} PARENT_SCOPE)
54+
set(mvc_sources ${local_sources} PARENT_SCOPE)
5655
endfunction()
5756

58-
add_mvc_source(DeviceList Settings)
59-
add_executable(file-share
60-
source/main.cpp
61-
source/Application.cpp
62-
source/Debug.cpp
63-
source/Components/Button.cpp
64-
source/Components/Foldout.cpp
65-
source/Components/InputFileDialog.cpp
66-
source/Components/List.cpp
67-
source/Components/ListMenu.cpp
68-
${executables}
69-
)
57+
if (BUILD_GUI)
58+
add_mvc_sources(DeviceList Settings)
59+
add_executable(file-share
60+
source/main.cpp
61+
source/Application.cpp
62+
source/Debug.cpp
63+
source/Components/Button.cpp
64+
source/Components/Foldout.cpp
65+
source/Components/InputFileDialog.cpp
66+
source/Components/List.cpp
67+
source/Components/ListMenu.cpp
68+
${mvc_sources}
69+
)
7070

71-
target_compile_definitions(file-share PRIVATE _LARGEFILE_SOURCE _FILE_OFFSET_BITS=64)
72-
target_link_libraries(file-share tgui sfml-graphics sfml-window sfml-system sqlite_orm::sqlite_orm fsp)
73-
target_compile_options(file-share PRIVATE
74-
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:-Wall -Wextra>
75-
$<$<CXX_COMPILER_ID:MSVC>:/W4>
76-
)
71+
target_compile_definitions(file-share PRIVATE _LARGEFILE_SOURCE _FILE_OFFSET_BITS=64)
72+
target_link_libraries(file-share tgui sfml-graphics sfml-window sfml-system sqlite_orm::sqlite_orm fsp)
73+
target_compile_options(file-share PRIVATE
74+
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:-Wall -Wextra>
75+
$<$<CXX_COMPILER_ID:MSVC>:/W4>
76+
)
77+
endif()
7778

78-
add_executable(file-share-cli
79-
source/cli/main.cpp
80-
)
79+
if (BUILD_CLI)
80+
add_executable(file-share-cli
81+
source/cli/main.cpp
82+
source/cli/interactive.cpp
83+
)
84+
85+
target_compile_definitions(file-share-cli PRIVATE _LARGEFILE_SOURCE _FILE_OFFSET_BITS=64)
86+
target_link_libraries(file-share-cli argparse fsp)
87+
if (!APPLE)
88+
target_precompile_headers(file-share-cli
89+
PRIVATE "${argparse_SOURCE_DIR}/include/argparse/argparse.hpp"
90+
)
91+
endif()
8192

82-
target_compile_definitions(file-share-cli PRIVATE _LARGEFILE_SOURCE _FILE_OFFSET_BITS=64)
83-
target_link_libraries(file-share-cli argparse fsp)
84-
if (!APPLE)
85-
target_precompile_headers(file-share-cli
86-
PRIVATE
87-
"${argparse_SOURCE_DIR}/include/argparse/argparse.hpp"
93+
target_compile_options(file-share-cli PRIVATE
94+
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:-Wall -Wextra>
95+
$<$<CXX_COMPILER_ID:MSVC>:/W4>
8896
)
8997
endif()
90-
target_compile_options(file-share-cli PRIVATE
91-
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:-Wall -Wextra>
92-
$<$<CXX_COMPILER_ID:MSVC>:/W4>
93-
)
9498

95-
add_custom_target(test
96-
COMMAND ${CMAKE_COMMAND} --log-level=WARNING
97-
-B "${CMAKE_CURRENT_BINARY_DIR}/tests"
98-
-S "${CMAKE_CURRENT_SOURCE_DIR}/tests"
99-
-G ${CMAKE_GENERATOR}
100-
COMMAND ${CMAKE_COMMAND} -E cmake_echo_color
101-
--switch=$(COLOR) --cyan "Building tests..."
102-
COMMAND ${CMAKE_COMMAND}
103-
--build "${CMAKE_CURRENT_BINARY_DIR}/tests" -- --quiet
104-
COMMAND ${CMAKE_MAKE_PROGRAM}
105-
-C "${CMAKE_CURRENT_BINARY_DIR}/tests" test ARGS=--output-on-failure
106-
)
99+
option(FILE_SHARE_BUILD_TESTS "TRUE to build the FileShare tests" FALSE)
100+
if(FILE_SHARE_BUILD_TESTS)
101+
add_subdirectory(tests)
102+
endif()

dependencies/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
## Author Francois Michaut
55
##
66
## Started on Wed Jul 10 10:27:39 2024 Francois Michaut
7-
## Last update Sat Aug 10 09:39:35 2024 Francois Michaut
7+
## Last update Sun Aug 24 12:51:51 2025 Francois Michaut
88
##
99
## CMakeLists.txt : CMake to fetch and build the dependecies of the FileShare executable
1010
##
@@ -33,14 +33,14 @@ set(TGUI_BUILD_FRAMEWORK FALSE)
3333
FetchContent_Declare(
3434
tgui
3535
GIT_REPOSITORY https://github.com/texus/TGUI
36-
GIT_TAG 002ec9d21111d5a42ded92e589b8fb485933b3f9
36+
GIT_TAG v1.10.0
3737
FIND_PACKAGE_ARGS NAMES TGUI
3838
)
3939

4040
FetchContent_Declare(
4141
fsp
4242
GIT_REPOSITORY https://github.com/FileShare-Project/libfsp.git
43-
GIT_TAG b2272f6740ff1458751d5e09812a2da28afd37b8
43+
GIT_TAG e36512b59f700abcc5cb379d77ee18aa8b6757fb
4444
)
4545

4646
FetchContent_MakeAvailable(fsp argparse SFML sqlite_orm tgui)

0 commit comments

Comments
 (0)