Skip to content

Commit

Permalink
various changes
Browse files Browse the repository at this point in the history
- add lua style formatter
- cleanup build scripts
- update ovbase/ovutil
  • Loading branch information
oov committed Oct 10, 2024
1 parent 48b7521 commit 3086a8a
Show file tree
Hide file tree
Showing 15 changed files with 249 additions and 163 deletions.
6 changes: 6 additions & 0 deletions .stylua.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
column_width = 120
line_endings = "Windows"
indent_type = "Spaces"
indent_width = 2
quote_style = "AutoPreferDouble"
no_call_parentheses = false
10 changes: 5 additions & 5 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
},
"configurePresets": [
{
"name": "default",
"displayName": "Default build",
"description": "Default build using Ninja generator",
"name": "debug",
"displayName": "debug build",
"description": "debug build using Ninja generator",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/default",
"binaryDir": "${sourceDir}/build/debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_C_STANDARD": "11",
"CMAKE_C_STANDARD_REQUIRED": "ON",
"CMAKE_C_EXTENSIONS": "OFF",
Expand Down
79 changes: 46 additions & 33 deletions build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,29 @@ set -eu
CUR_DIR="${PWD}"
cd "$(dirname "${BASH_SOURCE:-$0}")"

mkdir -p build/tools
. src/c/3rd/ovbase/setup-llvm-mingw.bash --dir $PWD/build/tools

cd build

INSTALL_TOOLS=1
REBUILD=0
SKIP_TESTS=0
CREATE_ZIP=0
CMAKE_BUILD_TYPE=Release
GENERATE_TRANSMAP=0
ADDITIONAL_CMAKE_OPTIONS=""
FORMAT_SOURCES=ON

while [[ $# -gt 0 ]]; do
case $1 in
--no-install-tools)
INSTALL_TOOLS=0
shift
;;
-d|--debug)
CMAKE_BUILD_TYPE=Debug
shift
;;
--no-format)
FORMAT_SOURCES=OFF
shift
;;
-r|--rebuild)
REBUILD=1
shift
Expand All @@ -47,44 +53,51 @@ while [[ $# -gt 0 ]]; do
esac
done

if [ "${INSTALL_TOOLS}" -eq 1 ]; then
mkdir -p "build/tools"
. "src/c/3rd/ovbase/setup-llvm-mingw.bash" --dir "${PWD}/build/tools"
fi

TARGETS=ALL
if [ "${GENERATE_TRANSMAP}" -eq 1 ]; then
TARGETS=generate_transmap
fi

for arch in i686; do
destdir="${PWD}/${CMAKE_BUILD_TYPE}/${arch}"
if [ "${REBUILD}" -eq 1 ] || [ ! -e "${destdir}/CMakeCache.txt" ]; then
rm -rf "${destdir}"
cmake -S .. -B "${destdir}" --preset default \
-DFORMAT_SOURCES=ON \
-DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \
-DCMAKE_TOOLCHAIN_FILE="src/c/3rd/ovbase/cmake/llvm-mingw.cmake" \
-DCMAKE_C_COMPILER="${arch}-w64-mingw32-clang"
fi
if [ "${GENERATE_TRANSMAP}" -eq 1 ]; then
cmake --build "${destdir}" --target "${TARGETS}"
exit
fi
cmake --build "${destdir}"
if [ "${SKIP_TESTS}" -eq 0 ]; then
ctest --test-dir "${destdir}/src/c" --output-on-failure --output-junit testlog.xml
fi
done
ARCHDIR=${ARCHDIR:-i686}
destdir="${PWD}/build/${CMAKE_BUILD_TYPE}/${ARCHDIR}"
CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX:-"${destdir}/local"}
CMAKE_C_COMPILER=${CMAKE_C_COMPILER:-i686-w64-mingw32-clang}
CMAKE_TOOL_CHANIN_FILE=${CMAKE_TOOL_CHANIN_FILE:-"src/c/3rd/ovbase/cmake/llvm-mingw.cmake"}

if [ "${REBUILD}" -eq 1 ] || [ ! -e "${destdir}/CMakeCache.txt" ]; then
rm -rf "${destdir}"
cmake -S . -B "${destdir}" --preset debug \
-DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \
-DFORMAT_SOURCES="${FORMAT_SOURCES}" \
-DCMAKE_INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}" \
-DCMAKE_C_COMPILER="${CMAKE_C_COMPILER}" \
-DCMAKE_TOOLCHAIN_FILE="${CMAKE_TOOL_CHANIN_FILE}"
fi
if [ "${GENERATE_TRANSMAP}" -eq 1 ]; then
cmake --build "${destdir}" --target "${TARGETS}"
exit
fi
cmake --build "${destdir}"
if [ "${SKIP_TESTS}" -eq 0 ]; then
ctest --test-dir "${destdir}/src/c" --output-on-failure --output-junit testlog.xml
fi

