diff options
-rw-r--r-- | .github/workflows/build.yml | 6 | ||||
-rw-r--r-- | compiler/.gitignore | 1 | ||||
-rw-r--r-- | compiler/app/Main.hs | 29 | ||||
-rw-r--r-- | compiler/app/ViewerDist.hs | 39 | ||||
-rw-r--r-- | compiler/package.yaml | 14 | ||||
-rw-r--r-- | ldgallery-quickstart.7.md | 14 | ||||
-rw-r--r-- | scripts/dev_win_build.cmd | 5 | ||||
-rw-r--r-- | scripts/dev_win_build_compiler.cmd | 5 |
8 files changed, 77 insertions, 36 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: | |||
45 | run: | | 45 | run: | |
46 | STACK_ROOT=~/.stack # make it the same on all platforms | 46 | STACK_ROOT=~/.stack # make it the same on all platforms |
47 | stack setup --no-terminal | 47 | stack setup --no-terminal |
48 | stack build --no-terminal | 48 | stack build --no-terminal \ |
49 | stack install --local-bin-path dist | 49 | --flag ldgallery-compiler:portable \ |
50 | --copy-bins \ | ||
51 | --local-bin-path dist | ||
50 | - uses: actions/upload-artifact@v2 | 52 | - uses: actions/upload-artifact@v2 |
51 | with: | 53 | with: |
52 | name: compiler-dist-${{ matrix.os }} | 54 | name: compiler-dist-${{ matrix.os }} |
diff --git a/compiler/.gitignore b/compiler/.gitignore index 778e7ef..3415fc8 100644 --- a/compiler/.gitignore +++ b/compiler/.gitignore | |||
@@ -1,3 +1,4 @@ | |||
1 | .stack-work/ | 1 | .stack-work/ |
2 | dist/ | ||
2 | ldgallery-compiler.cabal | 3 | ldgallery-compiler.cabal |
3 | *~ \ No newline at end of file | 4 | *~ \ No newline at end of file |
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 @@ | |||
19 | module Main where | 19 | module Main where |
20 | 20 | ||
21 | import GHC.Generics (Generic) | 21 | import GHC.Generics (Generic) |
22 | import Paths_ldgallery_compiler (version, getDataFileName) | 22 | import Paths_ldgallery_compiler (version) |
23 | import Control.Monad (when) | 23 | import Control.Monad (when) |
24 | import Data.Functor ((<&>)) | 24 | import Data.Functor ((<&>)) |
25 | import Data.Maybe (isJust) | 25 | import Data.Maybe (isJust) |
@@ -31,7 +31,7 @@ import System.Console.CmdArgs | |||
31 | 31 | ||
32 | import Compiler | 32 | import Compiler |
33 | import Files (readDirectory, copyTo, remove) | 33 | import Files (readDirectory, copyTo, remove) |
34 | 34 | import ViewerDist (viewerDistPath) | |
35 | 35 | ||
36 | newtype ViewerConfig = ViewerConfig | 36 | newtype ViewerConfig = ViewerConfig |
37 | { galleryRoot :: String | 37 | { galleryRoot :: String |
@@ -106,10 +106,7 @@ main = | |||
106 | do | 106 | do |
107 | opts <- cmdArgs options | 107 | opts <- cmdArgs options |
108 | buildGallery opts | 108 | buildGallery opts |
109 | 109 | deployViewer opts | |
110 | when (isJust $ withViewer opts) $ do | ||
111 | viewerDist <- viewerDistPath $ withViewer opts | ||
112 | deployViewer viewerDist opts | ||
113 | 110 | ||
114 | where | 111 | where |
115 | gallerySubdir :: String | 112 | gallerySubdir :: String |
@@ -118,11 +115,6 @@ main = | |||
118 | viewerConfig :: ViewerConfig | 115 | viewerConfig :: ViewerConfig |
119 | viewerConfig = ViewerConfig (gallerySubdir ++ "/") | 116 | viewerConfig = ViewerConfig (gallerySubdir ++ "/") |
120 | 117 | ||
121 | viewerDistPath :: Maybe FilePath -> IO FilePath | ||
122 | viewerDistPath (Just "") = getDataFileName "viewer" | ||
123 | viewerDistPath (Just dist) = return dist | ||
124 | viewerDistPath Nothing = fail "No viewer distribution" | ||
125 | |||
126 | buildGallery :: Options -> IO () | 118 | buildGallery :: Options -> IO () |
127 | buildGallery opts = | 119 | buildGallery opts = |
128 | checkDistinctPaths (inputDir opts) (outputDir opts) | 120 | checkDistinctPaths (inputDir opts) (outputDir opts) |
@@ -146,10 +138,11 @@ main = | |||
146 | | isJust withViewer = outputDir </> gallerySubdir | 138 | | isJust withViewer = outputDir </> gallerySubdir |
147 | | otherwise = outputDir | 139 | | otherwise = outputDir |
148 | 140 | ||
149 | deployViewer :: FilePath -> Options -> IO () | 141 | deployViewer :: Options -> IO () |
150 | deployViewer distPath Options{outputDir, cleanOutput} = | 142 | deployViewer Options{withViewer = Nothing} = pure () |
143 | deployViewer Options{withViewer = Just viewerPath, outputDir, cleanOutput} = | ||
151 | when cleanOutput (cleanViewerDir outputDir) | 144 | when cleanOutput (cleanViewerDir outputDir) |
152 | >> copyViewer distPath outputDir | 145 | >> viewerDistOr viewerPath >>= deployTo outputDir |
153 | >> writeJSON (outputDir </> "config.json") viewerConfig | 146 | >> writeJSON (outputDir </> "config.json") viewerConfig |
154 | 147 | ||
155 | where | 148 | where |
@@ -159,8 +152,12 @@ main = | |||
159 | <&> filter (/= gallerySubdir) | 152 | <&> filter (/= gallerySubdir) |
160 | >>= mapM_ (remove . (target </>)) | 153 | >>= mapM_ (remove . (target </>)) |
161 | 154 | ||
162 | copyViewer :: FilePath -> FilePath -> IO () | 155 | viewerDistOr :: FilePath -> IO FilePath |
163 | copyViewer dist target = | 156 | viewerDistOr "" = viewerDistPath |
157 | viewerDistOr custom = pure custom | ||
158 | |||
159 | deployTo :: FilePath -> FilePath -> IO () | ||
160 | deployTo target dist = | ||
164 | putStrLn "Copying viewer webapp" | 161 | putStrLn "Copying viewer webapp" |
165 | >> readDirectory dist | 162 | >> readDirectory dist |
166 | >>= copyTo target | 163 | >>= 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 @@ | |||
1 | -- ldgallery - A static generator which turns a collection of tagged | ||
2 | -- pictures into a searchable web gallery. | ||
3 | -- | ||
4 | -- Copyright (C) 2021 Pacien TRAN-GIRARD | ||
5 | -- | ||
6 | -- This program is free software: you can redistribute it and/or modify | ||
7 | -- it under the terms of the GNU Affero General Public License as | ||
8 | -- published by the Free Software Foundation, either version 3 of the | ||
9 | -- License, or (at your option) any later version. | ||
10 | -- | ||
11 | -- This program is distributed in the hope that it will be useful, | ||
12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | -- GNU Affero General Public License for more details. | ||
15 | -- | ||
16 | -- You should have received a copy of the GNU Affero General Public License | ||
17 | -- along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
18 | |||
19 | {-# LANGUAGE CPP #-} | ||
20 | |||
21 | module ViewerDist where | ||
22 | |||
23 | #ifndef FLAG_PORTABLE | ||
24 | |||
25 | import Paths_ldgallery_compiler (getDataFileName) | ||
26 | |||
27 | viewerDistPath = getDataFileName "viewer" | ||
28 | |||
29 | #else | ||
30 | |||
31 | import Data.Functor ((<&>)) | ||
32 | import System.FilePath (takeDirectory, (</>)) | ||
33 | import System.Environment (getExecutablePath) | ||
34 | |||
35 | viewerDistPath = fmap takeDirectory getExecutablePath <&> (</> "viewer") | ||
36 | |||
37 | #endif | ||
38 | |||
39 | 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" | |||
5 | license: AGPL-3 | 5 | license: AGPL-3 |
6 | author: "Pacien TRAN-GIRARD, Guillaume FOUET" | 6 | author: "Pacien TRAN-GIRARD, Guillaume FOUET" |
7 | maintainer: "" | 7 | maintainer: "" |
8 | copyright: "2019-2020 Pacien TRAN-GIRARD, Guillaume FOUET" | 8 | copyright: "2019-2021 Pacien TRAN-GIRARD, Guillaume FOUET" |
9 | 9 | ||
10 | extra-source-files: | 10 | extra-source-files: |
11 | - readme.md | 11 | - readme.md |
@@ -54,6 +54,15 @@ data-files: ["**/*"] | |||
54 | library: | 54 | library: |
55 | source-dirs: src | 55 | source-dirs: src |
56 | 56 | ||
57 | flags: | ||
58 | portable: | ||
59 | description: > | ||
60 | Make the output binary portable. | ||
61 | It will look in its own runtime location for its assets instead of | ||
62 | absolute installation paths. | ||
63 | manual: true | ||
64 | default: false | ||
65 | |||
57 | executables: | 66 | executables: |
58 | ldgallery: | 67 | ldgallery: |
59 | main: Main.hs | 68 | main: Main.hs |
@@ -64,6 +73,9 @@ executables: | |||
64 | - -with-rtsopts=-N | 73 | - -with-rtsopts=-N |
65 | dependencies: | 74 | dependencies: |
66 | - ldgallery-compiler | 75 | - ldgallery-compiler |
76 | when: | ||
77 | - condition: flag(portable) | ||
78 | cpp-options: -DFLAG_PORTABLE | ||
67 | 79 | ||
68 | tests: | 80 | tests: |
69 | ldgallery-compiler-test: | 81 | ldgallery-compiler-test: |
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 @@ | |||
2 | pagetitle: Quickstart guide - ldgallery | 2 | pagetitle: Quickstart guide - ldgallery |
3 | title: LDGALLERY-QUICKSTART(7) ldgallery | 3 | title: LDGALLERY-QUICKSTART(7) ldgallery |
4 | author: Pacien TRAN-GIRARD, Guillaume FOUET | 4 | author: Pacien TRAN-GIRARD, Guillaume FOUET |
5 | date: 2020-09-19 (v2.0) | 5 | date: 2021-06-29 (SNAPSHOT) |
6 | --- | 6 | --- |
7 | 7 | ||
8 | # ABOUT | 8 | # ABOUT |
@@ -85,16 +85,6 @@ ldgallery \ | |||
85 | --output-dir ./monument-gallery-output | 85 | --output-dir ./monument-gallery-output |
86 | ``` | 86 | ``` |
87 | 87 | ||
88 | If the compiler was installed manually through the extraction of a pre-built archive, | ||
89 | it might be necessary to specify the full path of the installation: | ||
90 | |||
91 | ```sh | ||
92 | <installation path>/ldgallery \ | ||
93 | --with-viewer=<installation path>/viewer \ | ||
94 | --input-dir ./monument-gallery-source \ | ||
95 | --output-dir ./monument-gallery-output | ||
96 | ``` | ||
97 | |||
98 | Running the command above produces a directory named "monument-gallery-output" in the current directory, | 88 | Running the command above produces a directory named "monument-gallery-output" in the current directory, |
99 | which contains the compiled gallery and a web viewer ready to be copied to some web server. | 89 | which contains the compiled gallery and a web viewer ready to be copied to some web server. |
100 | 90 | ||
@@ -125,7 +115,7 @@ The ldgallery source code is available on <https://ldgallery.pacien.org>. | |||
125 | 115 | ||
126 | # LICENSE | 116 | # LICENSE |
127 | 117 | ||
128 | Copyright (C) 2019-2020 Pacien TRAN-GIRARD and Guillaume FOUET. | 118 | Copyright (C) 2019-2021 Pacien TRAN-GIRARD and Guillaume FOUET. |
129 | 119 | ||
130 | 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. | 120 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as publi |