Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotedit short-variant #648

Merged
merged 4 commits into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions aura/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
17 changes: 8 additions & 9 deletions aura/doc/aura.8
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion aura/exec/Aura/Flags.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
30 changes: 20 additions & 10 deletions aura/lib/Aura/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -59,33 +66,36 @@ 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
notify ss (buildPackages_1 $ bName p) *> hFlush stdout
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
-- during subsequent builds.
--
-- 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
Expand All @@ -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
Expand Down
37 changes: 22 additions & 15 deletions aura/lib/Aura/Install.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

---

Expand Down Expand Up @@ -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
Expand All @@ -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
------------
Expand Down
8 changes: 8 additions & 0 deletions aura/lib/Aura/Languages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> "パッケージ作成に失敗しました。"
Expand Down