Skip to content

Commit 2f80029

Browse files
committed
Use cmake to generate the src/version.h file
1 parent 70cc278 commit 2f80029

File tree

6 files changed

+23
-30
lines changed

6 files changed

+23
-30
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ jobs:
4444
uses: microsoft/[email protected]
4545
if: runner.os == 'Windows'
4646

47-
- name: generate fake src/version.h so we can try to build
48-
shell: bash
49-
run: yarn update_version
50-
51-
5247
- name: build libsession-util-nodejs
5348
shell: bash
5449
run: yarn install --frozen-lockfile

CMakeLists.txt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,28 @@ set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
66

77
set(VERBOSE ON)
88

9+
# Get current commit hash as GIT_COMMIT
10+
find_package(Git)
11+
set(GIT_COMMIT "unknown") # Default value for when Git is not found
12+
if (EXISTS "${CMAKE_SOURCE_DIR}/.git/index" AND GIT_FOUND)
13+
execute_process(COMMAND "${GIT_EXECUTABLE}" rev-parse HEAD RESULT_VARIABLE GIT_GET_HASH_RESULT OUTPUT_VARIABLE GIT_COMMIT OUTPUT_STRIP_TRAILING_WHITESPACE)
14+
if(GIT_GET_HASH_RESULT)
15+
message(STATUS "You are currently on commit ${GIT_COMMIT}")
16+
else()
17+
message(WARNING "Cannot determine current commit. Make sure that you are building either from a Git working tree or from a source archive.")
18+
endif()
19+
endif()
20+
21+
# Read the package.json file and extract the top-level .version as LIBSESSION_NODEJS_VERSION
22+
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/package.json" PACKAGE_JSON)
23+
string(JSON LIBSESSION_NODEJS_VERSION GET "${PACKAGE_JSON}" version)
24+
25+
# Generate src/version.h
26+
file(WRITE "${CMAKE_CURRENT_SOURCE_DIR}/src/version.h"
27+
"const char* LIBSESSION_NODEJS_VERSION = \"${LIBSESSION_NODEJS_VERSION}\";
28+
const char* LIBSESSION_NODEJS_COMMIT = \"${GIT_COMMIT}\";\n"
29+
)
30+
931
# Detect the number of processors
1032
include(ProcessorCount)
1133
ProcessorCount(N)
@@ -18,7 +40,6 @@ else()
1840
endif()
1941
message(STATUS "Number of processors detected: ${N}")
2042

21-
2243
add_definitions(-DNAPI_VERSION=8)
2344
set(CMAKE_CONFIGURATION_TYPES Release)
2445

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ git clone --recursive [email protected]:session-foundation/libsession-util-nodejs.g
2020
```
2121

2222
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.
23-
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.
23+
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.
2424
Once your changes are ready to be tested in the `session-desktop` you can compile an electron build using this command:
2525

2626
```

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"email": "[email protected]"
1010
},
1111
"scripts": {
12-
"update_version": "sh update_version.sh",
1312
"clean": "rimraf .cache build",
1413
"lint:cpp": "cppcheck --std=c++20 -j8 --quiet src libsession-util/src",
1514
"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",

prepare_release.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ python -m venv .venv
1414
. .venv/bin/activate
1515
pip install git-archive-all
1616
PACKAGE_VERSION=$(node -p "require('./package.json').version")
17-
yarn update_version
1817
echo "PACKAGE_VERSION: $PACKAGE_VERSION"
1918
echo "Is '$PACKAGE_VERSION' the correct version? If yes, press 'y' to create the release. Press anything else to exit."
2019
read_char char_read

update_version.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)