def extractTaskName = "extractQjs${abi.capitalize()}" tasks.register(extractTaskName, Copy) { group 'QuickJS' dependsOn tasks.getByName(downloadTaskName) from({ tarTree( tarFile.path.endsWith('.gz') ? resources.gzip(tarFile) : resources.bzip2(tarFile) )}) into "$projectDir/src/main/jniLibs/${abi}" includeEmptyDirs = false } preBuild.dependsOn tasks.getByName(extractTaskName) } else { println("[🌹] libqjs.so already exists for ${abi}, skipping download and extraction. use flutter clean, and rerun if you insist on download and extraction. or Set flujs.qjs.force_download=true to force download.") } }
ifFile.exist?(framework_lib) && !@force_download puts "[darwin] libqjs.dylib already exists in Frameworks/, skipping download and extraction.use flutter clean, and rerun if you insist on download and extraction. or set FORCE_DOWNLOAD=true" @framework_path = "Frameworks/" return elsifFile.exist?(cache_lib) puts "[darwin] libqjs.dylib found in .cache/, execute extraction." @framework_path = "Frameworks/" FileUtils.mkdir_p(@framework_path) FileUtils.cp(cache_lib, @framework_path) return end
FileUtils.mkdir_p('.cache') puts "[darwin] #{platform} libqjs.dylib not found, downloading and extracting..." _download(platform) end
def_unzip(file, destination) system("tar -xzf #{file} -C #{destination}") end
def_fetch(link, dest) begin URI.open(link) do |file| File.open(dest, "wb") do |output| output.write(file.read) end end puts "[_fetch] succeed #{dest}" rescueStandardError => e puts "[_fetch] failed: #{e.message}, #{link}" end end
# Set BASEURL from environment variable or use default if(DEFINED ENV{BASEURL}) set(BASEURL "$ENV{BASEURL}") else() set(BASEURL "https://gitee.com/flujs_project/flujs_libs_quickjs/releases/download") endif()
# Set QJS_VERSION from environment variable or use default if(DEFINED ENV{QJS_VERSION}) set(QJS_VERSION "$ENV{QJS_VERSION}") else() set(QJS_VERSION "0.8.0") endif()
# download quickjs and set QJS_LIBRARY function(prepareQJS) set(QJS_TAR_PATH "${CMAKE_BINARY_DIR}/${QJS_TAR_NAME}")
if(CMAKE_HOST_SYSTEM_NAME MATCHES"Linux") set(QJS_LIBRARY "${CMAKE_BINARY_DIR}/libqjs.so") # cannot use PARENT_SCOPE, it will not check the existence of QJS_LIBRARY elseif(CMAKE_HOST_SYSTEM_NAME MATCHES"Windows") set(QJS_LIBRARY "${CMAKE_BINARY_DIR}/release/lib/libqjs.dll") endif()
message(STATUS "[prepareQJS] QJS_LIBRARY = ${QJS_LIBRARY} ${FORCE_DOWNLOAD}") if(EXISTS"${QJS_LIBRARY}"ANDNOT FORCE_DOWNLOAD) message(STATUS "[prepareQJS] ${QJS_LIBRARY} already exists, skipping download and extraction. use flutter clean, and rerun if you insist on download and extraction. or set FORCE_DOWNLOAD=true") set(QJS_LIBRARY "${QJS_LIBRARY}" PARENT_SCOPE) return() endif()
message(STATUS "[prepareQJS] ${QJS_LIBRARY_PATH} not found, downloading and extracting...") set(URL "${BASEURL}/${QJS_VERSION}/${QJS_TAR_NAME}") downloadVerify("${URL}"${QJS_TAR_PATH}) if(CMAKE_HOST_SYSTEM_NAME MATCHES"Linux") add_custom_target( "QJS_EXTRACT" ALL COMMAND"${CMAKE_COMMAND}" -E tar xz "${QJS_TAR_PATH}" WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" COMMENT "Extracting QJS library" ) set(QJS_LIBRARY "${CMAKE_BINARY_DIR}/libqjs.so" PARENT_SCOPE) elseif(CMAKE_HOST_SYSTEM_NAME MATCHES"Windows") execute_process(COMMAND powershell -Command"Expand-Archive -Path '${QJS_TAR_PATH}' -DestinationPath '${CMAKE_BINARY_DIR}' -Force" RESULT_VARIABLE extractResult) if(NOT extractResult EQUAL0) message(FATAL_ERROR "Failed to extract ZIP file: ${QJS_TAR_PATH}") endif() set(QJS_LIBRARY "${CMAKE_BINARY_DIR}/release/lib/libqjs.dll" PARENT_SCOPE) endif() endfunction(prepareQJS)
# download url resource to locationForArchive function(downloadVerify url locationForArchive ) message(STATUS "[downloadVerify] info = ${url}") if (EXISTS"${locationForArchive}"ANDNOT FORCE_DOWNLOAD) message(STATUS "[downloadVerify] ${locationForArchive} exists!.") return() endif()
# check target dir is empty, return result if it is true; function(checkDirectoryEmpty dir result) if(EXISTS"${dir}") file(GLOB dir_contents "${dir}/*") if(dir_contents) set(${result}FALSE PARENT_SCOPE) else() set(${result}TRUE PARENT_SCOPE) message(WARN "[checkDirectoryEmpty] Directory ${dir} exists but empty!") endif() else() set(${result}TRUE PARENT_SCOPE) message(WARN "[checkDirectoryEmpty] Directory ${dir} not exists!") endif() endfunction(checkDirectoryEmpty)
# List of absolute paths to libraries that should be bundled with the plugin. # This list could contain prebuilt libraries, or libraries created by an # external build triggered from this build file. set("flujs_qjs_bundled_libraries" $<TARGET_FILE:${QJS}> PARENT_SCOPE)