Skip to content
Open
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
95 changes: 92 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ jobs:
uses: actions/checkout@v4
with:
path: up-zenoh-example-cpp
repository: eclipse-uprotocol/up-zenoh-example-cpp

- name: Fetch up-cpp conan recipe
uses: actions/checkout@v4
Expand All @@ -39,7 +38,7 @@ jobs:
- name: Build up-core-api conan recipe
shell: bash
run: |
conan create --version 1.6.0 up-conan-recipes/up-core-api/release
conan create --version 1.6.0-alpha2 --build=missing up-conan-recipes/up-core-api/release

- name: Build up-cpp conan recipe
shell: bash
Expand All @@ -59,8 +58,98 @@ jobs:
cmake --preset conan-release -DCMAKE_EXPORT_COMPILE_COMMANDS=yes
cd build/Release
cmake --build . -- -j

- name: Upload compile commands
uses: actions/upload-artifact@v4
with:
name: compile-commands
path: up-zenoh-example-cpp/build/Release/compile_commands.json

- name: Save conan cache to archive
shell: bash
run: |
conan cache save --file ./conan-cache.tgz '*'

- name: Upload conan cache for linting
uses: actions/upload-artifact@v4
with:
name: conan-cache
path: ./conan-cache.tgz


lint:
name: Lint C++ sources
runs-on: ubuntu-22.04
needs: build
permissions:
contents: write
pull-requests: read
steps:
- name: Fetch up-zenoh-example-cpp
uses: actions/checkout@v4
with:
path: up-zenoh-example-cpp

- name: Get build commands
uses: actions/download-artifact@v4
with:
name: compile-commands

- name: Install Conan
id: conan
uses: turtlebrowser/get-conan@main
with:
version: 2.3.2

- name: Install conan CI profile
shell: bash
run: |
conan profile detect
cp up-zenoh-example-cpp/.github/workflows/ci_conan_profile "$(conan profile path default)"
conan profile show

- name: Get conan cache
uses: actions/download-artifact@v4
with:
name: conan-cache

- name: Restore conan cache from archive
shell: bash
run: |
conan cache restore conan-cache.tgz

- name: Run linters on source
id: source-linter
uses: cpp-linter/cpp-linter-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
repo-root: up-zenoh-example-cpp
ignore: 'test'
style: 'file' # read .clang-format for configuration
tidy-checks: '' # Read .clang-tidy for configuration
database: compile_commands.json
version: 13

- name: Run linters on tests
id: test-linter
uses: cpp-linter/cpp-linter-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
repo-root: up-zenoh-example-cpp
ignore: 'src|include'
style: 'file' # read .clang-format for configuration
tidy-checks: '' # Read .clang-tidy for configuration
database: compile_commands.json
version: 13

- name: Report lint failure
if:
steps.source-linter.outputs.checks-failed > 0 ||
steps.test-linter.outputs.checks-failed > 0
run: |
exit 1

# NOTE: In GitHub repository settings, the "Require status checks to pass
# before merging" branch protection rule ensures that commits are only merged
# from branches where specific status checks have passed. These checks are
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/ci_conan_profile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=gnu17
compiler.libcxx=libstdc++11
compiler.version=11
os=Linux
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ C++ Example application and service that utilizes up-client-zenoh-cpp

Use the up-conan-recipes repo and compile the following recipes:
```
$ conan create --version 1.6.0 --build=missing up-core-api/developer
$ conan create --version 1.0.1-rc1 --build=missing up-cpp/developer
$ conan create --version 1.6.0-alpha4 --build=missing up-core-api/release
$ conan create --version 1.0.1-rc1 --build=missing up-cpp/release
$ conan create --version 1.0.0-dev --build=missing up-transport-socket-cpp/developer
```

Expand Down
4 changes: 2 additions & 2 deletions conanfile.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[requires]
up-cpp/[^1.0.1, include_prerelease]
up-cpp/1.0.1-rc1
spdlog/[~1.13]
up-core-api/1.6.0
up-core-api/1.6.0-alpha2
protobuf/[>=3.21.12]
up-transport-socket-cpp/[>=1.0.0, include_prerelease]

Expand Down
28 changes: 28 additions & 0 deletions lint/clang-format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

PROJECT_ROOT="$(realpath "$(dirname "$0")/../")"

if [ -n "$(which clang-format-13)" ]; then
# NOTE: Using clang-format-13 in CI system, too
FORMATTER=clang-format-13
elif [ -n "$(which clang-format)" ]; then
echo "Did not find clang-format-13. Trying clang-format. Results may not"
echo "match formatting in GitHub CI process."
FORMATTER=clang-format
else
echo "Could not find clang-format. Please make sure it is installed" 1>&2
exit 2
fi

echo "Running $FORMATTER on all files in '$PROJECT_ROOT'"
shopt -s globstar

pushd "$PROJECT_ROOT" > /dev/null
for f in **/*.h **/*.cpp; do
if [[ ! ("$f" =~ "build/") ]]; then
echo
echo "Checking file '$f'"
$FORMATTER -i "$f"
fi
done
popd > /dev/null
81 changes: 81 additions & 0 deletions lint/clang-tidy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/bash

PROJECT_ROOT="$(realpath "$(dirname "$0")/../")"

if [ -n "$(which clang-tidy-13)" ]; then
# NOTE: Using clang-tidy-13 in CI system, too
LINTER=clang-tidy-13
elif [ -n "$(which clang-tidy)" ]; then
echo "Did not find clang-tidy-13. Trying clang-tidy. Results may not"
echo "match formatting in GitHub CI process."
LINTER=clang-tidy
else
echo "Could not find clang-tidy. Please make sure it is installed" 1>&2
exit 2
fi

