Skip to content

Commit 209af30

Browse files
committed
Add openleetcodeui to cmake build
1 parent 1a1f0dc commit 209af30

File tree

13 files changed

+1351
-107
lines changed

13 files changed

+1351
-107
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ build/
4646
*.sln
4747
problem_builds/
4848
.vscode/
49+
install/
4950

5051
# Temporary folders generated by openleetcode
5152
testcase_output/

CMakeLists.txt

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
11
cmake_minimum_required(VERSION 3.12)
22

3-
if (NOT PROBLEM_BUILDS_NAME)
4-
set(PROBLEM_BUILDS_NAME "problem_builds")
5-
endif()
6-
7-
set(PROJECT_BUILDS_DIR_NAME ${CMAKE_CURRENT_SOURCE_DIR}/${PROBLEM_BUILDS_NAME})
8-
9-
if(NOT CMAKE_INSTALL_PREFIX)
10-
set(PROJECT_BUILDS_DIR "${PROJECT_BUILDS_DIR_NAME}")
11-
else()
12-
set(PROJECT_BUILDS_DIR "${CMAKE_INSTALL_PREFIX}")
13-
endif()
14-
15-
message (STATUS "Setting PROJECT_BUILDS_DIR to ${PROJECT_BUILDS_DIR}")
3+
option(BUILD_UI "Build the OpenLeetCode UI" OFF)
164

5+
set(PROBLEM_BUILDS_NAME "problem_builds")
176
set(CMAKE_FILE_DESTINATION_SUFIX "_destination")
187

198
if(NOT CMAKE_BUILD_TYPE)
@@ -25,8 +14,4 @@ project(openleetcode
2514
)
2615

2716
add_subdirectory(src)
28-
add_subdirectory(data)
29-
30-
if (TESTING)
31-
add_subdirectory(test)
32-
endif()
17+
add_subdirectory(data)

data/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
set(DIRECTORIES_TO_COPY problems languages)
22

33
foreach(DIR IN LISTS DIRECTORIES_TO_COPY)
4-
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${DIR} DESTINATION ${PROJECT_BUILDS_DIR})
5-
endforeach()
4+
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/${DIR}
5+
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
6+
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${DIR} DESTINATION ${PROJECT_NAME})
7+
endforeach()

src/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
22

3+
if(BUILD_UI)
4+
add_subdirectory(ui)
5+
endif()
6+
37
add_subdirectory(app)
4-
add_subdirectory(schema)
8+
add_subdirectory(schema)

src/app/CMakeLists.txt

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
set(PYTHON_SCRIPTS
23
functionextractor.py
34
logger.py
@@ -6,35 +7,35 @@ set(PYTHON_SCRIPTS
67
testrunner.py
78
)
89

9-
set(WINDOWS_SCRIPTS
10+
set(WINDOWS_SCRIPT
1011
openleetcode.bat
1112
)
1213

13-
set(UNIX_SCRIPTS
14+
set(UNIX_SCRIPT
1415
openleetcode.sh
1516
)
1617

1718
if (WIN32)
18-
foreach(WINDOWS_SCRIPT IN LISTS WINDOWS_SCRIPTS)
19-
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${WINDOWS_SCRIPT} ${PROJECT_BUILDS_DIR}/${WINDOWS_SCRIPT} COPYONLY)
20-
endforeach()
19+
set(SCRIPT ${WINDOWS_SCRIPT})
2120
elseif (UNIX)
22-
foreach(UNIX_SCRIPT IN LISTS UNIX_SCRIPTS)
23-
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${UNIX_SCRIPT} ${PROJECT_BUILDS_DIR}/${UNIX_SCRIPT} COPYONLY)
24-
endforeach()
21+
set(SCRIPT ${UNIX_SCRIPT})
22+
endif()
2523

26-
add_custom_target(
27-
make_openleetcode_executable ALL
28-
DEPENDS ${PROJECT_BUILDS_DIR}/openleetcode.sh
29-
)
24+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${SCRIPT}
25+
${CMAKE_CURRENT_BINARY_DIR}/${SCRIPT}
26+
COPYONLY)
27+
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${SCRIPT}
28+
DESTINATION ${PROJECT_NAME})
3029

