Skip to content

Commit

Permalink
feat: an option to mount host folders
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx committed Sep 30, 2024
1 parent 90a3fce commit b360aa6
Show file tree
Hide file tree
Showing 14 changed files with 211 additions and 129 deletions.
4 changes: 4 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
BasedOnStyle: Chromium
BreakBeforeBraces: Stroustrup
SortIncludes: Never
ColumnLimit: 120
2 changes: 1 addition & 1 deletion .github/workflows/alpine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ concurrency:
cancel-in-progress: true

env:
CACHE_VER: 06
CACHE_VER: 10
TZ: "Etc/UTC"
VERBOSE: no

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gem-test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ concurrency:
cancel-in-progress: true

env:
CACHE_VER: 08
CACHE_VER: 10
DEBIAN_FRONTEND: "noninteractive"
TZ: "Etc/UTC"
# show cmake output
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/lint-and-rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,23 @@ jobs:
env:
SHELLCHECK_OPTS: -x

clang-format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: DoozyX/clang-format-lint-action@master
with:
source: 'src'
extensions: 'h,cpp,c'
clangFormatVersion: 14
# inplace: True
# - name: Commit changes
# uses: EndBug/add-and-commit@v9
# with:
# message: clang-format fixes
# committer_name: GitHub Actions
#"" committer_email: [email protected]

rubocop:
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ concurrency:
cancel-in-progress: true

env:
CACHE_VER: 08
CACHE_VER: 10
VERBOSE: no

jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ concurrency:
cancel-in-progress: true

env:
CACHE_VER: 06
CACHE_VER: 10
DEBIAN_FRONTEND: "noninteractive"
TZ: "Etc/UTC"
# show cmake output (yes/no)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows-msys.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ concurrency:
cancel-in-progress: true

env:
CACHE_VER: 04
CACHE_VER: 10
VERBOSE: no

jobs:
Expand Down
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ string(CONCAT RUBY_API_VER ${RUBY_VER_BASE} ".0")
# list(GET LIBDWARFS_WR_VER_COMPONENTS 2 LIBDWARFS_WR_VER_PATCH)
# set (LIBDWARFS_WR_VER_M ${LIBDWARFS_WR_VER_MAJOR}.${LIBDWARFS_WR_VER_MINOR}.${LIBDWARFS_WR_VER_PATCH})
#else(DWARFS_PRELOAD)
def_ext_prj_g(DWARFS_WR "v0.5.9")
def_ext_prj_g(DWARFS_WR "v0.7.1")
#endif(DWARFS_PRELOAD)

def_ext_prj_g(PATCHELF "65e14792061c298f1d2bc44becd48a10cbf0bc81")
Expand Down Expand Up @@ -436,6 +436,10 @@ else (${SETUP_MODE})
DEPENDS ${DWARFS_WR_PRJ} ${RUBY_PRJ}
)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

