Android-cuttlefish cvd tool
chrome_os_build_string.h
Go to the documentation of this file.
1//
2// Copyright (C) 2024 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16#pragma once
17
18#include <optional>
19#include <ostream>
20#include <string>
21#include <variant>
22#include <vector>
23
24#include <fmt/format.h>
25
26#ifndef CONST_IF_LATER_FMTLIB
27#if FMT_VERSION >= 90000
28#define CONST_IF_LATER_FMTLIB const
29#else
30#define CONST_IF_LATER_FMTLIB
31#endif
32#endif
34
35namespace cuttlefish {
36
38 std::string project;
39 std::string bucket;
40 std::string builder;
41};
42std::ostream& operator<<(std::ostream&, const ChromeOsBuilder&);
43
44using ChromeOsBuildString = std::variant<ChromeOsBuilder, std::string>;
45std::ostream& operator<<(std::ostream&, const ChromeOsBuildString&);
46std::ostream& operator<<(std::ostream&,
47 const std::optional<ChromeOsBuildString>&);
48
49Flag GflagsCompatFlag(const std::string& name,
50 std::vector<std::optional<ChromeOsBuildString>>& value);
51
52} // namespace cuttlefish
53
54template <>
55struct fmt::formatter<cuttlefish::ChromeOsBuilder>
56 : formatter<std::string_view> {
57 template <typename FormatContext>
59 FormatContext& ctx) CONST_IF_LATER_FMTLIB {
60 auto formatted =
61 fmt::format("{}/{}/{}", cob.project, cob.bucket, cob.builder);
62 return formatter<std::string_view>::format(formatted, ctx);
63 }
64};
65
66template <>
67struct fmt::formatter<cuttlefish::ChromeOsBuildString>
68 : formatter<std::string_view> {
69 template <typename FormatContext>
71 FormatContext& ctx) CONST_IF_LATER_FMTLIB {
72 auto formatted =
73 std::visit([](auto&& value) { return fmt::format("{}", value); }, cobs);
74 return formatter<std::string_view>::format(formatted, ctx);
75 }
76};
77
78template <>
79struct fmt::formatter<std::optional<cuttlefish::ChromeOsBuildString>>
80 : formatter<std::string_view> {
81 template <typename FormatContext>
82 auto format(const std::optional<cuttlefish::ChromeOsBuildString>& cobs,
83 FormatContext& ctx) CONST_IF_LATER_FMTLIB {
84 auto formatted = cobs ? fmt::format("{}", *cobs) : "";
85 return formatter<std::string_view>::format(formatted, ctx);
86 }
87};
#define CONST_IF_LATER_FMTLIB
Definition: chrome_os_build_string.h:30
Definition: flag_parser.h:73
EventFormat format
Definition: kernel_log_server.cc:57
Definition: alloc_utils.cpp:23
Flag GflagsCompatFlag(const std::string &name)
Definition: flag_parser.cpp:583
std::variant< ChromeOsBuilder, std::string > ChromeOsBuildString
Definition: chrome_os_build_string.h:44
std::ostream & operator<<(std::ostream &out, Arch arch)
Definition: architecture.cpp:67
Definition: logging.h:464
Definition: chrome_os_build_string.h:37
std::string builder
Definition: chrome_os_build_string.h:40
std::string bucket
Definition: chrome_os_build_string.h:39
std::string project
Definition: chrome_os_build_string.h:38
auto format(const cuttlefish::ChromeOsBuildString &cobs, FormatContext &ctx) CONST_IF_LATER_FMTLIB
Definition: chrome_os_build_string.h:70
auto format(const cuttlefish::ChromeOsBuilder &cob, FormatContext &ctx) CONST_IF_LATER_FMTLIB
Definition: chrome_os_build_string.h:58
auto format(const std::optional< cuttlefish::ChromeOsBuildString > &cobs, FormatContext &ctx) CONST_IF_LATER_FMTLIB
Definition: chrome_os_build_string.h:82