Skip to content

Commit

Permalink
Merge pull request #361 from poacpm/improve/build-cmd
Browse files Browse the repository at this point in the history
Improve build command
  • Loading branch information
ken-matsui authored Jan 5, 2021
2 parents f2a9710 + 08c22cc commit 71d7aa4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 40 deletions.
15 changes: 8 additions & 7 deletions include/poac/cmd/build.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define POAC_CMD_BUILD_HPP

// std
#include <filesystem>
#include <string>

// external
Expand All @@ -15,22 +16,22 @@

namespace poac::cmd::build {
struct Options {
core::builder::Mode mode;
core::builder::mode_t mode;
};

[[nodiscard]] mitama::result<void, std::string>
[[nodiscard]] mitama::result<std::filesystem::path, std::string>
build([[maybe_unused]] Options&& opts, const toml::value& config) {
MITAMA_TRY(core::resolver::install_deps(config));
// core::Builder bs(config.get(), opts.mode, opts.verbose);
// MITAMA_TRY(bs.build());
return mitama::success();
[[maybe_unused]] const auto resolved_deps = MITAMA_TRY(core::resolver::install_deps(config));
// [[maybe_unused]] const auto output_binary = MITAMA_TRY(core::builder::build(config, opts.mode, resolved_deps));
return mitama::success("");
}

[[nodiscard]] mitama::result<void, std::string>
exec(Options&& opts) {
MITAMA_TRY(core::validator::require_config_exists());
const toml::value config = toml::parse("poac.toml");
return build(std::move(opts), config);
MITAMA_TRY(build(std::move(opts), config));
return mitama::success();
}
} // end namespace

Expand Down
43 changes: 16 additions & 27 deletions include/poac/core/builder/builder.hpp
Original file line number Diff line number Diff line change
@@ -1,52 +1,44 @@
#ifndef POAC_CORE_BUILDER_BUILDER_HPP
#define POAC_CORE_BUILDER_BUILDER_HPP

// std
#include <cstdint>
#include <chrono>
#include <filesystem>
#include <iostream>
#include <stdexcept>
#include <string>
#include <string_view>
#include <vector>
#include <optional>

//#include <poac/core/builder/compiler.hpp>
//#include <poac/core/builder/standard.hpp>
//#include <poac/core/except.hpp>
//#include <poac/io/config.hpp>
//#include <poac/io/term.hpp>
//#include <poac/util/pretty.hpp>
//#include <poac/util/semver/semver.hpp>
// external
#include <fmt/core.h>

namespace poac::core::builder {
enum class Mode {
Debug,
Release,
enum class mode_t {
debug,
release,
};

std::ostream&
operator<<(std::ostream& os, Mode mode) {
operator<<(std::ostream& os, mode_t mode) {
switch (mode) {
case Mode::Debug:
case mode_t::debug:
return (os << "dev");
case Mode::Release:
case mode_t::release:
return (os << "release");
default:
throw std::logic_error(
"To access out of range of the "
"enumeration values is undefined behavior.");
"To access out of range of the "
"enumeration values is undefined behavior."
);
}
}

std::string
make_definition(const std::string& first, const std::string& second) {
return "-D" + first + "=" + R"(\")" + second + R"(\")";
}
std::string
make_definition(const std::string& first, const std::uint_fast64_t& second) {
std::ostringstream oss;
oss << second;
return make_definition(first, oss.str());
template <class T>
std::string make_definition(std::string_view key, T&& value) {
return fmt::format("-D{}=\\\"{}\\\"", key, std::forward<T>(value));
}

// struct Builder {
Expand Down Expand Up @@ -179,8 +171,5 @@ namespace poac::core::builder {
// }
// };
} // end namespace
//namespace poac::core {
// using Builder = builder::Builder;
//}

#endif // POAC_CORE_BUILDER_BUILDER_HPP
7 changes: 4 additions & 3 deletions include/poac/core/resolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,16 @@ namespace poac::core::resolver {
}
}

[[nodiscard]] mitama::result<void, std::string>
[[nodiscard]] mitama::result<resolve::unique_deps_t<resolve::with_deps>, std::string>
install_deps(const toml::value& config) noexcept {
if (!config.contains("dependencies")) {
return mitama::success();
return mitama::success(resolve::unique_deps_t<resolve::with_deps>{});
}
const toml::value deps = toml::get<toml::table>(config).at("dependencies");
const auto resolvable_deps = MITAMA_TRY(to_resolvable_deps(deps));
const auto resolved_deps = MITAMA_TRY(do_resolve(resolvable_deps));
return download_deps(resolved_deps);
MITAMA_TRY(download_deps(resolved_deps));
return mitama::success(resolved_deps);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ main(const int argc, char* argv[]) {
subcommand subcmd = subcommand::nothing;

auto build_opts = poac::cmd::build::Options {
poac::core::builder::Mode::Debug,
poac::core::builder::mode_t::debug,
};
const clipp::group build_cmd =
( clipp::command("build")
.set(subcmd, subcommand::build)
.doc("Compile a project and all sources that depend on its")
, ( clipp::option("--debug", "-d")
.set(build_opts.mode, poac::core::builder::Mode::Debug)
.set(build_opts.mode, poac::core::builder::mode_t::debug)
.doc("Build artifacts in debug mode [default]")
| clipp::option("--release", "-r")
.set(build_opts.mode, poac::core::builder::Mode::Release)
.set(build_opts.mode, poac::core::builder::mode_t::release)
.doc("Build artifacts in release mode, with optimizations")
)
, ( clipp::option("--verbose", "-v")
Expand Down

0 comments on commit 71d7aa4

Please sign in to comment.