Update c.lua

This commit is contained in:
DarthMooMancer
2025-03-10 13:08:36 -04:00
parent 1c2794fdff
commit b3f1985e6a
+34 -27
View File
@@ -227,37 +227,44 @@ end
function M.build() function M.build()
local current_dir = vim.fn.expand("%:p:h") local current_dir = vim.fn.expand("%:p:h")
-- local compile_command = "mv " .. legacy_src_dir .. "/* " .. src_dir .. -- Try to detect the project root by looking for a known file or directory (e.g., CMakeLists.txt)
-- " && mv " .. legacy_out_dir .. "/* " .. build_dir .. local project_root = vim.fn.findfile("CMakeLists.txt", current_dir .. ";")
-- " && rm -rd " .. project_root .. "/" .. "root/"
vim.ui.input({ prompt = "Enter project name: " }, function(project_name) if project_root == "" then
if not project_name or project_name == "" then print("Could not find CMakeLists.txt. Are you in a project directory?")
print("Project creation canceled.") return
return end
end
local project_root = vim.fn.expand(M.config.project_root) .. "/" .. project_name
local into_build = "cd " .. project_root .. "/build"
local into_build_status = vim.fn.system(into_build)
if vim.v.shell_error ~= 0 then
print("Could not go into build dir:\n" .. into_build_status)
end
-- local project_root_build = current_dir:match("(.*)/build") -- Get the directory where CMakeLists.txt is located (this is the project root)
-- if not project_root_build then project_root = vim.fn.fnamemodify(project_root, ":h")
-- print("Error: Must be inside the 'build' directory.")
-- return
-- end
local compile_command = "cmake .. && make" -- Define the build directory path
local compile_status = vim.fn.system(compile_command) local build_dir = project_root .. "/build"
if vim.v.shell_error ~= 0 then -- Check if the build directory exists, create it if it doesn't
print("Error during compilation:\n" .. compile_status) if vim.fn.isdirectory(build_dir) == 0 then
else print("Build directory does not exist. Creating: " .. build_dir)
print("Compilation successful!") vim.fn.mkdir(build_dir, "p")
end end
end)
-- Change to the build directory
local into_build = "cd " .. build_dir
local into_build_status = vim.fn.system(into_build)
if vim.v.shell_error ~= 0 then
print("Could not go into build dir:\n" .. into_build_status)
return
end
-- Run CMake and Make to build the project
local compile_command = "cmake .. && make"
local compile_status = vim.fn.system(compile_command)
if vim.v.shell_error ~= 0 then
print("Error during compilation:\n" .. compile_status)
else
print("Compilation successful!")
end
end end