Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ if(ONE_INDEX)
add_subdirectory(src/resolver)
add_subdirectory(src/html)
add_subdirectory(src/web)
add_subdirectory(src/pkg)
add_subdirectory(src/index)
add_subdirectory(collections)
add_dependencies(sourcemeta_one_index
Expand Down
3 changes: 2 additions & 1 deletion src/index/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ sourcemeta_executable(NAMESPACE sourcemeta PROJECT one NAME index
set_target_properties(sourcemeta_one_index PROPERTIES OUTPUT_NAME sourcemeta-one-index)

target_compile_definitions(sourcemeta_one_index
PRIVATE SOURCEMETA_ONE_COLLECTIONS="${ONE_PREFIX}/share/sourcemeta/one/collections")
PRIVATE SOURCEMETA_ONE_DATA_DIRECTORY="${ONE_PREFIX}/share/sourcemeta/one")

target_link_libraries(sourcemeta_one_index PRIVATE sourcemeta::one::resolver)
target_link_libraries(sourcemeta_one_index PRIVATE sourcemeta::one::shared)
target_link_libraries(sourcemeta_one_index PRIVATE sourcemeta::one::configuration)
target_link_libraries(sourcemeta_one_index PRIVATE sourcemeta::one::web)
target_link_libraries(sourcemeta_one_index PRIVATE sourcemeta::one::pkg)

target_link_libraries(sourcemeta_one_index PRIVATE sourcemeta::core::build)
target_link_libraries(sourcemeta_one_index PRIVATE sourcemeta::core::uri)
Expand Down
52 changes: 51 additions & 1 deletion src/index/index.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <sourcemeta/core/uri.h>

#include <sourcemeta/one/configuration.h>
#include <sourcemeta/one/pkg.h>
#include <sourcemeta/one/resolver.h>
#include <sourcemeta/one/shared.h>
#include <sourcemeta/one/web.h>
Expand Down Expand Up @@ -40,6 +41,9 @@ static auto attribute_not_disabled(
collection.extra.at(property).to_boolean();
}

static const std::filesystem::path DATA_DIRECTORY{
SOURCEMETA_ONE_DATA_DIRECTORY};

static auto print_progress(std::mutex &mutex, const std::size_t threads,
const std::string_view title,
const std::string_view prefix,
Expand Down Expand Up @@ -98,7 +102,7 @@ static auto index_main(const std::string_view &program,
std::filesystem::canonical(app.positional().at(0))};
std::cerr << "Using configuration: " << configuration_path.string() << "\n";
const auto raw_configuration{sourcemeta::one::Configuration::read(
configuration_path, SOURCEMETA_ONE_COLLECTIONS)};
configuration_path, DATA_DIRECTORY / "collections")};

