diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 28163b4..9dac4d6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -44,11 +44,6 @@ jobs: uses: microsoft/setup-msbuild@v1.3.1 if: runner.os == 'Windows' - - name: generate fake src/version.h so we can try to build - shell: bash - run: yarn update_version - - - name: build libsession-util-nodejs shell: bash run: yarn install --frozen-lockfile diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e53f69..f8319a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,28 @@ set(CMAKE_POLICY_DEFAULT_CMP0069 NEW) set(VERBOSE ON) +# Get current commit hash as GIT_COMMIT +find_package(Git) +set(GIT_COMMIT "unknown") # Default value for when Git is not found +if (EXISTS "${CMAKE_SOURCE_DIR}/.git/index" AND GIT_FOUND) + execute_process(COMMAND "${GIT_EXECUTABLE}" rev-parse HEAD RESULT_VARIABLE GIT_GET_HASH_RESULT OUTPUT_VARIABLE GIT_COMMIT OUTPUT_STRIP_TRAILING_WHITESPACE) + if(GIT_GET_HASH_RESULT) + message(STATUS "You are currently on commit ${GIT_COMMIT}") + else() + message(WARNING "Cannot determine current commit. Make sure that you are building either from a Git working tree or from a source archive.") + endif() +endif() + +# Read the package.json file and extract the top-level .version as LIBSESSION_NODEJS_VERSION +file(READ "${CMAKE_CURRENT_SOURCE_DIR}/package.json" PACKAGE_JSON) +string(JSON LIBSESSION_NODEJS_VERSION GET "${PACKAGE_JSON}" version) + +# Generate src/version.h +file(WRITE "${CMAKE_CURRENT_SOURCE_DIR}/src/version.h" +"const char* LIBSESSION_NODEJS_VERSION = \"${LIBSESSION_NODEJS_VERSION}\"; +const char* LIBSESSION_NODEJS_COMMIT = \"${GIT_COMMIT}\";\n" +) + # Detect the number of processors include(ProcessorCount) ProcessorCount(N) @@ -18,7 +40,6 @@ else() endif() message(STATUS "Number of processors detected: ${N}") - add_definitions(-DNAPI_VERSION=8) set(CMAKE_CONFIGURATION_TYPES Release) diff --git a/README.md b/README.md index f0019bf..a963037 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ git clone --recursive git@github.com:session-foundation/libsession-util-nodejs.g ``` Always do your changes in `[FOLDER_NOT_IN_SESSION_DESKTOP]/libsession-util-nodejs`, never in the one under session-desktop's `node_modules` as you might override your local changes. -Then, you can quickly compile a non-electron build by first running `yarn naughty-patch && yarn update_version` and then `yarn install` from that folder. You should only have to run `yarn naughty-patch && yarn update_version` manually once when you first setup the project. This is a quick incremental build which can check for C++ compilation errors. +Then, you can quickly compile a non-electron build by first running `yarn naughty-patch` and then `yarn install` from that folder. You should only have to run `yarn naughty-patch` manually once when you first setup the project. This is a quick incremental build which can check for C++ compilation errors. Once your changes are ready to be tested in the `session-desktop` you can compile an electron build using this command: ``` diff --git a/package.json b/package.json index 7a948f5..b9618ab 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,6 @@ "email": "team@oxen.io" }, "scripts": { - "update_version": "sh update_version.sh", "clean": "rimraf .cache build", "lint:cpp": "cppcheck --std=c++20 -j8 --quiet src libsession-util/src", "install": "cmake-js build --runtime=electron --runtime-version=34.2.0 --CDSUBMODULE_CHECK=OFF --CDLOCAL_MIRROR=https://oxen.rocks/deps --CDENABLE_ONIONREQ=OFF --CDWITH_TESTS=OFF", diff --git a/prepare_release.sh b/prepare_release.sh index 0cf9079..8b34d6d 100755 --- a/prepare_release.sh +++ b/prepare_release.sh @@ -13,9 +13,24 @@ rm -f ./libsession_util_nodejs*.tar.gz python -m venv .venv . .venv/bin/activate pip install git-archive-all + PACKAGE_VERSION=$(node -p "require('./package.json').version") -yarn update_version -echo "PACKAGE_VERSION: $PACKAGE_VERSION" +GIT_COMMIT=$(git rev-parse HEAD) + +HEADER_PACKAGE_VERSION=$(grep 'LIBSESSION_NODEJS_VERSION' src/version.h | sed -E 's/.*"([0-9.]+)".*/\1/') +HEADER_GIT_COMMIT=$(grep 'LIBSESSION_NODEJS_COMMIT' src/version.h | sed -E 's/.*"([A-Za-z0-9.]+)".*/\1/') + +echo "Package: $PACKAGE_VERSION; Commit: $GIT_COMMIT" +if [ "$PACKAGE_VERSION" != "$HEADER_PACKAGE_VERSION" ]; then + echo "Error: Version mismatch! package.json version is $PACKAGE_VERSION, but src/version.h has $HEADER_PACKAGE_VERSION. Build the project first before packaging 'yarn install'" + exit 1 +fi + +if [ "$GIT_COMMIT" != "$HEADER_GIT_COMMIT" ]; then + echo "Error: Version mismatch! Git commit is $GIT_COMMIT, but src/version.h has $HEADER_GIT_COMMIT. Build the project first before packaging 'yarn install'" + exit 1 +fi + echo "Is '$PACKAGE_VERSION' the correct version? If yes, press 'y' to create the release. Press anything else to exit." read_char char_read case "$char_read" in diff --git a/update_version.sh b/update_version.sh deleted file mode 100755 index 055d29f..0000000 --- a/update_version.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh -set -e -# set -x - -VERSION_FILE="src/version.h" - -rm -f $VERSION_FILE - -export LIBSESSION_NODEJS_VERSION=$(node -p "require('./package.json').version") -LIBSESSION_NODEJS_COMMIT=$(git rev-parse HEAD) - -echo "Updating LIBSESSION_NODEJS_VERSION: $LIBSESSION_NODEJS_VERSION" -echo "Updating LIBSESSION_NODEJS_COMMIT: $LIBSESSION_NODEJS_COMMIT" - - -echo "const char* LIBSESSION_NODEJS_VERSION = \"$LIBSESSION_NODEJS_VERSION\";" > $VERSION_FILE -echo "const char* LIBSESSION_NODEJS_COMMIT = \"$LIBSESSION_NODEJS_COMMIT\";" >> $VERSION_FILE - -echo "\n'$VERSION_FILE' updated to:" -cat $VERSION_FILE -