Parcourir la source

Permit either `.json5`, `.jsonc`, or `.json` extensions

default_compile_flags
vector-of-bool il y a 4 ans
Parent
révision
2e4f592d17
4 fichiers modifiés avec 54 ajouts et 28 suppressions
  1. +3
    -5
      src/dds.main.cpp
  2. +32
    -0
      src/dds/package/manifest.cpp
  3. +8
    -0
      src/dds/package/manifest.hpp
  4. +11
    -23
      src/dds/source/dist.cpp

+ 3
- 5
src/dds.main.cpp Voir le fichier

@@ -591,11 +591,9 @@ struct cli_build {
params.out_root = out.Get();
params.toolchain = tc_filepath.get_toolchain();
params.parallel_jobs = n_jobs.Get();
dds::package_manifest man;
const auto man_filepath = project.root.Get() / "package.json5";
if (exists(man_filepath)) {
man = dds::package_manifest::load_from_file(man_filepath);
}

auto man = dds::package_manifest::load_from_directory(project.root.Get())
.value_or(dds::package_manifest{});

dds::builder bd;
dds::sdist_build_params main_params;

+ 32
- 0
src/dds/package/manifest.cpp Voir le fichier

@@ -145,3 +145,35 @@ package_manifest package_manifest::load_from_file(const fs::path& fpath) {

return ret;
}

std::optional<fs::path> package_manifest::find_in_directory(path_ref dirpath) {
auto cands = {
"package.json5",
"package.jsonc",
"package.json",
};
for (auto c : cands) {
auto cand = dirpath / c;
if (fs::is_regular_file(cand)) {
return cand;
}
}

auto dds_fname = dirpath / "package.dds";
if (fs::is_regular_file(dds_fname)) {
return dds_fname;
}
return std::nullopt;
}

std::optional<package_manifest> package_manifest::load_from_directory(path_ref dirpath) {
auto found = find_in_directory(dirpath);
if (!found.has_value()) {
return std::nullopt;
}
if (found->extension() == ".dds") {
return load_from_dds_file(*found);
} else {
return load_from_file(*found);
}
}

+ 8
- 0
src/dds/package/manifest.hpp Voir le fichier

@@ -36,6 +36,14 @@ struct package_manifest {
*/
static package_manifest load_from_file(path_ref);
static package_manifest load_from_dds_file(path_ref);

/**
* Find a package manifest contained within a directory. This will search
* for a few file candidates and return the result from the first matching.
* If none match, it will return nullopt.
*/
static std::optional<fs::path> find_in_directory(path_ref);
static std::optional<package_manifest> load_from_directory(path_ref);
};

} // namespace dds

+ 11
- 23
src/dds/source/dist.cpp Voir le fichier

@@ -88,36 +88,24 @@ sdist dds::create_sdist_in_dir(path_ref out, const sdist_params& params) {
sdist_copy_library(out, lib, params);
}

auto j5_man_path = params.project_dir / "package.json5";
auto dds_man_path = params.project_dir / "package.dds";
package_manifest pkg_man;

if (fs::is_regular_file(j5_man_path)) {
pkg_man = package_manifest::load_from_file(j5_man_path);
sdist_export_file(out, params.project_dir, j5_man_path);
} else if (fs::is_regular_file(dds_man_path)) {
pkg_man = package_manifest::load_from_dds_file(dds_man_path);
sdist_export_file(out, params.project_dir, dds_man_path);
} else {
auto man_path = package_manifest::find_in_directory(params.project_dir);
if (!man_path) {
throw_user_error<errc::invalid_pkg_filesystem>(
"Creating a source distribution requires a package.json5 file for the project "
"(Expected "
"[{}])",
j5_man_path.string());
"(Expected manifest in [{}])",
params.project_dir.string());
}

auto pkg_man = man_path->extension() == ".dds" ? package_manifest::load_from_dds_file(*man_path)
: package_manifest::load_from_file(*man_path);
sdist_export_file(out, params.project_dir, *man_path);
spdlog::info("Generated export as {}", pkg_man.pkg_id.to_string());

return sdist::from_directory(out);
}

sdist sdist::from_directory(path_ref where) {
/// XXX: Remove this logic once package.dds is all gone.
auto j5_path = where / "package.json5";
auto dds_path = where / "package.dds";

// Load based on whichever is actually present
auto pkg_man = fs::is_regular_file(j5_path) ? package_manifest::load_from_file(j5_path)
: package_manifest::load_from_dds_file(dds_path);
return sdist{std::move(pkg_man), where};
auto pkg_man = package_manifest::load_from_directory(where);
// Code paths should only call here if they *know* that the sdist is valid
assert(pkg_man.has_value());
return sdist{pkg_man.value(), where};
}

Chargement…
Annuler
Enregistrer