31-
add_custom_command(
32-
TARGET make_openleetcode_executable
33-
POST_BUILD
34-
COMMAND chmod +x ${PROJECT_BUILDS_DIR}/openleetcode.sh
35-
)
36-
endif()
30+
add_custom_target(
31+
openleetcode_script ALL
32+
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${SCRIPT}
33+
)
3734

3835
foreach(PYTHON_SCRIPT IN LISTS PYTHON_SCRIPTS)
39-
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${PYTHON_SCRIPT} ${PROJECT_BUILDS_DIR}/${PYTHON_SCRIPT} COPYONLY)
40-
endforeach()
36+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${PYTHON_SCRIPT}
37+
${CMAKE_CURRENT_BINARY_DIR}/${PYTHON_SCRIPT}
38+
COPYONLY)
39+
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PYTHON_SCRIPT}
40+
DESTINATION ${PROJECT_NAME})
41+
endforeach()

src/app/openleetcode.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ def main():
6969
"--list-problems to list all problems.")
7070
parser.add_argument(
7171
"--problem_builds_dir", "-d",
72-
default="problem_builds",
7372
metavar='dir',
7473
type=str,
75-
help=("Path to a directory with the problems. Usually "
76-
"./problem_builds/ directory. Default: problem_builds."))
74+
help=("Specifies the directory with the problems. Typically, this is "
75+
"'./problem_builds'. If not provided, the script defaults to "
76+
"'./problem_builds' in the same directory as the executable."))
7777
parser.add_argument(
7878
"--run-expected-tests", "-r",
7979
action="store_true",
@@ -95,10 +95,15 @@ def main():
9595

9696
logger.set_verbose(args.verbose)
9797

98-
problem_builds_dir = os.path.abspath(args.problem_builds_dir)
98+
openleetcode_dir = os.path.dirname(os.path.realpath(__file__))
99+
if args.problem_builds_dir is None:
100+
101+
problem_builds_dir = openleetcode_dir
102+
else:
103+
problem_builds_dir = os.path.abspath(args.problem_builds_dir)
99104

100105
if not os.path.isdir(problem_builds_dir):
101-
print(logger.red(f"The problems directory {args.problem_builds_dir} "
106+
print(logger.red(f"The problems directory {problem_builds_dir} "
102107
f"does not exist."))
103108
sys.exit(1)
104109

@@ -114,20 +119,14 @@ def main():
114119
print(problem)
115120
sys.exit(1)
116121

117-
if not os.path.isdir(args.problem_builds_dir):
118-
print(logger.red(f"The build directory '{args.problem_builds_dir}' "
119-
f"does not exist."))
120-
sys.exit(1)
121-
122-
problem_dir = os.path.join(args.problem_builds_dir,
123-
"problems", args.problem)
122+
problem_dir = os.path.join(problem_builds_dir, "problems", args.problem)
124123
if not os.path.isdir(problem_dir):
125124
print(logger.red(f"The problem directory {problem_dir} does not exist. "
126125
f"Check the problem_builds_dir and problem "
127126
f"arguments."))
128127
sys.exit(1)
129128

130-
src_template_dir = os.path.join(args.problem_builds_dir, "languages",
129+
src_template_dir = os.path.join(problem_builds_dir, "languages",
131130
args.language)
132131
if not os.path.isdir(src_template_dir):
133132
print(logger.red(f"The source template directory {src_template_dir} "
@@ -164,6 +163,7 @@ def main():
164163
" for testcase " + args.testcase + " in language " + args.language)
165164
logger.log(f"Building the problem {args.problem} "
166165
f"in {args.language} language.")
166+
logger.log(f"OpenLeetCode directory: {openleetcode_dir}")
167167
logger.log(f"Problem directory: {problem_dir}")
168168
logger.log(f"Problems directory: {problems_dir}")
169169
logger.log(f"Problem builds directory: {problem_builds_dir}")
@@ -189,7 +189,7 @@ def main():
189189
logger.log(f"Writing the function name to {solution_function_file_name}")
190190

191191
validation_schema_file = os.path.abspath(
192-
os.path.join(problem_builds_dir, VALIDATION_SCHEMA_FILE_NAME))
192+
os.path.join(openleetcode_dir, VALIDATION_SCHEMA_FILE_NAME))
193193
if not os.path.isfile(validation_schema_file):
194194
print(logger.red(f"The validation schema file {validation_schema_file} "
195195
f"does not exist."))

src/schema/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@ set (DATA
33
)
44

55
foreach(FILE IN LISTS DATA)
6-
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${FILE} ${PROJECT_BUILDS_DIR}/${FILE} COPYONLY)
7-
endforeach()
6+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${FILE}
7+
${CMAKE_CURRENT_BINARY_DIR}/${FILE}
8+
COPYONLY)
9+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${FILE}
10+
DESTINATION ${PROJECT_NAME})
11+
endforeach()

src/ui/CMakeLists.txt

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
2+
find_program(NPM_EXECUTABLE npm)
3+
find_program(NPX_EXECUTABLE npx)
4+
5+
set(OPENLEETCODEUI_FILES
6+
# JavaScript files
7+
directory-manager.js
8+
index.js
9+
main.js
10+
preload.js
11+
12+
# HTML files
13+
index.html
14+
15+
# CSS files
16+
styles.css
17+
18+
# Package files
19+
package.json
20+
package-lock.json
21+
)
22+
23+
message(STATUS "CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DIR}")
24+
25+
foreach(FILE ${OPENLEETCODEUI_FILES})
26+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${FILE}
27+
${CMAKE_CURRENT_BINARY_DIR}/${FILE}
28+
COPYONLY)
29+
endforeach()
30+
31+
add_custom_target(openleetcodeui_npm_install ALL
32+
COMMAND ${NPM_EXECUTABLE} install
33+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
34+
COMMENT "Running npm install for OpenLeetCodeUI"
35+
)
36+
37+
add_custom_target(openleetcodeui_build ALL
38+
COMMAND ${NPX_EXECUTABLE} electron-packager . --out=${CMAKE_CURRENT_BINARY_DIR}/OpenLeetCodeUI
39+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
40+
COMMENT "Packaging OpenLeetCodeUi"
41+
DEPENDS openleetcodeui_npm_install
42+
)
43+
44+
install(DIRECTORY
45+
${CMAKE_CURRENT_BINARY_DIR}/OpenLeetCodeUI/
46+
DESTINATION ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}
47+
USE_SOURCE_PERMISSIONS
48+
)
49+
50+
if (WIN32)
51+
set(SCRIPT openleetcodeui.bat)
52+
elseif (UNIX)
53+
set(SCRIPT openleetcodeui.sh)
54+
endif()
55+
56+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${SCRIPT}
57+
${CMAKE_CURRENT_BINARY_DIR}/${SCRIPT}
58+
COPYONLY)
59+
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${SCRIPT}
60+
DESTINATION ${PROJECT_NAME})
61+
62+
add_custom_target(
63+
openleetcodeui_script ALL
64+
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${SCRIPT}
65+
)

