aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-10-02 00:52:30 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-06 07:39:33 +0200
commitc206fd07db07dc6271185dabac822e10d78b4443 (patch)
tree91d3608a7a5abfb39a1e96a3c8926270c40e759f /src/main.cpp
parent3e401d97546fe407ca72e9766cbdbb9c9212091e (diff)
Add sibs package command
Currently in testing phase. Builds a redistributable binary by statically linking libraries (including standard library).
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp71
1 files changed, 70 insertions, 1 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 290ed9e..eae90d0 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -108,6 +108,7 @@ static void usage()
printf(" new\t\tCreate a new project\n");
printf(" init\t\tInitialize project in an existing directory\n");
printf(" test\t\tBuild and run tests for a sibs project\n");
+ printf(" package\t\tCreate a redistributable package from a sibs project. Note: Redistributable packages can't use system packages to build\n");
exit(1);
}
@@ -155,6 +156,9 @@ static void usageTest()
printf("Examples:\n");
printf(" sibs test\n");
printf(" sibs test dirA/dirB\n");
+ printf(" sibs test --no-sanitize\n");
+ printf(" sibs test --all-files\n");
+ printf(" sibs test --file src/foo.zig --file src/bar.zig\n");
exit(1);
}
@@ -163,7 +167,7 @@ static void usageInit()
printf("Usage: sibs init [project_path] <--exec|--static|--dynamic> [--lang c|c++|zig]\n\n");
printf("Create sibs project structure in an existing directory\n\n");
printf("Options:\n");
- printf(" project_path\t\tThe directory where you want to initialize sibs project - Optional (default: current directory)\n");
+ printf(" project_path\t\tThe directory where you want to initialize sibs project - Optional (default: current directory)\n");
printf(" --exec\t\t\tProject compiles to an executable\n");
printf(" --static\t\t\tProject compiles to a static library\n");
printf(" --dynamic\t\t\tProject compiles to a dynamic library\n");
@@ -174,6 +178,18 @@ static void usageInit()
exit(1);
}
+static void usagePackage()
+{
+ printf("Usage: sibs package [project_path]\n\n");
+ printf("Create a redistributable package from a sibs project. Note: Redistributable packages can't use system packages to build\n\n");
+ printf("Options:\n");
+ printf(" project_path\t\tThe directory containiung a project.conf file - Optional (default: current directory)\n");
+ printf("Examples:\n");
+ printf(" sibs package\n");
+ printf(" sibs package dirA/dirB");
+ exit(1);
+}
+
static void validateDirectoryPath(const _tinydir_char_t *projectPath)
{
FileType projectPathFileType = getFileType(projectPath);
@@ -911,6 +927,55 @@ static int initProject(int argc, const _tinydir_char_t **argv)
return 0;
}
+static int packageProject(int argc, const _tinydir_char_t **argv)
+{
+ if(argc > 1)
+ usagePackage();
+
+ FileString projectPath;
+ if(argc == 1)
+ projectPath = argv[0];
+
+ // 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())
+ projectPath = TINYDIR_STRING(".");
+
+ validateDirectoryPath(projectPath.c_str());
+ if(projectPath.back() != '/')
+ projectPath += TINYDIR_STRING("/");
+
+ Result<FileString> projectRealPathResult = getRealPath(projectPath.c_str());
+ if(!projectRealPathResult)
+ {
+ ferr << "Failed to get real path for: '" << projectPath.c_str() << "': " << toFileString(projectRealPathResult.getErrMsg()) << endl;
+ exit(40);
+ }
+ projectPath = projectRealPathResult.unwrap();
+
+ FileString projectConfFilePath = projectPath;
+ projectConfFilePath += TINYDIR_STRING("/project.conf");
+ validateFilePath(projectConfFilePath.c_str());
+
+ // TODO: Detect compiler to use at runtime. Should also be configurable
+ // by passing argument to `sibs package`
+#if OS_FAMILY == OS_FAMILY_POSIX
+ Compiler compiler = Compiler::GCC;
+#else
+ Compiler compiler = Compiler::MSVC;
+#endif
+
+ SibsConfig sibsConfig(compiler, projectPath, OPT_LEV_RELEASE, false);
+ sibsConfig.showWarnings = true;
+ sibsConfig.packaging = true;
+ int result = buildProject(projectPath, projectConfFilePath, sibsConfig);
+ if(result != 0)
+ return result;
+
+ string packagePath = toUtf8(projectPath + TINYDIR_STRING("/sibs-build/package"));
+ printf("Project %s was successfully packaged and can be found at %s\n", sibsConfig.getPackageName().c_str(), packagePath.c_str());
+ return 0;
+}
+
static void newProjectCreateMainDir(const FileString &projectPath)
{
Result<bool> createProjectDirResult = createDirectoryRecursive(projectPath.c_str());
@@ -1138,6 +1203,10 @@ int wmain(int argc, const _tinydir_char_t **argv)
{
return initProject(subCommandArgCount, subCommandArgPtr);
}
+ else if(_tinydir_strcmp(arg, TINYDIR_STRING("package")) == 0)
+ {
+ return packageProject(subCommandArgCount, subCommandArgPtr);
+ }
else
{
ferr << "Expected command to be either 'build', 'new' or 'test', was: " << arg << endl << endl;