From 671a372d87ff8311956f9158e8885ffc254fe1bc Mon Sep 17 00:00:00 2001 From: pacien Date: Tue, 29 Jun 2021 13:14:14 +0200 Subject: compiler: add "portable" target This adds a build flag for generating a portable version of the compiler binary which make it look in its own runtime directory for its assets. This is useful in particular for the portable release tarballs which contain the web viewer at the same location instead of a pre-defined one in the FHS. GitHub: closes #286 --- compiler/app/Main.hs | 29 +++++++++++++---------------- compiler/app/ViewerDist.hs | 39 +++++++++++++++++++++++++++++++++++++++ compiler/package.yaml | 14 +++++++++++++- 3 files changed, 65 insertions(+), 17 deletions(-) create mode 100644 compiler/app/ViewerDist.hs diff --git a/compiler/app/Main.hs b/compiler/app/Main.hs index dc97b38..3e6f254 100644 --- a/compiler/app/Main.hs +++ b/compiler/app/Main.hs @@ -19,7 +19,7 @@ module Main where import GHC.Generics (Generic) -import Paths_ldgallery_compiler (version, getDataFileName) +import Paths_ldgallery_compiler (version) import Control.Monad (when) import Data.Functor ((<&>)) import Data.Maybe (isJust) @@ -31,7 +31,7 @@ import System.Console.CmdArgs import Compiler import Files (readDirectory, copyTo, remove) - +import ViewerDist (viewerDistPath) newtype ViewerConfig = ViewerConfig { galleryRoot :: String @@ -106,10 +106,7 @@ main = do opts <- cmdArgs options buildGallery opts - - when (isJust $ withViewer opts) $ do - viewerDist <- viewerDistPath $ withViewer opts - deployViewer viewerDist opts + deployViewer opts where gallerySubdir :: String @@ -118,11 +115,6 @@ main = viewerConfig :: ViewerConfig viewerConfig = ViewerConfig (gallerySubdir ++ "/") - viewerDistPath :: Maybe FilePath -> IO FilePath - viewerDistPath (Just "") = getDataFileName "viewer" - viewerDistPath (Just dist) = return dist - viewerDistPath Nothing = fail "No viewer distribution" - buildGallery :: Options -> IO () buildGallery opts = checkDistinctPaths (inputDir opts) (outputDir opts) @@ -146,10 +138,11 @@ main = | isJust withViewer = outputDir gallerySubdir | otherwise = outputDir - deployViewer :: FilePath -> Options -> IO () - deployViewer distPath Options{outputDir, cleanOutput} = + deployViewer :: Options -> IO () + deployViewer Options{withViewer = Nothing} = pure () + deployViewer Options{withViewer = Just viewerPath, outputDir, cleanOutput} = when cleanOutput (cleanViewerDir outputDir) - >> copyViewer distPath outputDir + >> viewerDistOr viewerPath >>= deployTo outputDir >> writeJSON (outputDir "config.json") viewerConfig where @@ -159,8 +152,12 @@ main = <&> filter (/= gallerySubdir) >>= mapM_ (remove . (target )) - copyViewer :: FilePath -> FilePath -> IO () - copyViewer dist target = + viewerDistOr :: FilePath -> IO FilePath + viewerDistOr "" = viewerDistPath + viewerDistOr custom = pure custom + + deployTo :: FilePath -> FilePath -> IO () + deployTo target dist = putStrLn "Copying viewer webapp" >> readDirectory dist >>= copyTo target diff --git a/compiler/app/ViewerDist.hs b/compiler/app/ViewerDist.hs new file mode 100644 index 0000000..2b80ffc --- /dev/null +++ b/compiler/app/ViewerDist.hs @@ -0,0 +1,39 @@ +-- ldgallery - A static generator which turns a collection of tagged +-- pictures into a searchable web gallery. +-- +-- Copyright (C) 2021 Pacien TRAN-GIRARD +-- +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU Affero General Public License as +-- published by the Free Software Foundation, either version 3 of the +-- License, or (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Affero General Public License for more details. +-- +-- You should have received a copy of the GNU Affero General Public License +-- along with this program. If not, see . + +{-# LANGUAGE CPP #-} + +module ViewerDist where + +#ifndef FLAG_PORTABLE + +import Paths_ldgallery_compiler (getDataFileName) + +viewerDistPath = getDataFileName "viewer" + +#else + +import Data.Functor ((<&>)) +import System.FilePath (takeDirectory, ()) +import System.Environment (getExecutablePath) + +viewerDistPath = fmap takeDirectory getExecutablePath <&> ( "viewer") + +#endif + +viewerDistPath :: IO FilePath diff --git a/compiler/package.yaml b/compiler/package.yaml index faa2174..b02a40a 100644 --- a/compiler/package.yaml +++ b/compiler/package.yaml @@ -5,7 +5,7 @@ github: "pacien/ldgallery" license: AGPL-3 author: "Pacien TRAN-GIRARD, Guillaume FOUET" maintainer: "" -copyright: "2019-2020 Pacien TRAN-GIRARD, Guillaume FOUET" +copyright: "2019-2021 Pacien TRAN-GIRARD, Guillaume FOUET" extra-source-files: - readme.md @@ -54,6 +54,15 @@ data-files: ["**/*"] library: source-dirs: src +flags: + portable: + description: > + Make the output binary portable. + It will look in its own runtime location for its assets instead of + absolute installation paths. + manual: true + default: false + executables: ldgallery: main: Main.hs @@ -64,6 +73,9 @@ executables: - -with-rtsopts=-N dependencies: - ldgallery-compiler + when: + - condition: flag(portable) + cpp-options: -DFLAG_PORTABLE tests: ldgallery-compiler-test: -- cgit v1.2.3 From 35458421aef45475bc1145a22c4eaa7b7638fb65 Mon Sep 17 00:00:00 2001 From: pacien Date: Tue, 29 Jun 2021 13:19:02 +0200 Subject: ci: compile the portable version of the compiler So that the generated build artifacts and release tarballs are portable. --- .github/workflows/build.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 532c1f7..9395862 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -45,8 +45,10 @@ jobs: run: | STACK_ROOT=~/.stack # make it the same on all platforms stack setup --no-terminal - stack build --no-terminal - stack install --local-bin-path dist + stack build --no-terminal \ + --flag ldgallery-compiler:portable \ + --copy-bins \ + --local-bin-path dist - uses: actions/upload-artifact@v2 with: name: compiler-dist-${{ matrix.os }} -- cgit v1.2.3 From 744588264310f189c711fe4bf52ce0bc0aab0b70 Mon Sep 17 00:00:00 2001 From: pacien Date: Tue, 29 Jun 2021 13:21:08 +0200 Subject: doc: remove obsolete note on asset path for portable archives It is no longer necessary for the user to explicitly specify the path of the viewer distribution directory when using a portable archive, since the compiler built with the "portable" flag now automatically looks at its runtime location. --- ldgallery-quickstart.7.md | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/ldgallery-quickstart.7.md b/ldgallery-quickstart.7.md index 684e90d..e8ccfb1 100644 --- a/ldgallery-quickstart.7.md +++ b/ldgallery-quickstart.7.md @@ -2,7 +2,7 @@ pagetitle: Quickstart guide - ldgallery title: LDGALLERY-QUICKSTART(7) ldgallery author: Pacien TRAN-GIRARD, Guillaume FOUET -date: 2020-09-19 (v2.0) +date: 2021-06-29 (SNAPSHOT) --- # ABOUT @@ -85,16 +85,6 @@ ldgallery \ --output-dir ./monument-gallery-output ``` -If the compiler was installed manually through the extraction of a pre-built archive, -it might be necessary to specify the full path of the installation: - -```sh -/ldgallery \ - --with-viewer=/viewer \ - --input-dir ./monument-gallery-source \ - --output-dir ./monument-gallery-output -``` - Running the command above produces a directory named "monument-gallery-output" in the current directory, which contains the compiled gallery and a web viewer ready to be copied to some web server. @@ -125,7 +115,7 @@ The ldgallery source code is available on . # LICENSE -Copyright (C) 2019-2020 Pacien TRAN-GIRARD and Guillaume FOUET. +Copyright (C) 2019-2021 Pacien TRAN-GIRARD and Guillaume FOUET. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. -- cgit v1.2.3 From 083f0658399afc206ea0751415d54a50d2aa4fe9 Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Tue, 29 Jun 2021 16:53:44 +0200 Subject: compiler: updated build script with arguments matching the CI --- compiler/.gitignore | 1 + scripts/dev_win_build.cmd | 5 ----- scripts/dev_win_build_compiler.cmd | 5 +++++ 3 files changed, 6 insertions(+), 5 deletions(-) delete mode 100644 scripts/dev_win_build.cmd create mode 100644 scripts/dev_win_build_compiler.cmd diff --git a/compiler/.gitignore b/compiler/.gitignore index 778e7ef..3415fc8 100644 --- a/compiler/.gitignore +++ b/compiler/.gitignore @@ -1,3 +1,4 @@ .stack-work/ +dist/ ldgallery-compiler.cabal *~ \ No newline at end of file diff --git a/scripts/dev_win_build.cmd b/scripts/dev_win_build.cmd deleted file mode 100644 index ed96211..0000000 --- a/scripts/dev_win_build.cmd +++ /dev/null @@ -1,5 +0,0 @@ -@echo off -cd ..\compiler\ -stack setup -stack build -pause \ No newline at end of file diff --git a/scripts/dev_win_build_compiler.cmd b/scripts/dev_win_build_compiler.cmd new file mode 100644 index 0000000..d88aa5d --- /dev/null +++ b/scripts/dev_win_build_compiler.cmd @@ -0,0 +1,5 @@ +@echo off +cd ..\compiler\ +stack setup +stack build --flag ldgallery-compiler:portable --copy-bins --local-bin-path dist +pause -- cgit v1.2.3