summaryrefslogtreecommitdiff
path: root/build.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-03-03 15:09:49 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-03-03 15:09:49 -0500
commita1646d84127a199fdacb6c5500d96e8829ebe8c1 (patch)
treeeb7d59e50813108105a5bc4539191a3b008a320d /build.c
parentd5488ef5c47878e04045a91d204cf1ccbdd9cd05 (diff)
:shell, bugfixes
Diffstat (limited to 'build.c')
-rw-r--r--build.c55
1 files changed, 27 insertions, 28 deletions
diff --git a/build.c b/build.c
index 7554c50..4a65857 100644
--- a/build.c
+++ b/build.c
@@ -11,25 +11,41 @@ static void build_stop(Ted *ted) {
process_kill(&ted->build_process);
ted->building = false;
ted->build_shown = false;
+ *ted->build_dir = '\0';
build_clear(ted);
}
-
-static void build_start(Ted *ted) {
+// make sure you set ted->build_dir before running this!
+static void build_start_with_command(Ted *ted, char const *command) {
+ assert(*ted->build_dir);
+ change_directory(ted->build_dir);
if (ted->building) {
build_stop(ted);
}
- Settings *settings = &ted->settings;
-
ted_save_all(ted);
- // get rid of any old build errors
- build_clear(ted);
-
+ if (process_run(&ted->build_process, command)) {
+ ted->building = true;
+ ted->build_shown = true;
+ TextBuffer *build_buffer = &ted->build_buffer;
+ // new empty build output buffer
+ buffer_new_file(build_buffer, NULL);
+ build_buffer->store_undo_events = false; // don't need undo events for build output buffer
+ char32_t text[] = {'$', ' '};
+ buffer_insert_text_at_cursor(build_buffer, str32(text, 2));
+ buffer_insert_utf8_at_cursor(build_buffer, command);
+ buffer_insert_char_at_cursor(build_buffer, '\n');
+ build_buffer->view_only = true;
+ } else {
+ ted_seterr(ted, "Couldn't start build: %s", process_geterr(&ted->build_process));
+ }
+}
+
+static void build_start(Ted *ted) {
bool cargo = false, make = false;
- change_directory(ted->cwd);
- strcpy(ted->build_dir, ted->cwd);
+ strbuf_cpy(ted->build_dir, ted->cwd);
+ Settings *settings = &ted->settings;
char *command = settings->build_default_command;
@@ -42,11 +58,9 @@ static void build_start(Ted *ted) {
if (fs_file_exists("Cargo.toml")) {
cargo = true;
} else if (fs_file_exists(".." PATH_SEPARATOR_STR "Cargo.toml")) {
- change_directory("..");
ted_full_path(ted, "..", ted->build_dir, sizeof ted->build_dir);
cargo = true;
} else if (fs_file_exists(".." PATH_SEPARATOR_STR ".." PATH_SEPARATOR_STR "Cargo.toml")) {
- change_directory(".." PATH_SEPARATOR_STR "..");
ted_full_path(ted, "../..", ted->build_dir, sizeof ted->build_dir);
cargo = true;
} else
@@ -54,7 +68,6 @@ static void build_start(Ted *ted) {
if (fs_file_exists("Makefile")) {
make = true;
} else if (fs_file_exists(".." PATH_SEPARATOR_STR "Makefile")) {
- change_directory("..");
ted_full_path(ted, "..", ted->build_dir, sizeof ted->build_dir);
make = true;
}
@@ -66,22 +79,8 @@ static void build_start(Ted *ted) {
} else if (make) {
command = "make";
}
-
- if (process_run(&ted->build_process, command)) {
- ted->building = true;
- ted->build_shown = true;
- TextBuffer *build_buffer = &ted->build_buffer;
- // new empty build output buffer
- buffer_new_file(build_buffer, NULL);
- build_buffer->store_undo_events = false; // don't need undo events for build output buffer
- char32_t text[] = {'$', ' '};
- buffer_insert_text_at_cursor(build_buffer, str32(text, 2));
- buffer_insert_utf8_at_cursor(build_buffer, command);
- buffer_insert_char_at_cursor(build_buffer, '\n');
- build_buffer->view_only = true;
- } else {
- ted_seterr(ted, "Couldn't start build: %s", process_geterr(&ted->build_process));
- }
+
+ build_start_with_command(ted, command);
}
static void build_go_to_error(Ted *ted) {