Files
Breeze/source/BreezeCore/include/breeze/Sdks.hpp
T
2026-10-24 09:53:48 -03:00

70 lines
2.3 KiB
C++

#pragma once
#include <filesystem>
#include <optional>
#include <string>
#include <vector>
#include "breeze/Project.hpp"
#include "breeze/Version.hpp"
/// SDK versions, where they come from and what moving a project between them means.
///
/// An SDK version is a snapshot of the whole template: breeze/ (the SDK proper, replaced as a whole
/// on a change), plus the files the project owns and starts from (project/Configuration.cmake, the
/// root CMakeLists.txt, CMakePresets.json, the dot files). Versions come from a *source*, either a
/// git repository whose tags are versions (v1.2.0, 1.2.0) or a directory with one subdirectory per
/// version.
namespace breeze::sdk
{
class Source
{
public:
struct Entry
{
Version version;
/// The tag, or the directory name, it was found under.
std::string ref;
};
/// The configured source (`breeze config sdk-source`, or BREEZE_SDK_SOURCE); throws Error
/// when there is none.
static Source configured();
explicit Source(std::string location);
[[nodiscard]] const std::string& location() const { return m_location; }
/// All versions, oldest first.
[[nodiscard]] std::vector<Entry> versions() const;
/// The files of one version, fetched into the CLI's cache on first use.
[[nodiscard]] std::filesystem::path snapshot(const Entry& entry) const;
/// "latest" (or nothing), or a version number: the matching entry. Throws Error, listing
/// what exists, when there is no such version.
[[nodiscard]] Entry resolve(const std::optional<std::string>& wanted) const;
private:
std::string m_location;
bool m_isRepository = false;
};
/// Creates ./<name> from an SDK version: a project with that SDK, the settings set to the new
/// project's name and id, no demo modules, and one executable module named after the project.
void createProject(const std::string& name, const std::optional<std::string>& id,
const std::optional<std::string>& sdkVersion);
/// Reports which SDK versions exist and whether the project is behind.
void update(const Project& project);
/// Moves the project to the newest version with the same major as its own.
void upgrade(const Project& project);
/// Moves the project to exactly this version, whichever way and across majors, and a legacy
/// (flat) project to the breeze/ layout.
void migrate(const Project& project, const std::string& version);
}