From 98ad7dd049a366e21d60a34548736a3c8ef72877 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 30 Dec 2017 04:32:49 +0100 Subject: Add support for windows (ugly fast solution) --- src/GlobalLib.cpp | 157 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 102 insertions(+), 55 deletions(-) (limited to 'src/GlobalLib.cpp') diff --git a/src/GlobalLib.cpp b/src/GlobalLib.cpp index d994a27..db85abd 100644 --- a/src/GlobalLib.cpp +++ b/src/GlobalLib.cpp @@ -9,23 +9,27 @@ using namespace std; namespace sibs { - Result GlobalLib::validatePackageExists(const string &globalLibRootDir, const string &name) + Result GlobalLib::validatePackageExists(const FileString &globalLibRootDir, const std::string &name) { - string packageDir = globalLibRootDir + "/"; + FileString packageDir = globalLibRootDir + TINYDIR_STRING("/"); +#if OS_FAMILY == OS_FAMILY_POSIX packageDir += name; +#else + packageDir += utf8To16(name); +#endif FileType packageDirFileType = getFileType(packageDir.c_str()); switch(packageDirFileType) { case FileType::FILE_NOT_FOUND: { string errMsg = "Global lib dependency not found: "; - errMsg += name; + errMsg += toUtf8(packageDir); return Result::Err(errMsg, DependencyError::DEPENDENCY_NOT_FOUND); } case FileType::REGULAR: { string errMsg = "Corrupt library directory. "; - errMsg += packageDir; + errMsg += toUtf8(packageDir); errMsg += " is a file, expected it to be a directory"; return Result::Err(errMsg); } @@ -40,13 +44,13 @@ namespace sibs } } - const char *sourceFileExtensions[] = { "c", "cc", "cpp", "cxx" }; + const _tinydir_char_t *sourceFileExtensions[] = { TINYDIR_STRING("c"),TINYDIR_STRING("cc"), TINYDIR_STRING("cpp"), TINYDIR_STRING("cxx") }; bool isSourceFile(tinydir_file *file) { if(!file->is_reg) return false; - for(const char *sourceFileExtension : sourceFileExtensions) + for(const _tinydir_char_t *sourceFileExtension : sourceFileExtensions) { if(_tinydir_strcmp(sourceFileExtension, file->extension) == 0) return true; @@ -55,29 +59,37 @@ namespace sibs return false; } - bool isPathSubPathOf(const char *path, const string &subPathOf) + bool isPathSubPathOf(const _tinydir_char_t *path, const FileString &subPathOf) { return _tinydir_strncmp(path, subPathOf.c_str(), subPathOf.size()) == 0; } - Result GlobalLib::getLibsLinkerFlags(const SibsConfig &parentConfig, const string &globalLibRootDir, const string &name, const string &version, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallbackFunc) + Result GlobalLib::getLibsLinkerFlags(const SibsConfig &parentConfig, const FileString &globalLibRootDir, const std::string &name, const std::string &version, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallbackFunc) { Result packageExistsResult = validatePackageExists(globalLibRootDir, name); if(packageExistsResult.isErr()) return Result::Err(packageExistsResult); - string packageDir = globalLibRootDir + "/"; - packageDir += name; +#if OS_FAMILY == OS_FAMILY_POSIX + FileString namePlatformNative = name; + FileString versionPlatformNative = version; +#else + FileString namePlatformNative = utf8To16(name); + FileString versionPlatformNative = utf8To16(version); +#endif + + FileString packageDir = globalLibRootDir + TINYDIR_STRING("/"); + packageDir += namePlatformNative; // TODO: Instead of checking if version is exact match, check if package has same major version // and same or newer minor version - string foundVersion; - walkDir(packageDir.c_str(), [&foundVersion, &version](tinydir_file *file) + FileString foundVersion; + walkDir(packageDir.c_str(), [&foundVersion, &versionPlatformNative](tinydir_file *file) { if(file->is_dir) { //printf("version: %s\n", file->name); - if(_tinydir_strcmp(version.c_str(), file->name) == 0) + if(_tinydir_strcmp(versionPlatformNative.c_str(), file->name) == 0) foundVersion = file->name; } }); @@ -85,11 +97,11 @@ namespace sibs if(foundVersion.empty()) return Result::Err("Global lib dependency found, but version doesn't match dependency version", DependencyError::DEPENDENCY_VERSION_NO_MATCH); - packageDir += "/"; - packageDir += version; + packageDir += TINYDIR_STRING("/"); + packageDir += versionPlatformNative; - string projectConfFilePath = packageDir; - projectConfFilePath += "/project.conf"; + FileString projectConfFilePath = packageDir; + projectConfFilePath += TINYDIR_STRING("/project.conf"); FileType projectConfFileType = getFileType(projectConfFilePath.c_str()); switch(projectConfFileType) @@ -97,20 +109,20 @@ namespace sibs case FileType::FILE_NOT_FOUND: { string errMsg = "Global lib dependency found: "; - errMsg += packageDir; + errMsg += toUtf8(packageDir); errMsg += ", but it's missing a project.conf file"; return Result::Err(errMsg); } case FileType::DIRECTORY: { string errMsg = "Global lib dependency found: "; - errMsg += packageDir; + errMsg += toUtf8(packageDir); errMsg += ", but it's corrupt (Found directory instead of file)"; return Result::Err(errMsg); } } - SibsConfig sibsConfig(packageDir, parentConfig.getOptimizationLevel()); + SibsConfig sibsConfig(parentConfig.getCompiler(), packageDir, parentConfig.getOptimizationLevel()); Result result = Config::readFromFile(projectConfFilePath.c_str(), sibsConfig); if(result.isErr()) return Result::Err(result.getErrMsg()); @@ -148,7 +160,8 @@ namespace sibs { if (isSourceFile(file)) { - ninja.addSourceFile(file->path + sibsConfig.getProjectPath().size() + 1); + string fileNameNative = toUtf8(file->path + sibsConfig.getProjectPath().size() + 1); + ninja.addSourceFile(fileNameNative.c_str()); } else { @@ -160,8 +173,11 @@ namespace sibs // TODO: If compiling without "test" option, do not add test source dir to ninja. Ninja logic will then not build tests... // OR I believe there is no reason to run tests in dependencies. The main projects tests should cover that? // But you might want to know exactly which dependency is causing issue and which part of it... - if(!sibsConfig.getTestPath().empty() && isPathSubPathOf(file->path, sibsConfig.getTestPath())) - ninja.addTestSourceDir(file->path); + if (!sibsConfig.getTestPath().empty() && isPathSubPathOf(file->path, sibsConfig.getTestPath())) + { + string filePathUtf8 = toUtf8(file->path); + ninja.addTestSourceDir(filePathUtf8.c_str()); + } else walkDir(file->path, collectSourceFiles); } @@ -175,36 +191,64 @@ namespace sibs } else { - string buildPath = packageDir + "/sibs-build/"; + FileString buildPath = packageDir + TINYDIR_STRING("/sibs-build/"); switch(sibsConfig.getOptimizationLevel()) { case OPT_LEV_DEBUG: - buildPath += "debug"; + buildPath += TINYDIR_STRING("debug"); break; case OPT_LEV_RELEASE: - buildPath += "release"; + buildPath += TINYDIR_STRING("release"); break; } - - string libPath = buildPath; - libPath += "/lib"; - libPath += name; - if(libraryType == backend::Ninja::LibraryType::STATIC) - { - libPath += ".a"; - string libPathCmd = "'"; - libPathCmd += libPath; - libPathCmd += "'"; - staticLinkerFlagCallbackFunc(libPathCmd); - libPath += ".a"; - } - else + + string libPath = toUtf8(buildPath); + switch (sibsConfig.getCompiler()) { - libPath += ".so"; - string libPathCmd = "'"; - libPathCmd += libPath; - libPathCmd += "'"; - dynamicLinkerFlagCallbackFunc(libPathCmd); + case Compiler::GCC: + { + libPath += "/lib"; + libPath += name; + if (libraryType == backend::Ninja::LibraryType::STATIC) + { + libPath += ".a"; + string libPathCmd = "'"; + libPathCmd += libPath; + libPathCmd += "'"; + staticLinkerFlagCallbackFunc(libPathCmd); + } + else + { + libPath += ".so"; + string libPathCmd = "'"; + libPathCmd += libPath; + libPathCmd += "'"; + dynamicLinkerFlagCallbackFunc(libPathCmd); + } + break; + } + case Compiler::MSVC: + { + libPath += "/"; + libPath += name; + if (libraryType == backend::Ninja::LibraryType::STATIC) + { + libPath += ".lib"; + string libPathCmd = "\""; + libPathCmd += libPath; + libPathCmd += "\""; + staticLinkerFlagCallbackFunc(libPathCmd); + } + else + { + libPath += ".lib"; + string libPathCmd = "\""; + libPathCmd += libPath; + libPathCmd += "\""; + dynamicLinkerFlagCallbackFunc(libPathCmd); + } + break; + } } // TODO: Use different directories depending on the project type, but .o build files should be in the same directory @@ -229,21 +273,24 @@ namespace sibs url += dependency.version; url += ".tar.gz"; - string libPath = getHomeDir(); - libPath += "/.sibs/lib/"; - libPath += dependency.name; - libPath += "/"; - libPath += dependency.version; + Result libPathResult = getHomeDir(); + if (!libPathResult) + return Result::Err(libPathResult); + FileString libPath = libPathResult.unwrap(); + libPath += TINYDIR_STRING("/.sibs/lib/"); + libPath += toFileString(dependency.name); + libPath += TINYDIR_STRING("/"); + libPath += toFileString(dependency.version); - string libArchivedFilePath = getHomeDir(); - libArchivedFilePath += "/.sibs/archive/"; - libArchivedFilePath += dependency.name; + FileString libArchivedFilePath = libPathResult.unwrap(); + libArchivedFilePath += TINYDIR_STRING("/.sibs/archive/"); + libArchivedFilePath += toFileString(dependency.name); Result createArchiveDirResult = createDirectoryRecursive(libArchivedFilePath.c_str()); if(createArchiveDirResult.isErr()) return createArchiveDirResult; - libArchivedFilePath += "/"; - libArchivedFilePath += dependency.version; + libArchivedFilePath += TINYDIR_STRING("/"); + libArchivedFilePath += toFileString(dependency.version); Result downloadResult = curl::downloadFile(url.c_str(), libArchivedFilePath.c_str()); if(downloadResult.isErr()) return downloadResult; -- cgit v1.2.3