Skip to content
Snippets Groups Projects
Commit 48badcd5 authored by Jean-Paul Calderone's avatar Jean-Paul Calderone
Browse files

Replace `LANGUAGE CPP` with two platform-specific source files

`LANGUAGE CPP` works but comes with some downsides (surprising source
rewriting, more recompilations).  We can avoid them by having cabal deal with
the platform differences instead.
parent 47c30744
No related branches found
No related tags found
1 merge request!12Replace `LANGUAGE CPP` with two platform-specific source files
Pipeline #3438 passed
-- | Implement platform-specific path-related operations for the Android
-- platform.
module FrontendPaths (getFilesDir) where
import qualified Android.HaskellActivity as Android
-- | Get the path to a directory that is private to the application where
-- internal application data may be written (and read back).
--
-- The application requires no special permissions to use this directory. If
-- the app is uninstalled the directory and its children will be deleted.
--
-- https://developer.android.com/reference/android/content/Context#getFilesDir()
getFilesDir :: IO (Maybe FilePath)
getFilesDir = Android.getHaskellActivity >>= Android.getFilesDir
......@@ -3,6 +3,11 @@ version: 0.1
cabal-version: >= 1.8
build-type: Simple
-- This ensures the platform-specific source files are also included in `cabal
-- sdist`.
extra-source-files: android-src/ActivityPath.hs
linux-src/ActivityPath.hs
library
hs-source-dirs: src
build-depends: base
......@@ -17,8 +22,14 @@ library
, bytestring
, tahoe-chk
if os(android)
-- Pull in the Android implementation of some platform-specific modules.
hs-source-dirs: android-src
-- And their dependencies.
build-depends: android-activity
else
-- Here, get the Linux implementation of those platform-specific modules.
hs-source-dirs: linux-src
-- And their dependencies.
build-depends: xdg-basedir
build-depends: directory
exposed-modules:
......
{-# LANGUAGE CPP #-}
-- | Implement platform-specific path-related operations for the Linux
-- platform.
module FrontendPaths (getFilesDir) where
#if defined(linux_HOST_OS)
import System.Environment.XDG.BaseDir (getUserDataDir)
import System.Directory (createDirectoryIfMissing)
......@@ -17,19 +15,3 @@ getFilesDir = do
createDirectoryIfMissing True dataPath
pure $ Just dataPath
#else
import qualified Android.HaskellActivity as Android
-- | Get the path to a directory that is private to the application where
-- internal application data may be written (and read back).
--
-- The application requires no special permissions to use this directory. If
-- the app is uninstalled the directory and its children will be deleted.
--
-- https://developer.android.com/reference/android/content/Context#getFilesDir()
getFilesDir :: IO (Maybe FilePath)
getFilesDir = Android.getHaskellActivity >>= Android.getFilesDir
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment