diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2021-03-03 15:09:49 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2021-03-03 15:09:49 -0500 |
commit | a1646d84127a199fdacb6c5500d96e8829ebe8c1 (patch) | |
tree | eb7d59e50813108105a5bc4539191a3b008a320d /build.c | |
parent | d5488ef5c47878e04045a91d204cf1ccbdd9cd05 (diff) |
:shell, bugfixes
Diffstat (limited to 'build.c')
-rw-r--r-- | build.c | 55 |
1 files changed, 27 insertions, 28 deletions
@@ -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) { |