Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/tools/VersionMain.cpp
blob: 6f1c13cb78c4b9b4789219963071c4296af75c61 (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
// Copyright (c) 2026 Progmasoft.
// SPDX-License-Identifier: MPL-2.0 WITH AdditionRef-Progmasoft-Exception-2.0

// bazelisk run //tools:version                  prints the current version
// bazelisk run //tools:version -- --next        moves to the next version
// bazelisk run //tools:version -- 0.3.1.0       moves to that version
//
// Moving writes every place that states the version, and the amalgamation.

#include <iostream>
#include <string>
#include <string_view>

#include "tools/Amalgamation.hpp"
#include "tools/Repository.hpp"
#include "tools/Versions.hpp"

int
main(int argc, char **argv)
{
    using namespace Progmasoft::Catch3::Tools;

    if (argc > 2)
    {
        std::cerr
            << "usage: bazelisk run //tools:version [-- --next|<version>]\n";
        return 2;
    }
    const auto root = RepositoryRoot();
    if (!root)
    {
        std::cerr << "run this tool with bazelisk run\n";
        return 2;
    }
    Problems problems;
    const auto current = CurrentVersion(*root, problems);
    if (!current)
    {
        return Finish(problems);
    }
    if (argc == 1)
    {
        std::cout << *current << '\n';
        return 0;
    }
    const std::string_view argument{ argv[1] };
    const auto parsed = ParseVersion(
        argument == "--next" ? *current : std::string{ argument });
    if (!parsed)
    {
        std::cerr << "not a version of three or four numbers: " << argument
                  << '\n';
        return 2;
    }
    const auto version
        = FormatVersion(argument == "--next" ? NextVersion(*parsed) : *parsed);
    // The sources have to make a distribution before anything is changed.
    (void)GenerateAmalgamation(*root, problems);
    if (problems.empty())
    {
        SetVersion(*root, version, problems);
    }
    if (problems.empty())
    {
        const auto amalgamation = GenerateAmalgamation(*root, problems);
        if (problems.empty())
        {
            WriteAmalgamation(*root, amalgamation, problems);
        }
    }
    if (problems.empty())
    {
        std::cout << *current << " -> " << version << '\n';
    }
    return Finish(problems);
}