file(GLOB GEMSPECS LIST_DIRECTORIES false ${FS_ROOT}/*.gemspec)
file(GLOB GEMFILES LIST_DIRECTORIES false ${FS_ROOT}/Gemfile)
file(GLOB GEMS LIST_DIRECTORIES false ${FS_ROOT}/*.gem)
Expand Down
2 changes: 1 addition & 1 deletion common.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BUILD_TYPE=Release
DEPS=deps
INCBIN_TAG=348e36b
DWARFS_WR_TAG=v0.5.9
DWARFS_WR_TAG=v0.7.1
RUBY_VER=3.2.5
6 changes: 4 additions & 2 deletions lib/tebako/packager/patch_libraries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ class << self
DARWIN_DEP_LIBS_2 = ["glog", "gflags", "brotlienc", "brotlidec", "brotlicommon", "fmt"].freeze
# rubocop:enable Style/WordArray

LIBTEBAKOFS = "-Wl,--push-state,--whole-archive -l:libtebako-fs.a -Wl,--pop-state"

COMMON_LINUX_LIBRARIES = [
"-l:libdwarfs-wr.a", "-l:libtebako-fs.a", "-l:libdwarfs.a", "LIBCOMPRESSION",
LIBTEBAKOFS, "-l:libdwarfs-wr.a", "-l:libdwarfs.a", "LIBCOMPRESSION",
"-l:libfolly.a", "-l:libfsst.a", "-l:libmetadata_thrift.a", "-l:libthrift_light.a",
"-l:libxxhash.a", "-l:libfmt.a", "-l:libdouble-conversion.a", "-l:libglog.a",
"-l:libgflags.a", "-l:libevent.a"
Expand Down Expand Up @@ -80,7 +82,7 @@ class << self
MSYS_LIBRARIES = [
"-l:liblz4.a", "-l:libz.a", "-l:libzstd.a", "-l:liblzma.a",
"-l:libncurses.a", "-l:libunwind.a", "-l:liblzma.a", "-l:libiberty.a",
"LIBYAML", "-l:libffi.a", "-l:libboost_system-mt.a", "-l:libboost_chrono-mt.a",
"LIBYAML", "-l:libffi.a", "-l:libboost_chrono-mt.a", # "-l:libboost_system-mt.a",
"-l:libstdc++.a", "-l:libdl.a", "-static-libgcc", "-static-libstdc++",
"-l:libssl.a", "-l:libcrypto.a", "-l:libz.a", "-l:libwinpthread.a",
"-lcrypt32", "-lshlwapi", "-lwsock32", "-liphlpapi",
Expand Down
2 changes: 1 addition & 1 deletion lib/tebako/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
# POSSIBILITY OF SUCH DAMAGE.

module Tebako
VERSION = "0.8.8"
VERSION = "0.9.0"
end
206 changes: 87 additions & 119 deletions src/tebako-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,146 +35,114 @@
#include <sys/stat.h>
#include <fcntl.h>


#include <string>
#include <cstdint>
#include <vector>
#include <stdexcept>
#include <tuple>

#ifdef _WIN32
#include <winsock2.h>
#include <windows.h>
#include <winsock2.h>
#include <windows.h>
#endif


#include <tebako/tebako-config.h>
#include <tebako/tebako-io.h>

#include <tebako/tebako-version.h>
#include <tebako/tebako-main.h>
#include <tebako/tebako-fs.h>
#include <tebako/tebako-cmdline-helpers.h>

static int running_miniruby = 0;

extern "C" int tebako_main(int* argc, char*** argv) {
int ret = -1, fsret = -1;
char** new_argv = NULL;
char* argv_memory = NULL;

if (strstr((*argv)[0], "miniruby") != NULL) {
// Ruby build script is designed in such a way that this patch is also applied towards miniruby
// Just pass through in such case
ret = 0;
running_miniruby = -1;
}
else {
try {
fsret = load_fs(&gfsData[0],
gfsSize,
tebako::fs_log_level,
NULL /* cachesize*/,
NULL /* workers */,
NULL /* mlock */,
NULL /* decompress_ratio*/,
NULL /* image_offset */
);

if (fsret == 0) {
if ((*argc > 1) && strcmp((*argv)[1], "--tebako-extract")==0) {
// ruby -e "require 'fileutils'; FileUtils.copy_entry '<tebako::fs_mount_point>',argv[2] || 'source_filesystem'"
std::string dest = std::string(((*argc) < 3 ? "source_filesystem" : (*argv)[2]));
std::string cmd = std::string("require 'fileutils'; FileUtils.copy_entry '") + (tebako::fs_mount_point) + "', '" + dest + "'";
printf("Extracting tebako image to '%s' \n", dest.c_str());
size_t new_argv_size = 3 + cmd.size() + 1 + strlen((*argv)[0]) + 1;
char** new_argv = new char* [3];
char* argv_memory = new char[new_argv_size];
if (new_argv != NULL && argv_memory != NULL) {
strcpy(argv_memory, (*argv)[0]);
new_argv[0] = argv_memory;
argv_memory += (strlen((*argv)[0]) + 1);
strcpy(argv_memory, "-e");
new_argv[1] = argv_memory;
argv_memory += 3;
strcpy(argv_memory, cmd.c_str());
new_argv[2] = argv_memory;
ret = 0;
*argv = new_argv;
(*argc) = 3;
}
}
else {
size_t new_argv_size = strlen(tebako::fs_mount_point) + strlen(tebako::fs_entry_point) + 1;
for (int i = 0; i < (*argc); i++) {
new_argv_size += (strlen((*argv)[i]) + 1);
}
/* argv memory should be adjacent */
char** new_argv = new char* [(*argc) + 1];
char* argv_memory = new char[new_argv_size];
if (new_argv != NULL && argv_memory != NULL) {
memcpy(argv_memory, (*argv)[0], strlen((*argv)[0]) + 1);
new_argv[0] = argv_memory;
argv_memory += (strlen((*argv)[0]) + 1);
memcpy(argv_memory, tebako::fs_mount_point, strlen(tebako::fs_mount_point));
new_argv[1] = argv_memory;
argv_memory += strlen(tebako::fs_mount_point);
memcpy(argv_memory, tebako::fs_entry_point, strlen(tebako::fs_entry_point) + 1);
argv_memory += (strlen(tebako::fs_entry_point) + 1);
for (int i = 1; i < (*argc); i++) {
memcpy(argv_memory, (*argv)[i], strlen((*argv)[i]) + 1);
new_argv[i+1] = argv_memory;
argv_memory += (strlen((*argv)[i]) + 1);
}
*argv = new_argv;
(*argc) += 1;
ret = 0;
}
}
atexit(drop_fs);
}
}
catch (...) {

}

