aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp45
1 files changed, 33 insertions, 12 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 47da4bb..3d11fd5 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -129,19 +129,19 @@ static void usage()
static void usageBuild()
{
- printf("Usage: sibs build [project_path] [--debug|--release] [--sanitize] [--platform <platform>]\n\n");
+ printf("Usage: sibs build [project_path] [--debug|--release] [--sanitize=(address|undefined|leak|none)] [--platform <platform>]\n\n");
printf("Build a sibs project\n\n");
printf("Options:\n");
printf(" project_path\t\tThe directory containing a project.conf file - Optional (default: current directory)\n");
printf(" --debug|--release\t\tOptimization level to build project and dependencies with (if not a system package) - Optional (default: --debug)\n");
- printf(" --sanitize\t\tAdd runtime address/undefined behavior sanitization. Program can be up to 3 times slower and use 10 times as much RAM. Ignored if compiler doesn't support sanitization - Optional (default: disabled)\n");
+ printf(" --sanitize\t\tAdd runtime address/undefined behavior sanitization. Program can be up to 3 times slower and use 10 times as much RAM. Ignored if compiler doesn't support sanitization - Optional (default: none)\n");
printf(" --platform\t\tThe platform to build for - Optional (default: the running platform)\n");
printf("Examples:\n");
printf(" sibs build\n");
printf(" sibs build dirA/dirB\n");
printf(" sibs build --release\n");
printf(" sibs build dirA --release\n");
- printf(" sibs build --sanitize\n");
+ printf(" sibs build --sanitize=address\n");
printf(" sibs build --release --platform win64\n");
exit(1);
}
@@ -163,17 +163,17 @@ static void usageNew()
static void usageTest()
{
- printf("Usage: sibs test [project_path] [--no-sanitize] [--file <filepath>...|--all-files]\n\n");
+ printf("Usage: sibs test [project_path] [--sanitize=(address|undefined|leak|none)] [--file <filepath>...|--all-files]\n\n");
printf("Build and run tests for a sibs project\n\n");
printf("Options:\n");
printf(" project_path\t\tThe directory containing a project.conf file - Optional (default: current directory)\n");
- printf(" --no-sanitize\t\tDisable runtime address/undefined behavior - Optional (default: enabled), Only applicable for C and C++\n");
+ printf(" --sanitize\t\tAdd runtime address/undefined behavior sanitization. Program can be up to 3 times slower and use 10 times as much RAM. Ignored if compiler doesn't support sanitization - Optional (default: address)\n");
printf(" --file\t\t\tSpecify file to test, path to test file should be defined after this. Can be defined multiple times to test multiple files - Optional (default: not used), Only applicable for Zig\n");
printf(" --all-files\t\t\tTest all files - Optional (default: not used), Only applicable for Zig\n");
printf("Examples:\n");
printf(" sibs test\n");
printf(" sibs test dirA/dirB\n");
- printf(" sibs test --no-sanitize\n");
+ printf(" sibs test --sanitize=none\n");
printf(" sibs test --all-files\n");
printf(" sibs test --file src/foo.zig --file src/bar.zig\n");
exit(1);
@@ -450,11 +450,24 @@ static int buildProject(const FileString &projectPath, const FileString &project
return 0;
}
+static Sanitize sanitize_string_to_type(const _tinydir_char_t *str) {
+ if(strcmp(str, TINYDIR_STRING("address")) == 0)
+ return Sanitize::ADDRESS;
+ else if(strcmp(str, TINYDIR_STRING("undefined")) == 0)
+ return Sanitize::UNDEFINED;
+ else if(strcmp(str, TINYDIR_STRING("leak")) == 0)
+ return Sanitize::LEAK;
+ else if(strcmp(str, TINYDIR_STRING("none")) == 0)
+ return Sanitize::NONE;
+ else
+ return SANITIZE_INVALID;
+}
+
static int buildProject(int argc, const _tinydir_char_t **argv)
{
OptimizationLevel optimizationLevel = OPT_LEV_NONE;
FileString projectPath;
- bool sanitize = false;
+ Sanitize sanitize = Sanitize::NONE;
FileString platformName;
for(int i = 0; i < argc; ++i)
@@ -478,9 +491,13 @@ static int buildProject(int argc, const _tinydir_char_t **argv)
}
optimizationLevel = OPT_LEV_RELEASE;
}
- else if(_tinydir_strcmp(arg, TINYDIR_STRING("--sanitize")) == 0)
+ else if(_tinydir_strncmp(arg, TINYDIR_STRING("--sanitize="), 10) == 0)
{
- sanitize = true;
+ sanitize = sanitize_string_to_type(arg + 11);
+ if(sanitize == SANITIZE_INVALID) {
+ ferr << "Error: Invalid sanitize option " << (arg + 11) << ", expected address, undefined, leak or none" << endl;
+ usageBuild();
+ }
}
else if(_tinydir_strcmp(arg, TINYDIR_STRING("--platform")) == 0)
{
@@ -587,14 +604,18 @@ static int testProject(int argc, const _tinydir_char_t **argv)
FileString projectPath;
vector<FileString> filesToTest;
bool testAllFiles = false;
- bool sanitize = true;
+ Sanitize sanitize = Sanitize::ADDRESS;
for(int i = 0; i < argc; ++i)
{
const _tinydir_char_t *arg = argv[i];
- if(_tinydir_strcmp(arg, TINYDIR_STRING("--no-sanitize")) == 0)
+ if(_tinydir_strncmp(arg, TINYDIR_STRING("--sanitize="), 10) == 0)
{
- sanitize = false;
+ sanitize = sanitize_string_to_type(arg + 11);
+ if(sanitize == SANITIZE_INVALID) {
+ ferr << "Error: Invalid sanitize option " << (arg + 11) << ", expected address, undefined, leak or none" << endl;
+ usageTest();
+ }
}
else if(_tinydir_strcmp(arg, TINYDIR_STRING("--file")) == 0)
{