From fa0426953247884c11eb95873ababd6bf485316d Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Sat, 16 Dec 2023 14:14:02 -0800 Subject: [PATCH] Remove old build & run impls --- srcOld/Cmd/Build.cc | 75 -------------------------------------------- srcOld/Cmd/Build.hpp | 36 --------------------- srcOld/Cmd/Run.cc | 47 --------------------------- srcOld/Cmd/Run.hpp | 23 -------------- 4 files changed, 181 deletions(-) delete mode 100644 srcOld/Cmd/Build.cc delete mode 100644 srcOld/Cmd/Build.hpp delete mode 100644 srcOld/Cmd/Run.cc delete mode 100644 srcOld/Cmd/Run.hpp diff --git a/srcOld/Cmd/Build.cc b/srcOld/Cmd/Build.cc deleted file mode 100644 index ad89692dd..000000000 --- a/srcOld/Cmd/Build.cc +++ /dev/null @@ -1,75 +0,0 @@ -#include "Build.hpp" - -// external -#include // NOLINT(build/include_order) -#include // NOLINT(build/include_order) - -// internal -#include "../Config.hpp" -#include "../Core/Resolver.hpp" // install_deps -#include "../Data/Manifest.hpp" -#include "../Util/Log.hpp" -#include "../Util/Pretty.hpp" // to_time -#include "../Util/ResultMacros.hpp" -#include "../Util/Validator.hpp" - -namespace poac::cmd::build { - -[[nodiscard]] static auto build_impl( - const toml::value& manifest, const Mode& mode, - const ResolvedDeps& resolved_deps -) -> Result { - const spdlog::stopwatch sw; - const Path output_path = - Try(core::builder::build::start(manifest, mode, resolved_deps)); - - log::status( - "Finished", "{} target(s) in {}", to_string(mode), - util::pretty::to_time(sw.elapsed().count()) - ); - return Ok(output_path); -} - -[[nodiscard]] auto build(const Options& opts, const toml::value& manifest) - -> Result> { - const auto resolved_deps = - Try(core::resolver::install_deps(manifest).with_context([] { - return Err().get(); - })); - - // TODO(ken-matsui): We have to keep in mind a case of only dependencies - // require to be built, but this package does not. - if (!fs::exists(config::main_cpp_file)) { - log::status("Finished", "no build target(s) found"); - return Ok(None); - } - - const auto profile = - Try(util::validator::valid_profile(opts.profile, opts.release) - .map_err(to_anyhow)) - .value_or("debug"); - if (profile != "debug" && profile != "release") { - return Err(profile); - } - - const Mode mode = profile == "release" ? Mode::release : Mode::debug; - const Path output_path = Try(build_impl(manifest, mode, resolved_deps)); - return Ok(output_path); -} - -[[nodiscard]] auto exec(const Options& opts) -> Result { - spdlog::trace("Checking if required config exists ..."); - Try(util::validator::required_config_exists().map_err(to_anyhow)); - - spdlog::trace("Parsing the manifest file ..."); - // TODO(ken-matsui): parse as a static type rather than toml::value - const toml::value manifest = toml::parse(data::manifest::NAME); - - Try(build(opts, manifest).with_context([&manifest] { - return Err(toml::find(manifest, "package", "name")) - .get(); - })); - return Ok(); -} - -} // namespace poac::cmd::build diff --git a/srcOld/Cmd/Build.hpp b/srcOld/Cmd/Build.hpp deleted file mode 100644 index edfd4dc35..000000000 --- a/srcOld/Cmd/Build.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -// external -#include -#include - -// internal -#include "../Core/Builder/Build.hpp" -#include "../Core/Resolver/Types.hpp" // ResolvedDeps -#include "../Util/Result.hpp" -#include "../Util/Rustify.hpp" - -namespace poac::cmd::build { - -using core::builder::build::Mode; -using core::resolver::ResolvedDeps; - -struct Options : structopt::sub_command { - /// Build artifacts in release mode, with optimizations - Option release = false; - /// Build artifacts with the specified profile - Option profile; -}; - -using FailedToBuild = Error<"failed to build package `{}`", String>; -using FailedToInstallDeps = Error<"failed to install dependencies">; -using UnsupportedProfile = Error<"unsupported profile `{}`", String>; - -[[nodiscard]] auto build(const Options& opts, const toml::value& manifest) - -> Result>; - -[[nodiscard]] auto exec(const Options& opts) -> Result; - -} // namespace poac::cmd::build - -STRUCTOPT(poac::cmd::build::Options, release, profile); diff --git a/srcOld/Cmd/Run.cc b/srcOld/Cmd/Run.cc deleted file mode 100644 index b4edf8bb5..000000000 --- a/srcOld/Cmd/Run.cc +++ /dev/null @@ -1,47 +0,0 @@ -#include "Run.hpp" - -// external -#include // NOLINT(build/include_order) -#include -#include - -// internal -#include "../Data/Manifest.hpp" -#include "../Util/Format.hpp" -#include "../Util/Log.hpp" -#include "../Util/ResultMacros.hpp" -#include "../Util/Shell.hpp" -#include "../Util/Validator.hpp" -#include "./Build.hpp" - -namespace poac::cmd::run { - -[[nodiscard]] auto exec(const Options& opts) -> Result { - spdlog::trace("Checking if required config exists ..."); - Try(util::validator::required_config_exists().map_err(to_anyhow)); - - spdlog::trace("Parsing the manifest file ..."); - // TODO(ken-matsui): parse as a static type rather than toml::value - const toml::value manifest = toml::parse(data::manifest::NAME); - const String name = toml::find(manifest, "package", "name"); - - const Option output = Try( - build::build({.release = opts.release, .profile = opts.profile}, manifest) - .with_context([&name] { - return Err(name).get(); - }) - ); - if (!output.has_value()) { - return Ok(); - } - - const Path executable = output.value() / name; - log::status("Running", executable); - if (const i32 code = util::shell::Cmd(executable).exec_no_capture(); - code != 0) { - return Err(executable, code); - } - return Ok(); -} - -} // namespace poac::cmd::run diff --git a/srcOld/Cmd/Run.hpp b/srcOld/Cmd/Run.hpp deleted file mode 100644 index fe133a0f7..000000000 --- a/srcOld/Cmd/Run.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -// external -#include - -// internal -#include "../Util/Result.hpp" -#include "../Util/Rustify.hpp" - -namespace poac::cmd::run { - -struct Options : structopt::sub_command { - /// Build artifacts in release mode, with optimizations - Option release = false; - /// Build artifacts with the specified profile - Option profile; -}; - -[[nodiscard]] auto exec(const Options& opts) -> Result; - -} // namespace poac::cmd::run - -STRUCTOPT(poac::cmd::run::Options, release, profile);