From d1df773e47c8bedde49572a90a2bb5270c8d7484 Mon Sep 17 00:00:00 2001 From: Vyacheslav Egorov Date: Tue, 2 Apr 2024 21:22:21 +0300 Subject: [PATCH] Testing changes for Android and iOS tests --- CMakeLists.txt | 28 ++++++++--------- tests/RequireByString.test.cpp | 56 ++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e99e931..8246bb4e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -188,6 +188,12 @@ if(MSVC_IDE) target_sources(Luau.VM PRIVATE tools/natvis/VM.natvis) endif() +# On Windows and Android threads are provided, on Linux/Mac/iOS we use pthreads +add_library(osthreads INTERFACE) +if(CMAKE_SYSTEM_NAME MATCHES "Linux|Darwin|iOS") + target_link_libraries(osthreads INTERFACE "-lpthread") +endif () + if(LUAU_BUILD_CLI) target_compile_options(Luau.Repl.CLI PRIVATE ${LUAU_OPTIONS}) target_compile_options(Luau.Reduce.CLI PRIVATE ${LUAU_OPTIONS}) @@ -200,13 +206,8 @@ if(LUAU_BUILD_CLI) target_link_libraries(Luau.Repl.CLI PRIVATE Luau.Compiler Luau.Config Luau.CodeGen Luau.VM Luau.CLI.lib isocline) - if(UNIX) - find_library(LIBPTHREAD pthread) - if (LIBPTHREAD) - target_link_libraries(Luau.Repl.CLI PRIVATE pthread) - target_link_libraries(Luau.Analyze.CLI PRIVATE pthread) - endif() - endif() + target_link_libraries(Luau.Repl.CLI PRIVATE osthreads) + target_link_libraries(Luau.Analyze.CLI PRIVATE osthreads) target_link_libraries(Luau.Analyze.CLI PRIVATE Luau.Analysis Luau.CLI.lib) @@ -230,18 +231,17 @@ if(LUAU_BUILD_TESTS) target_compile_options(Luau.Conformance PRIVATE ${LUAU_OPTIONS}) target_include_directories(Luau.Conformance PRIVATE extern) target_link_libraries(Luau.Conformance PRIVATE Luau.Analysis Luau.Compiler Luau.CodeGen Luau.VM) - file(REAL_PATH "tests/conformance" LUAU_CONFORMANCE_SOURCE_DIR) + if(CMAKE_SYSTEM_NAME MATCHES "Android|iOS") + set(LUAU_CONFORMANCE_SOURCE_DIR "Client/Luau/tests/conformance") + else() + file(REAL_PATH "tests/conformance" LUAU_CONFORMANCE_SOURCE_DIR) + endif() target_compile_definitions(Luau.Conformance PRIVATE LUAU_CONFORMANCE_SOURCE_DIR="${LUAU_CONFORMANCE_SOURCE_DIR}") target_compile_options(Luau.CLI.Test PRIVATE ${LUAU_OPTIONS}) target_include_directories(Luau.CLI.Test PRIVATE extern CLI) target_link_libraries(Luau.CLI.Test PRIVATE Luau.Compiler Luau.Config Luau.CodeGen Luau.VM Luau.CLI.lib isocline) - if(UNIX) - find_library(LIBPTHREAD pthread) - if (LIBPTHREAD) - target_link_libraries(Luau.CLI.Test PRIVATE pthread) - endif() - endif() + target_link_libraries(Luau.CLI.Test PRIVATE osthreads) endif() diff --git a/tests/RequireByString.test.cpp b/tests/RequireByString.test.cpp index 39ed571e..5ed7f7a1 100644 --- a/tests/RequireByString.test.cpp +++ b/tests/RequireByString.test.cpp @@ -13,6 +13,46 @@ #include #include +#if __APPLE__ +#include +#if TARGET_OS_IPHONE +#include + +std::optional getResourcePath0() +{ + CFBundleRef mainBundle = CFBundleGetMainBundle(); + if (mainBundle == NULL) + { + return std::nullopt; + } + CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle); + if (mainBundleURL == NULL) + { + CFRelease(mainBundle); + return std::nullopt; + } + + char pathBuffer[PATH_MAX]; + if (!CFURLGetFileSystemRepresentation(mainBundleURL, true, (UInt8*)pathBuffer, PATH_MAX)) + { + CFRelease(mainBundleURL); + CFRelease(mainBundle); + return std::nullopt; + } + + CFRelease(mainBundleURL); + CFRelease(mainBundle); + return std::string(pathBuffer); +} + +std::optional getResourcePath() +{ + static std::optional path0 = getResourcePath0(); + return path0; +} +#endif +#endif + LUAU_FASTFLAG(LuauUpdatedRequireByStringSemantics) class ReplWithPathFixture @@ -49,7 +89,23 @@ public: std::string luauDirRel = "."; std::string luauDirAbs; +#if !__APPLE__ || !TARGET_OS_IPHONE std::optional cwd = getCurrentWorkingDirectory(); +#else + std::optional cwd0 = getCurrentWorkingDirectory(); + std::optional cwd = getResourcePath(); + if (cwd && cwd0) + { + // when running in xcode cwd0 is "/", however that is not always the case + const auto& _res = *cwd; + const auto& _cwd = *cwd0; + if (_res.find(_cwd) == 0) + { + // we need relative path so we subtract cwd0 from cwd + luauDirRel = "./" + _res.substr(_cwd.length()); + } + } +#endif REQUIRE_MESSAGE(cwd, "Error getting Luau path"); std::replace((*cwd).begin(), (*cwd).end(), '\\', '/'); luauDirAbs = *cwd;