Skip to content

Commit 5b2ff35

Browse files
committed
Update CMake. Fix ODB Backend version check.
1 parent c685f3f commit 5b2ff35

File tree

5 files changed

+40
-27
lines changed

5 files changed

+40
-27
lines changed

β€ŽCMakeLists.txtβ€Ž

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ set(BUILD_SHARED_LIBS TRUE)
1010
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
1111

1212
set(INSTALL_CMOD share/lua/cmod CACHE PATH "Directory to install Lua binary modules (configure lua via LUA_CPATH)")
13-
set(LUA_NATIVE_OBJECTS_PATH ../LuaNativeObjects CACHE PATH
14-
"Directory to LuaNativeObjects bindings generator.")
1513
set(USE_PRE_GENERATED_BINDINGS TRUE CACHE BOOL
1614
"Set this to FALSE to re-generate bindings using LuaNativeObjects")
1715

@@ -28,7 +26,7 @@ include_directories(${LUA_INCLUDE_DIR})
2826

2927
## LibGit2
3028
include(FindPkgConfig)
31-
pkg_search_module(GIT2 REQUIRED libgit2=0.17.0)
29+
pkg_search_module(GIT2 REQUIRED libgit2>=0.17.0)
3230
add_definitions(${GIT2_CFLAGS})
3331
link_directories(${GIT2_LIBRARY_DIRS})
3432
include_directories(${GIT2_INCLUDE_DIRS})