if (app.contains("verbose")) {
sourcemeta::core::prettify(raw_configuration, std::cerr);
Expand Down Expand Up @@ -235,6 +239,7 @@ static auto index_main(const std::string_view &program,
constexpr auto THREAD_STACK_SIZE{8 * 1024 * 1024};

const auto explorer_path{output.path() / "explorer"};

sourcemeta::core::parallel_for_each(
resolver.begin(), resolver.end(),
[&output, &schemas_path, &explorer_path, &resolver, &mutex, &adapter,
Expand Down Expand Up @@ -470,6 +475,51 @@ static auto index_main(const std::string_view &program,
concurrency);
}

/////////////////////////////////////////////////////////////////////////////
// (12) Generate integration packages
/////////////////////////////////////////////////////////////////////////////

// TODO: Determine from the configuration file
const auto generate_package{true};

if (generate_package) {
const auto pkg_path{output.path() / "pkg"};
// TODO: Only if "pkg" is set?
sourcemeta::core::parallel_for_each(
resolver.begin(), resolver.end(),
[&output, &schemas_path, &resolver, &mutex, &adapter,
&mark_version_path,
&pkg_path](const auto &schema, const auto threads, const auto cursor) {
print_progress(mutex, threads, "Packaging", schema.first, cursor,
resolver.size());
// TODO: Test overlaps here?
// TODO: Maybe indeed keep the same SENTINEL structure, and deal with
// it by always exposing a resolve() for the URI that gets you the
// schema and TS type? The resolve signature itself on TS can be an
// enum of all valid URIs
DISPATCH<sourcemeta::one::GENERATE_PKG_EXTRACT_JSON>(
pkg_path / (schema.second.relative_path.string() + ".json"),
{schemas_path / schema.second.relative_path / SENTINEL /
"bundle.metapack",
mark_version_path},
resolver, mutex, "Packaging", schema.first, "bundle", adapter,
output);
},
concurrency, THREAD_STACK_SIZE);

DISPATCH<sourcemeta::one::GENERATE_PKG_COPY_FILE>(
pkg_path / ".npmignore",
{DATA_DIRECTORY / "pkg" / "npm" / "npmignore", mark_version_path},
resolver, mutex, "Packaging", "npm", "npmignore", adapter, output);

// TODO: Also do this with a dispatch that takes base and just fills in some
// details
auto manifest_npm{sourcemeta::core::JSON::make_object()};
manifest_npm.assign("name", sourcemeta::core::JSON{"XXXXXXXX"});
manifest_npm.assign("version", sourcemeta::core::JSON{"0.0.0"});
output.write_json_if_different(pkg_path / "package.json", manifest_npm);
}

// TODO: Print the size of the output directory here

output.remove_unknown_files();
Expand Down
15 changes: 15 additions & 0 deletions src/pkg/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
sourcemeta_library(NAMESPACE sourcemeta PROJECT one NAME pkg
SOURCES pkg.cc)

target_link_libraries(sourcemeta_one_pkg PUBLIC sourcemeta::core::build)
target_link_libraries(sourcemeta_one_pkg PRIVATE sourcemeta::core::json)
target_link_libraries(sourcemeta_one_pkg PUBLIC sourcemeta::one::resolver)
target_link_libraries(sourcemeta_one_pkg PUBLIC sourcemeta::one::configuration)
target_link_libraries(sourcemeta_one_pkg PRIVATE sourcemeta::one::shared)

install(FILES npm/npmignore
DESTINATION "${CMAKE_INSTALL_DATADIR}/sourcemeta/one/pkg/npm"
COMPONENT sourcemeta_one)

target_sources(sourcemeta_one_pkg PRIVATE
npm/npmignore)
34 changes: 34 additions & 0 deletions src/pkg/include/sourcemeta/one/pkg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef SOURCEMETA_ONE_PKG_H_
#define SOURCEMETA_ONE_PKG_H_

#include <sourcemeta/core/build.h>
#include <sourcemeta/one/configuration.h>
#include <sourcemeta/one/resolver.h>

#include <filesystem> // std::filesystem

namespace sourcemeta::one {

struct GENERATE_PKG_EXTRACT_JSON {
using Context = sourcemeta::one::Resolver;
static auto
handler(const std::filesystem::path &destination,
const sourcemeta::core::BuildDependencies<std::filesystem::path>
&dependencies,
const sourcemeta::core::BuildDynamicCallback<std::filesystem::path> &,
const Context &resolver) -> void;
};

struct GENERATE_PKG_COPY_FILE {
using Context = sourcemeta::one::Resolver;
static auto
handler(const std::filesystem::path &destination,
const sourcemeta::core::BuildDependencies<std::filesystem::path>
&dependencies,
const sourcemeta::core::BuildDynamicCallback<std::filesystem::path> &,
const Context &resolver) -> void;
};

} // namespace sourcemeta::one

#endif
1 change: 1 addition & 0 deletions src/pkg/npm/npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.deps
36 changes: 36 additions & 0 deletions src/pkg/pkg.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <sourcemeta/one/pkg.h>

#include <sourcemeta/one/shared.h>

#include <cassert> // assert
#include <fstream> // std::ofstream

namespace sourcemeta::one {

auto GENERATE_PKG_EXTRACT_JSON::handler(
const std::filesystem::path &destination,
const sourcemeta::core::BuildDependencies<std::filesystem::path>
&dependencies,
const sourcemeta::core::BuildDynamicCallback<std::filesystem::path> &,
const Context &) -> void {
auto document{sourcemeta::one::read_json(dependencies.front())};
assert(destination.is_absolute());
std::filesystem::create_directories(destination.parent_path());
std::ofstream stream{destination};
assert(!stream.fail());
sourcemeta::core::prettify(document, stream);
}

auto GENERATE_PKG_COPY_FILE::handler(
const std::filesystem::path &destination,
const sourcemeta::core::BuildDependencies<std::filesystem::path>
&dependencies,
const sourcemeta::core::BuildDynamicCallback<std::filesystem::path> &,
const Context &) -> void {
assert(destination.is_absolute());
std::filesystem::create_directories(destination.parent_path());
std::filesystem::copy_file(dependencies.front(), destination,
std::filesystem::copy_options::overwrite_existing);
}

} // namespace sourcemeta::one
1 change: 1 addition & 0 deletions src/shared/include/sourcemeta/one/shared_metapack.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ auto write_json(const std::filesystem::path &destination,
const sourcemeta::core::JSON &extension,
const std::chrono::milliseconds duration) -> void;

// TODO: This doesn't do anything anymore, as we have `.format()`. Delete it
auto write_pretty_json(const std::filesystem::path &destination,
const sourcemeta::core::JSON &document,
const sourcemeta::core::JSON::String &mime,
Expand Down
Loading
Loading