|
| 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/fetched_android_build.h" |
| 17 | + |
| 18 | +#include <memory> |
| 19 | +#include <utility> |
| 20 | +#include <vector> |
| 21 | + |
| 22 | +#include "cuttlefish/host/commands/assemble_cvd/android_build/android_build.h" |
| 23 | +#include "cuttlefish/host/commands/assemble_cvd/android_build/combined_android_build.h" |
| 24 | +#include "cuttlefish/host/commands/assemble_cvd/android_build/img_zip.h" |
| 25 | +#include "cuttlefish/host/commands/assemble_cvd/android_build/target_files.h" |
| 26 | +#include "cuttlefish/host/libs/config/fetcher_config.h" |
| 27 | +#include "cuttlefish/host/libs/config/file_source.h" |
| 28 | +#include "cuttlefish/result/result.h" |
| 29 | + |
| 30 | +namespace cuttlefish { |
| 31 | + |
| 32 | +Result<std::unique_ptr<AndroidBuild>> FetchedAndroidBuild( |
| 33 | + const FetcherConfig& config, FileSource source) { |
| 34 | + Result<std::unique_ptr<AndroidBuild>> img_zip = ImgZip(config, source); |
| 35 | + Result<std::unique_ptr<AndroidBuild>> target = TargetFiles(config, source); |
| 36 | + |
| 37 | + if (!img_zip.ok() && !target.ok()) { |
| 38 | + CF_EXPECT(std::move(img_zip)); |
| 39 | + return CF_ERR("unreachable"); |
| 40 | + } |
| 41 | + |
| 42 | + std::vector<std::unique_ptr<AndroidBuild>> builds; |
| 43 | + if (img_zip.ok()) { |
| 44 | + builds.emplace_back(std::move(*img_zip)); |
| 45 | + } |
| 46 | + if (target.ok()) { |
| 47 | + builds.emplace_back(std::move(*target)); |
| 48 | + } |
| 49 | + return CF_EXPECT( |
| 50 | + CombinedAndroidBuild("FetchedAndroidBuild", std::move(builds))); |
| 51 | +} |
| 52 | + |
| 53 | +} // namespace cuttlefish |
0 commit comments