Skip to content

Commit 3086a8a

Browse files
committed
various changes
- add lua style formatter - cleanup build scripts - update ovbase/ovutil
1 parent 48b7521 commit 3086a8a

15 files changed

+249
-163
lines changed

.stylua.toml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
column_width = 120
2+
line_endings = "Windows"
3+
indent_type = "Spaces"
4+
indent_width = 2
5+
quote_style = "AutoPreferDouble"
6+
no_call_parentheses = false

CMakePresets.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
},
88
"configurePresets": [
99
{
10-
"name": "default",
11-
"displayName": "Default build",
12-
"description": "Default build using Ninja generator",
10+
"name": "debug",
11+
"displayName": "debug build",
12+
"description": "debug build using Ninja generator",
1313
"generator": "Ninja",
14-
"binaryDir": "${sourceDir}/build/default",
14+
"binaryDir": "${sourceDir}/build/debug",
1515
"cacheVariables": {
16-
"CMAKE_BUILD_TYPE": "Release",
16+
"CMAKE_BUILD_TYPE": "Debug",
1717
"CMAKE_C_STANDARD": "11",
1818
"CMAKE_C_STANDARD_REQUIRED": "ON",
1919
"CMAKE_C_EXTENSIONS": "OFF",

build.bash

+46-33
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,29 @@ set -eu
44
CUR_DIR="${PWD}"
55
cd "$(dirname "${BASH_SOURCE:-$0}")"
66

7-
mkdir -p build/tools
8-
. src/c/3rd/ovbase/setup-llvm-mingw.bash --dir $PWD/build/tools
9-
10-
cd build
11-
7+
INSTALL_TOOLS=1
128
REBUILD=0
139
SKIP_TESTS=0
1410
CREATE_ZIP=0
1511
CMAKE_BUILD_TYPE=Release
1612
GENERATE_TRANSMAP=0
13+
ADDITIONAL_CMAKE_OPTIONS=""
14+
FORMAT_SOURCES=ON
1715

1816
while [[ $# -gt 0 ]]; do
1917
case $1 in
18+
--no-install-tools)
19+
INSTALL_TOOLS=0
20+
shift
21+
;;
2022
-d|--debug)
2123
CMAKE_BUILD_TYPE=Debug
2224
shift
2325
;;
26+
--no-format)
27+
FORMAT_SOURCES=OFF
28+
shift
29+
;;
2430
-r|--rebuild)
2531
REBUILD=1
2632
shift
@@ -47,44 +53,51 @@ while [[ $# -gt 0 ]]; do
4753
esac
4854
done
4955

56+
if [ "${INSTALL_TOOLS}" -eq 1 ]; then
57+
mkdir -p "build/tools"
58+
. "src/c/3rd/ovbase/setup-llvm-mingw.bash" --dir "${PWD}/build/tools"
59+
fi
60+
5061
TARGETS=ALL
5162
if [ "${GENERATE_TRANSMAP}" -eq 1 ]; then
5263
TARGETS=generate_transmap
5364
fi
5465

55-
for arch in i686; do
56-
destdir="${PWD}/${CMAKE_BUILD_TYPE}/${arch}"
57-
if [ "${REBUILD}" -eq 1 ] || [ ! -e "${destdir}/CMakeCache.txt" ]; then
58-
rm -rf "${destdir}"
59-
cmake -S .. -B "${destdir}" --preset default \
60-
-DFORMAT_SOURCES=ON \
61-
-DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \
62-
-DCMAKE_TOOLCHAIN_FILE="src/c/3rd/ovbase/cmake/llvm-mingw.cmake" \
63-
-DCMAKE_C_COMPILER="${arch}-w64-mingw32-clang"
64-
fi
65-
if [ "${GENERATE_TRANSMAP}" -eq 1 ]; then
66-
cmake --build "${destdir}" --target "${TARGETS}"
67-
exit
68-
fi
69-
cmake --build "${destdir}"
70-
if [ "${SKIP_TESTS}" -eq 0 ]; then
71-
ctest --test-dir "${destdir}/src/c" --output-on-failure --output-junit testlog.xml
72-
fi
73-
done
66+
ARCHDIR=${ARCHDIR:-i686}
67+
destdir="${PWD}/build/${CMAKE_BUILD_TYPE}/${ARCHDIR}"
68+
CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX:-"${destdir}/local"}
69+
CMAKE_C_COMPILER=${CMAKE_C_COMPILER:-i686-w64-mingw32-clang}
70+
CMAKE_TOOL_CHANIN_FILE=${CMAKE_TOOL_CHANIN_FILE:-"src/c/3rd/ovbase/cmake/llvm-mingw.cmake"}
71+
72+
if [ "${REBUILD}" -eq 1 ] || [ ! -e "${destdir}/CMakeCache.txt" ]; then
73+
rm -rf "${destdir}"
74+
cmake -S . -B "${destdir}" --preset debug \
75+
-DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \
76+
-DFORMAT_SOURCES="${FORMAT_SOURCES}" \
77+
-DCMAKE_INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}" \
78+
-DCMAKE_C_COMPILER="${CMAKE_C_COMPILER}" \
79+
-DCMAKE_TOOLCHAIN_FILE="${CMAKE_TOOL_CHANIN_FILE}"
80+
fi
81+
if [ "${GENERATE_TRANSMAP}" -eq 1 ]; then
82+
cmake --build "${destdir}" --target "${TARGETS}"
83+
exit
84+
fi
85+
cmake --build "${destdir}"
86+
if [ "${SKIP_TESTS}" -eq 0 ]; then
87+
ctest --test-dir "${destdir}/src/c" --output-on-failure --output-junit testlog.xml
88+
fi
7489

75-
destdir="${PWD}/${CMAKE_BUILD_TYPE}"
7690
if [ "${REBUILD}" -eq 1 ]; then
77-
rm -rf "${destdir}/bin"
91+
rm -rf "${destdir}/../bin"
7892
fi
79-
mkdir -p "${destdir}/bin"
80-
cp -r "${destdir}/i686/bin/"* "${destdir}/bin"
93+
mkdir -p "${destdir}/../bin"
94+
cp -r "${destdir}/bin/"* "${destdir}/../bin"
8195

8296
if [ "${CREATE_ZIP}" -eq 1 ]; then
83-
rm -rf "${destdir}/dist"
84-
mkdir -p "${destdir}/dist"
85-
cd "${destdir}/bin"
86-
cmake -E tar cf "${destdir}/dist/${CMAKE_BUILD_TYPE}.zip" --format=zip .
87-
cd ../..
97+
rm -rf "${destdir}/../dist"
98+
mkdir -p "${destdir}/../dist"
99+
cd "${destdir}/../bin"
100+
cmake -E tar cf "${destdir}/../dist/${CMAKE_BUILD_TYPE}.zip" --format=zip .
88101
fi
89102

90103
cd "${CUR_DIR}"

src/c/CMakeLists.txt

+28-20
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,38 @@ option(FORMAT_SOURCES "execute clang-format" ON)
33
enable_testing()
44
enable_language(RC)
55

6+
include(FetchContent)
7+
set(LUA51_URL "https://github.com/oov/lua-5.1.5/releases/download/v5.1.5/lua_v5.1.5_i686.zip")
8+
FetchContent_Populate(
9+
lua51
10+
URL ${LUA51_URL}
11+
)
12+
set(LUA51_DLL "${lua51_SOURCE_DIR}/bin/lua51.dll")
13+
set(LUA51_INCLUDE "${lua51_SOURCE_DIR}/include")
14+
615
if(FORMAT_SOURCES)
716
file(GLOB_RECURSE sources LIST_DIRECTORIES false CONFIGURE_DEPENDS "*.h" "*.c")
817
list(FILTER sources EXCLUDE REGEX "${CMAKE_CURRENT_SOURCE_DIR}/3rd")
918
find_program(CLANG_FORMAT_EXE clang-format)
10-
add_custom_target(${PROJECT_NAME}-format ALL
19+
add_custom_target(${PROJECT_NAME}-format-c
1120
COMMAND ${CLANG_FORMAT_EXE} -style=file -i ${sources}
1221
)
13-
endif()
1422

15-
set(LUA51_PLATFORM i686)
16-
set(LUA51_URL "https://github.com/oov/lua-5.1.5/releases/download/v5.1.5/lua_v5.1.5_${LUA51_PLATFORM}.zip")
17-
string(REGEX MATCH "[^/]+$" LUA51_ARCHIVE_NAME "${LUA51_URL}")
18-
set(LUA51_ARCHIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}/${LUA51_ARCHIVE_NAME}")
19-
set(LUA51_DIR "${CMAKE_CURRENT_BINARY_DIR}/lua51")
20-
set(LUA51_DLL "${LUA51_DIR}/bin/lua51.dll")
21-
set(LUA51_INCLUDE "${LUA51_DIR}/include")
22-
if(NOT EXISTS "${LUA51_DIR}")
23-
if(NOT EXISTS "${LUA51_ARCHIVE_PATH}")
24-
file(DOWNLOAD "${LUA51_URL}" "${LUA51_ARCHIVE_PATH}")
23+
if(CMAKE_HOST_WIN32)
24+
set(STYLUA_FILE "stylua-windows-x86_64.zip")
25+
else()
26+
set(STYLUA_FILE "stylua-linux-x86_64-musl.zip")
2527
endif()
26-
string(REGEX REPLACE "\\.[^.]+$" "" LUA51_ARCHIVE_NOEXT "${LUA51_ARCHIVE_NAME}")
27-
file(MAKE_DIRECTORY "${LUA51_DIR}")
28-
execute_process(
29-
COMMAND ${CMAKE_COMMAND} -E tar xf ${LUA51_ARCHIVE_PATH}
30-
WORKING_DIRECTORY "${LUA51_DIR}"
28+
FetchContent_Populate(
29+
stylua
30+
URL "https://github.com/JohnnyMorganz/StyLua/releases/download/v0.20.0/${STYLUA_FILE}"
3131
)
32-
execute_process(
33-
COMMAND ${CMAKE_COMMAND} -E copy "${LUA51_DLL}" "${CMAKE_CURRENT_BINARY_DIR}/lua51.dll"
32+
add_custom_target(${PROJECT_NAME}-format-lua
33+
COMMAND "${stylua_SOURCE_DIR}/stylua" --config-path "${PROJECT_SOURCE_DIR}/.stylua.toml" "${CMAKE_CURRENT_SOURCE_DIR}/../lua"
3434
)
35+
add_custom_target(${PROJECT_NAME}-format DEPENDS ${PROJECT_NAME}-format-c ${PROJECT_NAME}-format-lua)
36+
else()
37+
add_custom_target(${PROJECT_NAME}-format) # do nothing
3538
endif()
3639

3740
add_compile_options(-flto)
@@ -216,7 +219,7 @@ target_link_libraries(gcmzdrops_auf PRIVATE
216219
crc64
217220
detect
218221
)
219-
add_dependencies(gcmzdrops_auf generate_version_h generate_rc copy_related_files)
222+
add_dependencies(gcmzdrops_auf generate_version_h generate_rc copy_related_files ${PROJECT_NAME}-format)
220223

221224
add_executable(datauri_test error_gcmz.c task.c sniffer.c datauri_test.c)
222225
target_link_libraries(datauri_test PRIVATE gcmzdrops_intf crc64 detect gcmzdrops_test_intf)
@@ -232,3 +235,8 @@ add_executable(luafuncs_test error_gcmz.c task.c files.c luautil.c luafuncs_test
232235
target_link_libraries(luafuncs_test PRIVATE gcmzdrops_intf crc64 detect gcmzdrops_test_intf)
233236
add_dependencies(luafuncs_test generate_version_h)
234237
add_test(NAME luafuncs_test COMMAND luafuncs_test)
238+
add_custom_command(
239+
TARGET luafuncs_test
240+
POST_BUILD
241+
COMMAND ${CMAKE_COMMAND} -E copy "${LUA51_DLL}" "$<TARGET_FILE_DIR:luafuncs_test>"
242+
)

src/lua/_entrypoint.lua

+52-37
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ P.handlers = {}
66
function P.init(handlers)
77
for i, v in ipairs(handlers) do
88
local h = require(v)
9-
if (type(h.name) == "string")and
10-
(type(h.priority) == "number")and
11-
(type(h.ondragenter) == "function")and
12-
(type(h.ondragover) == "function")and
13-
(type(h.ondragleave) == "function")and
14-
(type(h.ondrop) == "function") then
9+
if
10+
(type(h.name) == "string")
11+
and (type(h.priority) == "number")
12+
and (type(h.ondragenter) == "function")
13+
and (type(h.ondragover) == "function")
14+
and (type(h.ondragleave) == "function")
15+
and (type(h.ondrop) == "function")
16+
then
1517
table.insert(P.handlers, h)
1618
end
1719
end
@@ -27,11 +29,14 @@ function P.ondragenter(files, state)
2729
if h.ondragenter(files, state) then
2830
r = true
2931
else
30-
debug_print(string.format(i18n({
31-
ja_JP = [=[%s: ondragenter で false を返しました]=],
32-
en_US = [=[%s: false returned on ondragenter]=],
33-
zh_CN = [=[%s: 在ondragenter上返回false]=],
34-
}), h.name))
32+
debug_print(string.format(
33+
i18n({
34+
ja_JP = [=[%s: ondragenter で false を返しました]=],
35+
en_US = [=[%s: false returned on ondragenter]=],
36+
zh_CN = [=[%s: 在ondragenter上返回false]=],
37+
}),
38+
h.name
39+
))
3540
P.handlers[i] = false
3641
end
3742
end
@@ -46,11 +51,14 @@ function P.ondragover(files, state)
4651
if h.ondragover(files, state) then
4752
r = true
4853
else
49-
debug_print(string.format(i18n({
50-
ja_JP = [=[%s: ondragover で false を返しました]=],
51-
en_US = [=[%s: false returned on ondragover]=],
52-
zh_CN = [=[%s: 在ondragover上返回false]=],
53-
}), h.name))
54+
debug_print(string.format(
55+
i18n({
56+
ja_JP = [=[%s: ondragover で false を返しました]=],
57+
en_US = [=[%s: false returned on ondragover]=],
58+
zh_CN = [=[%s: 在ondragover上返回false]=],
59+
}),
60+
h.name
61+
))
5462
P.handlers[i] = false
5563
end
5664
end
@@ -72,29 +80,38 @@ function P.ondrop(files, state)
7280
if h ~= false then
7381
local f, s = h.ondrop(files, state)
7482
if f == nil then
75-
debug_print(string.format(i18n({
76-
ja_JP = [=[%s: 処理がキャンセルされました]=],
77-
en_US = [=[%s: The process has been canceled]=],
78-
zh_CN = [=[%s: 处理已取消]=],
79-
}), h.name))
83+
debug_print(string.format(
84+
i18n({
85+
ja_JP = [=[%s: 処理がキャンセルされました]=],
86+
en_US = [=[%s: The process has been canceled]=],
87+
zh_CN = [=[%s: 处理已取消]=],
88+
}),
89+
h.name
90+
))
8091
return false
8192
elseif f ~= false then
8293
for i2, f2 in ipairs(f) do
8394
debug_print(string.format("[%d] %s", i2, f2.filepath))
8495
end
8596
GCMZDrops.drop(f, s)
86-
debug_print(string.format(i18n({
87-
ja_JP = [=[%s: 処理が完了しました。]=],
88-
en_US = [=[%s: The process has been completed.]=],
89-
zh_CN = [=[%s: 处理已完成]=],
90-
}), h.name))
97+
debug_print(string.format(
98+
i18n({
99+
ja_JP = [=[%s: 処理が完了しました。]=],
100+
en_US = [=[%s: The process has been completed.]=],
101+
zh_CN = [=[%s: 处理已完成]=],
102+
}),
103+
h.name
104+
))
91105
return true
92106
else
93-
debug_print(string.format(i18n({
94-
ja_JP = [=[%s: 処理を続行します。]=],
95-
en_US = [=[%s: Continue processing.]=],
96-
zh_CN = [=[%s: 继续处理]=],
97-
}), h.name))
107+
debug_print(string.format(
108+
i18n({
109+
ja_JP = [=[%s: 処理を続行します。]=],
110+
en_US = [=[%s: Continue processing.]=],
111+
zh_CN = [=[%s: 继续处理]=],
112+
}),
113+
h.name
114+
))
98115
end
99116
end
100117
end
@@ -122,9 +139,7 @@ function P.initdropper(droppers)
122139
end)
123140
for i, v in ipairs(droppers) do
124141
local d = require(v)
125-
if (type(d.name) == "string")and
126-
(type(d.oninitmenu) == "function")and
127-
(type(d.onselect) == "function") then
142+
if (type(d.name) == "string") and (type(d.oninitmenu) == "function") and (type(d.onselect) == "function") then
128143
table.insert(P.droppers, d)
129144
end
130145
end
@@ -150,7 +165,7 @@ function P.selectdropper(dropperindex, menuindex, state)
150165
return false
151166
end
152167
if type(rstate) ~= "table" then
153-
rstate = {x = state.x, y = state.y}
168+
rstate = { x = state.x, y = state.y }
154169
end
155170
rstate.control = rstate.control or false
156171
rstate.shift = rstate.shift or false
@@ -159,7 +174,7 @@ function P.selectdropper(dropperindex, menuindex, state)
159174
rstate.mbutton = rstate.mbutton or false
160175
rstate.rbutton = rstate.rbutton or false
161176
rstate.frameadvance = rstate.frameadvance or 0
162-
if (not rstate.lbutton)and(not rstate.mbutton)and(not rstate.rbutton) then
177+
if (not rstate.lbutton) and not rstate.mbutton and not rstate.rbutton then
163178
rstate.lbutton = true
164179
end
165180
return P.ondropsimulated(files, rstate)
@@ -178,7 +193,7 @@ function _G.i18n(utf8string_map)
178193
end
179194
end
180195
local idx = GCMZDrops.choose_language(preferred_languages, langs)
181-
return GCMZDrops.convertencoding(utf8string_map[langs[idx]], 'utf8', 'ansi')
196+
return GCMZDrops.convertencoding(utf8string_map[langs[idx]], "utf8", "ansi")
182197
end
183198

184199
return P

0 commit comments

Comments
 (0)