feat(ide): package the VS Code extension as a VSIX
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 8s
VoidBuildSystem CI / sanitizers-gcc16 (push) Failing after 6s
VoidBuildSystem CI / fuzz-clang (push) Failing after 6s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 11s
VoidBuildSystem CI / wine-windows-gcc16 (push) Failing after 48s
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 8s
VoidBuildSystem CI / sanitizers-gcc16 (push) Failing after 6s
VoidBuildSystem CI / fuzz-clang (push) Failing after 6s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 11s
VoidBuildSystem CI / wine-windows-gcc16 (push) Failing after 48s
This commit is contained in:
1 parent
3f5b21a570
commit
f032c9f7fe
10 files changed
+269
-74
No files matched your search
@@ -1,6 +1,7 @@
|
||||
#include <Void/Build/BootstrapConfig.hpp>
|
||||
#include <Void/Build/Editor/CompDb.hpp>
|
||||
|
||||
#include <Void/Build/Package/Archive.hpp>
|
||||
#include <Void/Build/Platform/FileOps.hpp>
|
||||
#include <Void/Build/Util/Json.hpp>
|
||||
#include <Void/Build/Util/Sha256.hpp>
|
||||
@@ -1451,6 +1452,65 @@ console.log('extension tests passed: ' + terminals.length + ' commands');
|
||||
return std::unexpected{written.error()};
|
||||
}
|
||||
}
|
||||
|
||||
// Optional VSIX package: a ZIP that `code --install-extension` accepts.
|
||||
if (options.vsix_path) {
|
||||
const std::string vsix_manifest =
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
|
||||
"<PackageManifest Version=\"2.0.0\" "
|
||||
"xmlns=\"http://schemas.microsoft.com/developer/vsx-schema/2011\">\n"
|
||||
" <Metadata>\n"
|
||||
" <Identity Language=\"en-US\" Id=\"vbs-tools\" Version=\"0.1.0\" "
|
||||
"Publisher=\"void\" />\n"
|
||||
" <DisplayName>VoidBuildSystem</DisplayName>\n"
|
||||
" <Description xml:space=\"preserve\">Build, test, install and package with "
|
||||
"VoidBuildSystem.</Description>\n"
|
||||
" <Tags>vbs</Tags>\n"
|
||||
" <Categories>Other</Categories>\n"
|
||||
" <GalleryFlags>Public</GalleryFlags>\n"
|
||||
" </Metadata>\n"
|
||||
" <Installation>\n"
|
||||
" <InstallationTarget Id=\"Microsoft.VisualStudio.Code\" />\n"
|
||||
" </Installation>\n"
|
||||
" <Dependencies />\n"
|
||||
" <Assets>\n"
|
||||
" <Asset Type=\"Microsoft.VisualStudio.Code.Manifest\" "
|
||||
"Path=\"extension/package.json\" Addressable=\"true\" />\n"
|
||||
" </Assets>\n"
|
||||
"</PackageManifest>\n";
|
||||
const std::string content_types =
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
|
||||
"<Types xmlns=\"http://schemas.openxmlformats.org/package/2006/content-types\">\n"
|
||||
" <Default Extension=\".json\" ContentType=\"application/json\" />\n"
|
||||
" <Default Extension=\".js\" ContentType=\"application/javascript\" />\n"
|
||||
" <Default Extension=\".md\" ContentType=\"text/markdown\" />\n"
|
||||
" <Default Extension=\".vsixmanifest\" ContentType=\"text/xml\" />\n"
|
||||
" <Default Extension=\".xml\" ContentType=\"text/xml\" />\n"
|
||||
"</Types>\n";
|
||||
const auto manifest_path = output / ".vsix" / "extension.vsixmanifest";
|
||||
const auto types_path = output / ".vsix" / "[Content_Types].xml";
|
||||
if (auto written = Platform::atomic_write_file(manifest_path, vsix_manifest, true);
|
||||
!written) {
|
||||
return std::unexpected{written.error()};
|
||||
}
|
||||
if (auto written = Platform::atomic_write_file(types_path, content_types, true); !written) {
|
||||
return std::unexpected{written.error()};
|
||||
}
|
||||
std::vector<Package::ArchiveEntrySpec> vsix_entries{
|
||||
{"extension.vsixmanifest", manifest_path, 0644u},
|
||||
{"[Content_Types].xml", types_path, 0644u}};
|
||||
for (const auto &name :
|
||||
{"package.json", "extension.js", "README.md", "test/extension.test.js"}) {
|
||||
vsix_entries.push_back({std::string{"extension/"} + name, output / name, 0644u});
|
||||
}
|
||||
if (options.vsix_path->has_parent_path()) {
|
||||
std::filesystem::create_directories(options.vsix_path->parent_path(), ec);
|
||||
}
|
||||
if (auto zipped = Package::create_stored_zip(*options.vsix_path, vsix_entries); !zipped) {
|
||||
return std::unexpected{zipped.error()};
|
||||
}
|
||||
std::filesystem::remove_all(output / ".vsix", ec);
|
||||
}
|
||||
return report;
|
||||
}
|
||||
|
||||
|
||||
@@ -95,79 +95,6 @@ std::uint32_t crc32_bytes(std::string_view data) {
|
||||
return crc ^ 0xFFFFFFFFu;
|
||||
}
|
||||
|
||||
// Stored (uncompressed) deterministic ZIP archive of the installed files.
|
||||
Void::Result::Result<void, Void::Result::Error>
|
||||
write_stored_zip(const std::filesystem::path &output,
|
||||
const std::vector<Package::ArchiveEntrySpec> &entries) {
|
||||
struct Record {
|
||||
std::string name;
|
||||
std::uint32_t crc{0};
|
||||
std::uint32_t size{0};
|
||||
std::uint32_t offset{0};
|
||||
std::uint32_t mode{0644};
|
||||
};
|
||||
std::string local;
|
||||
std::vector<Record> records;
|
||||
for (const auto &entry : entries) {
|
||||
auto content = Void::FileSystem::read_file(entry.source_file);
|
||||
if (!content) {
|
||||
return std::unexpected{content.error()};
|
||||
}
|
||||
const auto crc = crc32_bytes(*content);
|
||||
const auto size = static_cast<std::uint32_t>(content->size());
|
||||
records.push_back(
|
||||
{entry.archive_path, crc, size, static_cast<std::uint32_t>(local.size()), entry.mode});
|
||||
put_u32(local, 0x04034b50u);
|
||||
put_u16(local, 20); // version needed
|
||||
put_u16(local, 0); // flags
|
||||
put_u16(local, 0); // stored
|
||||
put_u16(local, 0); // time
|
||||
put_u16(local, 0x21); // 1980-01-01
|
||||
put_u32(local, crc);
|
||||
put_u32(local, size);
|
||||
put_u32(local, size);
|
||||
put_u16(local, static_cast<std::uint16_t>(entry.archive_path.size()));
|
||||
put_u16(local, 0); // extra
|
||||
local += entry.archive_path;
|
||||
local += *content;
|
||||
}
|
||||
|
||||
std::string central;
|
||||
for (const auto &record : records) {
|
||||
put_u32(central, 0x02014b50u);
|
||||
put_u16(central, 0x031e); // made by UNIX
|
||||
put_u16(central, 20);
|
||||
put_u16(central, 0);
|
||||
put_u16(central, 0);
|
||||
put_u16(central, 0);
|
||||
put_u16(central, 0x21);
|
||||
put_u32(central, record.crc);
|
||||
put_u32(central, record.size);
|
||||
put_u32(central, record.size);
|
||||
put_u16(central, static_cast<std::uint16_t>(record.name.size()));
|
||||
put_u16(central, 0); // extra
|
||||
put_u16(central, 0); // comment
|
||||
put_u16(central, 0); // disk
|
||||
put_u16(central, 0); // internal attrs
|
||||
put_u32(central, (record.mode & 0777u) << 16);
|
||||
put_u32(central, record.offset);
|
||||
central += record.name;
|
||||
}
|
||||
|
||||
std::string eocd;
|
||||
put_u32(eocd, 0x06054b50u);
|
||||
put_u16(eocd, 0);
|
||||
put_u16(eocd, 0);
|
||||
put_u16(eocd, static_cast<std::uint16_t>(records.size()));
|
||||
put_u16(eocd, static_cast<std::uint16_t>(records.size()));
|
||||
put_u32(eocd, static_cast<std::uint32_t>(central.size()));
|
||||
put_u32(eocd, static_cast<std::uint32_t>(local.size()));
|
||||
put_u16(eocd, 0);
|
||||
|
||||
std::string zip = local + central + eocd;
|
||||
return Platform::atomic_write_file(output, zip, true);
|
||||
}
|
||||
|
||||
std::string ar_member_header(std::string_view name, std::uint64_t size) {
|
||||
std::string header;
|
||||
std::string padded_name{name};
|
||||
@@ -1132,7 +1059,8 @@ install_project(const Graph::ProjectDescription &description, const Graph::Build
|
||||
}
|
||||
|
||||
if (options.archive_format == "zip") {
|
||||
if (auto zipped = write_stored_zip(*options.archive_path, archive_entries); !zipped) {
|
||||
if (auto zipped = Package::create_stored_zip(*options.archive_path, archive_entries);
|
||||
!zipped) {
|
||||
return std::unexpected{zipped.error()};
|
||||
}
|
||||
} else if (options.archive_format == "deb") {
|
||||
|
||||
@@ -3292,6 +3292,7 @@ struct IdeCmdOptions {
|
||||
std::optional<std::string> compiler_arg;
|
||||
std::string editor_name{"all"};
|
||||
std::optional<std::string> plugin_output_arg;
|
||||
std::optional<std::string> plugin_vsix_arg;
|
||||
bool force{false};
|
||||
};
|
||||
|
||||
@@ -3320,6 +3321,13 @@ int execute_ide_command(std::string_view sub, const IdeCmdOptions &opts) {
|
||||
plugin_opts.editor = ide_kind;
|
||||
plugin_opts.output_dir = *opts.plugin_output_arg;
|
||||
plugin_opts.force = opts.force;
|
||||
if (opts.plugin_vsix_arg) {
|
||||
if (ide_kind != Editor::IdeKind::VsCode) {
|
||||
std::cerr << "vbs ide plugin: --vsix is only supported for vscode\n";
|
||||
return 2;
|
||||
}
|
||||
plugin_opts.vsix_path = *opts.plugin_vsix_arg;
|
||||
}
|
||||
if (auto exe = Platform::current_executable_path(); exe) {
|
||||
plugin_opts.vbs_executable = *exe;
|
||||
}
|
||||
@@ -4006,6 +4014,8 @@ int main(int argc, char **argv) {
|
||||
ide_plugin_cmd
|
||||
.option_default("--editor", "-e", "Editor preset (vscode)", ide_opts.editor_name, "vscode")
|
||||
.option("--output", "-o", "Output directory", ide_opts.plugin_output_arg)
|
||||
.option("--vsix", "", "Package the VS Code extension as a .vsix (ZIP)",
|
||||
ide_opts.plugin_vsix_arg)
|
||||
.flag("--force", "", "Overwrite existing plugin files", ide_opts.force);
|
||||
auto &ide_gen_cmd =
|
||||
ide_cmd.subcommand("generate", "Generate .clangd, .vscode/, .zed/, and .idea/ IDE configs");
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <Void/System/Types.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <format>
|
||||
#include <set>
|
||||
|
||||
@@ -118,6 +119,111 @@ create_source_package(const std::filesystem::path &project_root,
|
||||
return create_deterministic_tar(output_tar, std::move(entries), reproducibility_epoch);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
void zip_put_u16(std::string &out, std::uint16_t value) {
|
||||
out.push_back(static_cast<char>(value & 0xFFu));
|
||||
out.push_back(static_cast<char>((value >> 8) & 0xFFu));
|
||||
}
|
||||
|
||||
void zip_put_u32(std::string &out, std::uint32_t value) {
|
||||
for (int shift = 0; shift < 32; shift += 8) {
|
||||
out.push_back(static_cast<char>((value >> shift) & 0xFFu));
|
||||
}
|
||||
}
|
||||
|
||||
std::uint32_t zip_crc32(std::string_view data) {
|
||||
static const auto table = [] {
|
||||
std::array<std::uint32_t, 256> t{};
|
||||
for (std::uint32_t i = 0; i < 256; ++i) {
|
||||
std::uint32_t c = i;
|
||||
for (int k = 0; k < 8; ++k) {
|
||||
c = (c & 1u) != 0u ? (0xEDB88320u ^ (c >> 1)) : (c >> 1);
|
||||
}
|
||||
t[i] = c;
|
||||
}
|
||||
return t;
|
||||
}();
|
||||
std::uint32_t crc = 0xFFFFFFFFu;
|
||||
for (const char ch : data) {
|
||||
crc = table[(crc ^ static_cast<std::uint8_t>(ch)) & 0xFFu] ^ (crc >> 8);
|
||||
}
|
||||
return crc ^ 0xFFFFFFFFu;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Void::Result::Result<void, Void::Result::Error>
|
||||
create_stored_zip(const std::filesystem::path &output_zip,
|
||||
const std::vector<ArchiveEntrySpec> &entries) {
|
||||
struct Record {
|
||||
std::string name;
|
||||
std::uint32_t crc{0};
|
||||
std::uint32_t size{0};
|
||||
std::uint32_t offset{0};
|
||||
std::uint32_t mode{0644};
|
||||
};
|
||||
std::string local;
|
||||
std::vector<Record> records;
|
||||
for (const auto &entry : entries) {
|
||||
auto content = Void::FileSystem::read_file(entry.source_file);
|
||||
if (!content) {
|
||||
return std::unexpected{content.error()};
|
||||
}
|
||||
const auto crc = zip_crc32(*content);
|
||||
const auto size = static_cast<std::uint32_t>(content->size());
|
||||
records.push_back(
|
||||
{entry.archive_path, crc, size, static_cast<std::uint32_t>(local.size()), entry.mode});
|
||||
zip_put_u32(local, 0x04034b50u);
|
||||
zip_put_u16(local, 20); // version needed
|
||||
zip_put_u16(local, 0); // flags
|
||||
zip_put_u16(local, 0); // stored
|
||||
zip_put_u16(local, 0); // time
|
||||
zip_put_u16(local, 0x21); // 1980-01-01
|
||||
zip_put_u32(local, crc);
|
||||
zip_put_u32(local, size);
|
||||
zip_put_u32(local, size);
|
||||
zip_put_u16(local, static_cast<std::uint16_t>(entry.archive_path.size()));
|
||||
zip_put_u16(local, 0); // extra
|
||||
local += entry.archive_path;
|
||||
local += *content;
|
||||
}
|
||||
|
||||
std::string central;
|
||||
for (const auto &record : records) {
|
||||
zip_put_u32(central, 0x02014b50u);
|
||||
zip_put_u16(central, 0x031e); // made by UNIX
|
||||
zip_put_u16(central, 20);
|
||||
zip_put_u16(central, 0);
|
||||
zip_put_u16(central, 0);
|
||||
zip_put_u16(central, 0);
|
||||
zip_put_u16(central, 0x21);
|
||||
zip_put_u32(central, record.crc);
|
||||
zip_put_u32(central, record.size);
|
||||
zip_put_u32(central, record.size);
|
||||
zip_put_u16(central, static_cast<std::uint16_t>(record.name.size()));
|
||||
zip_put_u16(central, 0); // extra
|
||||
zip_put_u16(central, 0); // comment
|
||||
zip_put_u16(central, 0); // disk
|
||||
zip_put_u16(central, 0); // internal attrs
|
||||
zip_put_u32(central, (record.mode & 0777u) << 16);
|
||||
zip_put_u32(central, record.offset);
|
||||
central += record.name;
|
||||
}
|
||||
|
||||
std::string eocd;
|
||||
zip_put_u32(eocd, 0x06054b50u);
|
||||
zip_put_u16(eocd, 0);
|
||||
zip_put_u16(eocd, 0);
|
||||
zip_put_u16(eocd, static_cast<std::uint16_t>(records.size()));
|
||||
zip_put_u16(eocd, static_cast<std::uint16_t>(records.size()));
|
||||
zip_put_u32(eocd, static_cast<std::uint32_t>(central.size()));
|
||||
zip_put_u32(eocd, static_cast<std::uint32_t>(local.size()));
|
||||
zip_put_u16(eocd, 0);
|
||||
|
||||
return Platform::atomic_write_file(output_zip, local + central + eocd, true);
|
||||
}
|
||||
|
||||
Void::Result::Result<ArchiveExtractionStats, Void::Result::Error>
|
||||
extract_safe_tar(const std::filesystem::path &tar_path,
|
||||
const std::filesystem::path &destination_dir, const ArchiveLimits &limits) {
|
||||
|
||||
Reference in new issue
Block a user