Update c.lua

This commit is contained in:
DarthMooMancer
2025-03-10 13:08:36 -04:00
parent 1c2794fdff
commit b3f1985e6a
+24 -17
View File
@@ -227,28 +227,36 @@ end
function M.build()
local current_dir = vim.fn.expand("%:p:h")
-- local compile_command = "mv " .. legacy_src_dir .. "/* " .. src_dir ..
-- " && mv " .. legacy_out_dir .. "/* " .. build_dir ..
-- " && rm -rd " .. project_root .. "/" .. "root/"
-- Try to detect the project root by looking for a known file or directory (e.g., CMakeLists.txt)
local project_root = vim.fn.findfile("CMakeLists.txt", current_dir .. ";")
vim.ui.input({ prompt = "Enter project name: " }, function(project_name)
if not project_name or project_name == "" then
print("Project creation canceled.")
if project_root == "" then
print("Could not find CMakeLists.txt. Are you in a project directory?")
return
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)
-- Get the directory where CMakeLists.txt is located (this is the project root)
project_root = vim.fn.fnamemodify(project_root, ":h")
-- Define the build directory path
local build_dir = project_root .. "/build"
-- Check if the build directory exists, create it if it doesn't
if vim.fn.isdirectory(build_dir) == 0 then
print("Build directory does not exist. Creating: " .. build_dir)
vim.fn.mkdir(build_dir, "p")
end
-- local project_root_build = current_dir:match("(.*)/build")
-- if not project_root_build then
-- print("Error: Must be inside the 'build' directory.")
-- return
-- 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)
@@ -257,7 +265,6 @@ function M.build()
else
print("Compilation successful!")
end
end)
end