destdir="${PWD}/${CMAKE_BUILD_TYPE}"
if [ "${REBUILD}" -eq 1 ]; then
rm -rf "${destdir}/bin"
rm -rf "${destdir}/../bin"
fi
mkdir -p "${destdir}/bin"
cp -r "${destdir}/i686/bin/"* "${destdir}/bin"
mkdir -p "${destdir}/../bin"
cp -r "${destdir}/bin/"* "${destdir}/../bin"

if [ "${CREATE_ZIP}" -eq 1 ]; then
rm -rf "${destdir}/dist"
mkdir -p "${destdir}/dist"
cd "${destdir}/bin"
cmake -E tar cf "${destdir}/dist/${CMAKE_BUILD_TYPE}.zip" --format=zip .
cd ../..
rm -rf "${destdir}/../dist"
mkdir -p "${destdir}/../dist"
cd "${destdir}/../bin"
cmake -E tar cf "${destdir}/../dist/${CMAKE_BUILD_TYPE}.zip" --format=zip .
fi

cd "${CUR_DIR}"
48 changes: 28 additions & 20 deletions src/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,38 @@ option(FORMAT_SOURCES "execute clang-format" ON)
enable_testing()
enable_language(RC)

include(FetchContent)
set(LUA51_URL "https://github.com/oov/lua-5.1.5/releases/download/v5.1.5/lua_v5.1.5_i686.zip")
FetchContent_Populate(
lua51
URL ${LUA51_URL}
)
set(LUA51_DLL "${lua51_SOURCE_DIR}/bin/lua51.dll")
set(LUA51_INCLUDE "${lua51_SOURCE_DIR}/include")

