on master help sign in
Allow the ob impl to be a symlink
commit77175d603a38ce4d78caaeb10230eff266d50944 authorRyan Trinkle <ryan.trinkle@gmail.com> dateMon 8 Jan 2018, 21:17 (9 years ago) parentc565d49
3 files changed+32−13
command/src/Obelisk/Command.hs+10−6 command/src/Obelisk/Command/Project.hs+21−6 default.nix+1−1
command/src/Obelisk/Command.hs+10−6
@@ -8,9 +8,6 @@ import System.Environment
88import System.IO
99import System.Posix.Process
1010
11−import GitHub.Data.Name
12−import GitHub.Data.GitData
13−
1411import Obelisk.Command.Project
1512import Obelisk.Command.Thunk
1613import Obelisk.Command.Repl
@@ -39,8 +36,15 @@ argsInfo = info (args <**> helper) $ mconcat
3936 , progDesc "Manage Obelisk projects"
4037 ]
4138
39+initSource :: Parser InitSource
40+initSource = foldl1 (<|>)
41+ [ pure InitSource_Default
42+ , InitSource_Branch <$> strOption (long "branch" <> metavar "BRANCH")
43+ , InitSource_Symlink <$> strOption (long "symlink" <> metavar "PATH")
44+ ]
45+
4246data ObCommand
43− = ObCommand_Init (Maybe (Name Branch))
47+ = ObCommand_Init InitSource
4448 | ObCommand_Dev
4549 | ObCommand_Thunk ThunkCommand
4650 | ObCommand_Repl FilePath
@@ -48,7 +52,7 @@ data ObCommand
4852
4953obCommand :: Parser ObCommand
5054obCommand = hsubparser $ mconcat
51− [ command "init" $ info (ObCommand_Init <$> (optional (strOption (long "branch" <> metavar "BRANCH")))) $ progDesc "Initialize an Obelisk project"
55+ [ command "init" $ info (ObCommand_Init <$> initSource) $ progDesc "Initialize an Obelisk project"
5256 , command "dev" $ info (pure ObCommand_Dev) $ progDesc "Run the current project in development mode"
5357 , command "thunk" $ info (ObCommand_Thunk <$> thunkCommand) $ progDesc "Manipulate thunk directories"
5458 , command "repl" $ info (ObCommand_Repl <$> (strArgument (action "directory"))) $ progDesc "Open an interactive interpreter"
@@ -93,7 +97,7 @@ main = do
9397
9498ob :: ObCommand -> IO ()
9599ob = \case
96− ObCommand_Init branch -> initProject "." branch
100+ ObCommand_Init source -> initProject source
97101 ObCommand_Dev -> putStrLn "Dev!"
98102 ObCommand_Thunk tc -> case tc of
99103 ThunkCommand_Update thunks -> mapM_ updateThunkToLatest thunks
command/src/Obelisk/Command/Project.hs+21−6
@@ -1,7 +1,8 @@
11{-# LANGUAGE LambdaCase #-}
22{-# LANGUAGE OverloadedStrings #-}
33module Obelisk.Command.Project
4− ( initProject
4+ ( InitSource (..)
5+ , initProject
56 , findProjectObeliskCommand
67 , findProjectRoot
78 , inProjectShell
@@ -20,6 +21,7 @@ import System.Exit
2021import System.FilePath
2122import System.IO
2223import System.Posix (FileStatus, getFileStatus , deviceID, fileID, getRealUserID , fileOwner, fileMode, UserID)
24+import System.Posix.Files
2325import System.Process
2426
2527import GitHub.Data.Name (Name)
@@ -43,12 +45,25 @@ obeliskSourceWithBranch branch = ThunkSource_GitHub $ GitHubSource
4345 , _gitHubSource_private = True
4446 }
4547
46−initProject :: FilePath -> Maybe (Name Branch) -> IO ()
47−initProject target branch = do
48− let obDir = target </> ".obelisk"
48+data InitSource
49+ = InitSource_Default
50+ | InitSource_Branch (Name Branch)
51+ | InitSource_Symlink FilePath
52+
53+-- | Create a new project rooted in the current directory
54+initProject :: InitSource -> IO ()
55+initProject source = do
56+ let obDir = ".obelisk"
4957 implDir = obDir </> "impl"
5058 createDirectory obDir
51− createThunkWithLatest implDir $ maybe obeliskSource obeliskSourceWithBranch branch
59+ case source of
60+ InitSource_Default -> createThunkWithLatest implDir obeliskSource
61+ InitSource_Branch branch -> createThunkWithLatest implDir $ obeliskSourceWithBranch branch
62+ InitSource_Symlink path -> do
63+ let symlinkPath = if isAbsolute path
64+ then path
65+ else ".." </> path
66+ createSymbolicLink symlinkPath implDir
5267 _ <- nixBuildAttrWithCache implDir "command"
5368 --TODO: We should probably handoff to the impl here
5469 skeleton <- nixBuildAttrWithCache implDir "skeleton" --TODO: I don't think there's actually any reason to cache this
@@ -57,7 +72,7 @@ initProject target branch = do
5772 , "--no-preserve=mode"
5873 , "-T"
5974 , skeleton </> "."
60− , target
75+ , "."
6176 ] Nothing Nothing
6277 ExitSuccess <- waitForProcess p
6378 return ()
default.nix+1−1
@@ -47,7 +47,7 @@ rec {
4747 command = ghcObelisk.obelisk-command;
4848 #TODO: Why can't I build ./skeleton directly as a derivation? `nix-build -E ./.` doesn't work
4949 skeleton = pkgs.runCommand "skeleton" {
50− dir = ./skeleton;
50+ dir = builtins.filterSource (path: type: builtins.trace path (baseNameOf path != ".obelisk")) ./skeleton;
5151 } ''
5252 ln -s "$dir" "$out"
5353 '';