summaryrefslogtreecommitdiff
path: root/test/suite/ctor_files/ctor.cc.generated
blob: 5bc29405d908ee8cc2be81a78ce1f4b5e38ecc8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// -*- c++ -*-
// Distributed under the BSD 2-Clause License.
// See accompanying file LICENSE for details.
#include <ctor.h>
#include <filesystem>
#include <iostream>
#include <fstream>

namespace
{
ctor::build_configurations ctorConfigs(const ctor::settings& settings)
{
	return
	{
		{
			.target = "world",
			.sources = {
				{ "world.cc", ctor::source_type::generated },
			},
		},
		{
			.target = "foo",
			.sources = {
				{ "foo.cc", ctor::source_type::generated },
			},
		},
		{
			.target = "this_is_unused",
			.sources = {
				{"hello.cc", ctor::output_file{"world.cc"}},
				{"hello.cc", ctor::output_file{"foo.cc"}},
			},
			.function = [](const std::string& input,
			               const std::string& output,
			               const ctor::build_configuration& config,
			               const ctor::settings& settings)
			{
				namespace fs = std::filesystem;
				std::cout << "Input: " << input << '\n';
				std::cout << "Output: " << output << '\n';
				fs::copy_file(input, output, fs::copy_options::overwrite_existing);
				return 0;
			}
		},

		{
			.target = "many_to_one",
			.sources = {
				{"many_to_one.cc", ctor::source_type::generated}
			}
		},
		{
			.target = "many_to_one.cc",
			.sources = {
				{"foo.cc", ctor::source_type::generated},
				{"hello.cc"},
			},
			.function = [](const std::vector<std::string>& input,
			               const std::string& output,
			               const ctor::build_configuration& config,
			               const ctor::settings& settings)
			{
				std::cout << "Output: " << output << '\n';
				std::ofstream ofs(output);
				bool comment{true};
				for(const auto& input_file : input)
				{
					std::cout << "Input: " << input_file << '\n';
					std::ifstream ifs(input_file);
					std::string line;
					while(std::getline(ifs, line))
					{
						ofs << line << '\n';
					}
					if(comment) ofs << "/*\n";
					comment = false;
				}
				ofs << "*/\n";
				return 0;
			}
		},

	};
}
}

REG(ctorConfigs);