if(FORMAT_SOURCES)
file(GLOB_RECURSE sources LIST_DIRECTORIES false CONFIGURE_DEPENDS "*.h" "*.c")
list(FILTER sources EXCLUDE REGEX "${CMAKE_CURRENT_SOURCE_DIR}/3rd")
find_program(CLANG_FORMAT_EXE clang-format)
add_custom_target(${PROJECT_NAME}-format ALL
add_custom_target(${PROJECT_NAME}-format-c
COMMAND ${CLANG_FORMAT_EXE} -style=file -i ${sources}
)
endif()

set(LUA51_PLATFORM i686)
set(LUA51_URL "https://github.com/oov/lua-5.1.5/releases/download/v5.1.5/lua_v5.1.5_${LUA51_PLATFORM}.zip")
string(REGEX MATCH "[^/]+$" LUA51_ARCHIVE_NAME "${LUA51_URL}")
set(LUA51_ARCHIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}/${LUA51_ARCHIVE_NAME}")
set(LUA51_DIR "${CMAKE_CURRENT_BINARY_DIR}/lua51")
set(LUA51_DLL "${LUA51_DIR}/bin/lua51.dll")
set(LUA51_INCLUDE "${LUA51_DIR}/include")
if(NOT EXISTS "${LUA51_DIR}")
if(NOT EXISTS "${LUA51_ARCHIVE_PATH}")
file(DOWNLOAD "${LUA51_URL}" "${LUA51_ARCHIVE_PATH}")
if(CMAKE_HOST_WIN32)
set(STYLUA_FILE "stylua-windows-x86_64.zip")
else()
set(STYLUA_FILE "stylua-linux-x86_64-musl.zip")
endif()
string(REGEX REPLACE "\\.[^.]+$" "" LUA51_ARCHIVE_NOEXT "${LUA51_ARCHIVE_NAME}")
file(MAKE_DIRECTORY "${LUA51_DIR}")
execute_process(
COMMAND ${CMAKE_COMMAND} -E tar xf ${LUA51_ARCHIVE_PATH}
WORKING_DIRECTORY "${LUA51_DIR}"
FetchContent_Populate(
stylua
URL "https://github.com/JohnnyMorganz/StyLua/releases/download/v0.20.0/${STYLUA_FILE}"
)
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy "${LUA51_DLL}" "${CMAKE_CURRENT_BINARY_DIR}/lua51.dll"
add_custom_target(${PROJECT_NAME}-format-lua
COMMAND "${stylua_SOURCE_DIR}/stylua" --config-path "${PROJECT_SOURCE_DIR}/.stylua.toml" "${CMAKE_CURRENT_SOURCE_DIR}/../lua"
)
add_custom_target(${PROJECT_NAME}-format DEPENDS ${PROJECT_NAME}-format-c ${PROJECT_NAME}-format-lua)
else()
add_custom_target(${PROJECT_NAME}-format) # do nothing
endif()

add_compile_options(-flto)
Expand Down Expand Up @@ -216,7 +219,7 @@ target_link_libraries(gcmzdrops_auf PRIVATE
crc64
detect
)
add_dependencies(gcmzdrops_auf generate_version_h generate_rc copy_related_files)
add_dependencies(gcmzdrops_auf generate_version_h generate_rc copy_related_files ${PROJECT_NAME}-format)

add_executable(datauri_test error_gcmz.c task.c sniffer.c datauri_test.c)
target_link_libraries(datauri_test PRIVATE gcmzdrops_intf crc64 detect gcmzdrops_test_intf)
Expand All @@ -232,3 +235,8 @@ add_executable(luafuncs_test error_gcmz.c task.c files.c luautil.c luafuncs_test
target_link_libraries(luafuncs_test PRIVATE gcmzdrops_intf crc64 detect gcmzdrops_test_intf)
add_dependencies(luafuncs_test generate_version_h)
add_test(NAME luafuncs_test COMMAND luafuncs_test)
add_custom_command(
TARGET luafuncs_test
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "${LUA51_DLL}" "$<TARGET_FILE_DIR:luafuncs_test>"
)
89 changes: 52 additions & 37 deletions src/lua/_entrypoint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ P.handlers = {}
function P.init(handlers)
for i, v in ipairs(handlers) do
local h = require(v)
if (type(h.name) == "string")and
(type(h.priority) == "number")and
(type(h.ondragenter) == "function")and
(type(h.ondragover) == "function")and
(type(h.ondragleave) == "function")and
(type(h.ondrop) == "function") then
if
(type(h.name) == "string")
and (type(h.priority) == "number")
and (type(h.ondragenter) == "function")
and (type(h.ondragover) == "function")
and (type(h.ondragleave) == "function")
and (type(h.ondrop) == "function")
then
table.insert(P.handlers, h)
end
end
Expand All @@ -27,11 +29,14 @@ function P.ondragenter(files, state)
if h.ondragenter(files, state) then
r = true
else
debug_print(string.format(i18n({
ja_JP = [=[%s: ondragenter で false を返しました]=],
en_US = [=[%s: false returned on ondragenter]=],
zh_CN = [=[%s: 在ondragenter上返回false]=],
}), h.name))
debug_print(string.format(
i18n({
ja_JP = [=[%s: ondragenter で false を返しました]=],
en_US = [=[%s: false returned on ondragenter]=],
zh_CN = [=[%s: 在ondragenter上返回false]=],
}),
h.name
))
P.handlers[i] = false
end
end
Expand All @@ -46,11 +51,14 @@ function P.ondragover(files, state)
if h.ondragover(files, state) then
r = true
else
debug_print(string.format(i18n({
ja_JP = [=[%s: ondragover で false を返しました]=],
en_US = [=[%s: false returned on ondragover]=],
zh_CN = [=[%s: 在ondragover上返回false]=],
}), h.name))
debug_print(string.format(
i18n({
ja_JP = [=[%s: ondragover で false を返しました]=],
en_US = [=[%s: false returned on ondragover]=],
zh_CN = [=[%s: 在ondragover上返回false]=],
}),
h.name
))
P.handlers[i] = false
end
end
Expand All @@ -72,29 +80,38 @@ function P.ondrop(files, state)
if h ~= false then
local f, s = h.ondrop(files, state)
if f == nil then
debug_print(string.format(i18n({
ja_JP = [=[%s: 処理がキャンセルされました]=],
en_US = [=[%s: The process has been canceled]=],
zh_CN = [=[%s: 处理已取消]=],
}), h.name))
debug_print(string.format(
i18n({
ja_JP = [=[%s: 処理がキャンセルされました]=],
en_US = [=[%s: The process has been canceled]=],
zh_CN = [=[%s: 处理已取消]=],
}),
h.name
))
return false
elseif f ~= false then
for i2, f2 in ipairs(f) do
debug_print(string.format("[%d] %s", i2, f2.filepath))
end
GCMZDrops.drop(f, s)
debug_print(string.format(i18n({
ja_JP = [=[%s: 処理が完了しました。]=],
en_US = [=[%s: The process has been completed.]=],
zh_CN = [=[%s: 处理已完成]=],
}), h.name))
debug_print(string.format(
i18n({
ja_JP = [=[%s: 処理が完了しました。]=],
en_US = [=[%s: The process has been completed.]=],
zh_CN = [=[%s: 处理已完成]=],
}),
h.name
))
return true
else
debug_print(string.format(i18n({
ja_JP = [=[%s: 処理を続行します。]=],
en_US = [=[%s: Continue processing.]=],
zh_CN = [=[%s: 继续处理]=],
}), h.name))
debug_print(string.format(
i18n({
ja_JP = [=[%s: 処理を続行します。]=],
en_US = [=[%s: Continue processing.]=],
zh_CN = [=[%s: 继续处理]=],
}),
h.name
))
end
end
end
Expand Down Expand Up @@ -122,9 +139,7 @@ function P.initdropper(droppers)
end)
for i, v in ipairs(droppers) do
local d = require(v)
if (type(d.name) == "string")and
(type(d.oninitmenu) == "function")and
(type(d.onselect) == "function") then
if (type(d.name) == "string") and (type(d.oninitmenu) == "function") and (type(d.onselect) == "function") then
table.insert(P.droppers, d)
end
end
Expand All @@ -150,7 +165,7 @@ function P.selectdropper(dropperindex, menuindex, state)
return false
end
if type(rstate) ~= "table" then
rstate = {x = state.x, y = state.y}
rstate = { x = state.x, y = state.y }
end
rstate.control = rstate.control or false
rstate.shift = rstate.shift or false
Expand All @@ -159,7 +174,7 @@ function P.selectdropper(dropperindex, menuindex, state)
rstate.mbutton = rstate.mbutton or false
rstate.rbutton = rstate.rbutton or false
rstate.frameadvance = rstate.frameadvance or 0
if (not rstate.lbutton)and(not rstate.mbutton)and(not rstate.rbutton) then
if (not rstate.lbutton) and not rstate.mbutton and not rstate.rbutton then
rstate.lbutton = true
end
return P.ondropsimulated(files, rstate)
Expand All @@ -178,7 +193,7 @@ function _G.i18n(utf8string_map)
end
end
local idx = GCMZDrops.choose_language(preferred_languages, langs)
return GCMZDrops.convertencoding(utf8string_map[langs[idx]], 'utf8', 'ansi')
return GCMZDrops.convertencoding(utf8string_map[langs[idx]], "utf8", "ansi")
end

return P
Loading

0 comments on commit 3086a8a

Please sign in to comment.