diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-09-23 12:22:37 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-06 07:39:33 +0200 |
commit | 5006226e945fc645e6d9b21252c9eee53cc191cc (patch) | |
tree | 94371016233562351d70fb3b9ff312c6dacd9bb4 /src | |
parent | 8fdc481d78a0426f6dbf235e872c3798ec57251e (diff) |
Fix various things, add generated zig header files to global include
Fix compile_commands.json missing build steps.
Fix c includes -> zig includes flags.
Fix crash when running sibs new/init without defining lang.
Add generated zig header files to global include so they can be used
from c/c++.
Add zig and zig/c (using zig and c in the same project) examples.
Diffstat (limited to 'src')
-rw-r--r-- | src/FileUtil.cpp | 30 | ||||
-rw-r--r-- | src/main.cpp | 9 |
2 files changed, 34 insertions, 5 deletions
diff --git a/src/FileUtil.cpp b/src/FileUtil.cpp index aca2778..53430c4 100644 --- a/src/FileUtil.cpp +++ b/src/FileUtil.cpp @@ -288,6 +288,31 @@ namespace sibs return Result<FileString>::Err(strerror(errno)); } + Result<bool> createDirectory(const _tinydir_char_t *path) + { + size_t pathLength = strlen(path); + if(pathLength > _TINYDIR_PATH_MAX - 1) + { + string errMsg = "Directory path too long: "; + errMsg += string(path, pathLength); + return Result<bool>::Err(errMsg, ENAMETOOLONG); + } + + if(mkdir(path, S_IRWXU) != 0) + { + int error = errno; + if(error != EEXIST) + { + string errMsg = "Failed to create directory: "; + errMsg += toUtf8(path); + errMsg += "; reason: "; + errMsg += strerror(error); + return Result<bool>::Err(errMsg, error); + } + } + return Result<bool>::Ok(true); + } + Result<bool> createDirectoryRecursive(const _tinydir_char_t *path) { char pathBuffer[_TINYDIR_PATH_MAX]; @@ -303,7 +328,8 @@ namespace sibs char *p = pathBuffer; for(size_t i = 0; i < pathLength; ++i) { - if(i > 0 && *p == '/') + char c = *p; + if(i > 0 && (c == '/' || c == '\\')) { *p = '\0'; if(mkdir(pathBuffer, S_IRWXU) != 0) @@ -318,7 +344,7 @@ namespace sibs return Result<bool>::Err(errMsg, error); } } - *p = '/'; + *p = c; } ++p; } diff --git a/src/main.cpp b/src/main.cpp index b232d93..0d29a75 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -701,6 +701,9 @@ int initProject(int argc, const _tinydir_char_t **argv) ferr << "Error: Project type not defined, expected to be either --exec, --static or --dynamic" << endl; usageInit(); } + + if(!lang) + lang = TINYDIR_STRING("c++"); string projectTypeConf; if(_tinydir_strcmp(projectType, TINYDIR_STRING("--exec")) == 0) @@ -714,9 +717,6 @@ int initProject(int argc, const _tinydir_char_t **argv) ferr << "Expected project type to be either --exec, --static or --dynamic; was: " << projectType << endl << endl; usageInit(); } - - if(!lang) - lang = TINYDIR_STRING("c++"); // TODO: If projectPath is not defined and working directory does not contain project.conf, then search every parent directory until one is found if(projectPath.empty()) @@ -920,6 +920,9 @@ int newProject(int argc, const _tinydir_char_t **argv) ferr << "Error: Project type not defined, expected to be either --exec, --static or --dynamic" << endl; usageNew(); } + + if(!lang) + lang = TINYDIR_STRING("c++"); string projectTypeConf; if(_tinydir_strcmp(projectType, TINYDIR_STRING("--exec")) == 0) |