-
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added sub command init for generating new project #178
Changes from all commits
000b9fa
48bae2b
a6b32af
854adc2
461f1ae
92fbbb8
d781c02
b2d9009
b2f76e6
01af0f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
|
||
#include "assembly.h" | ||
#include "builder.h" | ||
#include "common.h" | ||
#include "conf.h" | ||
#include "stb_ds.h" | ||
#include <locale.h> | ||
|
@@ -44,7 +45,7 @@ static char *get_exec_dir(void) { | |
return strdup(tmp); | ||
} | ||
|
||
static void get_config_file_location(str_buf_t* filepath) { | ||
static void get_config_file_location(str_buf_t *filepath) { | ||
str_buf_append_fmt(filepath, "{s}/../{s}", builder_get_exec_dir(), BL_CONFIG_FILE); | ||
} | ||
|
||
|
@@ -245,6 +246,7 @@ void print_help(FILE *stream, struct getarg_opt *opts) { | |
" blc [options] [source-files]\n\n" | ||
"Alternative usage:\n" | ||
" blc [options] <-build> [build-arguments]\n" | ||
" blc [options] <-init> <project-name>\n" | ||
" blc [options] <-run> <source-file> [arguments] [forwarded-arguments]\n\n" | ||
"Options:\n"; | ||
fprintf(stream, "%s", text); | ||
|
@@ -354,14 +356,22 @@ int main(s32 argc, char *argv[]) { | |
#define ID_VMDBG_BREAK_ON 5 | ||
#define ID_RELEASE 6 | ||
#define ID_SILENT_RUN 7 | ||
#define ID_INIT_PROJECT 8 | ||
|
||
struct getarg_opt optlist[] = { | ||
{ | ||
.name = "-init", | ||
.help = "Creates a project setup in your current folder. " | ||
"Use as '-init [project-name]", | ||
.id = ID_INIT_PROJECT, | ||
}, | ||
{ | ||
.name = "-build", | ||
.help = "Invoke project build pipeline. All following arguments are forwarded into the " | ||
"build script and ignored by compiler itself. Use as '-build [arguments]'.", | ||
.id = ID_BUILD, | ||
}, | ||
|
||
{ | ||
.name = "-run", | ||
.help = | ||
|
@@ -673,6 +683,54 @@ int main(s32 argc, char *argv[]) { | |
case ID_RELEASE: | ||
opt.target->opt = ASSEMBLY_OPT_RELEASE_FAST; | ||
break; | ||
case ID_INIT_PROJECT: | ||
if (file_exists(BUILD_SCRIPT_FILE) || file_exists("./src/main.bl")) { | ||
builder_error("Project seems to be already initialized in this directory."); | ||
EXIT(EXIT_FAILURE); | ||
} | ||
char *project_name = "out"; | ||
if (argv[index + 1]) project_name = argv[index + 1]; | ||
|
||
FILE *build_file = fopen(BUILD_SCRIPT_FILE, "w+"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if (!build_file) { | ||
builder_error("Could not create build file!"); | ||
EXIT(EXIT_FAILURE); | ||
} | ||
const char *build_function_code_template = "build :: fn () #build_entry {\n" | ||
" exe := add_executable(\"%s\");\n" | ||
" set_output_dir(exe,\"bin\");\n" | ||
" add_unit(exe, \"src/main.bl\");\n" | ||
" compile(exe);\n" | ||
"}\n"; | ||
|
||
fprintf(build_file, build_function_code_template, project_name); | ||
|
||
if (!create_dir("bin")) { | ||
builder_error("Could not create bin directory!"); | ||
EXIT(EXIT_FAILURE); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add an error report instead of a silent failure. Same for this |
||
} | ||
if (!create_dir("src")) { | ||
builder_error("Could not create src directory!"); | ||
EXIT(EXIT_FAILURE); | ||
} | ||
|
||
FILE *main_file = fopen("./src/main.bl", "w+"); | ||
if (!main_file) { | ||
builder_error("Could not create main file!"); | ||
EXIT(EXIT_FAILURE); | ||
} | ||
const char *main_example = "\n\nmain :: fn() s32 {\n" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the previous one, please do not add empty lines before/after code to generated files. |
||
" print(\"Hello World!\\n\");\n" | ||
" return 0;\n" | ||
"}\n"; | ||
fprintf(main_file, "%s", main_example); | ||
|
||
builder_info("Project was initialized successfully"); | ||
builder_info("Try blc -build"); | ||
|
||
fclose(main_file); | ||
fclose(build_file); | ||
EXIT(EXIT_SUCCESS); | ||
default: | ||
if (positional) { | ||
target_add_file(opt.target, positional); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be
<-init> [project-name]