on master help sign in
Merge branch 'develop' into ts-dont-store-config-backup
commit019a2b9d34d9c9c5a2872130864e83b5127fce2b authorLuigy Leon <luichi.19@gmail.com> dateTue 18 Dec 2018, 13:00 (8 years ago) parent611e94766bf5a6
11 files changed+130−46
FAQ.md+15 dep/reflex-platform/github.json+2−2 lib/command/obelisk-command.cabal+1 lib/command/src/Obelisk/Command.hs+3−3 lib/command/src/Obelisk/Command/Deploy.hs+1−1 lib/command/src/Obelisk/Command/Project.hs+5−2 lib/command/src/Obelisk/Command/Run.hs+2−2 lib/command/src/Obelisk/Command/Thunk.hs+61−29 lib/command/src/Obelisk/Command/Utils.hs+15−6 lib/route/src/Obelisk/Route/Frontend.hs+7 lib/selftest/src/Obelisk/SelfTest.hs+18−1
FAQ.mdnew file+15
@@ -0,0 +1,15 @@
1+# Frequently Asked Questions
2+
3+1. [How do I fix invalid entitlements? ](#how-do-i-fix-invalid-entitlements)
4+
5+### How do I fix invalid entitlements?
6+
7+You probably did not set `ios.bundleIdentifier` correctly in `default.nix`.
8+When this happens you'll see an error something like this:
9+
10+```
11+2018-11-25 09:34:22.438 ios-deploy[58106:8521046] [ !! ] Error 0xe8008016: The executable was signed with invalid entitlements. AMDeviceSecureInstallApplication(0, device, url, options, install_callback, 0)
12+```
13+
14+Fixing the value of `ios.bundleIdentifier` should fix the error.
15+
dep/reflex-platform/github.json+2−2
@@ -2,6 +2,6 @@
22 "owner": "reflex-frp",
33 "repo": "reflex-platform",
44 "branch": "develop",
5− "rev": "89a9b09259a8e0681661756bb587a8285927c1e8",
6− "sha256": "13pja2jy5f8xk2bbywhqaj582f4kqd2ww8j5jd7kk5ldzl6zv8g3"
5+ "rev": "a7cd9a23e7faa9c2545a4c111229e28208e42351",
6+ "sha256": "0y52rfrhk4zszgprpyni51l0pgq18dg695k5bmpd62c3zxar5mvm"
77}
lib/command/obelisk-command.cabal+1
@@ -19,6 +19,7 @@ library
1919 , data-default
2020 , directory
2121 , either
22+ , errors
2223 , filepath
2324 , github
2425 , here
lib/command/src/Obelisk/Command.hs+3−3
@@ -208,14 +208,14 @@ thunkDirectoryParser = fmap (dropTrailingPathSeparator . normalise) . strArgumen
208208 ]
209209
210210data ThunkCommand
211− = ThunkCommand_Update [FilePath]
211+ = ThunkCommand_Update [FilePath] (Maybe String)
212212 | ThunkCommand_Unpack [FilePath]
213213 | ThunkCommand_Pack [FilePath]
214214 deriving Show
215215
216216thunkCommand :: Parser ThunkCommand
217217thunkCommand = hsubparser $ mconcat
218− [ command "update" $ info (ThunkCommand_Update <$> some thunkDirectoryParser) $ progDesc "Update thunk to latest revision available"
218+ [ command "update" $ info (ThunkCommand_Update <$> some thunkDirectoryParser <*> optional (strOption (long "branch" <> metavar "BRANCH"))) $ progDesc "Update thunk to latest revision available"
219219 , command "unpack" $ info (ThunkCommand_Unpack <$> some thunkDirectoryParser) $ progDesc "Unpack thunk into git checkout of revision it points to"
220220 , command "pack" $ info (ThunkCommand_Pack <$> some thunkDirectoryParser) $ progDesc "Pack git checkout into thunk that points at the current branch's upstream"
221221 ]
@@ -342,7 +342,7 @@ ob = \case
342342 ObCommand_Run -> inNixShell' $ static run
343343 -- inNixShell ($(mkClosure 'ghcidAction) ())
344344 ObCommand_Thunk tc -> case tc of
345− ThunkCommand_Update thunks -> mapM_ updateThunkToLatest thunks
345+ ThunkCommand_Update thunks mBranch -> mapM_ ((flip updateThunkToLatest) mBranch) thunks
346346 ThunkCommand_Unpack thunks -> mapM_ unpackThunk thunks
347347 ThunkCommand_Pack thunks -> forM_ thunks packThunk
348348 ObCommand_Repl -> runRepl
lib/command/src/Obelisk/Command/Deploy.hs+1−1
@@ -166,7 +166,7 @@ deployPush deployPath getNixBuilders = do
166166 callProcessAndLogOutput (Notice, Notice) p
167167
168168deployUpdate :: MonadObelisk m => FilePath -> m ()
169−deployUpdate deployPath = updateThunkToLatest $ deployPath </> "src"
169+deployUpdate deployPath = updateThunkToLatest (deployPath </> "src") Nothing
170170
171171keytoolToAndroidConfig :: KeytoolConfig -> HM.HashMap Text (NValueNF Identity)
172172keytoolToAndroidConfig conf = runIdentity $ do
lib/command/src/Obelisk/Command/Project.hs+5−2
@@ -26,7 +26,7 @@ import System.FilePath
2626import System.IO.Temp
2727import System.Posix (FileStatus, UserID, deviceID, fileID, fileMode, fileOwner, getFileStatus, getRealUserID)
2828import System.Posix.Files
29−import System.Process (CreateProcess, cwd, proc, waitForProcess)
29+import System.Process (CreateProcess, cwd, proc, waitForProcess, delegate_ctlc)
3030
3131import GitHub.Data.GitData (Branch)
3232import GitHub.Data.Name (Name)
@@ -204,7 +204,7 @@ inImpureProjectShell shellName command = withProjectRoot "." $ \root ->
204204
205205projectShell :: MonadObelisk m => FilePath -> Bool -> String -> String -> m ()
206206projectShell root isPure shellName command = do
207− (_, _, _, ph) <- createProcess_ "runNixShellAttr" $ setCwd (Just root) $ proc "nix-shell" $
207+ (_, _, _, ph) <- createProcess_ "runNixShellAttr" $ setCtlc $ setCwd (Just root) $ proc "nix-shell" $
208208 [ "--pure" | isPure ] <>
209209 [ "-A"
210210 , "shells." <> shellName
@@ -212,5 +212,8 @@ projectShell root isPure shellName command = do
212212 ]
213213 void $ liftIO $ waitForProcess ph
214214
215+setCtlc :: CreateProcess -> CreateProcess
216+setCtlc cfg = cfg { delegate_ctlc = True }
217+
215218setCwd :: Maybe FilePath -> CreateProcess -> CreateProcess
216219setCwd fp cfg = cfg { cwd = fp }
lib/command/src/Obelisk/Command/Run.hs+2−2
@@ -175,7 +175,7 @@ runGhciRepl
175175 :: MonadObelisk m
176176 => FilePath -- ^ Path to .ghci
177177 -> m ()
178−runGhciRepl dotGhci = inProjectShell "ghc" $ unwords $ "ghci" : ["-ghci-script", dotGhci]
178+runGhciRepl dotGhci = inProjectShell "ghc" $ unwords $ "ghci" : ["-no-user-package-db", "-ghci-script", dotGhci]
179179
180180-- | Run ghcid
181181runGhcid
@@ -188,7 +188,7 @@ runGhcid dotGhci mcmd = callCommand $ unwords $ "ghcid" : opts
188188 opts =
189189 [ "-W"
190190 --TODO: The decision of whether to use -fwarn-redundant-constraints should probably be made by the user
191− , "--command='ghci -Wall -ignore-dot-ghci -fwarn-redundant-constraints -ghci-script " <> dotGhci <> "' "
191+ , "--command='ghci -Wall -ignore-dot-ghci -fwarn-redundant-constraints -no-user-package-db -ghci-script " <> dotGhci <> "' "
192192 , "--reload=config"
193193 , "--outputfile=ghcid-output.txt"
194194 ] <> testCmd
lib/command/src/Obelisk/Command/Thunk.hs+61−29
@@ -378,19 +378,38 @@ createThunkWithLatest target s = do
378378 , _thunkPtr_rev = rev
379379 }
380380
381−updateThunkToLatest :: MonadObelisk m => FilePath -> m ()
382−updateThunkToLatest target = withSpinner' ("Updating thunk " <> T.pack target <> " to latest") (pure $ const $ "Thunk " <> T.pack target <> " updated to latest") $ do
383− (overwrite, ptr) <- readThunk target >>= \case
384− Left err -> failWith $ T.pack $ "thunk update: " <> show err
385− Right c -> case c of
386− ThunkData_Packed t -> return (target, t)
387− ThunkData_Checkout _ -> failWith "cannot update an unpacked thunk"
388− let src = _thunkPtr_source ptr
389− rev <- getLatestRev src
390− overwriteThunk overwrite $ ThunkPtr
391− { _thunkPtr_source = src
392− , _thunkPtr_rev = rev
393− }
381+updateThunkToLatest :: MonadObelisk m => FilePath -> Maybe String -> m ()
382+updateThunkToLatest target mBranch = withSpinner' ("Updating thunk " <> T.pack target <> " to latest") (pure $ const $ "Thunk " <> T.pack target <> " updated to latest") $ do
383+ checkThunkDirectory "ob thunk update directory cannot be '.'" target
384+ -- check to see if thunk should be updated to a specific branch or just update it's current branch
385+ case mBranch of
386+ Nothing -> do
387+ (overwrite, ptr) <- readThunk target >>= \case
388+ Left err -> failWith $ T.pack $ "thunk update: " <> show err
389+ Right c -> case c of
390+ ThunkData_Packed t -> return (target, t)
391+ ThunkData_Checkout _ -> failWith "cannot update an unpacked thunk"
392+ let src = _thunkPtr_source ptr
393+ rev <- getLatestRev src
394+ overwriteThunk overwrite $ ThunkPtr
395+ { _thunkPtr_source = src
396+ , _thunkPtr_rev = rev
397+ }
398+ Just branch -> readThunk target >>= \case
399+ Left err -> failWith $ T.pack $ "thunk update: " <> show err
400+ Right c -> case c of
401+ ThunkData_Packed t -> case _thunkPtr_source t of
402+ ThunkSource_Git tsg -> setThunk target tsg branch
403+ ThunkSource_GitHub tsgh -> do
404+ let tsg = forgetGithub False tsgh
405+ setThunk target tsg branch
406+ ThunkData_Checkout _ -> failWith $ T.pack $ "thunk located at " <> (show target) <> " is unpacked. Use ob thunk pack on the desired directory and then try ob thunk update again."
407+
408+setThunk :: MonadObelisk m => FilePath -> GitSource -> String -> m ()
409+setThunk target gs branch = do
410+ newThunkPtr <- uriThunkPtr (_gitSource_url gs) (Just $ T.pack branch) Nothing
411+ overwriteThunk target newThunkPtr
412+ updateThunkToLatest target Nothing
394413
395414-- | All recognized github standalone loaders, ordered from newest to oldest.
396415-- This tool will only ever produce the newest one when it writes a thunk.
@@ -565,15 +584,14 @@ unpackThunk :: MonadObelisk m => FilePath -> m ()
565584unpackThunk = unpackThunk' False
566585
567586-- | Check that we are not somewhere inside the thunk directory
568−checkThunkDirectory :: MonadObelisk m => FilePath -> m ()
569−checkThunkDirectory thunkDir = do
587+checkThunkDirectory :: MonadObelisk m => Text -> FilePath -> m ()
588+checkThunkDirectory msg thunkDir = do
570589 currentDir <- liftIO getCurrentDirectory
571590 thunkDir' <- liftIO $ canonicalizePath thunkDir
572− when (thunkDir' `L.isInfixOf` currentDir) $
573− failWith "Can't pack/unpack from within the thunk directory"
591+ when (thunkDir' `L.isInfixOf` currentDir) $ failWith msg
574592
575593unpackThunk' :: MonadObelisk m => Bool -> FilePath -> m ()
576−unpackThunk' noTrail thunkDir = checkThunkDirectory thunkDir >> readThunk thunkDir >>= \case
594+unpackThunk' noTrail thunkDir = checkThunkDirectory "Can't pack/unpack from within the thunk directory" thunkDir >> readThunk thunkDir >>= \case
577595 Left err -> failWith $ "thunk unpack: " <> T.pack (show err)
578596 --TODO: Overwrite option that rechecks out thunk; force option to do so even if working directory is dirty
579597 Right (ThunkData_Checkout _) -> failWith "thunk unpack: thunk is already unpacked"
@@ -610,7 +628,7 @@ packThunk :: MonadObelisk m => FilePath -> m ThunkPtr
610628packThunk = packThunk' False
611629
612630packThunk' :: MonadObelisk m => Bool -> FilePath -> m ThunkPtr
613−packThunk' noTrail thunkDir = checkThunkDirectory thunkDir >> readThunk thunkDir >>= \case
631+packThunk' noTrail thunkDir = checkThunkDirectory "Can't pack/unpack from within the thunk directory" thunkDir >> readThunk thunkDir >>= \case
614632 Left err -> failWith $ T.pack $ "thunk pack: " <> show err
615633 Right (ThunkData_Packed _) -> failWith "pack: thunk is already packed"
616634 Right (ThunkData_Checkout _) -> do
@@ -639,6 +657,22 @@ getThunkPtr' checkClean thunkDir = do
639657 ] ++ T.lines stashOutput
640658 True -> return ()
641659
660+ -- Get current branch ``
661+ (mCurrentBranch, mCurrentCommit) <- do
662+ b <- listToMaybe
663+ <$> T.lines
664+ <$> readGitProcess thunkDir ["rev-parse", "--abbrev-ref", "HEAD"]
665+ c <- listToMaybe
666+ <$> T.lines
667+ <$> readGitProcess thunkDir ["rev-parse", "HEAD"]
668+ case b of
669+ (Just "HEAD") -> failWith $ T.unlines $
670+ [ "thunk pack: You are in 'detached HEAD' state."
671+ , "If you want to pack at the current ref \
672+ \then please create a new branch with 'git checkout -b <new-branch-name>' and push this upstream."
673+ ]
674+ _ -> return (b, c)
675+
642676 -- Get information on all branches and their (optional) designated upstream
643677 -- correspondents
644678 (headDump :: [Text]) <- T.lines <$> readGitProcess thunkDir
@@ -714,11 +748,6 @@ getThunkPtr' checkClean thunkDir = do
714748 -- We assume it's safe to pack the thunk at this point
715749 putLog Informational $ "All changes safe in git remotes. OK to pack thunk."
716750
717− -- Get current branch ``
718− mCurrentBranch <- listToMaybe
719− <$> T.lines
720− <$> readGitProcess thunkDir ["rev-parse", "--abbrev-ref", "HEAD"]
721−
722751 let remote = maybe "origin" snd $ flip Map.lookup headUpstream =<< mCurrentBranch
723752
724753 [remoteUri'] <- fmap T.lines $ readGitProcess thunkDir
@@ -730,7 +759,7 @@ getThunkPtr' checkClean thunkDir = do
730759 remoteUri <- case parseGitUri remoteUri' of
731760 Nothing -> failWith $ "Could not identify git remote: " <> remoteUri'
732761 Just uri -> pure uri
733− uriThunkPtr remoteUri mCurrentBranch
762+ uriThunkPtr remoteUri mCurrentBranch mCurrentCommit
734763
735764-- | Get the latest revision available from the given source
736765getLatestRev :: MonadObelisk m => ThunkSource -> m ThunkRev
@@ -749,9 +778,11 @@ getLatestRev os = do
749778-- performance. If that doesn't work (e.g. authentication issue), we fall back
750779-- on just doing things the normal way for git repos in general, and save it as
751780-- a regular git thunk.
752−uriThunkPtr :: MonadObelisk m => URI -> Maybe Text -> m ThunkPtr
753−uriThunkPtr uri mbranch = do
754− (_, commit) <- gitGetCommitBranch uri mbranch
781+uriThunkPtr :: MonadObelisk m => URI -> Maybe Text -> Maybe Text -> m ThunkPtr
782+uriThunkPtr uri mbranch mcommit = do
783+ commit <- case mcommit of
784+ Nothing -> gitGetCommitBranch uri mbranch >>= return . snd
785+ (Just c) -> return c
755786 (src, rev) <- case uriToThunkSource uri mbranch of
756787 ThunkSource_GitHub s -> do
757788 rev <- runExceptT $ githubThunkRev s commit
@@ -865,9 +896,10 @@ gitThunkRev s commit = do
865896gitGetCommitBranch
866897 :: MonadObelisk m => URI -> Maybe Text -> m (Text, CommitId)
867898gitGetCommitBranch uri mbranch = withExitFailMessage ("Failure for git remote " <> uriMsg) $ do
868− bothMaps <- gitLsRemote
899+ (_, bothMaps) <- gitLsRemote
869900 (T.unpack $ render uri)
870901 (GitRef_Branch <$> mbranch)
902+ Nothing
871903 branch <- case mbranch of
872904 Nothing -> withExitFailMessage "Failed to find default branch" $ do
873905 b <- rethrowE $ gitLookupDefaultBranch bothMaps
lib/command/src/Obelisk/Command/Utils.hs+15−6
@@ -22,6 +22,7 @@ import qualified Data.Text as T
2222import Data.Void (Void)
2323import System.Directory (canonicalizePath)
2424import System.Environment (getExecutablePath)
25+import System.Exit (ExitCode)
2526import qualified System.Process as P
2627import Text.Megaparsec as MP
2728import Text.Megaparsec.Char as MP
@@ -78,6 +79,9 @@ copyDir src dest =
7879readGitProcess :: MonadObelisk m => FilePath -> [String] -> m Text
7980readGitProcess repo = readProcessAndLogOutput (Debug, Notice) . gitProc repo
8081
82+readGitProcessNoRepo :: MonadObelisk m => [String] -> m Text
83+readGitProcessNoRepo = readProcessAndLogOutput (Debug, Notice) . gitProcNoRepo
84+
8185processToShellString :: FilePath -> [String] -> String
8286processToShellString cmd args = unwords $ map quoteAndEscape (cmd : args)
8387 where quoteAndEscape x = T.unpack $ "'" <> T.replace "'" "'\''" (T.pack x) <> "'"
@@ -119,16 +123,21 @@ gitLsRemote
119123 :: MonadObelisk m
120124 => String
121125 -> Maybe GitRef
122− -> m GitLsRemoteMaps
123−gitLsRemote repository mRef = do
124− t <- readProc $ gitProcNoRepo $
125− ["ls-remote", "--symref", repository]
126− ++ (maybeToList $ T.unpack . showGitRef <$> mRef)
126+ -> Maybe String
127+ -> m (ExitCode, GitLsRemoteMaps)
128+gitLsRemote repository mRef mBranch = do
129+ (exitCode, out, _err) <- case mBranch of
130+ Nothing -> readCreateProcessWithExitCode $ gitProcNoRepo $
131+ ["ls-remote", "--exit-code", "--symref", repository]
132+ ++ (maybeToList $ T.unpack . showGitRef <$> mRef)
133+ Just branchName -> readCreateProcessWithExitCode $ gitProcNoRepo $
134+ ["ls-remote", "--exit-code", repository, branchName]
135+ let t = T.pack out
127136 maps <- case MP.runParser parseLsRemote "" t of
128137 Left err -> failWith $ T.pack $ MP.parseErrorPretty' t err
129138 Right table -> pure $ bimap M.fromList M.fromList $ partitionEithers $ table
130139 putLog Debug $ "git ls-remote maps: " <> T.pack (show maps)
131− pure maps
140+ pure (exitCode, maps)
132141
133142lexeme :: Parsec Void Text a -> Parsec Void Text a
134143lexeme = ML.lexeme $ void $ MP.takeWhileP (Just "within-line white space") $
lib/route/src/Obelisk/Route/Frontend.hs+7
@@ -161,6 +161,13 @@ instance (Monad m, MonadQuery t vs m) => MonadQuery t vs (RoutedT t r m) where
161161 askQueryResult = lift askQueryResult
162162 queryIncremental = lift . queryIncremental
163163
164+instance (Monad m, RouteToUrl r m) => RouteToUrl r (QueryT t q m) where
165+ askRouteToUrl = lift askRouteToUrl
166+
167+instance (Monad m, SetRoute t r m) => SetRoute t r (QueryT t q m) where
168+ setRoute = lift . setRoute
169+ modifyRoute = lift . modifyRoute
170+
164171runRoutedT :: RoutedT t r m a -> Dynamic t r -> m a
165172runRoutedT = runReaderT . unRoutedT
166173
lib/selftest/src/Obelisk/SelfTest.hs+18−1
@@ -22,7 +22,7 @@ import qualified Network.HTTP.Client as HTTP
2222import qualified Network.HTTP.Types as HTTP
2323import qualified Network.Socket as Socket
2424import Shelly
25−import System.Directory (withCurrentDirectory)
25+import System.Directory (withCurrentDirectory, getDirectoryContents)
2626import System.Environment
2727import System.Exit (ExitCode (..))
2828import System.Info
@@ -213,6 +213,23 @@ main = do
213213 void $ unpack
214214 testThunkPack (dir </> thunk)
215215
216+ describe "ob thunk update --branch" $ parallel $ do
217+ it "can change a thunk to the latest version of a desired branch" $ withTmp $ \dir -> do
218+ let branch1 = "master"
219+ branch2 = "develop"
220+ run_ "git" ["clone", "https://github.com/reflex-frp/reflex.git", toTextIgnore dir, "--branch", branch1]
221+ run_ "ob" ["thunk" , "pack", toTextIgnore dir]
222+ run_ "ob" ["thunk", "update", toTextIgnore dir, "--branch", branch2]
223+
224+ it "doesn't create anything when given an invalid branch" $ withTmp $ \dir -> do
225+ let checkDir dir' = liftIO $ getDirectoryContents $ T.unpack $ toTextIgnore dir'
226+ run_ "git" ["clone", "https://github.com/reflex-frp/reflex.git", toTextIgnore dir, "--branch", "master"]
227+ run_ "ob" ["thunk" , "pack", toTextIgnore dir]
228+ startingContents <- checkDir dir
229+ void $ errExit False $ run "ob" ["thunk", "update", toTextIgnore dir, "--branch", "dumble-palooza"]
230+ checkDir dir >>= liftIO . assertEqual "" startingContents
231+
232+
216233-- | Run `ob run` in the given directory (maximum of one level deep)
217234testObRunInDir :: Socket.PortNumber -> Socket.PortNumber -> Maybe Shelly.FilePath -> HTTP.Manager -> Sh ()
218235testObRunInDir p0 p1 mdir httpManager = handle_sh (\case ExitSuccess -> pure (); e -> throw e) $ do