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 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'compiler/app/Main.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 -- cgit v1.2.3