Skip to content

Commit

Permalink
Merge pull request #2 from tonyseek/release/0-1-0
Browse files Browse the repository at this point in the history
Release 0.1.0
  • Loading branch information
tonyseek authored Feb 2, 2023
2 parents be8251a + be79f78 commit 5cd32d9
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ insert_final_newline = true
indent_style = space
indent_size = 4

[*.{sh,bash,cmake,json}]
[*.{sh,bash,cmake,json,yaml}]
indent_style = space
indent_size = 2

Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Build
on:
pull_request:
push:
branches:
- "master"
tags:
- "v*"
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
/var/lib/apt/lists
/var/cache/apt/archives/**.deb
!/var/lib/apt/lists/partial
!/var/lib/apt/lists/lock
!/var/cache/apt/archives/partial
!/var/cache/apt/archives/lock
key: ${{ runner.os }}-apt-v1
- uses: lukka/get-cmake@latest
- name: Setup APT packages
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends rpm
- name: Build release
run: ./build.sh pack
- name: Upload to GitHub artifact
uses: actions/upload-artifact@v3
with:
name: dist
path: "build/dist/"
- name: Upload to GitHub release
uses: xresloader/upload-to-github-release@v1
with:
file: "build/dist/*"
tags: true
draft: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## 0.1.0 (2023-02-02)

- The first release which uses a UDP socket on a loopback address. ([#1](https://github.com/tonyseek/trapit/pull/1))
19 changes: 18 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
cmake_minimum_required(VERSION 3.22..3.25)
project(trapit)
project(trapit VERSION 0.1.0)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

add_executable(trapit trapit.cc)
target_compile_definitions(
trapit PRIVATE TRAPIT_VERSION="${CMAKE_PROJECT_VERSION}")
install(TARGETS trapit)

set(CPACK_PACKAGE_VENDOR "Jiangge Zhang <tonyseek@gmail.com>")
set(CPACK_PACKAGE_CONTACT "Jiangge Zhang <tonyseek@gmail.com>")
set(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}/dist")
set(
CPACK_PACKAGE_DESCRIPTION_SUMMARY "Command line utility that traps \
short-lived processes to inspect them with PID-aware tools (e.g. strace)")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.md")
set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/tonyseek/trapit")
set(CPACK_STRIP_FILES TRUE)
set(
CPACK_SOURCE_IGNORE_FILES
"\\\\.git/" "\\\\.github/" "\\\\.sw[op]$" "/build/")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.2.5)")
include(CPack)
25 changes: 25 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set -e
SOURCE_DIR="$(pwd)"
BUILD_DIR="${SOURCE_DIR}/build"
BUILD_BIN="trapit"
PACK_DIR="${SOURCE_DIR}/build/dist"

if ! [ -f "${SOURCE_DIR}/CMakeLists.txt" ]; then
printf >&2 'ERROR: %s is not the source directory which includes %s' \
Expand Down Expand Up @@ -40,6 +41,27 @@ cmd_build() {
cmake_build
}

cmd_pack() {
cmd_clean
cmd_build
(
cd "${BUILD_DIR}"
cpack -G TXZ --config CPackSourceConfig.cmake
cpack -G TXZ
if command -v dpkg > /dev/null; then
cpack -G DEB
else
printf >&2 '=> Skip to pack DEB because lack of "dpkg" (dpkg)\n'
fi
if command -v rpmbuild > /dev/null; then
cpack -G RPM
else
printf >&2 '=> Skip to pack RPM because lack of "rpm-tools" (rpmbuild)\n'
fi
rm -rf "${PACK_DIR}/_CPack_Packages"
)
}

cmd_run() {
cmd_build
exec "${BUILD_DIR}/${BUILD_BIN}" "$@"
Expand All @@ -64,6 +86,9 @@ case "$1" in
build)
cmd_build
;;
pack)
cmd_pack
;;
run)
shift
cmd_run "$@"
Expand Down
16 changes: 15 additions & 1 deletion trapit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@
#define TRAPIT_PORT 26842
#endif

#ifndef TRAPIT_VERSION
#define TRAPIT_VERSION "unstable"
#endif

const std::string version(TRAPIT_VERSION);

int cmd_usage(const char *prog) noexcept;
int cmd_version(const char *prog) noexcept;
int cmd_trap(const char *prog, int argc, char **argv) noexcept;
int cmd_wake(const char *prog, int argc, char **argv) noexcept;

Expand Down Expand Up @@ -56,6 +63,8 @@ int main(int argc, char **argv) {
} else if (strcmp(argv[1], "help") == 0) {
cmd_usage(argv[0]);
return 0;
} else if (strcmp(argv[1], "version") == 0) {
return cmd_version(argv[0]);
} else {
return cmd_usage(argv[0]);
}
Expand All @@ -65,12 +74,17 @@ int main(int argc, char **argv) {
int cmd_usage(const char *prog) noexcept {
const char *hl = "Usage: ";
const char *pr = " ";
std::cerr << hl << prog << " [exec|wake|help]" << std::endl;
std::cerr << hl << prog << " [exec|wake|version|help]" << std::endl;
std::cerr << pr << prog << " exec -- [argument ...]" << std::endl;
std::cerr << pr << prog << " wake" << std::endl;
return 2;
}

int cmd_version(const char *prog) noexcept {
std::cout << version << std::endl;
return 0;
}

int cmd_trap(const char *prog, int argc, char **argv) noexcept {
/*
* Layout: [ARG 0] [ARG 0] [ARG 1] ... [NULL]
Expand Down

0 comments on commit 5cd32d9

Please sign in to comment.