β€Žcmake/LuaNativeObjects.cmakeβ€Ž

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,38 @@
11
#
22
# Lua Native Objects
33
#
4+
5+
find_program(LUA_NATIVE_OBJECTS_EXECUTABLE native_objects.lua
6+
PATHS ${CMAKE_SOURCE_DIR}/../LuaNativeObjects
7+
DOC "LuaNativeObjects executable path")
8+
set(USE_PRE_GENERATED_BINDINGS TRUE CACHE BOOL
9+
"Set this to FALSE to re-generate bindings using LuaNativeObjects")
10+
set(GENERATE_LUADOCS TRUE CACHE BOOL
11+
"Set this to FALSE to avoid generation of docs using LuaDoc")
12+
413
macro(GenLuaNativeObjects _src_files_var)
514
set(_new_src_files)
615
foreach(_src_file ${${_src_files_var}})
716
if(_src_file MATCHES ".nobj.lua")
817
string(REGEX REPLACE ".nobj.lua" ".nobj.c" _src_file_out ${_src_file})
9-
string(REGEX REPLACE ".nobj.lua" ".nobj.h" _header_file_out ${_src_file})
10-
add_custom_command(OUTPUT ${_src_file_out} ${_header_file_out}
11-
COMMAND lua ${LUA_NATIVE_OBJECTS_PATH}/native_objects.lua -outpath ${CMAKE_CURRENT_BINARY_DIR} -gen lua ${_src_file}
18+
string(REGEX REPLACE ".nobj.lua" ".nobj.ffi.lua" _ffi_file_out ${_src_file})
19+
add_custom_command(OUTPUT ${_src_file_out} ${_ffi_file_out}
20+
COMMAND ${LUA_NATIVE_OBJECTS_EXECUTABLE} -outpath ${CMAKE_CURRENT_BINARY_DIR} -gen lua ${_src_file}
1221
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
1322
DEPENDS ${_src_file}
1423
)
1524
set_source_files_properties(${_src_file_out} PROPERTIES GENERATED TRUE)
16-
set_source_files_properties(${_header_file_out} PROPERTIES GENERATED TRUE)
17-
string(REGEX REPLACE ".nobj.lua" "" _doc_base ${_src_file})
18-
string(REGEX REPLACE ".nobj.lua" ".luadoc" _doc_file_out ${_src_file})
19-
add_custom_target(${_doc_file_out} ALL
20-
COMMAND lua ${LUA_NATIVE_OBJECTS_PATH}/native_objects.lua -outpath docs -gen luadoc ${_src_file}
21-
COMMAND luadoc -nofiles -d docs docs
22-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
23-
DEPENDS ${_src_file}
24-
)
25+
set_source_files_properties(${_ffi_file_out} PROPERTIES GENERATED TRUE)
26+
if (${GENERATE_LUADOCS})
27+
string(REGEX REPLACE ".nobj.lua" "" _doc_base ${_src_file})
28+
string(REGEX REPLACE ".nobj.lua" ".luadoc" _doc_file_out ${_src_file})
29+
add_custom_target(${_doc_file_out} ALL
30+
COMMAND ${LUA_NATIVE_OBJECTS_EXECUTABLE} -outpath docs -gen luadoc ${_src_file}
31+
COMMAND luadoc -nofiles -d docs docs
32+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
33+
DEPENDS ${_src_file}
34+
)
35+
endif()
2536
set_source_files_properties(${_doc_file_out} PROPERTIES GENERATED TRUE)
2637
set(_new_src_files ${_new_src_files} ${_src_file_out})
2738
else(_src_file MATCHES ".nobj.lua")

β€Žsrc/odb_backend.nobj.luaβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ static void odb_backend_free_cb(git_odb_backend *backend)
228228
REF_CB(exists)
229229
REF_CB(free)
230230
#undef REF_CB
231+
232+
#ifdef GIT_ODB_BACKEND_VERSION
233+
${this}->backend.version = GIT_ODB_BACKEND_VERSION;
234+
#endif
231235
]]
232236
},
233237
destructor {

β€Žtests/test_backend.luaβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ end
1010
local git2 = require"git2"
1111
require"utils"
1212

13-
print(dump(git2))
13+
--print(dump(git2))
1414
local function dump_obj(obj)
1515
print('dump OdbObject:', obj)
1616
if obj == nil then
@@ -29,7 +29,7 @@ end
2929
local db = assert(git2.ODB.new())
3030
print("=============================================== new db=", db)
3131
print("dump ODB interface")
32-
print(dbg_dump(db))
32+
--print(dbg_dump(db))
3333

3434
-- create backend
3535
local obj_cache = {}

β€Žtests/test_rep.luaβ€Ž

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@ local git2 = require"git2"
1111
require"utils"
1212

1313
print("dump git2 interface")
14-
print(dbg_dump(git2))
14+
-- print(dbg_dump(git2))
1515

1616
local rep = assert(git2.Repository(git_path))
1717

1818
print("dump Repository interface")
19-
print(dbg_dump(rep))
19+
-- print(dbg_dump(rep))
2020

2121
local oid = git2.OID.hex("d5a93c463d4cca0068750eb6af7b4b54eea8599b")
2222
print("dump OID interface")
23-
print(dbg_dump(oid))
23+
-- print(dbg_dump(oid))
2424
print('convert OID value to string = <' .. tostring(oid) .. '>')
2525

2626
local db = rep:odb()
2727
print("dump Database interface")
28-
print(dbg_dump(db))
28+
-- print(dbg_dump(db))
2929

3030
print()
3131
print('test writing to the object database:')
@@ -36,7 +36,7 @@ print("read written object out of the database.")
3636
local odb_obj = db:read(oid)
3737
print()
3838
print("dump OdbObject interface")
39-
print(dbg_dump(odb_obj))
39+
-- print(dbg_dump(odb_obj))
4040
local function dump_odb_obj(obj)
4141
-- check obj type
4242
if obj == nil or not tostring(obj):match('^OdbObject: ') then
@@ -81,15 +81,15 @@ print("test parsing a commit object: ", commit_id)
8181
local commit1, err = git2.Commit.lookup(rep, commit_id)
8282
print(commit1, err)
8383
print("dump Commit interface")
84-
print(dbg_dump(commit1))
84+
--print(dbg_dump(commit1))
8585
local function dump_signature(pre, sig)
8686
print(pre .. '.name = ', sig:name())
8787
print(pre .. '.email = ', sig:email())
8888
print(pre .. '.when = ', sig:when())
8989
end
9090
local function dump_blob(blob)
9191
print("dump Blob interface")
92-
print(dbg_dump(blob))
92+
--print(dbg_dump(blob))
9393
print('blob.rawcontent.size =', blob:rawsize())
9494
print('blob.rawcontents =', blob:rawcontent())
9595
end
@@ -142,7 +142,7 @@ dump_commit(commit1)
142142

143143
local index = rep:index()
144144
print("dump Index interface")
145-
print(dbg_dump(index))
145+
--print(dbg_dump(index))
146146
local function dump_index_entry(entry)
147147
if entry == nil then
148148
return
@@ -177,7 +177,7 @@ dump_index(index)
177177

178178
local revwalk = git2.RevWalk(rep)
179179
print("dump RevWalk interface")
180-
print(dbg_dump(revwalk))
180+
--print(dbg_dump(revwalk))
181181
print('sorting:', revwalk:sorting(revwalk.SORT_TOPOLOGICAL + revwalk.SORT_REVERSE))
182182
local head_id = git2.OID.hex("5c697d74eb692d650799ca1b0a10254d7130953d")
183183
local head = assert(git2.Commit.lookup(rep, head_id))
@@ -194,7 +194,7 @@ end
194194
local tag_id = git2.OID.hex('82dfe36284d77b608ccc9d96e0ffa5782cb7c835')
195195
local tag = git2.Tag.lookup(rep, tag_id)
196196
print("dump Tag interface")
197-
print(dbg_dump(tag))
197+
--print(dbg_dump(tag))
198198
local function dump_tag(tag)
199199
if tag == nil then
200200
return

0 commit comments

Comments
 (0)