mbucko / openleetcode

An open source version of LeetCode
MIT License
28 stars 3 forks source link

Add Java solutions to existing problems #5

Open mbucko opened 9 months ago

ThomasChen0717 commented 9 months ago

Hi, I am looking to contribute to this project and I tried to run your program locally on my computer. I was able to build the project but afterwards, when I try to run the test for TwoSum, I am getting this error: The bin directory /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/bin does not exist. Check the problem_builds_dir and problem arguments. I noticed that there aren't a bin folder created after the build. I wonder how I can resolve that? Is it my misunderstanding?

mbucko commented 9 months ago

run it with -v option and it should print out all the folders that it's using. Also, can you tell me with what args you're running it?

ThomasChen0717 commented 9 months ago

Im running the default args as specified in README. Running -v tells me that the bin folder is missing. Am I supposed to build the project in the folder that I cloned the source code?

mbucko commented 9 months ago

Are you running it on windows? Can you paste the entire output including the build and running the app it "-v" option?

mbucko commented 9 months ago

When you call ./problem_builds/openleetcode --problem_builds_dir ./problem_builds --language cpp --problem TwoSum it runs cmake and build inside problem_builds/problems/TwoSum/cpp which is when the bin folder is created with the executable for the tests.

If you specify -v option to openleetcode you might have more info about the failure. My guess is that it's failing to build because you're missing some dependency like the compiler....

ThomasChen0717 commented 9 months ago

I am running it on macOs. This is my terminal output: styleys@ThomasdeMacBook-Pro openleetcode % cmake -B build -DCMAKE_BUILD_TYPE=Debug -DPROBLEM_BUILDS_NAME=problem_builds -- Setting PROJECT_BUILDS_DIR to /Users/styleys/documents/Portfolio/openleetcode/problem_builds -- The C compiler identification is AppleClang 14.0.3.14030022 -- The CXX compiler identification is AppleClang 14.0.3.14030022 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Configuring done (0.9s) -- Generating done (0.0s) -- Build files have been written to: /Users/styleys/documents/Portfolio/openleetcode/build styleys@ThomasdeMacBook-Pro openleetcode % cmake --build build
styleys@ThomasdeMacBook-Pro openleetcode % cmake --install build --config Debug -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/NumberOfIslands -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/NumberOfIslands/description.md -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/NumberOfIslands/cpp -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/NumberOfIslands/cpp/solution.cpp -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/NumberOfIslands/cpp/solution.md -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/NumberOfIslands/testcases -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/NumberOfIslands/testcases/TestCase1.test -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/NumberOfIslands/testcases/TestCase2.test -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/NumberOfIslands/testcases/TestCase3.test -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/NumberOfIslands/testcases/TestCase4.test -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/NumberOfIslands/testcases/TestCase5.test -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/description.md -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/solution.cpp -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/solution.md -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases/TestCase6.test -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases/TestCase13.test -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases/TestCase12.test -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases/TestCase7.test -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases/TestCase15.test -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases/TestCase14.test -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases/TestCase1.test -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases/TestCase2.test -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases/TestCase3.test -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases/TestCase11.test -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases/TestCase4.test -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases/TestCase8.test -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases/TestCase9.test -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases/TestCase5.test -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases/TestCase10.test -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/description.md -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/cpp -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/cpp/solution.cpp -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/cpp/solution.md -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/testcases -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/testcases/TestCase6.test -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/testcases/TestCase7.test -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/testcases/TestCase1.test -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/testcases/TestCase2.test -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/testcases/TestCase3.test -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/testcases/TestCase11test -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/testcases/TestCase4.test -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/testcases/TestCase8.test -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/testcases/TestCase9.test -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/testcases/TestCase5.test -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/testcases/TestCase10.test -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/languages -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/languages/cpp -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/languages/cpp/problemtest.cpp -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/languages/cpp/printer.h -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/languages/cpp/CMakeLists.txt -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/languages/cpp/typetraits.h -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/languages/cpp/problemtest.h -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/languages/cpp/parser.h -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/languages/cpp/stlincludes.h -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/languages/cpp/binder.h -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/languages/cpp/main.cpp -- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/languages/cpp/solutionwrapper.h styleys@ThomasdeMacBook-Pro openleetcode % python3 ./problem_builds/openleetcode.py --problem_builds_dir ./problem_builds --language cpp --problem TwoSum -v Running OpenLeetCode on problem: TwoSum Building the problem TwoSum in cpp language. Problem directory: ./problem_builds/problems/TwoSum Source directory: /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp Build directory: /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/build Template source directory: ./problem_builds/languages/cpp Copying ./problem_builds/languages/cpp/problemtest.cpp to /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/problemtest.cpp Copying ./problem_builds/languages/cpp/printer.h to /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/printer.h Copying ./problem_builds/languages/cpp/CMakeLists.txt to /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/CMakeLists.txt Copying ./problem_builds/languages/cpp/typetraits.h to /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/typetraits.h Copying ./problem_builds/languages/cpp/problemtest.h to /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/problemtest.h Copying ./problem_builds/languages/cpp/parser.h to /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/parser.h Copying ./problem_builds/languages/cpp/stlincludes.h to /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/stlincludes.h Copying ./problem_builds/languages/cpp/binder.h to /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/binder.h Copying ./problem_builds/languages/cpp/main.cpp to /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/main.cpp Copying ./problem_builds/languages/cpp/solutionwrapper.h to /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/solutionwrapper.h Extracted function name: twoSum Writing the function name to /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/solutionfunction.h The bin directory /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/bin does not exist. Check the problem_builds_dir and problem arguments.

