diff --git a/.github/workflows/mdbook.yml b/.github/workflows/mdbook.yml index 16e23d5..0836944 100644 --- a/.github/workflows/mdbook.yml +++ b/.github/workflows/mdbook.yml @@ -9,7 +9,7 @@ on: push: branches: ["main"] paths: - - 'src/**' + - 'book/src/**' # Allows you to run this workflow manually from the Actions tab workflow_dispatch: @@ -30,6 +30,11 @@ jobs: # Build job build: runs-on: ubuntu-latest + + defaults: + run: + working-directory: book + env: MDBOOK_VERSION: 0.4.36 steps: diff --git a/.gitignore b/.gitignore index 19d8f52..286ed3b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -book .xmake build .vscode \ No newline at end of file diff --git a/.gitmodules b/.gitmodules index 406596c..46662c6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,7 @@ -[submodule "DStruct"] - path = DStruct +[submodule "dstruct"] + path = dstruct url = https://github.com/Sunrisepeak/DStruct + +[submodule "courses"] + path = courses + url = git@github.com:Sunrisepeak/d2ds-courses.git diff --git a/book/.gitignore b/book/.gitignore new file mode 100644 index 0000000..e9c0728 --- /dev/null +++ b/book/.gitignore @@ -0,0 +1 @@ +book \ No newline at end of file diff --git a/book.toml b/book/book.toml similarity index 86% rename from book.toml rename to book/book.toml index 0809e3d..4e60bf7 100644 --- a/book.toml +++ b/book/book.toml @@ -1,5 +1,5 @@ [book] -authors = ["SPeak"] +authors = ["Sunrisepeak"] language = "en" multilingual = false src = "src" diff --git a/src/0_array.md b/book/src/0_array.md similarity index 100% rename from src/0_array.md rename to book/src/0_array.md diff --git a/src/1_linkedlist.md b/book/src/1_linkedlist.md similarity index 100% rename from src/1_linkedlist.md rename to book/src/1_linkedlist.md diff --git a/src/Instroduction.md b/book/src/Instroduction.md similarity index 100% rename from src/Instroduction.md rename to book/src/Instroduction.md diff --git a/src/Resources.md b/book/src/Resources.md similarity index 100% rename from src/Resources.md rename to book/src/Resources.md diff --git a/src/SUMMARY.md b/book/src/SUMMARY.md similarity index 100% rename from src/SUMMARY.md rename to book/src/SUMMARY.md diff --git a/src/chapter_01_array.md b/book/src/chapter_01_array.md similarity index 100% rename from src/chapter_01_array.md rename to book/src/chapter_01_array.md diff --git a/src/chapter_02_vector.md b/book/src/chapter_02_vector.md similarity index 100% rename from src/chapter_02_vector.md rename to book/src/chapter_02_vector.md diff --git a/src/chapter_04_embeddedlist.md b/book/src/chapter_04_embeddedlist.md similarity index 100% rename from src/chapter_04_embeddedlist.md rename to book/src/chapter_04_embeddedlist.md diff --git a/src/other/0_ds_base.md b/book/src/other/0_ds_base.md similarity index 100% rename from src/other/0_ds_base.md rename to book/src/other/0_ds_base.md diff --git a/src/other/1_cpp_base.md b/book/src/other/1_cpp_base.md similarity index 100% rename from src/other/1_cpp_base.md rename to book/src/other/1_cpp_base.md diff --git a/src/other/1_cpp_base.template.md b/book/src/other/1_cpp_base.template.md similarity index 100% rename from src/other/1_cpp_base.template.md rename to book/src/other/1_cpp_base.template.md diff --git a/src/other/2_cpp_base.rangefor.md b/book/src/other/2_cpp_base.rangefor.md similarity index 100% rename from src/other/2_cpp_base.rangefor.md rename to book/src/other/2_cpp_base.rangefor.md diff --git a/src/other/3_cpp_base.bigfive.md b/book/src/other/3_cpp_base.bigfive.md similarity index 100% rename from src/other/3_cpp_base.bigfive.md rename to book/src/other/3_cpp_base.bigfive.md diff --git a/tools/d2ds.lua b/common/d2ds.lua similarity index 100% rename from tools/d2ds.lua rename to common/d2ds.lua diff --git a/common/dslings.lua b/common/dslings.lua new file mode 100644 index 0000000..eda8129 --- /dev/null +++ b/common/dslings.lua @@ -0,0 +1,215 @@ +import("core.project.project") +import("core.project.target") +import("core.base.global") +import("core.base.option") + +-- TODO: optimze +target_to_code_file = { + ["0.dslings-0"] = "dslings/exercises/dslings.hpp", + ["0.dslings-1"] = "dslings/exercises/dslings.hpp", + ["0.dslings-2"] = "dslings/exercises/dslings.hpp", + ["1.template-0"] = "dslings/exercises/other/cpp-base/Template.hpp", + ["1.template-1"] = "dslings/exercises/other/cpp-base/Template.hpp", + ["1.template-2"] = "dslings/exercises/other/cpp-base/Template.hpp", + ["2.range_for-0"] = "dslings/exercises/other/cpp-base/RangeFor.hpp", + ["2.range_for-1"] = "dslings/exercises/other/cpp-base/RangeFor.hpp", + ["2.range_for-2"] = "dslings/exercises/other/cpp-base/RangeFor.hpp", + ["2.range_for-3"] = "dslings/exercises/other/cpp-base/RangeFor.hpp", + ["3.array-0"] = "dslings/exercises/array/Array.hpp", + ["3.array-1"] = "dslings/exercises/array/Array.hpp", + ["3.array-2"] = "dslings/exercises/array/Array.hpp", + ["3.array-3"] = "dslings/exercises/array/Array.hpp", + ["3.array-4"] = "dslings/exercises/array/Array.hpp", + ["3.array-5"] = "dslings/exercises/array/Array.hpp", + ["3.array-6"] = "dslings/exercises/array/Array.hpp", + ["4.vector-0-0"] = "dslings/exercises/array/Vector.hpp", + ["4.vector-0-1"] = "dslings/exercises/array/Vector.hpp", + ["4.vector-0-all"] = "dslings/exercises/array/Vector.hpp", + ["4.vector-1-0"] = "dslings/exercises/array/Vector.hpp", + ["4.vector-1-1"] = "dslings/exercises/array/Vector.hpp", + ["4.vector-1-2"] = "dslings/exercises/array/Vector.hpp", + ["4.vector-1-all"] = "dslings/exercises/array/Vector.hpp", + ["4.vector-2"] = "dslings/exercises/array/Vector.hpp", + ["4.vector-3-0"] = "dslings/exercises/array/Vector.hpp", + ["4.vector-3-all"] = "dslings/exercises/array/Vector.hpp", + ["4.vector-4"] = "dslings/exercises/array/Vector.hpp", + ["4.vector-5"] = "dslings/exercises/array/Vector.hpp", + ["5.embedded-slist-0"] = "dslings/exercises/linked-list/EmbeddedList.hpp", + ["5.embedded-slist-1"] = "dslings/exercises/linked-list/EmbeddedList.hpp", + ["5.embedded-slist-2"] = "dslings/exercises/linked-list/EmbeddedList.hpp", + ["5.embedded-slist-3"] = "dslings/exercises/linked-list/EmbeddedList.hpp", + ["5.embedded-slist-4"] = "dslings/exercises/linked-list/EmbeddedList.hpp", +} + +function clear_screen() + if os.host() == "windows" then + os.exec("tools\\clear_screen.bat") + else + os.exec("clear") + end +end + +function print_info(target_name, built_targets, total_targets, current_file_path, output, status) + + clear_screen() + + -- print progress_bar + local progress_bar_length = total_targets + local arrow_count = built_targets + local dash_count = progress_bar_length - arrow_count + local progress_bar = string.format( + "🌏Progress: [%s>%s] %d/%d", + string.rep("=", arrow_count), + string.rep("-", dash_count), + arrow_count, progress_bar_length + ) + print(progress_bar) + + print(string.format("\n[Target: %s]\n", target_name)) + + -- print status + if status then + print(string.format("βœ… Successfully ran %s!", current_file_path)) + print("\nπŸŽ‰ The code is compiling! πŸŽ‰\n") + else + print(string.format("❌ Error: Compilation/Running failed for %s:", current_file_path)) + print("\n The code exist some error!\n") + end + + -- print output + print("Output:") + print("====================") + print(output) + print("====================") + + print("\nHomepage: https://github.com/Sunrisepeak/d2ds-courses") +end + +-- main start +function main() + local checker_pass = false + local start_target = option.get("start_target") + + clear_screen() + + local base_dir = os.projectdir() + + -- θŽ·ε– project δΈ­ζ‰€ζœ‰ target + local targets = project.targets() + --local targets = {"d2ds_array", "d2ds_array1"} + --local total_targets = #targets -- + -- TODO: optimize total_targets + local total_targets = 0 + local built_targets = 0 + local sorted_targets = {} + for name, _ in pairs(targets) do + total_targets = total_targets + 1 + table.insert(sorted_targets, name) + end + + table.sort(sorted_targets) + + local skip = true + for _, name in pairs(sorted_targets) do + + if skip and (name == start_target or string.find(name, start_target)) then + skip = false; + end + + if not skip then + local files = targets[name]:sourcefiles() + for _, file in ipairs((files)) do + local relative_path = path.relative(file, base_dir) + local build_success = false + local sleep_sec = 1000 * 0.1 + local output = "" + + local file_modify_time + local compile_bypass_counter = 0 + + while not build_success do + local curr_file_mtime = os.mtime(file) + if target_to_code_file[name] then + curr_file_mtime = curr_file_mtime + os.mtime(target_to_code_file[name]) + end + + if file_modify_time ~= curr_file_mtime then + --build_success = task.run("build", {target = name}) + build_success = true + try + { + function() + os.iorunv("xmake", {"build", name}) + --os.iorunv("xmake", {"build", "-v", name}) + end, + catch + { + -- After an exception occurs, it is executed + function (e) + output = e + build_success = false + end + } + } + + if build_success then + try { + function () + output, _ = os.iorunv("xmake", {"r", name}) + end, + catch + { + function (e) + output = e + build_success = false + end + } + } + end + + local status = build_success + + if type(output) == "string" then + if string.find(output, "❌") then + status = false + build_success = false + elseif string.find(output, "D2DS_WAIT") or string.find(output, "D2DS_RETURN") then + build_success = false + end + end + + if build_success then + built_targets = built_targets + 1 + else + sleep_sec = 1000 * 1 + end + + print_info(name, built_targets, total_targets, relative_path, output, status) + output = "" + else + compile_bypass_counter = compile_bypass_counter + 1 + end + + file_modify_time = curr_file_mtime + if compile_bypass_counter > 20 then + compile_bypass_counter = 0 + file_modify_time = nil + end + os.sleep(sleep_sec) + + end + end + else + built_targets = built_targets + 1 + end + end + + local bingo = "\ + Bingo! πŸŽ‰πŸŽ‰πŸŽ‰\n \ +You have completed all exercises\n \ +Next: https://github.com/Sunrisepeak/dstruct\ +" + + print_info("D2DS", total_targets, total_targets, "...", bingo, true) + +end \ No newline at end of file diff --git a/courses b/courses new file mode 160000 index 0000000..5d08014 --- /dev/null +++ b/courses @@ -0,0 +1 @@ +Subproject commit 5d080140c65fc743837f582fe2320ea4169499f3 diff --git a/exercises/array/Array.hpp b/dslings/exercises/array/Array.hpp similarity index 100% rename from exercises/array/Array.hpp rename to dslings/exercises/array/Array.hpp diff --git a/exercises/array/Vector.hpp b/dslings/exercises/array/Vector.hpp similarity index 100% rename from exercises/array/Vector.hpp rename to dslings/exercises/array/Vector.hpp diff --git a/exercises/dslings.hpp b/dslings/exercises/dslings.hpp similarity index 100% rename from exercises/dslings.hpp rename to dslings/exercises/dslings.hpp diff --git a/exercises/linked-list/EmbeddedList.hpp b/dslings/exercises/linked-list/EmbeddedList.hpp similarity index 100% rename from exercises/linked-list/EmbeddedList.hpp rename to dslings/exercises/linked-list/EmbeddedList.hpp diff --git a/exercises/other/cpp-base/RangeFor.hpp b/dslings/exercises/other/cpp-base/RangeFor.hpp similarity index 100% rename from exercises/other/cpp-base/RangeFor.hpp rename to dslings/exercises/other/cpp-base/RangeFor.hpp diff --git a/exercises/other/cpp-base/Template.hpp b/dslings/exercises/other/cpp-base/Template.hpp similarity index 100% rename from exercises/other/cpp-base/Template.hpp rename to dslings/exercises/other/cpp-base/Template.hpp diff --git a/tests/array/array.0.cpp b/dslings/tests/array/array.0.cpp similarity index 100% rename from tests/array/array.0.cpp rename to dslings/tests/array/array.0.cpp diff --git a/tests/array/array.1.cpp b/dslings/tests/array/array.1.cpp similarity index 100% rename from tests/array/array.1.cpp rename to dslings/tests/array/array.1.cpp diff --git a/tests/array/array.2.cpp b/dslings/tests/array/array.2.cpp similarity index 100% rename from tests/array/array.2.cpp rename to dslings/tests/array/array.2.cpp diff --git a/tests/array/array.3.cpp b/dslings/tests/array/array.3.cpp similarity index 100% rename from tests/array/array.3.cpp rename to dslings/tests/array/array.3.cpp diff --git a/tests/array/array.4.cpp b/dslings/tests/array/array.4.cpp similarity index 100% rename from tests/array/array.4.cpp rename to dslings/tests/array/array.4.cpp diff --git a/tests/array/array.5.cpp b/dslings/tests/array/array.5.cpp similarity index 100% rename from tests/array/array.5.cpp rename to dslings/tests/array/array.5.cpp diff --git a/tests/array/array.6.cpp b/dslings/tests/array/array.6.cpp similarity index 100% rename from tests/array/array.6.cpp rename to dslings/tests/array/array.6.cpp diff --git a/tests/dslings.0.cpp b/dslings/tests/dslings.0.cpp similarity index 100% rename from tests/dslings.0.cpp rename to dslings/tests/dslings.0.cpp diff --git a/tests/dslings.1.cpp b/dslings/tests/dslings.1.cpp similarity index 100% rename from tests/dslings.1.cpp rename to dslings/tests/dslings.1.cpp diff --git a/tests/dslings.2.cpp b/dslings/tests/dslings.2.cpp similarity index 100% rename from tests/dslings.2.cpp rename to dslings/tests/dslings.2.cpp diff --git a/tests/embedded-list/embedded-slist.0.cpp b/dslings/tests/embedded-list/embedded-slist.0.cpp similarity index 100% rename from tests/embedded-list/embedded-slist.0.cpp rename to dslings/tests/embedded-list/embedded-slist.0.cpp diff --git a/tests/embedded-list/embedded-slist.1.cpp b/dslings/tests/embedded-list/embedded-slist.1.cpp similarity index 100% rename from tests/embedded-list/embedded-slist.1.cpp rename to dslings/tests/embedded-list/embedded-slist.1.cpp diff --git a/tests/embedded-list/embedded-slist.2.cpp b/dslings/tests/embedded-list/embedded-slist.2.cpp similarity index 100% rename from tests/embedded-list/embedded-slist.2.cpp rename to dslings/tests/embedded-list/embedded-slist.2.cpp diff --git a/tests/embedded-list/embedded-slist.3.cpp b/dslings/tests/embedded-list/embedded-slist.3.cpp similarity index 100% rename from tests/embedded-list/embedded-slist.3.cpp rename to dslings/tests/embedded-list/embedded-slist.3.cpp diff --git a/tests/embedded-list/embedded-slist.4.cpp b/dslings/tests/embedded-list/embedded-slist.4.cpp similarity index 100% rename from tests/embedded-list/embedded-slist.4.cpp rename to dslings/tests/embedded-list/embedded-slist.4.cpp diff --git a/tests/other/cpp-base/range_for.0.cpp b/dslings/tests/other/cpp-base/range_for.0.cpp similarity index 100% rename from tests/other/cpp-base/range_for.0.cpp rename to dslings/tests/other/cpp-base/range_for.0.cpp diff --git a/tests/other/cpp-base/range_for.1.cpp b/dslings/tests/other/cpp-base/range_for.1.cpp similarity index 100% rename from tests/other/cpp-base/range_for.1.cpp rename to dslings/tests/other/cpp-base/range_for.1.cpp diff --git a/tests/other/cpp-base/range_for.2.cpp b/dslings/tests/other/cpp-base/range_for.2.cpp similarity index 100% rename from tests/other/cpp-base/range_for.2.cpp rename to dslings/tests/other/cpp-base/range_for.2.cpp diff --git a/tests/other/cpp-base/range_for.3.cpp b/dslings/tests/other/cpp-base/range_for.3.cpp similarity index 100% rename from tests/other/cpp-base/range_for.3.cpp rename to dslings/tests/other/cpp-base/range_for.3.cpp diff --git a/tests/other/cpp-base/template.0.cpp b/dslings/tests/other/cpp-base/template.0.cpp similarity index 100% rename from tests/other/cpp-base/template.0.cpp rename to dslings/tests/other/cpp-base/template.0.cpp diff --git a/tests/other/cpp-base/template.1.cpp b/dslings/tests/other/cpp-base/template.1.cpp similarity index 100% rename from tests/other/cpp-base/template.1.cpp rename to dslings/tests/other/cpp-base/template.1.cpp diff --git a/tests/other/cpp-base/template.2.cpp b/dslings/tests/other/cpp-base/template.2.cpp similarity index 100% rename from tests/other/cpp-base/template.2.cpp rename to dslings/tests/other/cpp-base/template.2.cpp diff --git a/tests/vector/vector.0.0.cpp b/dslings/tests/vector/vector.0.0.cpp similarity index 100% rename from tests/vector/vector.0.0.cpp rename to dslings/tests/vector/vector.0.0.cpp diff --git a/tests/vector/vector.0.1.cpp b/dslings/tests/vector/vector.0.1.cpp similarity index 100% rename from tests/vector/vector.0.1.cpp rename to dslings/tests/vector/vector.0.1.cpp diff --git a/tests/vector/vector.0.cpp b/dslings/tests/vector/vector.0.cpp similarity index 100% rename from tests/vector/vector.0.cpp rename to dslings/tests/vector/vector.0.cpp diff --git a/tests/vector/vector.1.0.cpp b/dslings/tests/vector/vector.1.0.cpp similarity index 100% rename from tests/vector/vector.1.0.cpp rename to dslings/tests/vector/vector.1.0.cpp diff --git a/tests/vector/vector.1.1.cpp b/dslings/tests/vector/vector.1.1.cpp similarity index 100% rename from tests/vector/vector.1.1.cpp rename to dslings/tests/vector/vector.1.1.cpp diff --git a/tests/vector/vector.1.2.cpp b/dslings/tests/vector/vector.1.2.cpp similarity index 100% rename from tests/vector/vector.1.2.cpp rename to dslings/tests/vector/vector.1.2.cpp diff --git a/tests/vector/vector.1.cpp b/dslings/tests/vector/vector.1.cpp similarity index 100% rename from tests/vector/vector.1.cpp rename to dslings/tests/vector/vector.1.cpp diff --git a/tests/vector/vector.2.cpp b/dslings/tests/vector/vector.2.cpp similarity index 100% rename from tests/vector/vector.2.cpp rename to dslings/tests/vector/vector.2.cpp diff --git a/tests/vector/vector.3.0.cpp b/dslings/tests/vector/vector.3.0.cpp similarity index 100% rename from tests/vector/vector.3.0.cpp rename to dslings/tests/vector/vector.3.0.cpp diff --git a/tests/vector/vector.3.cpp b/dslings/tests/vector/vector.3.cpp similarity index 100% rename from tests/vector/vector.3.cpp rename to dslings/tests/vector/vector.3.cpp diff --git a/tests/vector/vector.4.cpp b/dslings/tests/vector/vector.4.cpp similarity index 100% rename from tests/vector/vector.4.cpp rename to dslings/tests/vector/vector.4.cpp diff --git a/tests/vector/vector.5.cpp b/dslings/tests/vector/vector.5.cpp similarity index 100% rename from tests/vector/vector.5.cpp rename to dslings/tests/vector/vector.5.cpp diff --git a/dslings/xmake.lua b/dslings/xmake.lua new file mode 100644 index 0000000..b16a696 --- /dev/null +++ b/dslings/xmake.lua @@ -0,0 +1,135 @@ +target("0.dslings-0") + set_kind("binary") + add_files("tests/dslings.0.cpp") + +target("0.dslings-1") + set_kind("binary") + add_files("tests/dslings.1.cpp") + +target("0.dslings-2") + set_kind("binary") + add_files("tests/dslings.2.cpp") + +target("1.template-0") + set_kind("binary") + add_files("tests/other/cpp-base/template.0.cpp") + +target("1.template-1") + set_kind("binary") + add_files("tests/other/cpp-base/template.1.cpp") + +target("1.template-2") + set_kind("binary") + add_files("tests/other/cpp-base/template.2.cpp") + +target("2.range_for-0") + set_kind("binary") + add_files("tests/other/cpp-base/range_for.0.cpp") + +target("2.range_for-1") + set_kind("binary") + add_files("tests/other/cpp-base/range_for.1.cpp") + +target("2.range_for-2") + set_kind("binary") + add_files("tests/other/cpp-base/range_for.2.cpp") + +target("2.range_for-3") + set_kind("binary") + add_files("tests/other/cpp-base/range_for.3.cpp") + +target("3.array-0") + set_kind("binary") + add_files("tests/array/array.0.cpp") + +target("3.array-1") + set_kind("binary") + add_files("tests/array/array.1.cpp") + +target("3.array-2") + set_kind("binary") + add_files("tests/array/array.2.cpp") + +target("3.array-3") + set_kind("binary") + add_files("tests/array/array.3.cpp") + +target("3.array-4") + set_kind("binary") + add_files("tests/array/array.4.cpp") + +target("3.array-5") + set_kind("binary") + add_files("tests/array/array.5.cpp") + +target("3.array-6") + set_kind("binary") + add_files("tests/array/array.6.cpp") + +target("4.vector-0-0") + set_kind("binary") + add_files("tests/vector/vector.0.0.cpp") + +target("4.vector-0-1") + set_kind("binary") + add_files("tests/vector/vector.0.1.cpp") + +target("4.vector-0-all") + set_kind("binary") + add_files("tests/vector/vector.0.cpp") + +target("4.vector-1-0") + set_kind("binary") + add_files("tests/vector/vector.1.0.cpp") + +target("4.vector-1-1") + set_kind("binary") + add_files("tests/vector/vector.1.1.cpp") + +target("4.vector-1-2") + set_kind("binary") + add_files("tests/vector/vector.1.2.cpp") + +target("4.vector-1-all") + set_kind("binary") + add_files("tests/vector/vector.1.cpp") + +target("4.vector-2") + set_kind("binary") + add_files("tests/vector/vector.2.cpp") + +target("4.vector-3-0") + set_kind("binary") + add_files("tests/vector/vector.3.0.cpp") + +target("4.vector-3-all") + set_kind("binary") + add_files("tests/vector/vector.3.cpp") + +target("4.vector-4") + set_kind("binary") + add_files("tests/vector/vector.4.cpp") + +target("4.vector-5") + set_kind("binary") + add_files("tests/vector/vector.5.cpp") + +target("5.embedded-slist-0") + set_kind("binary") + add_files("tests/embedded-list/embedded-slist.0.cpp") + +target("5.embedded-slist-1") + set_kind("binary") + add_files("tests/embedded-list/embedded-slist.1.cpp") + +target("5.embedded-slist-2") + set_kind("binary") + add_files("tests/embedded-list/embedded-slist.2.cpp") + +target("5.embedded-slist-3") + set_kind("binary") + add_files("tests/embedded-list/embedded-slist.3.cpp") + +target("5.embedded-slist-4") + set_kind("binary") + add_files("tests/embedded-list/embedded-slist.4.cpp") \ No newline at end of file diff --git a/DStruct b/dstruct similarity index 100% rename from DStruct rename to dstruct diff --git a/xmake.lua b/xmake.lua index 9800652..cc42eb1 100644 --- a/xmake.lua +++ b/xmake.lua @@ -2,147 +2,15 @@ add_rules("mode.debug") set_languages("cxx11") add_includedirs(".") +add_includedirs("dslings") -- verify lib -add_includedirs("DStruct") +add_includedirs("dstruct") -target("0.dslings-0") - set_kind("binary") - add_files("tests/dslings.0.cpp") +-- dslings exercises target list +includes("dslings/xmake.lua") -target("0.dslings-1") - set_kind("binary") - add_files("tests/dslings.1.cpp") - -target("0.dslings-2") - set_kind("binary") - add_files("tests/dslings.2.cpp") - -target("1.template-0") - set_kind("binary") - add_files("tests/other/cpp-base/template.0.cpp") - -target("1.template-1") - set_kind("binary") - add_files("tests/other/cpp-base/template.1.cpp") - -target("1.template-2") - set_kind("binary") - add_files("tests/other/cpp-base/template.2.cpp") - -target("2.range_for-0") - set_kind("binary") - add_files("tests/other/cpp-base/range_for.0.cpp") - -target("2.range_for-1") - set_kind("binary") - add_files("tests/other/cpp-base/range_for.1.cpp") - -target("2.range_for-2") - set_kind("binary") - add_files("tests/other/cpp-base/range_for.2.cpp") - -target("2.range_for-3") - set_kind("binary") - add_files("tests/other/cpp-base/range_for.3.cpp") - -target("3.array-0") - set_kind("binary") - add_files("tests/array/array.0.cpp") - -target("3.array-1") - set_kind("binary") - add_files("tests/array/array.1.cpp") - -target("3.array-2") - set_kind("binary") - add_files("tests/array/array.2.cpp") - -target("3.array-3") - set_kind("binary") - add_files("tests/array/array.3.cpp") - -target("3.array-4") - set_kind("binary") - add_files("tests/array/array.4.cpp") - -target("3.array-5") - set_kind("binary") - add_files("tests/array/array.5.cpp") - -target("3.array-6") - set_kind("binary") - add_files("tests/array/array.6.cpp") - -target("4.vector-0-0") - set_kind("binary") - add_files("tests/vector/vector.0.0.cpp") - -target("4.vector-0-1") - set_kind("binary") - add_files("tests/vector/vector.0.1.cpp") - -target("4.vector-0-all") - set_kind("binary") - add_files("tests/vector/vector.0.cpp") - -target("4.vector-1-0") - set_kind("binary") - add_files("tests/vector/vector.1.0.cpp") - -target("4.vector-1-1") - set_kind("binary") - add_files("tests/vector/vector.1.1.cpp") - -target("4.vector-1-2") - set_kind("binary") - add_files("tests/vector/vector.1.2.cpp") - -target("4.vector-1-all") - set_kind("binary") - add_files("tests/vector/vector.1.cpp") - -target("4.vector-2") - set_kind("binary") - add_files("tests/vector/vector.2.cpp") - -target("4.vector-3-0") - set_kind("binary") - add_files("tests/vector/vector.3.0.cpp") - -target("4.vector-3-all") - set_kind("binary") - add_files("tests/vector/vector.3.cpp") - -target("4.vector-4") - set_kind("binary") - add_files("tests/vector/vector.4.cpp") - -target("4.vector-5") - set_kind("binary") - add_files("tests/vector/vector.5.cpp") - -target("5.embedded-slist-0") - set_kind("binary") - add_files("tests/embedded-list/embedded-slist.0.cpp") - -target("5.embedded-slist-1") - set_kind("binary") - add_files("tests/embedded-list/embedded-slist.1.cpp") - -target("5.embedded-slist-2") - set_kind("binary") - add_files("tests/embedded-list/embedded-slist.2.cpp") - -target("5.embedded-slist-3") - set_kind("binary") - add_files("tests/embedded-list/embedded-slist.3.cpp") - -target("5.embedded-slist-4") - set_kind("binary") - add_files("tests/embedded-list/embedded-slist.4.cpp") - -add_moduledirs("tools") +add_moduledirs("common") task("d2ds") on_run("d2ds") @@ -156,230 +24,7 @@ task("d2ds") -- dslings: auto checker and update status for exercises task("dslings") - on_run(function() - import("core.project.project") - import("core.project.target") - import("core.base.global") - import("core.base.option") - - local checker_pass = false - local start_target = option.get("start_target") - - -- TODO: optimze - local target_to_code_file = { - ["0.dslings-0"] = "exercises/dslings.hpp", - ["0.dslings-1"] = "exercises/dslings.hpp", - ["0.dslings-2"] = "exercises/dslings.hpp", - ["1.template-0"] = "exercises/other/cpp-base/Template.hpp", - ["1.template-1"] = "exercises/other/cpp-base/Template.hpp", - ["1.template-2"] = "exercises/other/cpp-base/Template.hpp", - ["2.range_for-0"] = "exercises/other/cpp-base/RangeFor.hpp", - ["2.range_for-1"] = "exercises/other/cpp-base/RangeFor.hpp", - ["2.range_for-2"] = "exercises/other/cpp-base/RangeFor.hpp", - ["2.range_for-3"] = "exercises/other/cpp-base/RangeFor.hpp", - ["3.array-0"] = "exercises/array/Array.hpp", - ["3.array-1"] = "exercises/array/Array.hpp", - ["3.array-2"] = "exercises/array/Array.hpp", - ["3.array-3"] = "exercises/array/Array.hpp", - ["3.array-4"] = "exercises/array/Array.hpp", - ["3.array-5"] = "exercises/array/Array.hpp", - ["3.array-6"] = "exercises/array/Array.hpp", - ["4.vector-0-0"] = "exercises/array/Vector.hpp", - ["4.vector-0-1"] = "exercises/array/Vector.hpp", - ["4.vector-0-all"] = "exercises/array/Vector.hpp", - ["4.vector-1-0"] = "exercises/array/Vector.hpp", - ["4.vector-1-1"] = "exercises/array/Vector.hpp", - ["4.vector-1-2"] = "exercises/array/Vector.hpp", - ["4.vector-1-all"] = "exercises/array/Vector.hpp", - ["4.vector-2"] = "exercises/array/Vector.hpp", - ["4.vector-3-0"] = "exercises/array/Vector.hpp", - ["4.vector-3-all"] = "exercises/array/Vector.hpp", - ["4.vector-4"] = "exercises/array/Vector.hpp", - ["4.vector-5"] = "exercises/array/Vector.hpp", - ["5.embedded-slist-0"] = "exercises/linked-list/EmbeddedList.hpp", - ["5.embedded-slist-1"] = "exercises/linked-list/EmbeddedList.hpp", - ["5.embedded-slist-2"] = "exercises/linked-list/EmbeddedList.hpp", - ["5.embedded-slist-3"] = "exercises/linked-list/EmbeddedList.hpp", - ["5.embedded-slist-4"] = "exercises/linked-list/EmbeddedList.hpp", - } - - local function get_len(pairs_type) - length = 0 - for _, _ in pairs_type do - length = length + 1 - end - return length - end - - local function clear_screen() - if os.host() == "windows" then - os.exec("tools\\clear_screen.bat") - else - os.exec("clear") - end - end - - local function print_info(target_name, built_targets, total_targets, current_file_path, output, status) - - clear_screen() - - -- print progress_bar - local progress_bar_length = total_targets - local arrow_count = built_targets - local dash_count = progress_bar_length - arrow_count - local progress_bar = string.format( - "🌏Progress: [%s>%s] %d/%d", - string.rep("=", arrow_count), - string.rep("-", dash_count), - arrow_count, progress_bar_length - ) - print(progress_bar) - - print(string.format("\n[Target: %s]\n", target_name)) - - -- print status - if status then - print(string.format("βœ… Successfully ran %s!", current_file_path)) - print("\nπŸŽ‰ The code is compiling! πŸŽ‰\n") - else - print(string.format("❌ Error: Compilation/Running failed for %s:", current_file_path)) - print("\n The code exist some error!\n") - end - - -- print output - print("Output:") - print("====================") - print(output) - print("====================") - - print("\nHomepage: https://github.com/Sunrisepeak/d2ds-courses") - end - - -- main start - - clear_screen() - - local base_dir = os.projectdir() - - -- θŽ·ε– project δΈ­ζ‰€ζœ‰ target - local targets = project.targets() - --local targets = {"d2ds_array", "d2ds_array1"} - --local total_targets = #targets -- - -- TODO: optimize total_targets - local total_targets = 0 - local built_targets = 0 - local sorted_targets = {} - for name, _ in pairs(targets) do - total_targets = total_targets + 1 - table.insert(sorted_targets, name) - end - - table.sort(sorted_targets) - - local skip = true - for _, name in pairs(sorted_targets) do - - if skip and (name == start_target or string.find(name, start_target)) then - skip = false; - end - - if not skip then - local files = targets[name]:sourcefiles() - for _, file in ipairs((files)) do - local relative_path = path.relative(file, base_dir) - local build_success = false - local sleep_sec = 1000 * 0.1 - local output = "" - - local file_modify_time - local compile_bypass_counter = 0 - - while not build_success do - local curr_file_mtime = os.mtime(file) - if target_to_code_file[name] then - curr_file_mtime = curr_file_mtime + os.mtime(target_to_code_file[name]) - end - - if file_modify_time ~= curr_file_mtime then - --build_success = task.run("build", {target = name}) - build_success = true - try - { - function() - os.iorunv("xmake", {"build", name}) - --os.iorunv("xmake", {"build", "-v", name}) - end, - catch - { - -- After an exception occurs, it is executed - function (e) - output = e - build_success = false - end - } - } - - if build_success then - try { - function () - output, _ = os.iorunv("xmake", {"r", name}) - end, - catch - { - function (e) - output = e - build_success = false - end - } - } - end - - local status = build_success - - if type(output) == "string" then - if string.find(output, "❌") then - status = false - build_success = false - elseif string.find(output, "D2DS_WAIT") or string.find(output, "D2DS_RETURN") then - build_success = false - end - end - - if build_success then - built_targets = built_targets + 1 - else - sleep_sec = 1000 * 1 - end - - print_info(name, built_targets, total_targets, relative_path, output, status) - output = "" - else - compile_bypass_counter = compile_bypass_counter + 1 - end - - file_modify_time = curr_file_mtime - if compile_bypass_counter > 20 then - compile_bypass_counter = 0 - file_modify_time = nil - end - os.sleep(sleep_sec) - - end - end - else - built_targets = built_targets + 1 - end - end - - local bingo = "\ - Bingo! πŸŽ‰πŸŽ‰πŸŽ‰\n \ - You have completed all exercises\n \ -Next: https://github.com/Sunrisepeak/dstruct\ -" - - print_info("D2DS", total_targets, total_targets, "...", bingo, true) - - end) + on_run("dslings") set_menu{ usage = "xmake dslings [options] [arguments]", description = "exercises-code compile-time & runtime checker",