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

Fix: build and help #15

Merged
merged 15 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
34 changes: 24 additions & 10 deletions .github/workflows/build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,26 @@ jobs:
matrix:
os:
- { id: ubuntu-22.04, name: jammy }
- { id: ubuntu-24.04, name: noble }
compiler:
- 'clang-13'
- 'clang-15'
- 'clang-16'
- 'clang-17'
- 'clang-18'
- 'gcc-9'
- 'gcc-10'
- 'gcc-11'
- 'gcc-12'
- 'gcc-13'
exclude:
# Exclude compilers that don't exist on the new LTS
- os: { id: ubuntu-24.04, name: noble }
compiler: 'clang-13'
- os: { id: ubuntu-24.04, name: noble }
compiler: 'clang-15'
- os: { id: ubuntu-24.04, name: noble }
compiler: 'clang-16'
fail-fast: false
env:
BUILD_OPTS: ''
Expand Down Expand Up @@ -71,34 +82,37 @@ jobs:
CC: ${{ matrix.compiler }}
working-directory: ${{ runner.temp }}
- name: Remove old LLVM 12 plugins
if: matrix.compiler != 'clang-12'
run: |
sudo apt purge llvm-12-linker-tools
sudo apt purge llvm-12-linker-tools || true
- name: Remove old LLVM 13 plugins
if: matrix.compiler != 'clang-13'
run: |
sudo apt purge llvm-13-linker-tools
sudo apt purge llvm-13-linker-tools || true
- name: Remove old LLVM 14 plugins
if: matrix.compiler != 'clang-14'
run: |
sudo apt purge llvm-14-linker-tools
sudo apt purge llvm-14-linker-tools || true
- name: Remove old LLVM 15 plugins
if: matrix.compiler != 'clang-15'
run: |
sudo apt purge llvm-15-linker-tools
sudo apt purge llvm-15-linker-tools || true
- name: Install dependencies
shell: bash
run: sudo apt-get install libudev-dev
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
lfs: true
submodules: true
- name: Setup Meson + Ninja + gcovr
- name: Upgrade pip + wheel
if: matrix.os.name == 'jammy'
shell: bash
run: |
sudo python3 -m pip install --upgrade pip setuptools wheel
python3 -m pip install --user meson ninja gcovr
- name: Setup Meson + Ninja + gcovr
shell: bash
run: |
python3 -m pip install --break-system-packages --user meson ninja gcovr
working-directory: ${{ runner.temp }}
- name: Version tools
shell: bash
Expand Down Expand Up @@ -127,14 +141,14 @@ jobs:
ninja -C build coverage-xml
- name: Upload failure logs
if: failure()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: logs-${{ matrix.os.id }}-${{ matrix.compiler }}
path: ${{ github.workspace }}/build/meson-logs/*
retention-days: 5
- name: Codecov
if: success() && github.repository == 'blackmagic-debug/bmpflash' && matrix.compiler != 'clang-17'
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
directory: ./build/meson-logs/
files: coverage.xml
Expand Down
19 changes: 9 additions & 10 deletions .github/workflows/build-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ jobs:
strategy:
matrix:
os:
- macos-12
- macos-11
- macos-13
- macos-14
build_opts:
- ''
include:
Expand All @@ -41,7 +41,7 @@ jobs:
run: |
echo "GITHUB_WORKSPACE=`pwd`" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
lfs: true
submodules: true
Expand Down Expand Up @@ -75,14 +75,14 @@ jobs:
ninja -C build coverage-xml
- name: Upload failure logs
if: failure()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: logs-${{ matrix.os }}-appleclang
path: ${{ github.workspace }}/build/meson-logs/*
retention-days: 5
- name: Codecov
if: success() && github.repository == 'blackmagic-debug/bmpflash'
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
directory: ./build/meson-logs/
files: coverage.xml
Expand All @@ -100,9 +100,8 @@ jobs:
strategy:
matrix:
os:
- macos-11
- macos-latest
compiler:
- gcc@9
- gcc@11
- gcc@12
- gcc@13 # needs hardcoding for the GCOV replacement
Expand All @@ -126,7 +125,7 @@ jobs:
env:
COMPILER: ${{ matrix.compiler }}
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
lfs: true
submodules: true
Expand Down Expand Up @@ -162,14 +161,14 @@ jobs:
ninja -C build coverage-xml
- name: Upload failure logs
if: failure()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: logs-${{ matrix.os }}-homebrew-${{ matrix.compiler }}
path: ${{ github.workspace }}/build/meson-logs/*
retention-days: 5
- name: Codecov
if: success() && github.repository == 'blackmagic-debug/bmpflash'
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
directory: ./build/meson-logs/
files: coverage.xml
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
build-windows:
name: '${{ matrix.os }} (msvc ${{ matrix.arch }})'
runs-on: ${{ matrix.os }}
if: false
# if: false
strategy:
matrix:
os:
Expand All @@ -43,15 +43,15 @@ jobs:
arch: ${{ matrix.arch }}
- name: Install OpenCppCoverage
if: github.repository == 'blackmagic-debug/bmpflash'
uses: crazy-max/ghaction-chocolatey@v2.1.0
uses: crazy-max/ghaction-chocolatey@v3
with:
args: install OpenCppCoverage
- name: Setup OpenCppCoverage
if: github.repository == 'blackmagic-debug/bmpflash'
run: |
echo "C:/Program Files/OpenCppCoverage" >> $env:GITHUB_PATH
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
lfs: true
submodules: true
Expand Down Expand Up @@ -84,7 +84,7 @@ jobs:
meson test -C build
- name: Upload failure logs
if: failure()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: logs-${{ matrix.os }}-${{ matrix.arch }}
path: |
Expand All @@ -93,7 +93,7 @@ jobs:
retention-days: 5
- name: Codecov
if: success() && github.repository == 'blackmagic-debug/bmpflash'
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}

Expand All @@ -106,7 +106,7 @@ jobs:
strategy:
matrix:
os:
- windows-2019
- windows-2022
sys:
- mingw64
- ucrt64
Expand Down Expand Up @@ -139,7 +139,7 @@ jobs:
run: |
echo "GCOV=llvm-cov gcov" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
lfs: true
submodules: true
Expand Down Expand Up @@ -175,14 +175,14 @@ jobs:
ninja -C build coverage-xml
- name: Upload failure logs
if: failure()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: logs-${{ matrix.os }}-${{ matrix.sys }}
path: ${{ github.workspace }}/build/meson-logs/*
retention-days: 5
- name: Codecov
if: success() && github.repository == 'blackmagic-debug/bmpflash'
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
directory: ./build/meson-logs/
files: coverage.xml
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ project(
'warning_level=3',
'buildtype=release',
'strip=true',
'b_debug=if-release',
'b_ndebug=if-release',
'b_lto=true',
# libusb needs to pass functions to/from C++ land
'cpp_eh=s',
Expand Down
39 changes: 12 additions & 27 deletions src/bmpflash.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,6 @@
arguments_t args{};
uint64_t verbosity{0U};

namespace bmpflash
{
void displayHelp() noexcept
{
console.info("bmpflash - Black Magic Probe companion utility for SPI Flash provisioning and usage"sv);
console.writeln();
console.writeln("Usage:"sv);
console.writeln("\tbmpflash [options] {action} [actionOptions]"sv);
console.writeln();
programOptions.displayHelp();
console.writeln();
console.writeln("This utility is licensed under BSD-3-Clause"sv);
console.writeln("Please report bugs to https://github.com/blackmagic-debug/bmpflash/issues"sv);
}
}

[[nodiscard]] auto findBMPs(const usbContext_t &context)
{
std::vector<usbDevice_t> devices{};
Expand Down Expand Up @@ -76,14 +60,7 @@
console.showDebug(verbosity & 1U);

// Handle the version and help options first
const auto *const version{args["version"sv]};
const auto *const help{args["help"sv]};
if (version && help)
{
console.error("Can only specify one of --help and --version, not both."sv);
return 1;
}
if (version)
if (args["version"sv])
{
bmpflash::displayVersion();
const auto *const libusbVersion{libusb_get_version()};
Expand All @@ -92,9 +69,9 @@
return 0;
}
// Display the help if requested or there were no command line options given
if (help || args.count() == 0U)
if (args["help"sv] || args.count() == 0U)
{
bmpflash::displayHelp();
bmpflash::programOptions.displayHelp(args);

Check warning on line 74 in src/bmpflash.cxx

View check run for this annotation

Codecov / codecov/patch

src/bmpflash.cxx#L74

Added line #L74 was not covered by tests
return 0;
}

Expand All @@ -103,11 +80,19 @@
if (!actionArg)
{
console.error("Action to perform must be specified"sv);
bmpflash::displayHelp();
bmpflash::programOptions.displayHelp(args);

Check warning on line 83 in src/bmpflash.cxx

View check run for this annotation

Codecov / codecov/patch

src/bmpflash.cxx#L83

Added line #L83 was not covered by tests
return 1;
}
const auto &action{std::get<choice_t>(*actionArg)};

// Check if `-h`/`--help` was given for this action
if (action.arguments()["help"sv])
{
// Display the appropriate help
bmpflash::programOptions.displayHelp(args);
return 0;

Check warning on line 93 in src/bmpflash.cxx

View check run for this annotation

Codecov / codecov/patch

src/bmpflash.cxx#L92-L93

Added lines #L92 - L93 were not covered by tests
}

// Get a libusb context to perform everything in
const usbContext_t context{};
if (!context.valid())
Expand Down
29 changes: 20 additions & 9 deletions src/include/options.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace bmpflash
)
};

constexpr static auto provisioningOptions{options(serialOption, fileOption)};
constexpr static auto provisioningOptions{options(probeOptions, fileOption)};
constexpr static auto generalFlashOptions{options(deviceOptions, fileOption)};

constexpr static auto actions
Expand Down Expand Up @@ -109,14 +109,25 @@ namespace bmpflash

constexpr static auto programOptions
{
options
(
option_t{optionFlagPair_t{"-h"sv, "--help"sv}, "Display this help message and exit"sv},
option_t{"--version"sv, "Display the program version information and exit"sv},
option_t{optionFlagPair_t{"-v"sv, "--verbosity"sv}, "Set the program output verbosity"sv}
.takesParameter(optionValueType_t::unsignedInt).valueRange(0U, 1U),
optionSet_t{"action"sv, actions}
)
optionsRoot_t
{
options
(
option_t{optionFlagPair_t{"-h"sv, "--help"sv}, "Display this help message and exit"sv}
.exclusive().global(),
option_t{"--version"sv, "Display the program version information and exit"sv}.exclusive(),
option_t{optionFlagPair_t{"-v"sv, "--verbosity"sv}, "Set the program output verbosity"sv}
.takesParameter(optionValueType_t::unsignedInt).valueRange(0U, 1U),
optionSet_t{"action"sv, actions}
)
}
.helpHeader("bmpflash - Black Magic Probe companion utility for SPI Flash provisioning and usage"sv)
.usage("bmpflash [options] {action} [actionOptions]"sv)
.helpFooter
(
"This utility is licensed under BSD-3-Clause\n"
"Please report bugs to https://github.com/blackmagic-debug/bmpflash/issues"sv
)
};
} // namespace bmpflash

Expand Down
Loading