if (!tebako_is_running_miniruby()) {
if (getcwd(tebako::original_cwd, sizeof(tebako::original_cwd)) == NULL) {
printf("Failed to get current directory: %s\n", strerror(errno));
return -1;
}

if (tebako::needs_cwd) {
if (tebako_chdir(tebako::package_cwd) != 0) {
printf("Failed to chdir to '%s' : %s\n", tebako::package_cwd, strerror(errno));
ret = -1;
}
}
}

if (ret != 0) {
try {
printf("Tebako initialization failed\n");
if (new_argv) delete new_argv;
if (argv_memory) delete argv_memory;
if (fsret == 0) {
drop_fs();
}
}
catch (...) {
// Nested error, no recovery :(
}
}
}
return ret;
extern "C" int tebako_main(int* argc, char*** argv)
{
int ret = -1, fsret = -1;
char** new_argv = nullptr;
char* argv_memory = nullptr;

if (strstr((*argv)[0], "miniruby") != nullptr) {
// Ruby build script is designed in such a way that this patch is also applied towards miniruby
// Just pass through in such case
ret = 0;
running_miniruby = -1;
}
else {
try {
fsret = load_fs(&gfsData[0], gfsSize, tebako::fs_log_level, nullptr /* cachesize*/, nullptr /* workers */,
nullptr /* mlock */, nullptr /* decompress_ratio*/, nullptr /* image_offset */
);

if (fsret == 0) {
if ((*argc > 1) && strcmp((*argv)[1], "--tebako-extract") == 0) {
ret = tebako::build_arguments_for_extract(argc, argv, tebako::fs_mount_point);
}
else {
auto [mountpoints, parsed_argv] = tebako::parse_arguments(*argc, *argv);
// for (auto& mp : mountpoints) {
// printf("Mountpoint: %s\n", mp.c_str());
// }
tebako::process_mountpoints(mountpoints);
std::tie(*argc, *argv) = tebako::build_arguments(parsed_argv, tebako::fs_mount_point, tebako::fs_entry_point);
ret = 0;
}
}
atexit(drop_fs);
}

catch (std::exception e) {
printf("Failed to process command line: %s\n", e.what());
}

if (getcwd(tebako::original_cwd, sizeof(tebako::original_cwd)) == nullptr) {
printf("Failed to get current directory: %s\n", strerror(errno));
ret = -1;
}

if (tebako::needs_cwd) {
if (tebako_chdir(tebako::package_cwd) != 0) {
printf("Failed to chdir to '%s' : %s\n", tebako::package_cwd, strerror(errno));
ret = -1;
}
}
}

if (ret != 0) {
try {
printf("Tebako initialization failed\n");
if (new_argv) {
delete new_argv;
new_argv = nullptr;
}
if (argv_memory) {
delete argv_memory;
argv_memory = nullptr;
}
if (fsret == 0) {
drop_fs();
}
}
catch (...) {
// Nested error, no recovery :(
}
}
return ret;
}

extern "C" const char* tebako_mount_point(void) {
return tebako::fs_mount_point;
extern "C" const char* tebako_mount_point(void)
{
return tebako::fs_mount_point;
}

extern "C" const char* tebako_original_pwd(void) {
return tebako::original_cwd;
extern "C" const char* tebako_original_pwd(void)
{
return tebako::original_cwd;
}

extern "C" int tebako_is_running_miniruby(void) {
return running_miniruby;
extern "C" int tebako_is_running_miniruby(void)
{
return running_miniruby;
}

#ifdef RB_W32_PRE_33
Expand Down
Loading

0 comments on commit b360aa6

Please sign in to comment.