Sfoglia il codice sorgente

Add user-local default toolchain lookup semantics [Close #18] [Close

default_compile_flags
vector-of-bool 4 anni fa
parent
commit
562272f6c2
7 ha cambiato i file con 97 aggiunte e 3 eliminazioni
  1. +29
    -0
      docs/err/no-default-toolchain.rst
  2. +26
    -0
      docs/guide/toolchains.rst
  3. +14
    -3
      src/dds.main.cpp
  4. +11
    -0
      src/dds/error/errors.cpp
  5. +1
    -0
      src/dds/error/errors.hpp
  6. +15
    -0
      src/dds/toolchain/toolchain.cpp
  7. +1
    -0
      src/dds/toolchain/toolchain.hpp

+ 29
- 0
docs/err/no-default-toolchain.rst Vedi File

@@ -0,0 +1,29 @@
Error: Unable to find a default toolchain to use for the build
##############################################################

Unlike other build systems, ``dds`` will not attempt to make a "best guess"
about the local platform and the available build toolchains. Instead, a
toolchain must be provided for every build. This can be named on the command
line with ``--toolchain`` or by placing a toolchain file in one of a few
prescribed locations.


Solution: Request a built-in toolchain
**************************************

A built-in toolchain can be specified with the ``--toolchain`` (or ``-t``)
argument. Refer to the :ref:`toolchains.builtin` section for more information.


Solution: Set up a default toolchain file for the project or for your local user
********************************************************************************

If no toolchain argument is given when a build is invoked, ``dds`` will search
a predefined set of filepaths for the existence of a toolchain file to use as
the "default." Writing a simple toolchain to one of these paths will cause
``dds`` to use this toolchain when none was provided.


.. seealso::
For more information, refer to the full documentation page:
:doc:`/guide/toolchains`

+ 26
- 0
docs/guide/toolchains.rst Vedi File

@@ -88,6 +88,32 @@ The following pseudo-toolchains are also available:
Sets the C++ version to ``C++UV`` and uses the ``:XYZ`` toolchain.


.. _toolchains.default:

Providing a Default Toolchain File
**********************************

If you do not which to provide a new toolchain for every individual project,
and the built-in toolchains do not suit your needs, you can write a toolchain
file to one of a few predefined paths, and ``dds`` will find and use it for the
build. The following paths are searched, in order:

#. ``$pwd/toolchain.dds`` - If the working directory contains ``toolchain.dds``,
it will be used as the default.
#. ``$dds_config_dir/toolchain.dds`` - Searches for a toolchain file in
``dds``'s user-local configuration directory (see below).
#. ``$user_home/toolchain.dds`` - Searches for a toolchain file at the root of
the current user's home directory. (``$HOME`` on Unix-like systems, and
``$PROFILE`` on Windows.)

The ``$dds_user_config`` directory is the ``dds`` subdirectory of the
user-local configuration directory.

The user-local config directory is ``$XDG_CONFIG_DIR`` or ``~/.config`` on
Linux, ``~/Library/Preferences`` on macOS, and ``~/AppData/Roaming`` on
Windows.


Toolchain Definitions
*********************


+ 14
- 3
src/dds.main.cpp Vedi File

@@ -31,11 +31,22 @@ struct toolchain_flag : string_flag {
toolchain_flag(args::Group& grp)
: string_flag{grp,
"toolchain_file",
"Path/ident of the toolchain to use",
{"toolchain", 't'},
(dds::fs::current_path() / "toolchain.dds").string()} {}
"Path/identifier of the toolchain to use",
{"toolchain", 't'}} {}

dds::toolchain get_toolchain() {
if (*this) {
return get_arg();
} else {
auto found = dds::toolchain::get_default();
if (!found) {
dds::throw_user_error<dds::errc::no_default_toolchain>();
}
return *found;
}
}

dds::toolchain get_arg() {
const auto tc_path = this->Get();
if (tc_path.find(":") == 0) {
auto default_tc = tc_path.substr(1);

+ 11
- 0
src/dds/error/errors.cpp Vedi File

@@ -13,6 +13,8 @@ std::string error_url_suffix(dds::errc ec) noexcept {
switch (ec) {
case errc::invalid_builtin_toolchain:
return "invalid-builtin-toolchain.html";
case errc::no_default_toolchain:
return "no-default-toolchain.html";
case errc::no_such_catalog_package:
return "no-such-catalog-package.html";
case errc::git_url_ref_mutual_req:
@@ -84,6 +86,13 @@ toolchain. (Toolchain file paths cannot begin with a leading colon).

These toolchain names are encoded into the dds executable and cannot be
modified.
)";
case errc::no_default_toolchain:
return R"(
`dds` requires a toolchain to be specified in order to execute the build. `dds`
will not perform a "best-guess" at a default toolchain. You may either pass the
name of a built-in toolchain, or write a "default toolchain" file to one of the
supported filepaths. Refer to the documentation for more information.
)";
case errc::no_such_catalog_package:
return R"(
@@ -227,6 +236,8 @@ std::string_view dds::default_error_string(dds::errc ec) noexcept {
switch (ec) {
case errc::invalid_builtin_toolchain:
return "The built-in toolchain name is invalid";
case errc::no_default_toolchain:
return "Unable to find a default toolchain to use for the build";
case errc::no_such_catalog_package:
return "The catalog has no entry for the given package ID";
case errc::git_url_ref_mutual_req:

+ 1
- 0
src/dds/error/errors.hpp Vedi File

@@ -10,6 +10,7 @@ namespace dds {
enum class errc {
none = 0,
invalid_builtin_toolchain,
no_default_toolchain,
no_such_catalog_package,
git_url_ref_mutual_req,
test_failure,

+ 15
- 0
src/dds/toolchain/toolchain.cpp Vedi File

@@ -3,6 +3,7 @@
#include <dds/toolchain/from_dds.hpp>
#include <dds/toolchain/prep.hpp>
#include <dds/util/algo.hpp>
#include <dds/util/paths.hpp>
#include <dds/util/string.hpp>

#include <cassert>
@@ -235,3 +236,17 @@ std::optional<toolchain> toolchain::get_builtin(std::string_view tc_id) noexcept
tc_content += "Compiler-ID: " + opt_triple->id + "\n";
return parse_toolchain_dds(tc_content);
}

std::optional<dds::toolchain> dds::toolchain::get_default() {
auto candidates = {
fs::current_path() / "toolchain.dds",
dds_config_dir() / "toolchain.dds",
user_home_dir() / "toolchain.dds",
};
for (auto&& cand : candidates) {
if (fs::exists(cand)) {
return parse_toolchain_dds(slurp_file(cand));
}
}
return std::nullopt;
}

+ 1
- 0
src/dds/toolchain/toolchain.hpp Vedi File

@@ -82,6 +82,7 @@ public:
std::vector<std::string> create_link_executable_command(const link_exe_spec&) const noexcept;

static std::optional<toolchain> get_builtin(std::string_view key) noexcept;
static std::optional<toolchain> get_default();
};

} // namespace dds

Loading…
Annulla
Salva