Pārlūkot izejas kodu

DDS_TL simply won't work with ranges without full SFINAE

default_compile_flags
vector-of-bool pirms 5 gadiem
vecāks
revīzija
0079e7f8c4
6 mainītis faili ar 54 papildinājumiem un 95 dzēšanām
  1. +37
    -33
      src/dds/build.cpp
  2. +6
    -0
      src/dds/compile.hpp
  3. +3
    -4
      src/dds/project.cpp
  4. +1
    -2
      src/dds/sdist.cpp
  5. +7
    -8
      src/dds/source.cpp
  6. +0
    -48
      src/dds/util/tl.hpp

+ 37
- 33
src/dds/build.cpp Parādīt failu

@@ -8,7 +8,6 @@
#include <dds/toolchain.hpp>
#include <dds/util/algo.hpp>
#include <dds/util/string.hpp>
#include <dds/util/tl.hpp>
#include <libman/index.hpp>
#include <libman/parse.hpp>

@@ -139,10 +138,11 @@ void export_project(const build_params& params, const project& project) {

auto all_libs = iter_libraries(project);
extend(pairs,
all_libs //
| transform(DDS_TL(export_project_library(params, _1, project, export_root))) //
| transform(DDS_TL(lm::pair("Library", _1.string()))) //
);
all_libs //
| transform([&](auto&& lib) {
return export_project_library(params, lib, project, export_root);
}) //
| transform([](auto&& path) { return lm::pair("Library", path.string()); })); //

lm::write_pairs(export_root / "package.lmp", pairs);
}
@@ -233,22 +233,24 @@ std::vector<file_compilation> file_compilations_of_lib(const build_params& param
return //
sources //
| filter(should_compile_source) //
| transform(DDS_TL(file_compilation{rules,
_1,
object_file_path(_1.path, params),
lib.name(),
params.enable_warnings})) //
| transform([&](auto&& src) {
return file_compilation{rules,
src,
object_file_path(src.path, params),
lib.name(),
params.enable_warnings};
}) //
| to_vector;
}

std::vector<dds::file_compilation> collect_compiles(const build_params& params,
const project& project) {
auto libs = iter_libraries(project);
return //
libs //
| transform(DDS_TL(file_compilations_of_lib(params, _1))) //
| ranges::actions::join //
| to_vector //
return //
libs //
| transform([&](auto&& lib) { return file_compilations_of_lib(params, lib); }) //
| ranges::actions::join //
| to_vector //
;
}

