summaryrefslogtreecommitdiff
path: root/build.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-24 00:28:50 -0500
committerpommicket <pommicket@gmail.com>2022-12-24 00:28:50 -0500
commit1c346f2aba30fcb581f20f2b67bd5e6adcb4a7e6 (patch)
tree863b8ebbd37c67cb4dd0015d5c72a436dd89bc7e /build.c
parent8d96a4b0f0ebb059a63cc4c3193e0169ccf4f5b5 (diff)
find build directory in a much better way
this will be useful for LSPs
Diffstat (limited to 'build.c')
-rw-r--r--build.c39
1 files changed, 8 insertions, 31 deletions
diff --git a/build.c b/build.c
index 3ac0001..07d57eb 100644
--- a/build.c
+++ b/build.c
@@ -78,47 +78,24 @@ static void build_start_with_command(Ted *ted, char const *command) {
}
static void build_start(Ted *ted) {
- bool cargo = false, make = false;
-
- strbuf_cpy(ted->build_dir, ted->cwd);
Settings *settings = ted_active_settings(ted);
-
char *command = settings->build_default_command;
-
- change_directory(ted->cwd);
+ char *root = ted_get_root_dir(ted);
+ strbuf_cpy(ted->build_dir, root);
+ change_directory(root);
+ free(root);
+
#if _WIN32
if (fs_file_exists("make.bat")) {
command = "make.bat";
} else
#endif
- // check if Cargo.toml exists in this or the parent/parent's parent directory
if (fs_file_exists("Cargo.toml")) {
- cargo = true;
- } else if (fs_file_exists(".." PATH_SEPARATOR_STR "Cargo.toml")) {
- ted_path_full(ted, "..", ted->build_dir, sizeof ted->build_dir);
- cargo = true;
- } else if (fs_file_exists(".." PATH_SEPARATOR_STR ".." PATH_SEPARATOR_STR "Cargo.toml")) {
- ted_path_full(ted, "../..", ted->build_dir, sizeof ted->build_dir);
- cargo = true;
- } else
- // Check if Makefile exists in this or the parent/parent's parent directory
- if (fs_file_exists("Makefile")) {
- make = true;
- } else if (fs_file_exists(".." PATH_SEPARATOR_STR "Makefile")) {
- ted_path_full(ted, "..", ted->build_dir, sizeof ted->build_dir);
- make = true;
- } else if (fs_file_exists(".." PATH_SEPARATOR_STR ".." PATH_SEPARATOR_STR "Makefile")) {
- ted_path_full(ted, "../..", ted->build_dir, sizeof ted->build_dir);
- make = true;
- }
-
-
- // @TODO(eventually): `go build`
-
- if (cargo) {
command = "cargo build";
- } else if (make) {
+ } else if (fs_file_exists("Makefile")) {
command = "make -j12";
+ } else if (fs_file_exists("go.mod")) {
+ command = "go build";
}
build_start_with_command(ted, command);