add clean command

self-hosting
MoAlyousef 4 years ago
parent 77c328d51f
commit 606d942ca0

@ -90,6 +90,7 @@ arguments:
init [exe|shared|static] Starts a new project in the same directory.
gen Generates CMakeLists.txt file.
build <extra cmake args> Run cmake and build.
clean Clean the build directory.
help Show help.
version Current cmkr version.
```

@ -6,12 +6,16 @@ namespace cmkr::build {
int run(int argc, char **argv);
int clean();
} // namespace cmkr::build
extern "C" {
#endif
int cmkr_build_run(int argc, char **argv);
int cmkr_build_clean(void);
#ifdef __cplusplus
}
#endif

@ -39,6 +39,11 @@ const char *handle_args(int argc, char **argv) {
if (ret)
return "CMake build error!";
return "CMake run completed!";
} else if (main_arg == "clean") {
auto ret = build::clean();
if (ret)
return "CMake clean error!";
return "CMake run completed!";
} else {
return "Unknown argument!";
}

@ -10,6 +10,8 @@
#include <stdlib.h>
#include <system_error>
namespace fs = std::filesystem;
namespace cmkr::build {
int run(int argc, char **argv) {
@ -21,7 +23,7 @@ int run(int argc, char **argv) {
}
std::stringstream ss;
if (!std::filesystem::exists("CMakeLists.txt"))
if (!fs::exists("CMakeLists.txt"))
if (gen::generate_cmake("."))
throw std::runtime_error("CMake generation failure!");
@ -45,6 +47,16 @@ int run(int argc, char **argv) {
return ::system(ss.str().c_str());
}
int clean() {
int ret = 0;
cmake::CMake cmake(".", true);
if (fs::exists(cmake.bin_dir)) {
ret = fs::remove_all(cmake.bin_dir);
fs::create_directory(cmake.bin_dir);
}
return ret;
}
} // namespace cmkr::build
int cmkr_build_run(int argc, char **argv) {
@ -55,4 +67,14 @@ int cmkr_build_run(int argc, char **argv) {
} catch (...) {
return cmkr::error::Status(cmkr::error::Status::Code::BuildError);
}
}
int cmkr_build_clean(void) {
try {
return cmkr::build::clean();
} catch (const std::system_error &e) {
return e.code().value();
} catch (...) {
return cmkr::error::Status(cmkr::error::Status::Code::BuildError);
}
}

@ -11,6 +11,7 @@ arguments:
init [exe|shared|static] Starts a new project in the same directory.
gen Generates CMakeLists.txt file.
build <extra cmake args> Run cmake and build.
clean Clean the build directory.
help Show help.
version Current cmkr version.
)lit";

Loading…
Cancel
Save