Skip to content

Commit

Permalink
Merge pull request #1460 from Sonicadvance1/FEXRootFSFetcher
Browse files Browse the repository at this point in the history
FEXRootFSFetcher: Adds a new tool to help set up a new RootFS
  • Loading branch information
Sonicadvance1 authored Dec 25, 2021
2 parents 8f83567 + 2c31080 commit 72e8a99
Show file tree
Hide file tree
Showing 8 changed files with 1,024 additions and 23 deletions.
39 changes: 39 additions & 0 deletions Source/Common/Config.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include "Common/ArgumentLoader.h"
#include "Common/Config.h"

#include <FEXCore/Config/Config.h>

#include <cstring>
#include <filesystem>
#include <fstream>
#include <map>
#include <list>
Expand Down Expand Up @@ -38,4 +40,41 @@ namespace FEX::Config {
}
}

std::string LoadConfig(
bool NoFEXArguments,
bool LoadProgramConfig,
int argc,
char **argv,
char **const envp) {
FEXCore::Config::Initialize();
FEXCore::Config::AddLayer(FEXCore::Config::CreateMainLayer());

if (NoFEXArguments) {
FEX::ArgLoader::LoadWithoutArguments(argc, argv);
}
else {
FEXCore::Config::AddLayer(std::make_unique<FEX::ArgLoader::ArgLoader>(argc, argv));
}

FEXCore::Config::AddLayer(FEXCore::Config::CreateEnvironmentLayer(envp));
FEXCore::Config::Load();

auto Args = FEX::ArgLoader::Get();

if (LoadProgramConfig) {
if (Args.empty()) {
// Early exit if we weren't passed an argument
return {};
}

std::string Program = Args[0];

// These layers load on initialization
auto ProgramName = std::filesystem::path(Program).filename();
FEXCore::Config::AddLayer(FEXCore::Config::CreateAppLayer(ProgramName, true));
FEXCore::Config::AddLayer(FEXCore::Config::CreateAppLayer(ProgramName, false));
return Program;
}
return {};
}
}
8 changes: 8 additions & 0 deletions Source/Common/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,12 @@ namespace FEX::Config {
};

void SaveLayerToJSON(const std::string& Filename, FEXCore::Config::Layer *const Layer);

std::string LoadConfig(
bool NoFEXArguments,
bool LoadProgramConfig,
int argc,
char **argv,
char **const envp
);
}
33 changes: 10 additions & 23 deletions Source/Tests/FEXLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,33 +234,19 @@ int main(int argc, char **argv, char **const envp) {
}
#endif

FEXCore::Config::Initialize();
FEXCore::Config::AddLayer(FEXCore::Config::CreateMainLayer());
auto Program = FEX::Config::LoadConfig(
IsInterpreter,
true,
argc, argv, envp
);

if (IsInterpreter) {
FEX::ArgLoader::LoadWithoutArguments(argc, argv);
}
else {
FEXCore::Config::AddLayer(std::make_unique<FEX::ArgLoader::ArgLoader>(argc, argv));
}

FEXCore::Config::AddLayer(FEXCore::Config::CreateEnvironmentLayer(envp));
FEXCore::Config::Load();

auto Args = FEX::ArgLoader::Get();
auto ParsedArgs = FEX::ArgLoader::GetParsedArgs();

if (Args.empty()) {
if (Program.empty()) {
// Early exit if we weren't passed an argument
return 0;
}

std::string Program = Args[0];

// These layers load on initialization
auto ProgramName = std::filesystem::path(Program).filename();
FEXCore::Config::AddLayer(FEXCore::Config::CreateAppLayer(ProgramName, true));
FEXCore::Config::AddLayer(FEXCore::Config::CreateAppLayer(ProgramName, false));
auto Args = FEX::ArgLoader::Get();
auto ParsedArgs = FEX::ArgLoader::GetParsedArgs();

// Reload the meta layer
FEXCore::Config::ReloadMetaLayer();
Expand Down Expand Up @@ -367,6 +353,7 @@ int main(int argc, char **argv, char **const envp) {
if (LDPath().empty() ||
std::filesystem::exists(LDPath(), ec) == false) {
fmt::print(stderr, "RootFS path doesn't exist. This is required on AArch64 hosts\n");
fmt::print(stderr, "Use FEXRootFSFetcher to download a RootFS\n");
}
#endif
return -ENOEXEC;
Expand Down Expand Up @@ -552,7 +539,7 @@ int main(int argc, char **argv, char **const envp) {
FEXCore::Allocator::ClearHooks();
FEXCore::Allocator::ReclaimMemoryRegion(Base48Bit);
// Allocator is now original system allocator

auto ProgramName = std::filesystem::path(Program).filename();
FEXCore::Telemetry::Shutdown(ProgramName);
if (ShutdownReason == FEXCore::Context::ExitReason::EXIT_SHUTDOWN) {
return ProgramStatus;
Expand Down
1 change: 1 addition & 0 deletions Source/Tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ add_subdirectory(FEXConfig/)
add_subdirectory(FEXGetConfig/)
add_subdirectory(FEXMountDaemon/)
add_subdirectory(FEXLogServer/)
add_subdirectory(FEXRootFSFetcher/)

set(NAME Opt)
set(SRCS Opt.cpp)
Expand Down
24 changes: 24 additions & 0 deletions Source/Tools/FEXRootFSFetcher/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
set(NAME FEXRootFSFetcher)
set(SRCS Main.cpp
XXFileHash.cpp)

add_executable(${NAME} ${SRCS})
list(APPEND LIBS FEXCore Common CommonCore)

target_include_directories(${NAME} PRIVATE ${CMAKE_SOURCE_DIR}/Source/)

if (CMAKE_BUILD_TYPE MATCHES "RELEASE")
target_link_options(${NAME}
PRIVATE
"LINKER:--gc-sections"
"LINKER:--strip-all"
"LINKER:--as-needed"
)
endif()

install(TARGETS ${NAME}
RUNTIME
DESTINATION bin
COMPONENT runtime)

target_link_libraries(${NAME} PRIVATE ${LIBS} ${STATIC_PIE_OPTIONS} ${PTHREAD_LIB})
Loading

0 comments on commit 72e8a99

Please sign in to comment.