@@ -276,11 +278,11 @@ std::optional<fs::path> create_lib_archive(const build_params& params,
arc.out_path = lib_archive_path(params, lib);

// Collect object files that make up that library
arc.input_files = //
lib.sources() //
| filter(DDS_TL(_1.kind == source_kind::source)) //
| transform(DDS_TL(obj_for_source(obj_idx, _1.path))) //
| to_vector //
arc.input_files = //
lib.sources() //
| filter([](auto&& s) { return s.kind == source_kind::source; }) //
| transform([&](auto&& s) { return obj_for_source(obj_idx, s.path); }) //
| to_vector //
;

if (arc.input_files.empty()) {
@@ -345,11 +347,13 @@ std::vector<fs::path> link_executables(source_kind sk,
const build_params& params,
const library& lib,
const object_file_index& obj_idx) {
return //
lib.sources() //
| filter(DDS_TL(_1.kind == sk)) //
| transform(DDS_TL(link_one_exe(get_exe_path(_1), _1.path, params, lib, obj_idx))) //
| to_vector //
return //
lib.sources() //
| filter([&](auto&& s) { return s.kind == sk; }) //
| transform([&](auto&& s) {
return link_one_exe(get_exe_path(s), s.path, params, lib, obj_idx);
}) //
| to_vector //
;
}

@@ -396,15 +400,15 @@ link_project_lib(const build_params& params, const library& lib, const object_fi
std::vector<link_results> link_project(const build_params& params,
const project& pr,
const std::vector<file_compilation>& compilations) {
auto obj_index = //
compilations //
| transform(DDS_TL(std::pair(_1.source.path, _1.obj))) //
| to<object_file_index> //
auto obj_index = //
ranges::views::all(compilations) //
| transform([](auto&& comp) { return std::pair(comp.source.path, comp.obj); }) //
| ranges::to<object_file_index>() //
;

auto libs = iter_libraries(pr);
return libs //
| transform(DDS_TL(link_project_lib(params, _1, obj_index))) //
return libs //
| transform([&](auto&& lib) { return link_project_lib(params, lib, obj_index); }) //
| to_vector;
}

@@ -421,8 +425,8 @@ void dds::build(const build_params& params, const package_manifest&) {

auto link_res = link_project(params, project, compiles);

auto all_tests = link_res //
| transform(DDS_TL(_1.test_exes)) //
auto all_tests = link_res //
| transform([](auto&& link) { return link.test_exes; }) //
| ranges::actions::join;

int n_test_fails = 0;

+ 6
- 0
src/dds/compile.hpp Parādīt failu

@@ -43,6 +43,12 @@ struct file_compilation {
std::string owner_name;
bool enable_warnings = false;

file_compilation(compilation_rules rules,
source_file sf,
path_ref obj,
std::string owner,
bool);

void compile(const toolchain& tc) const;
};


+ 3
- 4
src/dds/project.cpp Parādīt failu

@@ -1,7 +1,6 @@
#include <dds/project.hpp>

#include <dds/source.hpp>
#include <dds/util/tl.hpp>

#include <range/v3/range/conversion.hpp>
#include <range/v3/view/filter.hpp>
@@ -18,9 +17,9 @@ std::vector<library> collect_submodules(path_ref pf_libs_dir) {
return {};
}
using namespace ranges::views;
return fs::directory_iterator(pf_libs_dir) //
| filter(has_library_dirs) //
| transform(DDS_TL(library::from_directory(_1))) //
return fs::directory_iterator(pf_libs_dir) //
| filter(has_library_dirs) //
| transform([](auto&& entry) { return library::from_directory(entry); }) //
| ranges::to_vector;
}


+ 1
- 2
src/dds/sdist.cpp Parādīt failu

@@ -3,7 +3,6 @@
#include <dds/project.hpp>
#include <dds/temp.hpp>
#include <dds/util/fs.hpp>
#include <dds/util/tl.hpp>

#include <libman/parse.hpp>

@@ -61,7 +60,7 @@ void sdist_copy_library(path_ref out_root,
}) //
| ranges::to_vector;

ranges::sort(sources_to_keep, std::less<>(), DDS_TL(_1.path));
ranges::sort(sources_to_keep, std::less<>(), [](auto&& s) { return s.path; });

auto lib_dds_path = lib.base_dir() / "library.dds";
if (fs::is_regular_file(lib_dds_path)) {

+ 7
- 8
src/dds/source.cpp Parādīt failu

@@ -1,6 +1,5 @@
#include "./source.hpp"

#include <dds/util/tl.hpp>
#include <dds/util/string.hpp>

#include <spdlog/spdlog.h>
@@ -71,15 +70,15 @@ std::optional<source_file> source_file::from_path(path_ref path) noexcept {
source_list source_file::collect_for_dir(path_ref src) {
using namespace ranges::views;
// Strips nullopt elements and lifts the value from the results
auto drop_nulls = //
filter(DDS_TL(_1.has_value())) //
| transform(DDS_TL(*_1));
auto drop_nulls = //
filter([](auto&& opt) { return opt.has_value(); }) //
| transform([](auto&& opt) { return *opt; }); //

// Collect all source files from the directory
return //
fs::recursive_directory_iterator(src) //
| filter(DDS_TL(_1.is_regular_file())) //
| transform(DDS_TL(source_file::from_path(_1))) //
return //
fs::recursive_directory_iterator(src) //
| filter([](auto&& entry) { return entry.is_regular_file(); }) //
| transform([](auto&& entry) { return source_file::from_path(entry); }) //
// source_file::from_path returns an optional. Drop nulls
| drop_nulls //
| ranges::to_vector;

+ 0
- 48
src/dds/util/tl.hpp Parādīt failu

@@ -1,48 +0,0 @@
#pragma once

#include <cstddef>

namespace dds {

namespace detail {

template <std::size_t I,
typename A = std::nullptr_t,
typename B = std::nullptr_t,
typename C = std::nullptr_t,
typename D = std::nullptr_t>
decltype(auto) nth_arg(A&& a[[maybe_unused]] = nullptr,
B&& b[[maybe_unused]] = nullptr,
C&& c[[maybe_unused]] = nullptr,
D&& d[[maybe_unused]] = nullptr) {
if constexpr (I == 0) {
return (A &&) a;
} else if constexpr (I == 1) {
return (B &&) b;
} else if constexpr (I == 2) {
return (C &&) c;
} else if constexpr (I == 3) {
return (D &&) d;
}
}

} // namespace detail

// Based on https://github.com/Quincunx271/TerseLambda
#define DDS_CTL(...) \
(auto&&... tl_args)->auto { \
[[maybe_unused]] auto&& _1 = ::dds::detail::nth_arg<0, decltype(tl_args)...>( \
static_cast<decltype(tl_args)&&>(tl_args)...); \
[[maybe_unused]] auto&& _2 = ::dds::detail::nth_arg<1, decltype(tl_args)...>( \
static_cast<decltype(tl_args)&&>(tl_args)...); \
[[maybe_unused]] auto&& _3 = ::dds::detail::nth_arg<2, decltype(tl_args)...>( \
static_cast<decltype(tl_args)&&>(tl_args)...); \
[[maybe_unused]] auto&& _4 = ::dds::detail::nth_arg<3, decltype(tl_args)...>( \
static_cast<decltype(tl_args)&&>(tl_args)...); \
static_assert(sizeof...(tl_args) <= 4); \
return (__VA_ARGS__); \
}

#define DDS_TL [&] DDS_CTL

} // namespace dds

Notiek ielāde…
Atcelt
Saglabāt