diff --git a/aura/CHANGELOG.md b/aura/CHANGELOG.md index 2ca957e30..4ec19b772 100644 --- a/aura/CHANGELOG.md +++ b/aura/CHANGELOG.md @@ -6,8 +6,10 @@ - `--nocheck` will be passed down to `makepkg` to avoid calling the `check()` function during the build process. [#647] +- `--hotedit` now has a short variant: `-e`. [#643] [#647]: https://github.com/fosskers/aura/pull/647 +[#643]: https://github.com/fosskers/aura/issues/643 ## 3.1.9 (2020-09-11) diff --git a/aura/doc/aura.8 b/aura/doc/aura.8 index 9e393ac30..c9f63a7e9 100644 --- a/aura/doc/aura.8 +++ b/aura/doc/aura.8 @@ -182,15 +182,14 @@ whose versions are already available in the local package cache. \fB\-\-hotedit\fR .RS 4 Prompt the user before building to ask if they wish to view/edit the PKGBUILD, -as well as any .install or .patch files. This is not default behavior and thus -does not have a single\-letter option. Research into packages (and by extension, -their PKGBUILDs) should be done before any building occurs. Please use -\fI\-Ap\fR and \fI\-Ad\fR for this, as they will be much faster at presenting -information than searching the AUR website manually. Note that, since aura is -run through sudo, your local value of $EDITOR may not be preserved. Run as "sudo -\fI\-E\fR aura -A --hotedit ..." to preserve your environment. To always allow -environment variables to be passed, have a look at the \fIenv_reset\fR and -\fIenv_keep\fR options in \fBsudoers\fR(5). +as well as any .install or .patch files. However, research into packages (and by +extension, their PKGBUILDs) should be done by the user before any building +occurs. Please use \fI\-Ap\fR and \fI\-Ad\fR for this, as they will be much +faster at presenting information than searching the AUR website manually. Note +that, since aura is run through sudo, your local value of $EDITOR may not be +preserved. Run as "sudo \fI\-E\fR aura -A --hotedit ..." to preserve your +environment. To always allow environment variables to be passed, have a look at +the \fIenv_reset\fR and \fIenv_keep\fR options in \fBsudoers\fR(5). .RE .P \fB\-\-skipdepcheck\fR diff --git a/aura/exec/Aura/Flags.hs b/aura/exec/Aura/Flags.hs index cccec79c0..54fcaeace 100644 --- a/aura/exec/Aura/Flags.hs +++ b/aura/exec/Aura/Flags.hs @@ -401,7 +401,7 @@ buildSwitches = S.fromList <$> many (lv <|> dmd <|> dsm <|> dpb <|> rbd <|> he < dsm = flag' DontSuppressMakepkg (long "unsuppress" <> short 'x' <> hidden <> help "Unsuppress makepkg output.") dpb = flag' DiffPkgbuilds (long "diff" <> short 'k' <> hidden <> help "Show PKGBUILD diffs.") rbd = flag' RebuildDevel (long "devel" <> hidden <> help "Rebuild all git/hg/svn/darcs-based packages.") - he = flag' HotEdit (long "hotedit" <> hidden <> help "Edit a PKGBUILD before building.") + he = flag' HotEdit (long "hotedit" <> short 'e' <> hidden <> help "Edit a PKGBUILD before building.") dr = flag' DryRun (long "dryrun" <> hidden <> help "Run dependency checks and PKGBUILD diffs, but don't build.") sa = flag' SortAlphabetically (long "abc" <> hidden <> help "Sort search results alphabetically.") lv = flag' LowVerbosity (long "quiet" <> short 'q' <> hidden <> help "Display less information.") diff --git a/aura/lib/Aura/Build.hs b/aura/lib/Aura/Build.hs index 0982e5c07..b9b2fd498 100644 --- a/aura/lib/Aura/Build.hs +++ b/aura/lib/Aura/Build.hs @@ -41,6 +41,13 @@ import System.Process.Typed --- +-- | There are multiple outcomes to a single call to `makepkg`. +data BuildResult = AllSourced | Built !(NonEmpty PackagePath) + +builtPPs :: BuildResult -> Maybe (NonEmpty PackagePath) +builtPPs (Built pps) = Just pps +builtPPs _ = Nothing + -- | Storage location for "source" packages built with @--allsource@. -- Can be overridden in config or with @--allsourcepath@. srcPkgStore :: FilePath @@ -59,16 +66,16 @@ installPkgFiles files = do liftIO $ checkDBLock ss liftIO . pacman (envOf ss) $ ["-U"] <> map (T.pack . ppPath) (toList files) <> asFlag (commonConfigOf ss) --- | All building occurs within temp directories, --- or in a location specified by the user with flags. +-- | All building occurs within temp directories, or in a location specified by +-- the user with flags. buildPackages :: NonEmpty Buildable -> RIO Env [PackagePath] buildPackages bs = mapMaybeA build (NEL.toList bs) >>= \case [] -> throwM $ Failure buildFail_10 - built -> pure $ concat built + built -> pure . foldMap toList $ mapMaybe builtPPs built -- | Handles the building of Packages. Fails nicely. -- Assumed: All dependencies are already installed. -build :: Buildable -> RIO Env (Maybe [PackagePath]) +build :: Buildable -> RIO Env (Maybe BuildResult) build p = do logDebug $ "Building: " <> display (pnName $ bName p) ss <- asks settings @@ -76,8 +83,8 @@ build p = do result <- build' p either buildFail (pure . Just) result --- | Should never throw an IO Exception. In theory all errors --- will come back via the @Language -> String@ function. +-- | Should never throw an IO Exception. In theory all errors will come back via +-- the @Language -> String@ function. -- -- If the package is a VCS package (i.e. ending in -git, etc.), it will be built -- and stored in a separate, deterministic location to prevent repeated clonings @@ -85,7 +92,10 @@ build p = do -- -- If `--allsource` was given, then the package isn't actually built. -- Instead, a @.src.tar.gz@ file is produced and copied to `srcPkgStore`. -build' :: Buildable -> RIO Env (Either Failure [PackagePath]) +-- +-- One `Buildable` can become multiple `PackagePath` due to "split packages". +-- i.e. a single call to `makepkg` can produce multiple related packages. +build' :: Buildable -> RIO Env (Either Failure BuildResult) build' b = do ss <- asks settings let !isDevel = isDevelPkg $ bName b @@ -110,10 +120,10 @@ build' b = do if S.member AllSource . makepkgFlagsOf $ buildConfigOf ss then do let !allsourcePath = fromMaybe srcPkgStore . allsourcePathOf $ buildConfigOf ss - liftIO (makepkgSource usr >>= traverse_ (moveToSourcePath allsourcePath)) $> [] + liftIO (makepkgSource usr >>= traverse_ (moveToSourcePath allsourcePath)) $> AllSourced else do - pNames <- ExceptT . liftIO . fmap (fmap NEL.toList) $ makepkg ss usr - liftIO $ traverse (moveToCachePath ss) pNames + pNames <- ExceptT . liftIO $ makepkg ss usr + liftIO . fmap Built $ traverse (moveToCachePath ss) pNames when (switch ss DeleteBuildDir) $ do logDebug . fromString $ "Deleting build directory: " <> buildDir removeDirectoryRecursive buildDir diff --git a/aura/lib/Aura/Install.hs b/aura/lib/Aura/Install.hs index 45a8568d7..74e4b9045 100644 --- a/aura/lib/Aura/Install.hs +++ b/aura/lib/Aura/Install.hs @@ -35,10 +35,12 @@ import Data.Text.Prettyprint.Doc import Data.Text.Prettyprint.Doc.Render.Terminal import RIO import RIO.Directory (setCurrentDirectory) +import RIO.FilePath (takeFileName) import qualified RIO.List as L import qualified RIO.Map as M import qualified RIO.NonEmpty as NEL import qualified RIO.Set as S +import Text.Printf (printf) --- @@ -144,14 +146,16 @@ repoInstall ps = do let !pacOpts = asFlag $ commonConfigOf ss liftIO . pacman (envOf ss) $ ["-S", "--asdeps"] <> pacOpts <> asFlag (NEL.map pName ps) +-- | Try to build and install all packages. Requested packages that already have +-- a version in the cache will not be rebuilt unless `--force` was passed. buildAndInstall :: NonEmpty (NonEmpty Buildable) -> RIO Env () buildAndInstall bss = do - ss <- asks settings + ss <- asks settings let !pth = either id id . cachePathOf $ commonConfigOf ss !allsource = S.member AllSource . makepkgFlagsOf $ buildConfigOf ss cache <- liftIO $ cacheContents pth when allsource $ notify ss buildPackages_2 - traverse_ (f cache) bss + traverse_ (f ss cache) bss when allsource $ do let !allsourcePath = fromMaybe srcPkgStore . allsourcePathOf $ buildConfigOf ss notify ss $ buildPackages_3 allsourcePath @@ -160,23 +164,26 @@ buildAndInstall bss = do -- `built` and the `traverse_` line below don't run, but `annotateDeps` is -- called anyway. There is definitely a better way to manage the `NonEmpty`s -- here. - f :: Cache -> NonEmpty Buildable -> RIO Env () - f (Cache cache) bs = do - ss <- asks settings - let (ps, cached) = fmapEither g $ NEL.toList bs - - -- | If we used @--force@, then take the package as-is. Otherwise, try - -- to look it up in the package cache. If we find a match, we don't - -- need to build it. - g :: Buildable -> Either Buildable PackagePath - g b = case bToSP b `M.lookup` cache of - Just pp | not (switch ss ForceBuilding) -> Right pp - _ -> Left b - + f :: Settings -> Cache -> NonEmpty Buildable -> RIO Env () + f ss cache bs = do + let (ps, cached) = fmapEither (g ss cache) $ NEL.toList bs + when (switch ss HotEdit && not (null cached)) $ do + warn ss buildPackages_4 + traverse_ (liftIO . printf " - %s\n" . takeFileName . ppPath) cached + warn ss buildPackages_5 built <- traverse buildPackages $ NEL.nonEmpty ps traverse_ installPkgFiles $ (built <> Just cached) >>= NEL.nonEmpty liftIO $ annotateDeps (envOf ss) bs + -- | If we used @--force@, then take the package as-is. Otherwise, try + -- to look it up in the package cache. If we find a match, we don't + -- need to build it. + g :: Settings -> Cache -> Buildable -> Either Buildable PackagePath + g ss (Cache cache) b = case bToSP b `M.lookup` cache of + Just pp | not (switch ss ForceBuilding) -> Right pp + _ -> Left b + + ------------ -- REPORTING ------------ diff --git a/aura/lib/Aura/Languages.hs b/aura/lib/Aura/Languages.hs index b2ab174bb..e0187ab0a 100644 --- a/aura/lib/Aura/Languages.hs +++ b/aura/lib/Aura/Languages.hs @@ -222,6 +222,14 @@ buildPackages_3 fp = \case Spanish -> "Todos los archivos .src.tar.gz fueron construidos y copiados a: " <> pretty fp _ -> "All .src.tar.gz files were built and copied to: " <> pretty fp +buildPackages_4 :: Language -> Doc AnsiStyle +buildPackages_4 = \case + _ -> bt @Text "--hotedit" <+> "detected, but the following have cache entries and will be skipped for editing:" + +buildPackages_5 :: Language -> Doc AnsiStyle +buildPackages_5 = \case + _ -> "You can use" <+> bt @Text "--force" <+> "to override this behaviour." + buildFail_5 :: Language -> Doc AnsiStyle buildFail_5 = \case Japanese -> "パッケージ作成に失敗しました。"