diff --git a/include/cppship/cmake/bin.h b/include/cppship/cmake/bin.h index f78ffff..c3dad68 100644 --- a/include/cppship/cmake/bin.h +++ b/include/cppship/cmake/bin.h @@ -30,4 +30,4 @@ class CmakeBin { BinDesc mDesc; }; -} \ No newline at end of file +} diff --git a/include/cppship/cmake/dep.h b/include/cppship/cmake/dep.h index 190a3d7..789f65c 100644 --- a/include/cppship/cmake/dep.h +++ b/include/cppship/cmake/dep.h @@ -1,10 +1,10 @@ #pragma once -#include "cppship/core/dependency.h" - #include #include +#include "cppship/core/dependency.h" + namespace cppship::cmake { struct Dep { @@ -16,4 +16,4 @@ struct Dep { std::vector resolve_deps( const std::vector& declared_deps, const ResolvedDependencies& resolved); -} \ No newline at end of file +} diff --git a/include/cppship/cmake/dependency_injector.h b/include/cppship/cmake/dependency_injector.h index b46b0d4..83d8ea4 100644 --- a/include/cppship/cmake/dependency_injector.h +++ b/include/cppship/cmake/dependency_injector.h @@ -39,4 +39,4 @@ class CmakeDependencyInjector : public DependencyInjector { ResolvedDependencies mAllDeps; }; -} \ No newline at end of file +} diff --git a/include/cppship/cmake/generator.h b/include/cppship/cmake/generator.h index ff04665..a7aae79 100644 --- a/include/cppship/cmake/generator.h +++ b/include/cppship/cmake/generator.h @@ -71,4 +71,4 @@ class CmakeGenerator { std::set mTestTargets; }; -} \ No newline at end of file +} diff --git a/include/cppship/cmake/lib.h b/include/cppship/cmake/lib.h index 2e9205d..7d10bdc 100644 --- a/include/cppship/cmake/lib.h +++ b/include/cppship/cmake/lib.h @@ -38,4 +38,4 @@ class CmakeLib { std::vector mDefinitions; }; -} \ No newline at end of file +} diff --git a/include/cppship/cmake/msvc.h b/include/cppship/cmake/msvc.h index fcf34f8..a3c1c3c 100644 --- a/include/cppship/cmake/msvc.h +++ b/include/cppship/cmake/msvc.h @@ -9,4 +9,4 @@ namespace cppship::msvc { // msvc generator has different binary path, fix it fs::path fix_bin_path(const cppship::cmd::BuildContext& ctx, std::string_view bin); -} \ No newline at end of file +} diff --git a/include/cppship/cmake/package_configurer.h b/include/cppship/cmake/package_configurer.h index 211abb1..b0b0081 100644 --- a/include/cppship/cmake/package_configurer.h +++ b/include/cppship/cmake/package_configurer.h @@ -1,9 +1,9 @@ #pragma once -#include "cppship/core/dependency.h" - #include +#include "cppship/core/dependency.h" + namespace cppship::cmake { struct ConfigOptions { @@ -17,4 +17,4 @@ struct ConfigOptions { void config_packages( const ResolvedDependencies& cppship_deps, const ResolvedDependencies& all_deps, const ConfigOptions& options); -} \ No newline at end of file +} diff --git a/include/cppship/cmd/build.h b/include/cppship/cmd/build.h index 9f47947..3b980a4 100644 --- a/include/cppship/cmd/build.h +++ b/include/cppship/cmd/build.h @@ -72,4 +72,4 @@ void cmake_setup(const BuildContext& ctx); int cmake_build(const BuildContext& ctx, const BuildOptions& options); -} \ No newline at end of file +} diff --git a/include/cppship/cmd/cmake.h b/include/cppship/cmd/cmake.h index fb44b46..85da0ed 100644 --- a/include/cppship/cmd/cmake.h +++ b/include/cppship/cmd/cmake.h @@ -6,4 +6,4 @@ struct CmakeOptions { }; int run_cmake(const CmakeOptions& options); -} \ No newline at end of file +} diff --git a/include/cppship/cmd/init.h b/include/cppship/cmd/init.h index 65410c8..fa557b8 100644 --- a/include/cppship/cmd/init.h +++ b/include/cppship/cmd/init.h @@ -18,4 +18,4 @@ struct InitOptions { int run_init(const InitOptions& options); -} \ No newline at end of file +} diff --git a/include/cppship/cmd/install.h b/include/cppship/cmd/install.h index 0faaf10..ba1ea57 100644 --- a/include/cppship/cmd/install.h +++ b/include/cppship/cmd/install.h @@ -6,8 +6,9 @@ namespace cppship::cmd { struct InstallOptions { Profile profile = Profile::debug; + std::string root; }; int run_install(const InstallOptions& options); -} \ No newline at end of file +} diff --git a/include/cppship/core/dependency.h b/include/cppship/core/dependency.h index f493e2d..60d39d2 100644 --- a/include/cppship/core/dependency.h +++ b/include/cppship/core/dependency.h @@ -4,13 +4,13 @@ #include #include #include -#include #include #include #include #include #include +#include #include "cppship/util/assert.h" #include "cppship/util/fs.h" diff --git a/include/cppship/core/manifest.h b/include/cppship/core/manifest.h index 9c658c7..8d9fa22 100644 --- a/include/cppship/core/manifest.h +++ b/include/cppship/core/manifest.h @@ -63,4 +63,4 @@ class Manifest { void generate_manifest(std::string_view name, CxxStd std, const fs::path& dir); -} \ No newline at end of file +} diff --git a/include/cppship/core/profile.h b/include/cppship/core/profile.h index 9458b4e..768b0f1 100644 --- a/include/cppship/core/profile.h +++ b/include/cppship/core/profile.h @@ -72,4 +72,4 @@ struct ProfileOptions { std::vector conditional_configs; }; -} \ No newline at end of file +} diff --git a/include/cppship/core/resolver.h b/include/cppship/core/resolver.h index 696b03f..92a8804 100644 --- a/include/cppship/core/resolver.h +++ b/include/cppship/core/resolver.h @@ -1,14 +1,15 @@ #pragma once -#include "cppship/core/dependency.h" -#include "cppship/core/manifest.h" - #include -#include #include #include #include +#include + +#include "cppship/core/dependency.h" +#include "cppship/core/manifest.h" + namespace cppship { struct ResolveResult { @@ -45,4 +46,4 @@ class Resolver { std::set mPackageSeen; }; -} \ No newline at end of file +} diff --git a/include/cppship/util/assert.h b/include/cppship/util/assert.h index d4ca947..80f778f 100644 --- a/include/cppship/util/assert.h +++ b/include/cppship/util/assert.h @@ -15,4 +15,4 @@ inline void enforce(bool expr, std::string_view msg) } } -} \ No newline at end of file +} diff --git a/include/cppship/util/fs.h b/include/cppship/util/fs.h index 562d69d..aaaf1ec 100644 --- a/include/cppship/util/fs.h +++ b/include/cppship/util/fs.h @@ -26,13 +26,9 @@ class ScopedCurrentDir { fs::path mPrevCwd; }; -inline void create_if_not_exist(const fs::path& path) -{ - if (fs::exists(path)) { - return; - } +void create_if_not_exist(const fs::path& path); - fs::create_directory(path); -} +inline constexpr std::string_view kCppShipDirName = ".cppship"; +fs::path get_cppship_dir(); -} \ No newline at end of file +} diff --git a/include/cppship/util/io.h b/include/cppship/util/io.h index fb105b1..cda2028 100644 --- a/include/cppship/util/io.h +++ b/include/cppship/util/io.h @@ -12,4 +12,4 @@ std::string read_as_string(const fs::path& file); std::string read_as_string(std::istream& iss); -} \ No newline at end of file +} diff --git a/lib/cmake/generator.cpp b/lib/cmake/generator.cpp index 1f4aed5..ec20409 100644 --- a/lib/cmake/generator.cpp +++ b/lib/cmake/generator.cpp @@ -1,12 +1,4 @@ #include "cppship/cmake/generator.h" -#include "cppship/cmake/bin.h" -#include "cppship/cmake/cfg_predicate.h" -#include "cppship/cmake/dep.h" -#include "cppship/cmake/group.h" -#include "cppship/cmake/lib.h" -#include "cppship/cmake/naming.h" -#include "cppship/core/manifest.h" -#include "cppship/exception.h" #include #include @@ -19,6 +11,15 @@ #include #include +#include "cppship/cmake/bin.h" +#include "cppship/cmake/cfg_predicate.h" +#include "cppship/cmake/dep.h" +#include "cppship/cmake/group.h" +#include "cppship/cmake/lib.h" +#include "cppship/cmake/naming.h" +#include "cppship/core/manifest.h" +#include "cppship/exception.h" + using namespace ranges::views; using namespace cppship; @@ -460,4 +461,4 @@ void CmakeGenerator::fill_profile_(Profile profile) appender.output(profile_str, config, "\t"); mOut << "endif()\n\n"; } -} \ No newline at end of file +} diff --git a/lib/cmake/msvc.cpp b/lib/cmake/msvc.cpp index 41917e2..2f8ef75 100644 --- a/lib/cmake/msvc.cpp +++ b/lib/cmake/msvc.cpp @@ -1,8 +1,9 @@ #include "cppship/cmake/msvc.h" -#include "cppship/util/io.h" #include +#include "cppship/util/io.h" + using namespace cppship; fs::path msvc::fix_bin_path(const cppship::cmd::BuildContext& ctx, std::string_view bin) @@ -13,4 +14,4 @@ fs::path msvc::fix_bin_path(const cppship::cmd::BuildContext& ctx, std::string_v } return bin; -} \ No newline at end of file +} diff --git a/lib/cmake/package_configurer.cpp b/lib/cmake/package_configurer.cpp index 9d40a95..dbe4df4 100644 --- a/lib/cmake/package_configurer.cpp +++ b/lib/cmake/package_configurer.cpp @@ -1,13 +1,14 @@ #include "cppship/cmake/package_configurer.h" + +#include +#include + #include "cppship/cmake/lib.h" #include "cppship/core/layout.h" #include "cppship/core/manifest.h" #include "cppship/util/io.h" #include "cppship/util/repo.h" -#include -#include - using namespace cppship; using namespace fmt::literals; @@ -27,7 +28,9 @@ void cmake::config_packages( add_library({target} INTERFACE IMPORTED) target_include_directories({target} INTERFACE {cmake_deps_dir}/{package}/include) )", - "target"_a = cmake_target, "package"_a = dep.package, "cmake_deps_dir"_a = options.cmake_deps_dir)); + "target"_a = cmake_target, + "package"_a = dep.package, + "cmake_deps_dir"_a = options.cmake_deps_dir)); continue; } @@ -56,4 +59,4 @@ target_include_directories({target} INTERFACE {cmake_deps_dir}/{package}/include write(package_cmake_config_file, content); } -} \ No newline at end of file +} diff --git a/lib/cmd/bench.cpp b/lib/cmd/bench.cpp index 3ba0843..092bab8 100644 --- a/lib/cmd/bench.cpp +++ b/lib/cmd/bench.cpp @@ -1,3 +1,5 @@ +#include "cppship/cmd/bench.h" + #include #include @@ -8,7 +10,6 @@ #include "cppship/cmake/msvc.h" #include "cppship/cmake/naming.h" -#include "cppship/cmd/bench.h" #include "cppship/cmd/build.h" #include "cppship/core/manifest.h" #include "cppship/util/fs.h" @@ -64,4 +65,4 @@ int cmd::run_bench(const BenchOptions& options) } return result; -} \ No newline at end of file +} diff --git a/lib/cmd/build.cpp b/lib/cmd/build.cpp index 0c22776..af28f47 100644 --- a/lib/cmd/build.cpp +++ b/lib/cmd/build.cpp @@ -1,16 +1,4 @@ #include "cppship/cmd/build.h" -#include "cppship/cmake/generator.h" -#include "cppship/cmake/group.h" -#include "cppship/cmake/package_configurer.h" -#include "cppship/core/compiler.h" -#include "cppship/core/dependency.h" -#include "cppship/core/resolver.h" -#include "cppship/exception.h" -#include "cppship/util/cmd.h" -#include "cppship/util/fs.h" -#include "cppship/util/git.h" -#include "cppship/util/io.h" -#include "cppship/util/log.h" #include #include @@ -29,6 +17,19 @@ #include #include +#include "cppship/cmake/generator.h" +#include "cppship/cmake/group.h" +#include "cppship/cmake/package_configurer.h" +#include "cppship/core/compiler.h" +#include "cppship/core/dependency.h" +#include "cppship/core/resolver.h" +#include "cppship/exception.h" +#include "cppship/util/cmd.h" +#include "cppship/util/fs.h" +#include "cppship/util/git.h" +#include "cppship/util/io.h" +#include "cppship/util/log.h" + using namespace cppship; using namespace boost::process; using namespace fmt::literals; @@ -181,8 +182,10 @@ void cmd::conan_install(const BuildContext& ctx) return; } - const auto cmd = fmt::format("conan install {} -of {}/conan -pr {} --build=missing", ctx.build_dir.string(), - ctx.profile_dir.string(), ctx.conan_profile_path.string()); + const auto cmd = fmt::format("conan install {} -of {}/conan -pr {} --build=missing", + ctx.build_dir.string(), + ctx.profile_dir.string(), + ctx.conan_profile_path.string()); status("dependency", "install dependencies: {}", cmd); int res = run_cmd(cmd); @@ -233,7 +236,8 @@ void cmd::cmake_setup(const BuildContext& ctx) const auto result = std::move(resolver).resolve(); ResolvedDependencies deps = toml::get(toml::parse(ctx.dependency_file)); - CmakeGenerator gen(&ctx.layout, ctx.manifest, + CmakeGenerator gen(&ctx.layout, + ctx.manifest, GeneratorOptions { .deps = cmake::resolve_deps(result.dependencies, deps), .dev_deps = cmake::resolve_deps(result.dev_dependencies, deps), @@ -242,7 +246,10 @@ void cmd::cmake_setup(const BuildContext& ctx) const std::string cmd = fmt::format("cmake -B {} -S build -DCMAKE_BUILD_TYPE={} -DCMAKE_EXPORT_COMPILE_COMMANDS=ON " "-DCONAN_GENERATORS_FOLDER={} -DCPPSHIP_DEPS_DIR={}", - ctx.profile_dir.string(), ctx.profile, (ctx.profile_dir / "conan").string(), ctx.deps_dir.string()); + ctx.profile_dir.string(), + ctx.profile, + (ctx.profile_dir / "conan").string(), + ctx.deps_dir.string()); status("config", "config cmake: {}", cmd); const int res = run_cmd(cmd); @@ -291,7 +298,9 @@ std::string_view to_cmake_group(cmd::BuildGroup group, const std::string_view li int cmd::cmake_build(const BuildContext& ctx, const BuildOptions& options) { - auto cmd = fmt::format("cmake --build {} -j {} --config {}", ctx.profile_dir.string(), options.max_concurrency, + auto cmd = fmt::format("cmake --build {} -j {} --config {}", + ctx.profile_dir.string(), + options.max_concurrency, to_string(options.profile)); if (options.target) { cmd += fmt::format(" --target {}", *options.target); @@ -305,4 +314,4 @@ int cmd::cmake_build(const BuildContext& ctx, const BuildOptions& options) status("build", "{}", cmd); return run_cmd(cmd); -} \ No newline at end of file +} diff --git a/lib/cmd/cmake.cpp b/lib/cmd/cmake.cpp index 620673a..7c7cf98 100644 --- a/lib/cmd/cmake.cpp +++ b/lib/cmd/cmake.cpp @@ -1,3 +1,5 @@ +#include "cppship/cmd/cmake.h" + #include #include @@ -6,7 +8,6 @@ #include "cppship/cmake/generator.h" #include "cppship/cmd/build.h" -#include "cppship/cmd/cmake.h" #include "cppship/core/resolver.h" #include "cppship/util/io.h" #include "cppship/util/log.h" @@ -30,7 +31,8 @@ int cmd::run_cmake(const CmakeOptions&) ResolvedDependencies deps = toml::get(toml::parse(ctx.dependency_file)); const auto declared_deps = concat(result.dependencies, result.dev_dependencies) | ranges::to(); - CmakeGenerator gen(&ctx.layout, ctx.manifest, + CmakeGenerator gen(&ctx.layout, + ctx.manifest, GeneratorOptions { .deps = cmake::resolve_deps(result.dependencies, deps), .dev_deps = cmake::resolve_deps(result.dev_dependencies, deps), @@ -45,4 +47,4 @@ int cmd::run_cmake(const CmakeOptions&) fs::copy_file(ctx.conan_file, ctx.root / "conanfile.txt", fs::copy_options::overwrite_existing); return 0; -} \ No newline at end of file +} diff --git a/lib/cmd/fmt.cpp b/lib/cmd/fmt.cpp index 557ce2c..d6e0d5b 100644 --- a/lib/cmd/fmt.cpp +++ b/lib/cmd/fmt.cpp @@ -41,4 +41,4 @@ int cmd::run_fmt(const FmtOptions& options) } return exit_code; -} \ No newline at end of file +} diff --git a/lib/cmd/install.cpp b/lib/cmd/install.cpp index 8e413a5..af002af 100644 --- a/lib/cmd/install.cpp +++ b/lib/cmd/install.cpp @@ -1,10 +1,11 @@ +#include "cppship/cmd/install.h" + #include #include #include #include "cppship/cmd/build.h" -#include "cppship/cmd/install.h" #include "cppship/core/manifest.h" #include "cppship/util/fs.h" #include "cppship/util/log.h" @@ -30,9 +31,11 @@ int cmd::run_install([[maybe_unused]] const InstallOptions& options) return EXIT_SUCCESS; } - const auto dst = fmt::format("/usr/local/bin/{}", manifest.name()); - status("install", "{} to {}", bin_file.string(), dst); + const auto root = fs::path(options.root); + const auto dst = root / "bin" / manifest.name(); + create_if_not_exist(dst.parent_path()); + status("install", "{} to {}", bin_file.string(), dst.string()); fs::copy_file(bin_file, dst, fs::copy_options::overwrite_existing); return EXIT_SUCCESS; #endif -} \ No newline at end of file +} diff --git a/lib/cmd/lint.cpp b/lib/cmd/lint.cpp index e78bbc0..5bd84ed 100644 --- a/lib/cmd/lint.cpp +++ b/lib/cmd/lint.cpp @@ -50,4 +50,4 @@ int cmd::run_lint(const LintOptions& options) pool.wait_for_tasks(); return ranges::any_of(tasks, [](auto& fut) { return fut.get() != 0; }) ? EXIT_FAILURE : EXIT_SUCCESS; -} \ No newline at end of file +} diff --git a/lib/cmd/run.cpp b/lib/cmd/run.cpp index bae6dd6..36e5221 100644 --- a/lib/cmd/run.cpp +++ b/lib/cmd/run.cpp @@ -1,3 +1,5 @@ +#include "cppship/cmd/run.h" + #include #include @@ -7,7 +9,6 @@ #include "cppship/cmake/msvc.h" #include "cppship/cmake/naming.h" #include "cppship/cmd/build.h" -#include "cppship/cmd/run.h" #include "cppship/core/manifest.h" #include "cppship/util/cmd.h" #include "cppship/util/fs.h" @@ -79,4 +80,4 @@ int cmd::run_run(const RunOptions& options) const auto cmd = fmt::format("{} {}", bin_file.string(), options.args); status("run", "{}", cmd); return boost::process::system(cmd); -} \ No newline at end of file +} diff --git a/lib/cmd/test.cpp b/lib/cmd/test.cpp index e5732da..76f195a 100644 --- a/lib/cmd/test.cpp +++ b/lib/cmd/test.cpp @@ -1,3 +1,5 @@ +#include "cppship/cmd/test.h" + #include #include @@ -6,7 +8,6 @@ #include "cppship/cmake/naming.h" #include "cppship/cmd/build.h" -#include "cppship/cmd/test.h" #include "cppship/util/fs.h" #include "cppship/util/log.h" @@ -45,4 +46,4 @@ int cmd::run_test(const TestOptions& options) status("test", "{}", cmd); return boost::process::system(cmd, boost::process::shell); -} \ No newline at end of file +} diff --git a/lib/core/compiler.cpp b/lib/core/compiler.cpp index 29b6730..d85338f 100644 --- a/lib/core/compiler.cpp +++ b/lib/core/compiler.cpp @@ -1,5 +1,4 @@ #include "cppship/core/compiler.h" -#include "cppship/util/cmd.h" #include #include @@ -8,6 +7,8 @@ #include +#include "cppship/util/cmd.h" + using namespace std::literals; using namespace cppship; using namespace cppship::compiler; @@ -113,4 +114,4 @@ CompilerInfo::CompilerInfo() mId = get_compiler_id(out); mLibCxx = get_libcxx(mId); -} \ No newline at end of file +} diff --git a/lib/core/dependency.cpp b/lib/core/dependency.cpp index 20ef669..e42eaa1 100644 --- a/lib/core/dependency.cpp +++ b/lib/core/dependency.cpp @@ -1,9 +1,10 @@ #include "cppship/core/dependency.h" -#include "cppship/exception.h" -#include "cppship/util/string.h" #include +#include "cppship/exception.h" +#include "cppship/util/string.h" + using namespace cppship; namespace { @@ -95,4 +96,4 @@ ResolvedDependencies cppship::collect_conan_deps(const fs::path& conan_dep_dir, } return deps; -} \ No newline at end of file +} diff --git a/lib/core/resolver.cpp b/lib/core/resolver.cpp index 485a1ca..8244b37 100644 --- a/lib/core/resolver.cpp +++ b/lib/core/resolver.cpp @@ -1,13 +1,14 @@ #include "cppship/core/resolver.h" -#include "cppship/core/manifest.h" -#include "cppship/util/io.h" -#include "cppship/util/log.h" -#include "cppship/util/repo.h" #include #include #include +#include "cppship/core/manifest.h" +#include "cppship/util/io.h" +#include "cppship/util/log.h" +#include "cppship/util/repo.h" + using namespace cppship; using namespace fmt::literals; @@ -138,4 +139,4 @@ void Resolver::resolve_package_(std::string_view package, const fs::path& packag mUnresolved.push(sub_dep); } -} \ No newline at end of file +} diff --git a/lib/util/fs.cpp b/lib/util/fs.cpp new file mode 100644 index 0000000..07ff415 --- /dev/null +++ b/lib/util/fs.cpp @@ -0,0 +1,14 @@ +#include "cppship/util/fs.h" + +#include +#include + +void cppship::create_if_not_exist(const fs::path& path) +{ + if (fs::exists(path)) { + return; + } + fs::create_directories(path); +} + +fs::path cppship::get_cppship_dir() { return fs::path(std::getenv("HOME")) / kCppShipDirName; } diff --git a/src/main.cpp b/src/main.cpp index c6d83cd..a84f17d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,6 +12,7 @@ #include "cppship/cppship.h" #include "cppship/exception.h" +#include "cppship/util/fs.h" #include "cppship/util/log.h" #ifndef CPPSHIP_VERSION @@ -161,6 +162,7 @@ std::list build_commands(const ArgumentParser& common) auto& install = commands.emplace_back("install", common, [](const ArgumentParser& cmd) { return cmd::run_install({ .profile = parse_profile(cmd.get("--profile")), + .root = cmd.get("--root"), }); }); @@ -169,6 +171,10 @@ std::list build_commands(const ArgumentParser& common) .help("build with specific profile") .metavar("profile") .default_value(std::string { kProfileRelease }); + install.parser.add_argument("--root") + .help("specify the installation root") + .metavar("root") + .default_value(get_cppship_dir().string()); // run auto& run = commands.emplace_back("run", common, [](const ArgumentParser& cmd) { @@ -322,4 +328,4 @@ try { } catch (const std::exception& e) { error("unknown error {}", e.what()); return EXIT_FAILURE; -} \ No newline at end of file +} diff --git a/tests/cmake/package_configurer.cpp b/tests/cmake/package_configurer.cpp index cac96d7..4045961 100644 --- a/tests/cmake/package_configurer.cpp +++ b/tests/cmake/package_configurer.cpp @@ -1,8 +1,4 @@ #include "cppship/cmake/package_configurer.h" -#include "cppship/core/dependency.h" -#include "cppship/util/fs.h" -#include "cppship/util/io.h" -#include "cppship/util/repo.h" #include @@ -10,6 +6,11 @@ #include #include +#include "cppship/core/dependency.h" +#include "cppship/util/fs.h" +#include "cppship/util/io.h" +#include "cppship/util/repo.h" + using namespace cppship; using namespace std::string_literals; @@ -33,7 +34,8 @@ TEST(package_configurer, HeaderOnly) }, } }; - cmake::config_packages(deps, deps, + cmake::config_packages(deps, + deps, { .deps_dir = deps_dir, .post_process @@ -81,7 +83,8 @@ fmt = "9.1.0" .cmake_target = "fmt::fmt", }); - cmake::config_packages(deps, all_deps, + cmake::config_packages(deps, + all_deps, { .deps_dir = deps_dir, .post_process @@ -142,7 +145,8 @@ fmt = "9.1.0" .cmake_target = "fmt::fmt", }); - cmake::config_packages(deps, all_deps, + cmake::config_packages(deps, + all_deps, { .deps_dir = deps_dir, .post_process @@ -163,4 +167,4 @@ target_link_libraries(test_pack_lib PUBLIC fmt::fmt) add_library(cppship::test_pack ALIAS test_pack_lib) )"); -} \ No newline at end of file +} diff --git a/tests/util/fs.cpp b/tests/util/fs.cpp index 11b4d24..3cc3f87 100644 --- a/tests/util/fs.cpp +++ b/tests/util/fs.cpp @@ -1,7 +1,7 @@ -#include - #include "cppship/util/fs.h" +#include + using namespace cppship; TEST(fs, ScopedCurrentDir) @@ -16,4 +16,39 @@ TEST(fs, ScopedCurrentDir) } EXPECT_EQ(fs::current_path(), cwd); -} \ No newline at end of file +} + +TEST(fs, CreateIfNotExist) +{ + const auto tmpdir = fs::temp_directory_path(); + const auto testdir = fs::path("cppship-unitests"); + + ScopedCurrentDir guard(tmpdir); + + if (fs::exists(testdir)) { + fs::remove_all(testdir); + } + fs::create_directory(testdir); + + { + ScopedCurrentDir guard2(testdir); + const auto newdir = fs::path("subdir1"); + EXPECT_FALSE(fs::exists(newdir)); + cppship::create_if_not_exist(newdir); + EXPECT_TRUE(fs::exists(newdir)); + } + { + ScopedCurrentDir guard2(testdir); + const auto newdir = fs::path("./subdir2/subsubdir1"); + EXPECT_FALSE(fs::exists(newdir)); + cppship::create_if_not_exist(newdir); + EXPECT_TRUE(fs::exists(newdir)); + } + { + ScopedCurrentDir guard2(testdir); + const auto newdir = fs::path("subdir3/subsubdir1/subsubsubdir1"); + EXPECT_FALSE(fs::exists(newdir)); + cppship::create_if_not_exist(newdir); + EXPECT_TRUE(fs::exists(newdir)); + } +}