mbucko commented 9 months ago

cmake is supposed to create the bin directory inside /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp

This is the case for Windows. It seems that the bin directory wasn't created in your case. Can you check and find where the executable was built? It should be somewhere in one of the subfolder in /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp.

Anyways, as of now I haven't tested it for iOS because I don't have a Mac. i can try to help you but you might need to do some digging. If you look at openleetcode.py which is the script that builds the solution file and executes the tests. You can try to figure out why what happened there

mbucko commented 9 months ago

Actually, I found a small typo in the cmake file. Can refresh your repo and try again?

ThomasChen0717 commented 9 months ago

I have found out the error. It stems from the difference in behavior of the operating system's subprocess.run() function in the openleetcode.py file. In macOS, the command should be passed in as command instead of command.split(). I have also made a bit of other changes. Can I commit the changes on another branch so that you could verify the changes and commit if everything looks good?

mbucko commented 9 months ago

Yes please do. Also, I am making some big changes to openleetcode.py. I need to standardize how the openleetcode.py will interact with the language-specific binaries. I will document it all so that it's easy to add support for a new language. Should land the changes today.

ThomasChen0717 commented 9 months ago

I am unable to push my changes to a new branch I name dev. I got the error: styleys@ThomasdeMacBook-Pro openleetcode % git push -u origin dev remote: Permission to mbucko/openleetcode.git denied to ThomasChen0717. fatal: unable to access 'https://github.com/mbucko/openleetcode.git/': The requested URL returned error: 403 I suspect that I would need permissions from your end.

mbucko commented 9 months ago

You're trying to push directly to the main repository. However, the typical workflow on GitHub involves working on your own fork of the repository and then submitting a pull request when you're ready to merge your changes.

ThomasChen0717 commented 9 months ago

πŸ‘Œ

Miro Bucko @.***>于2024εΉ΄2月25ζ—₯ 周ζ—₯δΈ‹εˆ6:57ε†™ι“οΌš

You're trying to push directly to the main repository. However, the typical workflow on GitHub involves working on your own fork of the repository and then submitting a pull request when you're ready to merge your changes.

β€” Reply to this email directly, view it on GitHub https://github.com/mbucko/openleetcode/issues/5#issuecomment-1962966029, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZOAZSXOT73ZQVDNZFMFVFTYVNGOHAVCNFSM6AAAAABDUM2QMWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRSHE3DMMBSHE . You are receiving this because you commented.Message ID: @.***>