usage() {
echo "$(basename "$0") path/to/compile_commands.json [source_to_lint]" 1>&2
echo 1>&2
echo " compile_commands.json" 1>&2
echo " Produced during a cmake build when configured with the" 1>&2
echo " -DCMAKE_EXPORT_COMPILE_COMMANDS=yes flag" 1>&2
echo 1>&2
echo " source_to_lint (optional)" 1>&2
echo " Source file to run clang-tidy against. If not specified," 1>&2
echo " all source files in the repo will be scanned." 1>&2
}

if [ "$1" == "-h" ] || [ "$1" == "--help" ] || [ "$1" == "/h" ] || [ "$1" == "/?" ]; then
usage
exit
fi

compile_database="$1"

if [ -z "$compile_database" ]; then
echo "No compile database specified. Make sure cmake was configured" 1>&2
echo "with '-DCMAKE_EXPORT_COMPILE_COMMANDS=yes' and re-run the build" 1>&2
echo 1>&2
echo "Usage:" 1>&2
usage
exit 1
elif [ ! -f "$compile_database" ]; then
echo "Compile database file not found. Make sure cmake was configured" 1>&2
echo "with '-DCMAKE_EXPORT_COMPILE_COMMANDS=yes' and re-run the build" 1>&2
echo 1>&2
echo "Usage:" 1>&2
usage
exit 1
fi

compile_database="$(realpath "$compile_database")"

target_source="$2"

if [ -z "$target_source" ]; then
echo "Running $LINTER on all files in '$PROJECT_ROOT'"
shopt -s globstar

pushd "$PROJECT_ROOT" > /dev/null
for f in **/*.h **/*.cpp; do
if [[ ! ("$f" =~ "build/") ]]; then
echo
echo "Checking file '$f'"
$LINTER -p "$(dirname "$compile_database")" "$f"
fi
done
popd > /dev/null
exit
fi

if [ ! -f "$target_source" ]; then
echo "Target source file '$target_source' not found." 1>&2
echo 1>&2
echo "Usage:" 1>&2
usage
exit 1
fi

echo "Running $LINTER on '$target_source'"
$LINTER -p "$(dirname "$compile_database")" "$target_source"
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
//
// SPDX-License-Identifier: Apache-2.0

#ifndef UTRANSPORT_DOMAIN_SOCKETS_H
#define UTRANSPORT_DOMAIN_SOCKETS_H
#ifndef UTRANSPORTDOMAINSOCKETS_H
#define UTRANSPORTDOMAINSOCKETS_H

#include <up-cpp/transport/UTransport.h>

#include <filesystem>
#include <thread>

using namespace uprotocol;
namespace uprotocol::transport {

class UTransportDomainSockets : public transport::UTransport {
class UTransportDomainSockets : public UTransport {
public:
explicit UTransportDomainSockets(const v1::UUri& uuri);
virtual ~UTransportDomainSockets();
~UTransportDomainSockets() override;

private:
int fdSocket_; // socket handle
Expand All @@ -44,5 +44,6 @@ class UTransportDomainSockets : public transport::UTransport {
void listenThread(); // listen for incoming messages (thread)
void cleanupListener(CallableConn listener) override {}
}; // class UTransportDomainSockets
} // namespace uprotocol::transport

#endif // UTRANSPORT_DOMAIN_SOCKETS_H
#endif // UTRANSPORTDOMAINSOCKETS_H
32 changes: 18 additions & 14 deletions pubsub/include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,37 @@
// SPDX-FileCopyrightText: 2024 General Motors GTO LLC
// SPDX-License-Identifier: Apache-2.0

#ifndef PUBSUB_COMMON_H
#define PUBSUB_COMMON_H
#ifndef COMMON_H
#define COMMON_H

#include <uprotocol/v1/uri.pb.h>

uprotocol::v1::UUri getUUri(int const resource_id) {
inline uprotocol::v1::UUri getUUri(int const resource_id) {
constexpr uint32_t PUBSUB_UE_ID = 0x18002;
uprotocol::v1::UUri uuri;
uuri.set_authority_name("test.app");
uuri.set_ue_id(0x18002);
uuri.set_ue_id(PUBSUB_UE_ID);
uuri.set_ue_version_major(1);
uuri.set_resource_id(resource_id);
return uuri;
}

uprotocol::v1::UUri const& getTimeUUri() {
static auto uuri = getUUri(0x8001);
return uuri;
inline uprotocol::v1::UUri const& getTimeUUri() {
constexpr uint32_t TIME_UURI_RESOURCE_ID = 0x8001;
static auto uuri = getUUri(TIME_UURI_RESOURCE_ID);
return uuri;
}

uprotocol::v1::UUri const& getRandomUUri() {
static auto uuri = getUUri(0x8002);
return uuri;
inline uprotocol::v1::UUri const& getRandomUUri() {
constexpr uint32_t RANDOM_UURI_RESOURCE_ID = 0x8002;
static auto uuri = getUUri(RANDOM_UURI_RESOURCE_ID);
return uuri;
}

uprotocol::v1::UUri const& getCounterUUri() {
static auto uuri = getUUri(0x8003);
return uuri;
inline uprotocol::v1::UUri const& getCounterUUri() {
constexpr uint32_t COUNTER_UURI_RESOURCE_ID = 0x8003;
static auto uuri = getUUri(COUNTER_UURI_RESOURCE_ID);
return uuri;
}

#endif // PUBSUB_COMMON_H
#endif // COMMON_H
Loading