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
27
28namespace cuttlefish {
29
31 std::string project;
32 std::string bucket;
33 std::string builder;
34};
35std::ostream& operator<<(std::ostream&, const ChromeOsBuilder&);
36
37using ChromeOsBuildString = std::variant<ChromeOsBuilder, std::string>;
38std::ostream& operator<<(std::ostream&, const ChromeOsBuildString&);
39std::ostream& operator<<(std::ostream&,
40 const std::optional<ChromeOsBuildString>&);
41
42Flag GflagsCompatFlag(const std::string& name,
43 std::vector<std::optional<ChromeOsBuildString>>& value);
44
45} // namespace cuttlefish
46
47template <>
48struct fmt::formatter<cuttlefish::ChromeOsBuilder>
49 : formatter<std::string_view> {
50 template <typename FormatContext>
52 FormatContext& ctx) const {
53 auto formatted =
54 fmt::format("{}/{}/{}", cob.project, cob.bucket, cob.builder);
55 return formatter<std::string_view>::format(formatted, ctx);
56 }
57};
58
59template <>
60struct fmt::formatter<cuttlefish::ChromeOsBuildString>
61 : formatter<std::string_view> {
62 template <typename FormatContext>
64 FormatContext& ctx) const {
65 auto formatted =
66 std::visit([](auto&& value) { return fmt::format("{}", value); }, cobs);
67 return formatter<std::string_view>::format(formatted, ctx);
68 }
69};
70
71template <>
72struct fmt::formatter<std::optional<cuttlefish::ChromeOsBuildString>>
73 : formatter<std::string_view> {
74 template <typename FormatContext>
75 auto format(const std::optional<cuttlefish::ChromeOsBuildString>& cobs,
76 FormatContext& ctx) const {
77 auto formatted = cobs ? fmt::format("{}", *cobs) : "";
78 return formatter<std::string_view>::format(formatted, ctx);
79 }
80};
Definition: flag.h:32
char * name
Definition: libf2fs.c:1403
EventFormat format
Definition: kernel_log_server.cc:60
Definition: alloc_driver.h:20
Flag GflagsCompatFlag(const std::string &name, std::string &value)
Definition: gflags_compat.cpp:280
std::variant< ChromeOsBuilder, std::string > ChromeOsBuildString
Definition: chrome_os_build_string.h:37
std::ostream & operator<<(std::ostream &out, DeviceType device_type)
Definition: device_type.cpp:72
Definition: logging.h:464
Definition: chrome_os_build_string.h:30
std::string builder
Definition: chrome_os_build_string.h:33
std::string bucket
Definition: chrome_os_build_string.h:32
std::string project
Definition: chrome_os_build_string.h:31
auto format(const cuttlefish::ChromeOsBuildString &cobs, FormatContext &ctx) const
Definition: chrome_os_build_string.h:63
auto format(const cuttlefish::ChromeOsBuilder &cob, FormatContext &ctx) const
Definition: chrome_os_build_string.h:51
auto format(const std::optional< cuttlefish::ChromeOsBuildString > &cobs, FormatContext &ctx) const
Definition: chrome_os_build_string.h:75