Skip to content

Commit

Permalink
Build TinyTex-2 on windows as self extracting archive using sfx (#398)
Browse files Browse the repository at this point in the history
To reduce size of bundles uploaded in tinytex-releases as we are close to limit already
  • Loading branch information
cderv committed Jan 11, 2023
1 parent f5f51b8 commit 60587ad
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
- name: Build TinyTeX-2 (scheme-full)
run: |
Rscript "tools/build-scheme-full.R"
7z a TinyTeX-2.zip $Env:APPDATA\\TinyTeX
7z a -sfx TinyTeX-2.exe $Env:APPDATA\\TinyTeX
- name: Test Installation script
env:
Expand All @@ -101,7 +101,7 @@ jobs:
max_attempts: 5
retry_wait_seconds: 10
command: |
gh release upload ${{needs.new-release.outputs.draft-tag}} TinyTeX-0.zip TinyTeX-1.zip TinyTeX.zip TinyTeX-2.zip --clobber
gh release upload ${{needs.new-release.outputs.draft-tag}} TinyTeX-0.zip TinyTeX-1.zip TinyTeX.zip TinyTeX-2.exe --clobber
build-linux:
needs: [new-release]
Expand Down
12 changes: 9 additions & 3 deletions R/install.R
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ install_prebuilt = function(
installer, if (version != '') paste0('-v', version), '.',
c('zip', 'tar.gz', 'tgz')[os_index]
)
# Full scheme is bundled as a self extracting archive on Windows
if (os_index == 1 && installer == 'TinyTeX-2') pkg = xfun::with_ext(pkg, "exe")
if (file.exists(pkg) && is.na(cache)) {
# invalidate cache (if unspecified) when the installer is more than one day old
if (as.numeric(difftime(Sys.time(), file.mtime(pkg), units = 'days')) > 1)
Expand All @@ -449,8 +451,12 @@ install_prebuilt = function(

# installation dir shouldn't be a file but a directory
file.remove(exist_files(c(dir1, dir2)))
extract = if (grepl('[.]zip$', pkg)) unzip else untar
extract(pkg, exdir = path.expand(target))
if (grepl('[.]exe$', pkg)) {
system2(pkg, args = c('-y', paste0('-o', path.expand(target))))
} else {
extract = if (grepl('[.]zip$', pkg)) unzip else untar
extract(pkg, exdir = path.expand(target))
}
# TinyTeX (or .TinyTeX) is extracted to the parent dir of `dir`; may need to rename
if (dir != '') {
if (basename(dir1) != b) file.rename(dir2, dir1)
Expand Down Expand Up @@ -487,7 +493,7 @@ download_installer = function(file, version) {
url = if (version != '') sprintf(
'https://github.com/rstudio/tinytex-releases/releases/download/v%s/%s', version, file
) else paste0(getOption('tinytex.install.url', 'https://yihui.org/tinytex/'), file)
download_file(url, file)
download_file(url, file, mode = if (is_windows()) "wb" else "w")
}

#' Copy TinyTeX to another location and use it in another system
Expand Down
31 changes: 20 additions & 11 deletions tools/install-bin-windows.bat
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,41 @@ for /d %%G in ("TinyTeX*") do rd /s /q "%%~G"

if not defined TINYTEX_INSTALLER set TINYTEX_INSTALLER=TinyTeX-1

set BUNDLE_EXT=zip
if "%TINYTEX_INSTALLER%" == "TinyTeX-2" set BUNDLE_EXT=exe

if not defined TINYTEX_VERSION (
set TINYTEX_URL=https://github.com/rstudio/tinytex-releases/releases/download/daily/%TINYTEX_INSTALLER%.zip
set TINYTEX_URL=https://github.com/rstudio/tinytex-releases/releases/download/daily/%TINYTEX_INSTALLER%.%BUNDLE_EXT%
) else (
set TINYTEX_URL=https://github.com/rstudio/tinytex-releases/releases/download/v%TINYTEX_VERSION%/%TINYTEX_INSTALLER%-v%TINYTEX_VERSION%.zip
set TINYTEX_URL=https://github.com/rstudio/tinytex-releases/releases/download/v%TINYTEX_VERSION%/%TINYTEX_INSTALLER%-v%TINYTEX_VERSION%.%BUNDLE_EXT%
)

set DOWNLOADED_FILE=install.%BUNDLE_EXT%

rem download the zip package - method 1
echo Download zip file... Method 1
powershell -Command "& { try {Add-Type -A 'System.Net.Http'; [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $response = (New-Object System.Net.Http.HttpClient).GetAsync($Env:TINYTEX_URL); $response.Wait(); $outputFileStream = [System.IO.FileStream]::new('install.zip', [System.IO.FileMode]::Create, [System.IO.FileAccess]::Write); $response.Result.Content.CopyToAsync($outputFileStream).Wait(); $outputFileStream.Close()} catch {throw $_}}"
echo Download %BUNDLE_EXT% file... Method 1
powershell -Command "& { try {Add-Type -A 'System.Net.Http'; [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $response = (New-Object System.Net.Http.HttpClient).GetAsync($Env:TINYTEX_URL); $response.Wait(); $outputFileStream = [System.IO.FileStream]::new($Env:DOWNLOADED_FILE, [System.IO.FileMode]::Create, [System.IO.FileAccess]::Write); $response.Result.Content.CopyToAsync($outputFileStream).Wait(); $outputFileStream.Close()} catch {throw $_}}"
if not errorlevel 1 goto unzip

rem Try another method if the first one failed
echo Download zip file... Method 2
powershell -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (New-Object System.Net.WebClient).DownloadFile($Env:TINYTEX_URL, 'install.zip')"
echo Download %BUNDLE_EXT% file... Method 2
powershell -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (New-Object System.Net.WebClient).DownloadFile($Env:TINYTEX_URL, $Env:DOWNLOADED_FILE)"
if not errorlevel 1 goto unzip

rem Try last method
echo Download zip file... Method 3
powershell -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest $Env:TINYTEX_URL -OutFile install.zip"
echo Download bundle file... Method 3
powershell -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest $Env:TINYTEX_URL -OutFile $Env:DOWNLOADED_FILE"
if errorlevel 1 exit /b %ERRORLEVEL%

:unzip
rem unzip the downloaded file
echo unzip TinyTeX
powershell -Command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('install.zip', '.'); }"
del install.zip
echo Unbundle TinyTeX
if %BUNDLE_EXT% == exe (
CALL %DOWNLOADED_FILE% -y
) ELSE (
powershell -Command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory($Env:DOWNLOADED_FILE, '.'); }"
)
del %DOWNLOADED_FILE%

echo Move to APPDATA folder
rd /s /q "%APPDATA%\TinyTeX"
Expand Down

0 comments on commit 60587ad

Please sign in to comment.