aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/triplet.cpp
blob: 14f19d5cd9c6d4ba6d6dcc3925ca15d1225ed0f1 (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
#include "triplet.h"
#include "vcpkg.h"
#include "vcpkg_System.h"
#include "vcpkg_Checks.h"

namespace vcpkg
{
    const triplet triplet::X86_WINDOWS = {"x86-windows"};
    const triplet triplet::X64_WINDOWS = {"x64-windows"};
    const triplet triplet::X86_UWP = {"x86-uwp"};
    const triplet triplet::X64_UWP = {"x64-uwp"};
    const triplet triplet::ARM_UWP = {"arm-uwp"};

    std::string to_string(const triplet& t)
    {
        return t.value;
    }

    std::string to_printf_arg(const triplet& t)
    {
        return to_string(t);
    }

    bool operator==(const triplet& left, const triplet& right)
    {
        return left.value == right.value;
    }

    bool operator!=(const triplet& left, const triplet& right)
    {
        return !(left == right);
    }

    std::ostream& operator<<(std::ostream& os, const triplet& t)
    {
        return os << to_string(t);
    }

    std::string triplet::architecture() const
    {
        if (*this == X86_WINDOWS || *this == X86_UWP)
            return "x86";
        if (*this == X64_WINDOWS || *this == X64_UWP)
            return "x64";
        if (*this == ARM_UWP)
            return "arm";

        Checks::exit_with_message("Unknown architecture: %s", value);
    }

    std::string triplet::system() const
    {
        if (*this == X86_WINDOWS || *this == X64_WINDOWS)
            return "windows";
        if (*this == X86_UWP || *this == X64_UWP || *this == ARM_UWP)
            return "uwp";

        Checks::exit_with_message("Unknown system: %s", value);
    }

    bool triplet::validate(const vcpkg_paths & paths)
    {
        auto it = fs::directory_iterator(paths.triplets);
        for(; it != fs::directory_iterator(); ++it)
        {
            std::string triplet_file_name = it->path().stem().generic_u8string();
            if(value == triplet_file_name) // TODO: fuzzy compare
            {
                //value = triplet_file_name; // NOTE: uncomment when implementing fuzzy compare
                return true;
            }
        }
        return false;
    }
}