src/ui/main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ function saveFilePaths() {
1010
var problemBuildsDir = "./problem_builds";
1111
var problemBuildsArg = process.argv.find(arg => arg.startsWith('--problem_builds_dir='));
1212

13-
if (problemBuildsArg) {
13+
if (problemBuildsArg && problemBuildsArg.length > 0) {
1414
problemBuildsDir = problemBuildsArg.split('=')[1];
1515
console.log("Setting problemBuildsDir to " + problemBuildsDir);
1616
} else {
1717
console.log("problemBuildsDir was not set. Using default " + problemBuildsDir);
18+
console.log("process.argv: " + process.argv);
1819
}
1920
problemBuildsDir = path.resolve(problemBuildsDir);
2021

src/ui/openleetcodeui.bat

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@echo off
2+
setlocal
3+
4+
pushd "%~dp0"
5+
6+
call :run_exe
7+
popd
8+
exit /b
9+
10+
:run_exe
11+
for /D %%D in (OpenLeetCodeUI-*-*) do (
12+
if exist "%%D\OpenLeetCodeUI.exe" (
13+
echo Running OpenLeetCodeUI.exe in %%D
14+
start "" "%%D\OpenLeetCodeUI.exe" --problem_builds_dir=%~dp0
15+
exit /b
16+
)
17+
)
18+
echo No OpenLeetCodeUI.exe found in %~dp0OpenLeetCodeUI-*-* directory.
19+
exit /b

0 commit comments

Comments
 (0)