Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0a07736

Browse files
committed
Add batch script to windows configuration
1 parent 4a1ecad commit 0a07736

File tree

5 files changed

+49
-25
lines changed

5 files changed

+49
-25
lines changed

‎CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
cmake_minimum_required(VERSION 3.12)
22

3-
set(PROJECT_BUILDS_DIR_NAME ${CMAKE_CURRENT_SOURCE_DIR}/problem_builds)
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})
48

59
if(NOT CMAKE_INSTALL_PREFIX)
610
set(PROJECT_BUILDS_DIR "${PROJECT_BUILDS_DIR_NAME}")
711
else()
812
set(PROJECT_BUILDS_DIR "${CMAKE_INSTALL_PREFIX}")
913
endif()
14+
1015
message (STATUS "Setting PROJECT_BUILDS_DIR to ${PROJECT_BUILDS_DIR}")
1116

1217
set(CMAKE_FILE_DESTINATION_SUFIX "_destination")

‎README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
OpenLeetCode - An open source version of LeetCode
22
--------------------------------------------------------
33

4+
## Windows Terminal
5+
46
### Build
5-
```bash
6-
cmake -B build -DCMAKE_BUILD_TYPE=Debug
7+
```cmd
8+
cmake -B build -DCMAKE_BUILD_TYPE=Debug -DPROBLEM_BUILDS_NAME=problem_builds
79
cmake --build build
810
cmake --install build --config Debug
911
```
1012

1113
### Run
12-
```bash
13-
python.exe problem_builds\main.py --problem_builds_dir ./problem_builds --language cpp --problem TwoSum
14+
```cmd
15+
./problem_builds/openleetcode --problem_builds_dir ./problem_builds --language cpp --problem TwoSum
1416
```
1517

16-
### How To Use
18+
## How To Use
1719
The above example runs **TwoSum** problem using **C++**.
1820
After the build succeeds the following directory structure will be generated in the folder specified by ``--problem_builds_dir`` flag. In this example it's a folder called ``problem_builds`` as follows:.
1921

@@ -53,14 +55,14 @@ Each line is either an integral type (1, 4.6 etc.), or an array of integral type
5355

5456
For C++ the supported types are: integral types, strings, vector of integral types.
5557

56-
### List of LeetCode Problems
58+
## List of LeetCode Problems
5759
* TwoSum
5860
* LongestSubstringWithoutRepeatingCharacters
5961
* NumberOfIslands
6062

