Skip to content

Commit

Permalink
[api] Added interface: pipy.version
Browse files Browse the repository at this point in the history
  • Loading branch information
pajama-coder committed May 18, 2024
1 parent 063545a commit 7094f35
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
6 changes: 2 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,8 @@ add_executable(pipy
deps/sqlite-3.43.2/sqlite3.c
)

add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/deps/version.h
COMMAND ${CMAKE_SOURCE_DIR}/generate_version_h.${EXT_SHELL}
ARGS ${CMAKE_BINARY_DIR}/deps/version.h
execute_process(
COMMAND ${CMAKE_SOURCE_DIR}/generate_version_h.${EXT_SHELL} ${CMAKE_BINARY_DIR}/deps/version.h
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)

Expand Down
14 changes: 11 additions & 3 deletions generate_version_h.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@ else
COMMIT_DATE=`git log -1 --format=%cD`
fi

echo "
OLD=`cat $1`

NEW="
#ifndef __VERSION_H__
#define __VERSION_H__
#define PIPY_VERSION \"$VERSION\"
#define PIPY_COMMIT \"$COMMIT\"
#define PIPY_COMMIT_DATE \"$COMMIT_DATE\"
#endif // __VERSION_H__
" > $1
#endif // __VERSION_H__"

if [ "$NEW" != "$OLD" ]; then
echo "Writing $1..."
echo "$NEW" > $1;
else
echo "Version file $1 has no changes"
fi
14 changes: 14 additions & 0 deletions src/api/pipy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@

#include <exception>

#include "version.h"

#ifndef _WIN32
#include <unistd.h>
#include <signal.h>
Expand All @@ -55,6 +57,14 @@ namespace pipy {
thread_local static pjs::Ref<pjs::Array> s_argv;
thread_local static std::list<pjs::Ref<pjs::Function>> s_exit_callbacks;

auto Pipy::version() -> pjs::Object* {
auto obj = pjs::Object::make();
obj->set("version", PIPY_VERSION);
obj->set("commit", PIPY_COMMIT);
obj->set("date", PIPY_COMMIT_DATE);
return obj;
}

auto Pipy::argv() -> pjs::Array* {
return s_argv;
}
Expand Down Expand Up @@ -607,6 +617,10 @@ template<> void ClassDef<Pipy>::init() {
variable("inbound", class_of<Pipy::Inbound>());
variable("outbound", class_of<Pipy::Outbound>());

accessor("version", [](Object *, Value &ret) {
ret.set(Pipy::version());
});

accessor("pid", [](Object *, Value &ret) {
ret.set(os::process_id());
});
Expand Down
1 change: 1 addition & 0 deletions src/api/pipy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class Pipy : public pjs::FunctionTemplate<Pipy> {
void on_file_changed(bool changed);
};

static auto version() -> pjs::Object*;
static auto argv() -> pjs::Array*;
static void argv(const std::vector<std::string> &argv);
static void on_exit(const std::function<void(int)> &on_exit);
Expand Down

0 comments on commit 7094f35

Please sign in to comment.