From c206fd07db07dc6271185dabac822e10d78b4443 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 2 Oct 2018 00:52:30 +0200 Subject: Add sibs package command Currently in testing phase. Builds a redistributable binary by statically linking libraries (including standard library). --- src/main.cpp | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) (limited to 'src/main.cpp') 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 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 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; -- cgit v1.2.3