6163
The problem names are automatically extracted from the folder names inside **data/problems/**.
6264

63-
### Usage
65+
## Usage
6466
```text
6567
$ python main.py --help
6668
OpenLeetCode problem builder
@@ -76,14 +78,14 @@ options:
7678
--verbose, -v Print verbose output
7779
```
7880

79-
### Note
81+
## Note
8082
Curently only C++ is supported but the framework is setup such that other languages can be added. Also, the question description and the solution is yet to be worked on.
8183

82-
### Requirements
84+
## Requirements
8385
This project requires the following to run:
8486

8587
- Python
8688
- CMake 3.12
8789

88-
### Contributing
90+
## Contributing
8991
Feel free to contribute with code, test cases, or even code reviews.

‎src/app/CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
set(PYTHON_SCRIPTS
22
functionextractor.py
33
logger.py
4-
main.py
4+
openleetcode.py
55
resultsdiffer.py
66
testrunner.py
77
)
88

9+
set(WINDOWS_SCRIPTS
10+
openleetcode.bat
11+
)
12+
13+
if (WIN32)
14+
foreach(WINDOWS_SCRIPT IN LISTS WINDOWS_SCRIPTS)
15+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${WINDOWS_SCRIPT} ${PROJECT_BUILDS_DIR}/${WINDOWS_SCRIPT} COPYONLY)
16+
endforeach()
17+
endif()
18+
919
foreach(PYTHON_SCRIPT IN LISTS PYTHON_SCRIPTS)
1020
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${PYTHON_SCRIPT} ${PROJECT_BUILDS_DIR}/${PYTHON_SCRIPT} COPYONLY)
1121
endforeach()

‎src/app/openleetcode.bat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@echo off
2+
3+
python "%~dp0openleetcode.py" %*

‎src/app/main.py renamed to ‎src/app/openleetcode.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# main.py
1+
# openleetcode.py
22

33
import argparse
44
import logger
@@ -15,6 +15,7 @@
1515
# add option to run a single testcase
1616
# List the problems in --help
1717
# clean up logs
18+
# test on cmd, PowerShell, Winddows Terminal
1819

1920
TESTCAST_OUTPUT_DIR = "testcase_output"
2021

@@ -32,7 +33,7 @@ def run(command):
3233
def main():
3334
parser = argparse.ArgumentParser(description="OpenLeetCode problem builder")
3435
parser.add_argument("--problem_builds_dir", "-d",
35-
default=".",
36+
default="problem_builds",
3637
metavar='dir',
3738
type=str,
3839
help=("Path to a directory with the problems. "
@@ -59,30 +60,33 @@ def main():
5960
print("Running OpenLeetCode on problem: " + args.problem)
6061

6162
if not os.path.isdir(args.problem_builds_dir):
62-
print(logger.red(f"The directory '{args.problem_builds_dir}' "
63+
print(logger.red(f"The build directory '{args.problem_builds_dir}' "
6364
f"does not exist."))
6465
sys.exit(1)
6566

6667
problem_dir = os.path.join(args.problem_builds_dir,
6768
"problems", args.problem)
6869
if not os.path.isdir(problem_dir):
69-
print(logger.red(f"The directory {problem_dir} does not exist. Check "
70-
f"the problem_builds_dir and problem arguments."))
70+
print(logger.red(f"The problem directory {problem_dir} does not exist. "
71+
f"Check the problem_builds_dir and problem "
72+
f"arguments."))
7173
sys.exit(1)
7274

7375
src_template_dir = os.path.join(args.problem_builds_dir, "languages",
7476
args.language)
7577
if not os.path.isdir(src_template_dir):
76-
print(logger.red(f"The directory {src_template_dir} does not exist. "
77-
"This usually happen when the language is not " f"supported. Check the language argument."))
78+
print(logger.red(f"The source template directory {src_template_dir} "
79+
f"does not exist. This usually happen when the "
80+
f"language is not supported. Check the language "
81+
f"argument."))
7882
sys.exit(1)
7983

8084

8185
src_dir = os.path.abspath(os.path.join(problem_dir, args.language))
8286
if not os.path.isdir(src_dir):
83-
print(logger.red(f"The directory {src_dir} does not exist. This"
84-
f"usually happen when the language is not supported."
85-
f"Check the language argument."))
87+
print(logger.red(f"The source directory {src_dir} does not exist. This"
88+
f"usually happen when the language is not supported."
89+
f"Check the language argument."))
8690
sys.exit(1)
8791

8892
build_dir = os.path.abspath(os.path.join(src_dir, "build"))
@@ -131,10 +135,10 @@ def main():
131135
print(logger.red("Install failed!"))
132136
sys.exit(1)
133137

134-
bin_dir = os.path.join("bin")
138+
bin_dir = os.path.abspath(os.path.join(src_dir, "bin"))
135139

136140
if not os.path.isdir(bin_dir):
137-
print(logger.red(f"The directory {bin_dir} does not exist. Check the "
141+
print(logger.red(f"The bin directory {bin_dir} does not exist. Check the "
138142
f"problem_builds_dir and problem arguments."))
139143
sys.exit(1)
140144

@@ -149,7 +153,7 @@ def main():
149153
testcases_dir = os.path.abspath("../testcases")
150154

151155
if not os.path.isdir(testcases_dir):
152-
print(logger.red(f"The directory {testcases_dir} does not exist. "
156+
print(logger.red(f"The test directory {testcases_dir} does not exist. "
153157
f"Check the problem_builds_dir and problem "
154158
f"arguments."))
155159
sys.exit(1)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /