Android-cuttlefish cvd tool
common.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 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
17#pragma once
18
19#include <sys/types.h>
20
21#include <sstream>
22#include <string>
23#include <string_view>
24
26
29
30namespace cuttlefish {
31
32// utility struct for std::variant uses
33template <typename... Ts>
34struct Overload : Ts... {
35 using Ts::operator()...;
36};
37
38template <typename... Ts>
39Overload(Ts...) -> Overload<Ts...>;
40
41// name of environment variable to mark the launch_cvd initiated by the cvd
42// server
43static constexpr char kCvdMarkEnv[] = "_STARTED_BY_CVD_SERVER_";
44
45constexpr char kServerExecPath[] = "/proc/self/exe";
46
47// The name of environment variable that points to the host out directory
48constexpr char kAndroidHostOut[] = "ANDROID_HOST_OUT";
49// kAndroidHostOut for old branches
50constexpr char kAndroidSoongHostOut[] = "ANDROID_SOONG_HOST_OUT";
51constexpr char kAndroidProductOut[] = "ANDROID_PRODUCT_OUT";
52constexpr char kLaunchedByAcloud[] = "LAUNCHED_BY_ACLOUD";
53
54template <typename Ostream, typename... Args>
55Ostream& ConcatToStream(Ostream& out, Args&&... args) {
56 (out << ... << std::forward<Args>(args));
57 return out;
58}
59
60template <typename... Args>
61std::string ConcatToString(Args&&... args) {
62 std::stringstream concatenator;
63 return ConcatToStream(concatenator, std::forward<Args>(args)...).str();
64}
65
67
69 const std::string& verbosity);
70
72
75
77
78std::string CvdDir();
79
80std::string PerUserDir();
81
82std::string PerUserCacheDir();
83
84std::string InstanceDatabasePath();
85
86std::string InstanceLocksPath();
87
88std::string DefaultBaseDir();
89
90Result<std::string> GroupDirFromHome(std::string_view group_home_dir);
91
92std::string AssemblyDirFromHome(const std::string& group_home_dir);
93
94// Returns the path to the directory containing the host binaries, shared
95// libraries and other files built with the Android build system. It searches,
96// in order, the ANDROID_HOST_OUT, ANDROID_SOONG_HOST_OUT and HOME environment
97// variables followed by the current directory.
99
100} // namespace cuttlefish
Definition: expected.h:86
LogSeverity
Definition: logging.h:87
@ INFO
Definition: logging.h:90
std::unordered_map< std::string, std::string > Envs
Definition: types.h:26
Definition: alloc_utils.cpp:23
Result< std::string > AndroidHostPath(const cvd_common::Envs &envs)
Definition: common.cpp:45
std::string AssemblyDirFromHome(const std::string &group_home_dir)
Definition: common.cpp:167
constexpr char kLaunchedByAcloud[]
Definition: common.h:52
Result< std::string > VerbosityToString(const android::base::LogSeverity verbosity)
Definition: common.cpp:99
constexpr char kAndroidSoongHostOut[]
Definition: common.h:50
Result< std::string > GroupDirFromHome(std::string_view dir)
Definition: common.cpp:158
constexpr android::base::LogSeverity kCvdDefaultVerbosity
Definition: common.h:66
android::base::LogSeverity GetMinimumVerbosity()
Definition: common.cpp:130
std::string CvdDir()
Definition: common.cpp:135
Overload(Ts...) -> Overload< Ts... >
android::base::LogSeverity SetMinimumVerbosity(const android::base::LogSeverity severity)
Definition: common.cpp:118
constexpr char kAndroidProductOut[]
Definition: common.h:51
Result< android::base::LogSeverity > EncodeVerbosity(const std::string &verbosity)
Definition: common.cpp:82
std::string InstanceDatabasePath()
Definition: common.cpp:145
std::string DefaultBaseDir()
Definition: common.cpp:153
std::string PerUserDir()
Definition: common.cpp:139
std::string InstanceLocksPath()
Definition: common.cpp:149
std::string ConcatToString(Args &&... args)
Definition: common.h:61
static constexpr char kCvdMarkEnv[]
Definition: common.h:43
std::string PerUserCacheDir()
Definition: common.cpp:141
Ostream & ConcatToStream(Ostream &out, Args &&... args)
Definition: common.h:55
constexpr char kServerExecPath[]
Definition: common.h:45
constexpr char kAndroidHostOut[]
Definition: common.h:48
std::vector< std::string_view > Args
Definition: incremental.h:28
Definition: common.h:34