Skip to content

Commit c6c1c0a

Browse files
committed
Create an AndroidBuild class
Implementations of this class represent android build artifacts from various different sources. Bug: b/469219913
1 parent 3baf052 commit c6c1c0a

File tree

3 files changed

+196
-0
lines changed

3 files changed

+196
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
load("//cuttlefish/bazel:rules.bzl", "cf_cc_library")
2+
3+
package(
4+
default_visibility = ["//:android_cuttlefish"],
5+
)
6+
7+
exports_files([".clang-tidy"])
8+
9+
cf_cc_library(
10+
name = "android_build",
11+
srcs = ["android_build.cc"],
12+
hdrs = ["android_build.h"],
13+
deps = [
14+
"//cuttlefish/common/libs/utils:result",
15+
"@abseil-cpp//absl/strings:str_format",
16+
"@fmt",
17+
],
18+
)
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//
2+
// Copyright (C) 2025 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+
#include "cuttlefish/host/commands/assemble_cvd/android_build/android_build.h"
17+
18+
#include <functional>
19+
#include <optional>
20+
#include <ostream>
21+
#include <set>
22+
#include <string>
23+
#include <string_view>
24+
25+
#include "cuttlefish/common/libs/utils/result.h"
26+
27+
namespace cuttlefish {
28+
29+
Result<std::set<std::string, std::less<void>>> AndroidBuild::Images() {
30+
return CF_ERRF("Unimplemented for '{}'", *this);
31+
}
32+
33+
Result<std::string> AndroidBuild::ImageFile(
34+
std::string_view name, std::optional<std::string_view> extract_dir) {
35+
return CF_ERRF("Unimplemented for '{}': (name = '{}', extract_dir = '{}'",
36+
*this, name, extract_dir.value_or("(empty)"));
37+
}
38+
39+
Result<std::set<std::string, std::less<void>>> AndroidBuild::AbPartitions() {
40+
return CF_ERRF("Unimplemented for '{}'", *this);
41+
}
42+
43+
Result<std::set<std::string, std::less<void>>>
44+
AndroidBuild::SystemPartitions() {
45+
return CF_ERRF("Unimplemented for '{}'", *this);
46+
}
47+
48+
Result<std::set<std::string, std::less<void>>>
49+
AndroidBuild::VendorPartitions() {
50+
return CF_ERRF("Unimplemented for '{}'", *this);
51+
}
52+
53+
Result<std::set<std::string, std::less<void>>>
54+
AndroidBuild::LogicalPartitions() {
55+
return CF_ERRF("Unimplemented for '{}'", *this);
56+
}
57+
58+
Result<std::set<std::string, std::less<void>>>
59+
AndroidBuild::PhysicalPartitions() {
60+
return CF_ERRF("Unimplemented for '{}'", *this);
61+
}
62+
63+
std::ostream& operator<<(std::ostream& out, const AndroidBuild& build) {
64+
return build.Format(out);
65+
}
66+
67+
} // namespace cuttlefish
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
//
2+
// Copyright (C) 2025 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 <functional>
19+
#include <optional>
20+
#include <ostream>
21+
#include <set>
22+
#include <string_view>
23+
24+
#include "absl/strings/str_format.h"
25+
#include "fmt/ostream.h"
26+
27+
#include "cuttlefish/common/libs/utils/result.h"
28+
29+
namespace cuttlefish {
30+
31+
/**
32+
* Represents an Android build, as defined by image files and some of the
33+
* metadata text files produced by the build system.
34+
*
35+
* The build system produces a subset of these files with faster `m` builds, and
36+
* does the complete set and packages them up into zip files in slower `m dist`
37+
* builds. The zip files are uploaded to the Android Build server, and the `cvd
38+
* fetch` tool can download subsets of them to the local filesystem.
39+
*
40+
* Image files also contain some duplication: the 'super' image contains logical
41+
* partitions that may also be present as standalone image files, depending on
42+
* the file subset available.
43+
*
44+
* Note the distinction between "images" and "partitions" in methods. Image
45+
* files may contain zero or more partitions.
46+
*
47+
* Instances of this class present a subset of the files produced by the build
48+
* system. This may be complete or incomplete subset.
49+
*/
50+
class AndroidBuild {
51+
public:
52+
virtual ~AndroidBuild() = default;
53+
54+
/**
55+
* Image information, as reported by the Android build system.
56+
*
57+
* An image may be one of three different categories:
58+
* - A partition in the top-level GPT, such as the the `super` partition.
59+
* - A logical partition stored inside the GPT `super` partition.
60+
* - A `super_empty` pseudo-partition file that reports what should be in the
61+
* `super` partition, but without the logical partition contents.
62+
*/
63+
virtual Result<std::set<std::string, std::less<void>>> Images();
64+
/*
65+
* A file on the host that represents an image. If the file is not already
66+
* stored in a distinct file on the host, it is first saved to `extract_dir`
67+
* and returned from there. If the file needs to be extracted and
68+
* `extract_dir` is not provided, returns an error.
69+
*
70+
* It's possible for there to be an image file in `Images()` that cannot be
71+
* extracted to the filesystem, if a metadata file reports that an image or
72+
* partition should exist, but it's not actually present anywhere.
73+
*/
74+
virtual Result<std::string> ImageFile(
75+
std::string_view name, std::optional<std::string_view> extract_dir = {});
76+
77+
virtual Result<std::set<std::string, std::less<void>>> AbPartitions();
78+
79+
/**
80+
* If this build is combined with another build by mixing system and vendor
81+
* from different places, reports which partitions this build expects to
82+
* contribute to a particular side of the mix. System and vendor partition
83+
* sets should be disjoint.
84+
*/
85+
virtual Result<std::set<std::string, std::less<void>>> SystemPartitions();
86+
virtual Result<std::set<std::string, std::less<void>>> VendorPartitions();
87+
88+
/** Partitions in the super image. Disjoint from GPT entries. */
89+
virtual Result<std::set<std::string, std::less<void>>> LogicalPartitions();
90+
/** Entries in the GPT. Disjoint from logical partitions. */
91+
virtual Result<std::set<std::string, std::less<void>>> PhysicalPartitions();
92+
93+
private:
94+
virtual std::ostream& Format(std::ostream&) const = 0;
95+
96+
template <typename Sink>
97+
friend void AbslStringify(Sink& sink, const AndroidBuild& provider) {
98+
sink.Append(absl::FormatStreamed(provider));
99+
}
100+
101+
friend std::ostream& operator<<(std::ostream&, const AndroidBuild&);
102+
};
103+
104+
} // namespace cuttlefish
105+
106+
namespace fmt {
107+
108+
template <>
109+
struct formatter<::cuttlefish::AndroidBuild> : ostream_formatter {};
110+
111+
} // namespace fmt

0 commit comments

Comments
 (0)