History log of /openbsd-current/usr.sbin/pkg_add/OpenBSD/PkgCreate.pm
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.197 11-Oct-2023 espie

put "stub" within grasp of -DREGRESSION_TESTING.
Extend it slightly: do not stub quirks, so that caching mechanisms work
as usual even when using stubs.


# 1.196 07-Oct-2023 espie

use more specific regression testing knob


Revision tags: OPENBSD_7_4_BASE
# 1.195 20-Jul-2023 espie

fix esoteric error message in case PackageName parses stuff to a bogus
fullpkgname, as seen by Matthias Schmidt


# 1.194 04-Jul-2023 espie

add some more fluff to documentation


# 1.193 04-Jul-2023 espie

fix some very minor syntactic nits


# 1.192 20-Jun-2023 espie

tweak fragment handling error messages a bit
don't pass parameters we don't need


# 1.191 13-Jun-2023 espie

move to use v5.36;
tested by me over the last few weeks, and tb@
also fixed a "manual install" bug properly reported by tb@

aside that there should be *no functional change*.
If you see any message like "hey, the number of params is wrong"
it is a fringe case I didn't run into and should be easy to fix.


# 1.190 23-May-2023 espie

don't pass state, we get them from the progressmeter


# 1.189 22-May-2023 espie

gc unused/old code


# 1.188 21-May-2023 espie

move the interface to SharedLibs to be somewhat object oriented

accordingly, load it "just in time" in State.

Most calls get simplified, and we can save more state for later.


# 1.187 17-May-2023 espie

stop using old-style prototypes except where strictly necessary
(for try/catch)

signatures will be much more powerful once I move to 5.36


# 1.186 16-May-2023 espie

use the new set_destdir interface


Revision tags: OPENBSD_7_3_BASE
# 1.185 25-Jan-2023 espie

change naming convention for the lru "save history" cache, so that
ports like "lang/chicken/core" do generate files like lang.chicken.core.lru
instead of lang.chicken.core (which can create confusion in people's mind)

do so transparently by reading the old file if need be, and removing it
afterwards.

Funny thing noticed by tb@

ok tb@, sthen@


# 1.184 01-Nov-2022 espie

Have -S actually behave like the other introspection options, namely only
eschew building the package is -n is mentionned.

Document that -S -n is heavily optimized for speed since it's mostly used
by dpb -R to figure out what to rebuild.


# 1.183 01-Nov-2022 espie

fix a logic error from 2018: be silent if any of -S, -n, -q are mentioned.

The actual bug reverted in 1.128 was from "make print-plist-libs"
which would invoke pkg_create -n -Q and filter out the libs: but
in that case, pkg_create would not be silent, thus yielding
reading plist|-/usr/local/lib/libpython3.9.so.0.0
to filter, which obviously wouldn't work.

So, turn on silent mode for -Q as well.


Revision tags: OPENBSD_7_2_BASE
# 1.182 28-Jun-2022 espie

if we can't open the user db, don't try to read from a closed fh


# 1.181 28-Jun-2022 espie

some old signing code was still around


# 1.180 06-Jun-2022 espie

have compute_checksum return a status, so that we don't report similar
errors several times (for instance, if a file doesn't exist, its checksum
is not going to match, obviously)


# 1.179 28-May-2022 espie

have pkg_create generate the hash for always-update


# 1.178 15-May-2022 espie

clean up and document the LRU stuff better
- create a separate path when we don't want history
- add a dummy entry to see the threshold between changed and unchanged
in verbose mode
- document better the various stuff that gets separated
- error out in case we want history (by default) and anything goes wrong


# 1.177 15-May-2022 espie

remove the gzip chunk after CONTENTS, it was only needed back when
we signed the packing-list separately. Now that we use signify to
create the signature without decompressing anything, it's completely
irrelevant.


# 1.176 12-May-2022 espie

yet another stupid shadowed variable, thx sthen@


# 1.175 12-May-2022 espie

explicitly write LRU in a comment so that it's easier to find ;)


Revision tags: OPENBSD_7_1_BASE
# 1.174 13-Jan-2022 espie

allow disabling the @ts tweak, which may come in handy for new fw_update
that doesn't grok them.


# 1.173 09-Nov-2021 espie

fix typo (noticed by sthen@)


# 1.172 08-Nov-2021 espie

add extra support to pass REVISION, EPOCH, FLAVOR_LIST from the ports
infrastructure, so that pkg_create can catch some naming errors.


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.171 26-Jan-2021 espie

remove test that's now bogus, as fullpkgpath takes precedence.
thanks bluhm@


# 1.170 11-Jan-2021 espie

- grab fullpkgpath early (to decide: hard error if not provided) ?
- tweak the look-up mechanism for dependencies to NOT look at installed
packages for inter-dependencies between subpackages (and debug packages)
of the SAME pkgpath.

The rationale for looking at installed packages in the usual case
is that it's normally much faster rather than have the ports tree
spew out packing-lists.

In the case of multi-packages updates, the new version may have been built
successfully (and correctly) while the old version is still around.
However, if pkg_create looks at the installed version, it may fail to create
the package because the shared library versions will be different.


Revision tags: OPENBSD_6_8_BASE
# 1.169 25-Jul-2020 ajacoutot

More DESC -> DESCR; spotted by espie@


# 1.168 25-Jul-2020 ajacoutot

tyop: DESC -> DESCR

ok landry@ robert@


Revision tags: OPENBSD_6_7_BASE
# 1.167 26-Jan-2020 espie

give pkg_create knowledge of WRKOBJDIR, so it can error out if a symlink
points in there.

okay aja@ sthen@


# 1.166 13-Jan-2020 espie

nit, use "fatal" with parameters as intended


# 1.165 09-Jan-2020 espie

have ask_tree be more specific in its error reporting.
make sure the child has the same effective and real ids,
as perl interprets it as "setuid, refuse to debug"
go to the end of the pipe so the child doesn't exit
prematurely (didn't use to happen but now it does)

help from afresh1@ in diagnosing that one.


# 1.164 07-Nov-2019 espie

when asking the ports tree, we fork a child.
instead of ditching stderr entirely, keep it in a temp file, and if the
child exits with an error, we got something to display.
(note that returning and undef'd plist is enough of an error, just we
had no clue what went wrong previously)

aja@ ran into this a few weeks ago.


Revision tags: OPENBSD_6_6_BASE
# 1.163 21-Jul-2019 espie

start re-adding the non-broken changes:
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle


# 1.162 17-Jul-2019 sthen

backout previous commits for now; some of this is shared with dpb and
results in problems. hints from pvk@ about what introduced the breakage
we were seeing, who confirms that this backout fixes things; comitting
early to unbreak package builds.

====
a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...

Members:
OpenBSD/AddCreateDelete.pm:1.44->1.45
OpenBSD/AddDelete.pm:1.87->1.88
OpenBSD/Error.pm:1.33->1.34
OpenBSD/PackageRepository.pm:1.164->1.165
OpenBSD/PkgCreate.pm:1.160->1.161
OpenBSD/State.pm:1.58->1.59
OpenBSD/Temp.pm:1.34->1.35
====


# 1.161 14-Jul-2019 espie

a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...


# 1.160 11-Jul-2019 espie

move the display of cmd into fatal, and don't say it's a fatal error, it's
already obvious


# 1.159 11-Jul-2019 espie

tweak the way we report bugs
- the catch/catchall distinction is no longer relevant, strip some info
by default now
- use state->{cmd} to display the command name properly

This makes sure final displays show the command name.


# 1.158 10-Jul-2019 espie

make pkg_create fail properly (return 1 is useless there)

OpenBSD::Temp error handling as well


# 1.157 08-Jul-2019 espie

actually use error, we can delay fatal problems


# 1.156 08-Jul-2019 espie

check ::Temp creation


# 1.155 28-May-2019 espie

oops, let cdrom normalize if it's there.
Noticed by sthen@


# 1.154 28-May-2019 espie

make PERMIT_CDROM info optional
as discussed with sthen@, code slightly adjusted


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.153 03-Aug-2018 espie

actually heed localbase when looking for groff


# 1.152 03-Aug-2018 espie

reorg groff runner so that failures are handled better
do the logic for manpage formatting better, so that we can't miss things
simplify filenames, fullname always has a slash


# 1.151 26-Jun-2018 espie

kill the solve_tags part of pkg_create for now, as it doesn't work at all


# 1.150 24-Jun-2018 espie

get ready to reuse verify_tag


# 1.149 23-Jun-2018 espie

solve_tags not yet functional, I'll reactivate the checks during creation
when it's cleaned up


# 1.148 23-Jun-2018 espie

well, when we read the plist from the ports tree, we need to register
the tag info similarly to registering libraries


# 1.147 23-Jun-2018 espie

PkgCreate has no business knowing details of define-tag


# 1.146 23-Jun-2018 espie

do some more basic checking of tags vs define-tag so that parameter usage
is handled more gracefully


# 1.145 22-Jun-2018 espie

move the tag base code into SolverBase, and use it in PkgCreate, so that
we refuse to create packages with tags without reachable definitions


# 1.144 21-Jun-2018 espie

split the common half of dependencies handling into SolverBase, as PkgCreate
only uses that


# 1.143 18-Jun-2018 espie

kill Frag/NoFrag, they only make sense in update-plist, so they've been
moved there.


# 1.142 15-Jun-2018 espie

Add a -Dstub option to facilitate creating/adding/deleting "stubbed" packages
with just the packing and dependency info with none of the files.

(useful for debugging tricky cases that involve large packages)


# 1.141 06-Jun-2018 espie

if the parser can't find a starting line in user db, it won't look
at any line, so it won't error out.
Add logic to make it error out.


# 1.140 30-May-2018 espie

port -u userlist option from update-plist, as suggested by sthen@.
main differences:
- error out on a problem instead of warning
- always parse the userlist if the option is specified. Avoid ticking time
bomb effect on bulk builds, where packages would be fine until the first
@new(user|group) usage in case the user list got corrupted.

Note it's still an option, so if you're using pkg_create outside of the
ports tree, you can do whatever you want.


# 1.139 13-May-2018 espie

adjust highly misleading comment to match reality


# 1.138 09-May-2018 espie

on the other hand, commenting this out was involuntary.
ask_tree will often say fun things because of (say) pipe closes


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.196 07-Oct-2023 espie

use more specific regression testing knob


Revision tags: OPENBSD_7_4_BASE
# 1.195 20-Jul-2023 espie

fix esoteric error message in case PackageName parses stuff to a bogus
fullpkgname, as seen by Matthias Schmidt


# 1.194 04-Jul-2023 espie

add some more fluff to documentation


# 1.193 04-Jul-2023 espie

fix some very minor syntactic nits


# 1.192 20-Jun-2023 espie

tweak fragment handling error messages a bit
don't pass parameters we don't need


# 1.191 13-Jun-2023 espie

move to use v5.36;
tested by me over the last few weeks, and tb@
also fixed a "manual install" bug properly reported by tb@

aside that there should be *no functional change*.
If you see any message like "hey, the number of params is wrong"
it is a fringe case I didn't run into and should be easy to fix.


# 1.190 23-May-2023 espie

don't pass state, we get them from the progressmeter


# 1.189 22-May-2023 espie

gc unused/old code


# 1.188 21-May-2023 espie

move the interface to SharedLibs to be somewhat object oriented

accordingly, load it "just in time" in State.

Most calls get simplified, and we can save more state for later.


# 1.187 17-May-2023 espie

stop using old-style prototypes except where strictly necessary
(for try/catch)

signatures will be much more powerful once I move to 5.36


# 1.186 16-May-2023 espie

use the new set_destdir interface


Revision tags: OPENBSD_7_3_BASE
# 1.185 25-Jan-2023 espie

change naming convention for the lru "save history" cache, so that
ports like "lang/chicken/core" do generate files like lang.chicken.core.lru
instead of lang.chicken.core (which can create confusion in people's mind)

do so transparently by reading the old file if need be, and removing it
afterwards.

Funny thing noticed by tb@

ok tb@, sthen@


# 1.184 01-Nov-2022 espie

Have -S actually behave like the other introspection options, namely only
eschew building the package is -n is mentionned.

Document that -S -n is heavily optimized for speed since it's mostly used
by dpb -R to figure out what to rebuild.


# 1.183 01-Nov-2022 espie

fix a logic error from 2018: be silent if any of -S, -n, -q are mentioned.

The actual bug reverted in 1.128 was from "make print-plist-libs"
which would invoke pkg_create -n -Q and filter out the libs: but
in that case, pkg_create would not be silent, thus yielding
reading plist|-/usr/local/lib/libpython3.9.so.0.0
to filter, which obviously wouldn't work.

So, turn on silent mode for -Q as well.


Revision tags: OPENBSD_7_2_BASE
# 1.182 28-Jun-2022 espie

if we can't open the user db, don't try to read from a closed fh


# 1.181 28-Jun-2022 espie

some old signing code was still around


# 1.180 06-Jun-2022 espie

have compute_checksum return a status, so that we don't report similar
errors several times (for instance, if a file doesn't exist, its checksum
is not going to match, obviously)


# 1.179 28-May-2022 espie

have pkg_create generate the hash for always-update


# 1.178 15-May-2022 espie

clean up and document the LRU stuff better
- create a separate path when we don't want history
- add a dummy entry to see the threshold between changed and unchanged
in verbose mode
- document better the various stuff that gets separated
- error out in case we want history (by default) and anything goes wrong


# 1.177 15-May-2022 espie

remove the gzip chunk after CONTENTS, it was only needed back when
we signed the packing-list separately. Now that we use signify to
create the signature without decompressing anything, it's completely
irrelevant.


# 1.176 12-May-2022 espie

yet another stupid shadowed variable, thx sthen@


# 1.175 12-May-2022 espie

explicitly write LRU in a comment so that it's easier to find ;)


Revision tags: OPENBSD_7_1_BASE
# 1.174 13-Jan-2022 espie

allow disabling the @ts tweak, which may come in handy for new fw_update
that doesn't grok them.


# 1.173 09-Nov-2021 espie

fix typo (noticed by sthen@)


# 1.172 08-Nov-2021 espie

add extra support to pass REVISION, EPOCH, FLAVOR_LIST from the ports
infrastructure, so that pkg_create can catch some naming errors.


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.171 26-Jan-2021 espie

remove test that's now bogus, as fullpkgpath takes precedence.
thanks bluhm@


# 1.170 11-Jan-2021 espie

- grab fullpkgpath early (to decide: hard error if not provided) ?
- tweak the look-up mechanism for dependencies to NOT look at installed
packages for inter-dependencies between subpackages (and debug packages)
of the SAME pkgpath.

The rationale for looking at installed packages in the usual case
is that it's normally much faster rather than have the ports tree
spew out packing-lists.

In the case of multi-packages updates, the new version may have been built
successfully (and correctly) while the old version is still around.
However, if pkg_create looks at the installed version, it may fail to create
the package because the shared library versions will be different.


Revision tags: OPENBSD_6_8_BASE
# 1.169 25-Jul-2020 ajacoutot

More DESC -> DESCR; spotted by espie@


# 1.168 25-Jul-2020 ajacoutot

tyop: DESC -> DESCR

ok landry@ robert@


Revision tags: OPENBSD_6_7_BASE
# 1.167 26-Jan-2020 espie

give pkg_create knowledge of WRKOBJDIR, so it can error out if a symlink
points in there.

okay aja@ sthen@


# 1.166 13-Jan-2020 espie

nit, use "fatal" with parameters as intended


# 1.165 09-Jan-2020 espie

have ask_tree be more specific in its error reporting.
make sure the child has the same effective and real ids,
as perl interprets it as "setuid, refuse to debug"
go to the end of the pipe so the child doesn't exit
prematurely (didn't use to happen but now it does)

help from afresh1@ in diagnosing that one.


# 1.164 07-Nov-2019 espie

when asking the ports tree, we fork a child.
instead of ditching stderr entirely, keep it in a temp file, and if the
child exits with an error, we got something to display.
(note that returning and undef'd plist is enough of an error, just we
had no clue what went wrong previously)

aja@ ran into this a few weeks ago.


Revision tags: OPENBSD_6_6_BASE
# 1.163 21-Jul-2019 espie

start re-adding the non-broken changes:
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle


# 1.162 17-Jul-2019 sthen

backout previous commits for now; some of this is shared with dpb and
results in problems. hints from pvk@ about what introduced the breakage
we were seeing, who confirms that this backout fixes things; comitting
early to unbreak package builds.

====
a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...

Members:
OpenBSD/AddCreateDelete.pm:1.44->1.45
OpenBSD/AddDelete.pm:1.87->1.88
OpenBSD/Error.pm:1.33->1.34
OpenBSD/PackageRepository.pm:1.164->1.165
OpenBSD/PkgCreate.pm:1.160->1.161
OpenBSD/State.pm:1.58->1.59
OpenBSD/Temp.pm:1.34->1.35
====


# 1.161 14-Jul-2019 espie

a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...


# 1.160 11-Jul-2019 espie

move the display of cmd into fatal, and don't say it's a fatal error, it's
already obvious


# 1.159 11-Jul-2019 espie

tweak the way we report bugs
- the catch/catchall distinction is no longer relevant, strip some info
by default now
- use state->{cmd} to display the command name properly

This makes sure final displays show the command name.


# 1.158 10-Jul-2019 espie

make pkg_create fail properly (return 1 is useless there)

OpenBSD::Temp error handling as well


# 1.157 08-Jul-2019 espie

actually use error, we can delay fatal problems


# 1.156 08-Jul-2019 espie

check ::Temp creation


# 1.155 28-May-2019 espie

oops, let cdrom normalize if it's there.
Noticed by sthen@


# 1.154 28-May-2019 espie

make PERMIT_CDROM info optional
as discussed with sthen@, code slightly adjusted


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.153 03-Aug-2018 espie

actually heed localbase when looking for groff


# 1.152 03-Aug-2018 espie

reorg groff runner so that failures are handled better
do the logic for manpage formatting better, so that we can't miss things
simplify filenames, fullname always has a slash


# 1.151 26-Jun-2018 espie

kill the solve_tags part of pkg_create for now, as it doesn't work at all


# 1.150 24-Jun-2018 espie

get ready to reuse verify_tag


# 1.149 23-Jun-2018 espie

solve_tags not yet functional, I'll reactivate the checks during creation
when it's cleaned up


# 1.148 23-Jun-2018 espie

well, when we read the plist from the ports tree, we need to register
the tag info similarly to registering libraries


# 1.147 23-Jun-2018 espie

PkgCreate has no business knowing details of define-tag


# 1.146 23-Jun-2018 espie

do some more basic checking of tags vs define-tag so that parameter usage
is handled more gracefully


# 1.145 22-Jun-2018 espie

move the tag base code into SolverBase, and use it in PkgCreate, so that
we refuse to create packages with tags without reachable definitions


# 1.144 21-Jun-2018 espie

split the common half of dependencies handling into SolverBase, as PkgCreate
only uses that


# 1.143 18-Jun-2018 espie

kill Frag/NoFrag, they only make sense in update-plist, so they've been
moved there.


# 1.142 15-Jun-2018 espie

Add a -Dstub option to facilitate creating/adding/deleting "stubbed" packages
with just the packing and dependency info with none of the files.

(useful for debugging tricky cases that involve large packages)


# 1.141 06-Jun-2018 espie

if the parser can't find a starting line in user db, it won't look
at any line, so it won't error out.
Add logic to make it error out.


# 1.140 30-May-2018 espie

port -u userlist option from update-plist, as suggested by sthen@.
main differences:
- error out on a problem instead of warning
- always parse the userlist if the option is specified. Avoid ticking time
bomb effect on bulk builds, where packages would be fine until the first
@new(user|group) usage in case the user list got corrupted.

Note it's still an option, so if you're using pkg_create outside of the
ports tree, you can do whatever you want.


# 1.139 13-May-2018 espie

adjust highly misleading comment to match reality


# 1.138 09-May-2018 espie

on the other hand, commenting this out was involuntary.
ask_tree will often say fun things because of (say) pipe closes


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.195 20-Jul-2023 espie

fix esoteric error message in case PackageName parses stuff to a bogus
fullpkgname, as seen by Matthias Schmidt


# 1.194 04-Jul-2023 espie

add some more fluff to documentation


# 1.193 04-Jul-2023 espie

fix some very minor syntactic nits


# 1.192 20-Jun-2023 espie

tweak fragment handling error messages a bit
don't pass parameters we don't need


# 1.191 13-Jun-2023 espie

move to use v5.36;
tested by me over the last few weeks, and tb@
also fixed a "manual install" bug properly reported by tb@

aside that there should be *no functional change*.
If you see any message like "hey, the number of params is wrong"
it is a fringe case I didn't run into and should be easy to fix.


# 1.190 23-May-2023 espie

don't pass state, we get them from the progressmeter


# 1.189 22-May-2023 espie

gc unused/old code


# 1.188 21-May-2023 espie

move the interface to SharedLibs to be somewhat object oriented

accordingly, load it "just in time" in State.

Most calls get simplified, and we can save more state for later.


# 1.187 17-May-2023 espie

stop using old-style prototypes except where strictly necessary
(for try/catch)

signatures will be much more powerful once I move to 5.36


# 1.186 16-May-2023 espie

use the new set_destdir interface


Revision tags: OPENBSD_7_3_BASE
# 1.185 25-Jan-2023 espie

change naming convention for the lru "save history" cache, so that
ports like "lang/chicken/core" do generate files like lang.chicken.core.lru
instead of lang.chicken.core (which can create confusion in people's mind)

do so transparently by reading the old file if need be, and removing it
afterwards.

Funny thing noticed by tb@

ok tb@, sthen@


# 1.184 01-Nov-2022 espie

Have -S actually behave like the other introspection options, namely only
eschew building the package is -n is mentionned.

Document that -S -n is heavily optimized for speed since it's mostly used
by dpb -R to figure out what to rebuild.


# 1.183 01-Nov-2022 espie

fix a logic error from 2018: be silent if any of -S, -n, -q are mentioned.

The actual bug reverted in 1.128 was from "make print-plist-libs"
which would invoke pkg_create -n -Q and filter out the libs: but
in that case, pkg_create would not be silent, thus yielding
reading plist|-/usr/local/lib/libpython3.9.so.0.0
to filter, which obviously wouldn't work.

So, turn on silent mode for -Q as well.


Revision tags: OPENBSD_7_2_BASE
# 1.182 28-Jun-2022 espie

if we can't open the user db, don't try to read from a closed fh


# 1.181 28-Jun-2022 espie

some old signing code was still around


# 1.180 06-Jun-2022 espie

have compute_checksum return a status, so that we don't report similar
errors several times (for instance, if a file doesn't exist, its checksum
is not going to match, obviously)


# 1.179 28-May-2022 espie

have pkg_create generate the hash for always-update


# 1.178 15-May-2022 espie

clean up and document the LRU stuff better
- create a separate path when we don't want history
- add a dummy entry to see the threshold between changed and unchanged
in verbose mode
- document better the various stuff that gets separated
- error out in case we want history (by default) and anything goes wrong


# 1.177 15-May-2022 espie

remove the gzip chunk after CONTENTS, it was only needed back when
we signed the packing-list separately. Now that we use signify to
create the signature without decompressing anything, it's completely
irrelevant.


# 1.176 12-May-2022 espie

yet another stupid shadowed variable, thx sthen@


# 1.175 12-May-2022 espie

explicitly write LRU in a comment so that it's easier to find ;)


Revision tags: OPENBSD_7_1_BASE
# 1.174 13-Jan-2022 espie

allow disabling the @ts tweak, which may come in handy for new fw_update
that doesn't grok them.


# 1.173 09-Nov-2021 espie

fix typo (noticed by sthen@)


# 1.172 08-Nov-2021 espie

add extra support to pass REVISION, EPOCH, FLAVOR_LIST from the ports
infrastructure, so that pkg_create can catch some naming errors.


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.171 26-Jan-2021 espie

remove test that's now bogus, as fullpkgpath takes precedence.
thanks bluhm@


# 1.170 11-Jan-2021 espie

- grab fullpkgpath early (to decide: hard error if not provided) ?
- tweak the look-up mechanism for dependencies to NOT look at installed
packages for inter-dependencies between subpackages (and debug packages)
of the SAME pkgpath.

The rationale for looking at installed packages in the usual case
is that it's normally much faster rather than have the ports tree
spew out packing-lists.

In the case of multi-packages updates, the new version may have been built
successfully (and correctly) while the old version is still around.
However, if pkg_create looks at the installed version, it may fail to create
the package because the shared library versions will be different.


Revision tags: OPENBSD_6_8_BASE
# 1.169 25-Jul-2020 ajacoutot

More DESC -> DESCR; spotted by espie@


# 1.168 25-Jul-2020 ajacoutot

tyop: DESC -> DESCR

ok landry@ robert@


Revision tags: OPENBSD_6_7_BASE
# 1.167 26-Jan-2020 espie

give pkg_create knowledge of WRKOBJDIR, so it can error out if a symlink
points in there.

okay aja@ sthen@


# 1.166 13-Jan-2020 espie

nit, use "fatal" with parameters as intended


# 1.165 09-Jan-2020 espie

have ask_tree be more specific in its error reporting.
make sure the child has the same effective and real ids,
as perl interprets it as "setuid, refuse to debug"
go to the end of the pipe so the child doesn't exit
prematurely (didn't use to happen but now it does)

help from afresh1@ in diagnosing that one.


# 1.164 07-Nov-2019 espie

when asking the ports tree, we fork a child.
instead of ditching stderr entirely, keep it in a temp file, and if the
child exits with an error, we got something to display.
(note that returning and undef'd plist is enough of an error, just we
had no clue what went wrong previously)

aja@ ran into this a few weeks ago.


Revision tags: OPENBSD_6_6_BASE
# 1.163 21-Jul-2019 espie

start re-adding the non-broken changes:
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle


# 1.162 17-Jul-2019 sthen

backout previous commits for now; some of this is shared with dpb and
results in problems. hints from pvk@ about what introduced the breakage
we were seeing, who confirms that this backout fixes things; comitting
early to unbreak package builds.

====
a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...

Members:
OpenBSD/AddCreateDelete.pm:1.44->1.45
OpenBSD/AddDelete.pm:1.87->1.88
OpenBSD/Error.pm:1.33->1.34
OpenBSD/PackageRepository.pm:1.164->1.165
OpenBSD/PkgCreate.pm:1.160->1.161
OpenBSD/State.pm:1.58->1.59
OpenBSD/Temp.pm:1.34->1.35
====


# 1.161 14-Jul-2019 espie

a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...


# 1.160 11-Jul-2019 espie

move the display of cmd into fatal, and don't say it's a fatal error, it's
already obvious


# 1.159 11-Jul-2019 espie

tweak the way we report bugs
- the catch/catchall distinction is no longer relevant, strip some info
by default now
- use state->{cmd} to display the command name properly

This makes sure final displays show the command name.


# 1.158 10-Jul-2019 espie

make pkg_create fail properly (return 1 is useless there)

OpenBSD::Temp error handling as well


# 1.157 08-Jul-2019 espie

actually use error, we can delay fatal problems


# 1.156 08-Jul-2019 espie

check ::Temp creation


# 1.155 28-May-2019 espie

oops, let cdrom normalize if it's there.
Noticed by sthen@


# 1.154 28-May-2019 espie

make PERMIT_CDROM info optional
as discussed with sthen@, code slightly adjusted


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.153 03-Aug-2018 espie

actually heed localbase when looking for groff


# 1.152 03-Aug-2018 espie

reorg groff runner so that failures are handled better
do the logic for manpage formatting better, so that we can't miss things
simplify filenames, fullname always has a slash


# 1.151 26-Jun-2018 espie

kill the solve_tags part of pkg_create for now, as it doesn't work at all


# 1.150 24-Jun-2018 espie

get ready to reuse verify_tag


# 1.149 23-Jun-2018 espie

solve_tags not yet functional, I'll reactivate the checks during creation
when it's cleaned up


# 1.148 23-Jun-2018 espie

well, when we read the plist from the ports tree, we need to register
the tag info similarly to registering libraries


# 1.147 23-Jun-2018 espie

PkgCreate has no business knowing details of define-tag


# 1.146 23-Jun-2018 espie

do some more basic checking of tags vs define-tag so that parameter usage
is handled more gracefully


# 1.145 22-Jun-2018 espie

move the tag base code into SolverBase, and use it in PkgCreate, so that
we refuse to create packages with tags without reachable definitions


# 1.144 21-Jun-2018 espie

split the common half of dependencies handling into SolverBase, as PkgCreate
only uses that


# 1.143 18-Jun-2018 espie

kill Frag/NoFrag, they only make sense in update-plist, so they've been
moved there.


# 1.142 15-Jun-2018 espie

Add a -Dstub option to facilitate creating/adding/deleting "stubbed" packages
with just the packing and dependency info with none of the files.

(useful for debugging tricky cases that involve large packages)


# 1.141 06-Jun-2018 espie

if the parser can't find a starting line in user db, it won't look
at any line, so it won't error out.
Add logic to make it error out.


# 1.140 30-May-2018 espie

port -u userlist option from update-plist, as suggested by sthen@.
main differences:
- error out on a problem instead of warning
- always parse the userlist if the option is specified. Avoid ticking time
bomb effect on bulk builds, where packages would be fine until the first
@new(user|group) usage in case the user list got corrupted.

Note it's still an option, so if you're using pkg_create outside of the
ports tree, you can do whatever you want.


# 1.139 13-May-2018 espie

adjust highly misleading comment to match reality


# 1.138 09-May-2018 espie

on the other hand, commenting this out was involuntary.
ask_tree will often say fun things because of (say) pipe closes


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.194 04-Jul-2023 espie

add some more fluff to documentation


# 1.193 04-Jul-2023 espie

fix some very minor syntactic nits


# 1.192 20-Jun-2023 espie

tweak fragment handling error messages a bit
don't pass parameters we don't need


# 1.191 13-Jun-2023 espie

move to use v5.36;
tested by me over the last few weeks, and tb@
also fixed a "manual install" bug properly reported by tb@

aside that there should be *no functional change*.
If you see any message like "hey, the number of params is wrong"
it is a fringe case I didn't run into and should be easy to fix.


# 1.190 23-May-2023 espie

don't pass state, we get them from the progressmeter


# 1.189 22-May-2023 espie

gc unused/old code


# 1.188 21-May-2023 espie

move the interface to SharedLibs to be somewhat object oriented

accordingly, load it "just in time" in State.

Most calls get simplified, and we can save more state for later.


# 1.187 17-May-2023 espie

stop using old-style prototypes except where strictly necessary
(for try/catch)

signatures will be much more powerful once I move to 5.36


# 1.186 16-May-2023 espie

use the new set_destdir interface


Revision tags: OPENBSD_7_3_BASE
# 1.185 25-Jan-2023 espie

change naming convention for the lru "save history" cache, so that
ports like "lang/chicken/core" do generate files like lang.chicken.core.lru
instead of lang.chicken.core (which can create confusion in people's mind)

do so transparently by reading the old file if need be, and removing it
afterwards.

Funny thing noticed by tb@

ok tb@, sthen@


# 1.184 01-Nov-2022 espie

Have -S actually behave like the other introspection options, namely only
eschew building the package is -n is mentionned.

Document that -S -n is heavily optimized for speed since it's mostly used
by dpb -R to figure out what to rebuild.


# 1.183 01-Nov-2022 espie

fix a logic error from 2018: be silent if any of -S, -n, -q are mentioned.

The actual bug reverted in 1.128 was from "make print-plist-libs"
which would invoke pkg_create -n -Q and filter out the libs: but
in that case, pkg_create would not be silent, thus yielding
reading plist|-/usr/local/lib/libpython3.9.so.0.0
to filter, which obviously wouldn't work.

So, turn on silent mode for -Q as well.


Revision tags: OPENBSD_7_2_BASE
# 1.182 28-Jun-2022 espie

if we can't open the user db, don't try to read from a closed fh


# 1.181 28-Jun-2022 espie

some old signing code was still around


# 1.180 06-Jun-2022 espie

have compute_checksum return a status, so that we don't report similar
errors several times (for instance, if a file doesn't exist, its checksum
is not going to match, obviously)


# 1.179 28-May-2022 espie

have pkg_create generate the hash for always-update


# 1.178 15-May-2022 espie

clean up and document the LRU stuff better
- create a separate path when we don't want history
- add a dummy entry to see the threshold between changed and unchanged
in verbose mode
- document better the various stuff that gets separated
- error out in case we want history (by default) and anything goes wrong


# 1.177 15-May-2022 espie

remove the gzip chunk after CONTENTS, it was only needed back when
we signed the packing-list separately. Now that we use signify to
create the signature without decompressing anything, it's completely
irrelevant.


# 1.176 12-May-2022 espie

yet another stupid shadowed variable, thx sthen@


# 1.175 12-May-2022 espie

explicitly write LRU in a comment so that it's easier to find ;)


Revision tags: OPENBSD_7_1_BASE
# 1.174 13-Jan-2022 espie

allow disabling the @ts tweak, which may come in handy for new fw_update
that doesn't grok them.


# 1.173 09-Nov-2021 espie

fix typo (noticed by sthen@)


# 1.172 08-Nov-2021 espie

add extra support to pass REVISION, EPOCH, FLAVOR_LIST from the ports
infrastructure, so that pkg_create can catch some naming errors.


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.171 26-Jan-2021 espie

remove test that's now bogus, as fullpkgpath takes precedence.
thanks bluhm@


# 1.170 11-Jan-2021 espie

- grab fullpkgpath early (to decide: hard error if not provided) ?
- tweak the look-up mechanism for dependencies to NOT look at installed
packages for inter-dependencies between subpackages (and debug packages)
of the SAME pkgpath.

The rationale for looking at installed packages in the usual case
is that it's normally much faster rather than have the ports tree
spew out packing-lists.

In the case of multi-packages updates, the new version may have been built
successfully (and correctly) while the old version is still around.
However, if pkg_create looks at the installed version, it may fail to create
the package because the shared library versions will be different.


Revision tags: OPENBSD_6_8_BASE
# 1.169 25-Jul-2020 ajacoutot

More DESC -> DESCR; spotted by espie@


# 1.168 25-Jul-2020 ajacoutot

tyop: DESC -> DESCR

ok landry@ robert@


Revision tags: OPENBSD_6_7_BASE
# 1.167 26-Jan-2020 espie

give pkg_create knowledge of WRKOBJDIR, so it can error out if a symlink
points in there.

okay aja@ sthen@


# 1.166 13-Jan-2020 espie

nit, use "fatal" with parameters as intended


# 1.165 09-Jan-2020 espie

have ask_tree be more specific in its error reporting.
make sure the child has the same effective and real ids,
as perl interprets it as "setuid, refuse to debug"
go to the end of the pipe so the child doesn't exit
prematurely (didn't use to happen but now it does)

help from afresh1@ in diagnosing that one.


# 1.164 07-Nov-2019 espie

when asking the ports tree, we fork a child.
instead of ditching stderr entirely, keep it in a temp file, and if the
child exits with an error, we got something to display.
(note that returning and undef'd plist is enough of an error, just we
had no clue what went wrong previously)

aja@ ran into this a few weeks ago.


Revision tags: OPENBSD_6_6_BASE
# 1.163 21-Jul-2019 espie

start re-adding the non-broken changes:
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle


# 1.162 17-Jul-2019 sthen

backout previous commits for now; some of this is shared with dpb and
results in problems. hints from pvk@ about what introduced the breakage
we were seeing, who confirms that this backout fixes things; comitting
early to unbreak package builds.

====
a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...

Members:
OpenBSD/AddCreateDelete.pm:1.44->1.45
OpenBSD/AddDelete.pm:1.87->1.88
OpenBSD/Error.pm:1.33->1.34
OpenBSD/PackageRepository.pm:1.164->1.165
OpenBSD/PkgCreate.pm:1.160->1.161
OpenBSD/State.pm:1.58->1.59
OpenBSD/Temp.pm:1.34->1.35
====


# 1.161 14-Jul-2019 espie

a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...


# 1.160 11-Jul-2019 espie

move the display of cmd into fatal, and don't say it's a fatal error, it's
already obvious


# 1.159 11-Jul-2019 espie

tweak the way we report bugs
- the catch/catchall distinction is no longer relevant, strip some info
by default now
- use state->{cmd} to display the command name properly

This makes sure final displays show the command name.


# 1.158 10-Jul-2019 espie

make pkg_create fail properly (return 1 is useless there)

OpenBSD::Temp error handling as well


# 1.157 08-Jul-2019 espie

actually use error, we can delay fatal problems


# 1.156 08-Jul-2019 espie

check ::Temp creation


# 1.155 28-May-2019 espie

oops, let cdrom normalize if it's there.
Noticed by sthen@


# 1.154 28-May-2019 espie

make PERMIT_CDROM info optional
as discussed with sthen@, code slightly adjusted


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.153 03-Aug-2018 espie

actually heed localbase when looking for groff


# 1.152 03-Aug-2018 espie

reorg groff runner so that failures are handled better
do the logic for manpage formatting better, so that we can't miss things
simplify filenames, fullname always has a slash


# 1.151 26-Jun-2018 espie

kill the solve_tags part of pkg_create for now, as it doesn't work at all


# 1.150 24-Jun-2018 espie

get ready to reuse verify_tag


# 1.149 23-Jun-2018 espie

solve_tags not yet functional, I'll reactivate the checks during creation
when it's cleaned up


# 1.148 23-Jun-2018 espie

well, when we read the plist from the ports tree, we need to register
the tag info similarly to registering libraries


# 1.147 23-Jun-2018 espie

PkgCreate has no business knowing details of define-tag


# 1.146 23-Jun-2018 espie

do some more basic checking of tags vs define-tag so that parameter usage
is handled more gracefully


# 1.145 22-Jun-2018 espie

move the tag base code into SolverBase, and use it in PkgCreate, so that
we refuse to create packages with tags without reachable definitions


# 1.144 21-Jun-2018 espie

split the common half of dependencies handling into SolverBase, as PkgCreate
only uses that


# 1.143 18-Jun-2018 espie

kill Frag/NoFrag, they only make sense in update-plist, so they've been
moved there.


# 1.142 15-Jun-2018 espie

Add a -Dstub option to facilitate creating/adding/deleting "stubbed" packages
with just the packing and dependency info with none of the files.

(useful for debugging tricky cases that involve large packages)


# 1.141 06-Jun-2018 espie

if the parser can't find a starting line in user db, it won't look
at any line, so it won't error out.
Add logic to make it error out.


# 1.140 30-May-2018 espie

port -u userlist option from update-plist, as suggested by sthen@.
main differences:
- error out on a problem instead of warning
- always parse the userlist if the option is specified. Avoid ticking time
bomb effect on bulk builds, where packages would be fine until the first
@new(user|group) usage in case the user list got corrupted.

Note it's still an option, so if you're using pkg_create outside of the
ports tree, you can do whatever you want.


# 1.139 13-May-2018 espie

adjust highly misleading comment to match reality


# 1.138 09-May-2018 espie

on the other hand, commenting this out was involuntary.
ask_tree will often say fun things because of (say) pipe closes


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.192 20-Jun-2023 espie

tweak fragment handling error messages a bit
don't pass parameters we don't need


# 1.191 13-Jun-2023 espie

move to use v5.36;
tested by me over the last few weeks, and tb@
also fixed a "manual install" bug properly reported by tb@

aside that there should be *no functional change*.
If you see any message like "hey, the number of params is wrong"
it is a fringe case I didn't run into and should be easy to fix.


# 1.190 23-May-2023 espie

don't pass state, we get them from the progressmeter


# 1.189 22-May-2023 espie

gc unused/old code


# 1.188 21-May-2023 espie

move the interface to SharedLibs to be somewhat object oriented

accordingly, load it "just in time" in State.

Most calls get simplified, and we can save more state for later.


# 1.187 17-May-2023 espie

stop using old-style prototypes except where strictly necessary
(for try/catch)

signatures will be much more powerful once I move to 5.36


# 1.186 16-May-2023 espie

use the new set_destdir interface


Revision tags: OPENBSD_7_3_BASE
# 1.185 25-Jan-2023 espie

change naming convention for the lru "save history" cache, so that
ports like "lang/chicken/core" do generate files like lang.chicken.core.lru
instead of lang.chicken.core (which can create confusion in people's mind)

do so transparently by reading the old file if need be, and removing it
afterwards.

Funny thing noticed by tb@

ok tb@, sthen@


# 1.184 01-Nov-2022 espie

Have -S actually behave like the other introspection options, namely only
eschew building the package is -n is mentionned.

Document that -S -n is heavily optimized for speed since it's mostly used
by dpb -R to figure out what to rebuild.


# 1.183 01-Nov-2022 espie

fix a logic error from 2018: be silent if any of -S, -n, -q are mentioned.

The actual bug reverted in 1.128 was from "make print-plist-libs"
which would invoke pkg_create -n -Q and filter out the libs: but
in that case, pkg_create would not be silent, thus yielding
reading plist|-/usr/local/lib/libpython3.9.so.0.0
to filter, which obviously wouldn't work.

So, turn on silent mode for -Q as well.


Revision tags: OPENBSD_7_2_BASE
# 1.182 28-Jun-2022 espie

if we can't open the user db, don't try to read from a closed fh


# 1.181 28-Jun-2022 espie

some old signing code was still around


# 1.180 06-Jun-2022 espie

have compute_checksum return a status, so that we don't report similar
errors several times (for instance, if a file doesn't exist, its checksum
is not going to match, obviously)


# 1.179 28-May-2022 espie

have pkg_create generate the hash for always-update


# 1.178 15-May-2022 espie

clean up and document the LRU stuff better
- create a separate path when we don't want history
- add a dummy entry to see the threshold between changed and unchanged
in verbose mode
- document better the various stuff that gets separated
- error out in case we want history (by default) and anything goes wrong


# 1.177 15-May-2022 espie

remove the gzip chunk after CONTENTS, it was only needed back when
we signed the packing-list separately. Now that we use signify to
create the signature without decompressing anything, it's completely
irrelevant.


# 1.176 12-May-2022 espie

yet another stupid shadowed variable, thx sthen@


# 1.175 12-May-2022 espie

explicitly write LRU in a comment so that it's easier to find ;)


Revision tags: OPENBSD_7_1_BASE
# 1.174 13-Jan-2022 espie

allow disabling the @ts tweak, which may come in handy for new fw_update
that doesn't grok them.


# 1.173 09-Nov-2021 espie

fix typo (noticed by sthen@)


# 1.172 08-Nov-2021 espie

add extra support to pass REVISION, EPOCH, FLAVOR_LIST from the ports
infrastructure, so that pkg_create can catch some naming errors.


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.171 26-Jan-2021 espie

remove test that's now bogus, as fullpkgpath takes precedence.
thanks bluhm@


# 1.170 11-Jan-2021 espie

- grab fullpkgpath early (to decide: hard error if not provided) ?
- tweak the look-up mechanism for dependencies to NOT look at installed
packages for inter-dependencies between subpackages (and debug packages)
of the SAME pkgpath.

The rationale for looking at installed packages in the usual case
is that it's normally much faster rather than have the ports tree
spew out packing-lists.

In the case of multi-packages updates, the new version may have been built
successfully (and correctly) while the old version is still around.
However, if pkg_create looks at the installed version, it may fail to create
the package because the shared library versions will be different.


Revision tags: OPENBSD_6_8_BASE
# 1.169 25-Jul-2020 ajacoutot

More DESC -> DESCR; spotted by espie@


# 1.168 25-Jul-2020 ajacoutot

tyop: DESC -> DESCR

ok landry@ robert@


Revision tags: OPENBSD_6_7_BASE
# 1.167 26-Jan-2020 espie

give pkg_create knowledge of WRKOBJDIR, so it can error out if a symlink
points in there.

okay aja@ sthen@


# 1.166 13-Jan-2020 espie

nit, use "fatal" with parameters as intended


# 1.165 09-Jan-2020 espie

have ask_tree be more specific in its error reporting.
make sure the child has the same effective and real ids,
as perl interprets it as "setuid, refuse to debug"
go to the end of the pipe so the child doesn't exit
prematurely (didn't use to happen but now it does)

help from afresh1@ in diagnosing that one.


# 1.164 07-Nov-2019 espie

when asking the ports tree, we fork a child.
instead of ditching stderr entirely, keep it in a temp file, and if the
child exits with an error, we got something to display.
(note that returning and undef'd plist is enough of an error, just we
had no clue what went wrong previously)

aja@ ran into this a few weeks ago.


Revision tags: OPENBSD_6_6_BASE
# 1.163 21-Jul-2019 espie

start re-adding the non-broken changes:
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle


# 1.162 17-Jul-2019 sthen

backout previous commits for now; some of this is shared with dpb and
results in problems. hints from pvk@ about what introduced the breakage
we were seeing, who confirms that this backout fixes things; comitting
early to unbreak package builds.

====
a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...

Members:
OpenBSD/AddCreateDelete.pm:1.44->1.45
OpenBSD/AddDelete.pm:1.87->1.88
OpenBSD/Error.pm:1.33->1.34
OpenBSD/PackageRepository.pm:1.164->1.165
OpenBSD/PkgCreate.pm:1.160->1.161
OpenBSD/State.pm:1.58->1.59
OpenBSD/Temp.pm:1.34->1.35
====


# 1.161 14-Jul-2019 espie

a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...


# 1.160 11-Jul-2019 espie

move the display of cmd into fatal, and don't say it's a fatal error, it's
already obvious


# 1.159 11-Jul-2019 espie

tweak the way we report bugs
- the catch/catchall distinction is no longer relevant, strip some info
by default now
- use state->{cmd} to display the command name properly

This makes sure final displays show the command name.


# 1.158 10-Jul-2019 espie

make pkg_create fail properly (return 1 is useless there)

OpenBSD::Temp error handling as well


# 1.157 08-Jul-2019 espie

actually use error, we can delay fatal problems


# 1.156 08-Jul-2019 espie

check ::Temp creation


# 1.155 28-May-2019 espie

oops, let cdrom normalize if it's there.
Noticed by sthen@


# 1.154 28-May-2019 espie

make PERMIT_CDROM info optional
as discussed with sthen@, code slightly adjusted


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.153 03-Aug-2018 espie

actually heed localbase when looking for groff


# 1.152 03-Aug-2018 espie

reorg groff runner so that failures are handled better
do the logic for manpage formatting better, so that we can't miss things
simplify filenames, fullname always has a slash


# 1.151 26-Jun-2018 espie

kill the solve_tags part of pkg_create for now, as it doesn't work at all


# 1.150 24-Jun-2018 espie

get ready to reuse verify_tag


# 1.149 23-Jun-2018 espie

solve_tags not yet functional, I'll reactivate the checks during creation
when it's cleaned up


# 1.148 23-Jun-2018 espie

well, when we read the plist from the ports tree, we need to register
the tag info similarly to registering libraries


# 1.147 23-Jun-2018 espie

PkgCreate has no business knowing details of define-tag


# 1.146 23-Jun-2018 espie

do some more basic checking of tags vs define-tag so that parameter usage
is handled more gracefully


# 1.145 22-Jun-2018 espie

move the tag base code into SolverBase, and use it in PkgCreate, so that
we refuse to create packages with tags without reachable definitions


# 1.144 21-Jun-2018 espie

split the common half of dependencies handling into SolverBase, as PkgCreate
only uses that


# 1.143 18-Jun-2018 espie

kill Frag/NoFrag, they only make sense in update-plist, so they've been
moved there.


# 1.142 15-Jun-2018 espie

Add a -Dstub option to facilitate creating/adding/deleting "stubbed" packages
with just the packing and dependency info with none of the files.

(useful for debugging tricky cases that involve large packages)


# 1.141 06-Jun-2018 espie

if the parser can't find a starting line in user db, it won't look
at any line, so it won't error out.
Add logic to make it error out.


# 1.140 30-May-2018 espie

port -u userlist option from update-plist, as suggested by sthen@.
main differences:
- error out on a problem instead of warning
- always parse the userlist if the option is specified. Avoid ticking time
bomb effect on bulk builds, where packages would be fine until the first
@new(user|group) usage in case the user list got corrupted.

Note it's still an option, so if you're using pkg_create outside of the
ports tree, you can do whatever you want.


# 1.139 13-May-2018 espie

adjust highly misleading comment to match reality


# 1.138 09-May-2018 espie

on the other hand, commenting this out was involuntary.
ask_tree will often say fun things because of (say) pipe closes


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.185 25-Jan-2023 espie

change naming convention for the lru "save history" cache, so that
ports like "lang/chicken/core" do generate files like lang.chicken.core.lru
instead of lang.chicken.core (which can create confusion in people's mind)

do so transparently by reading the old file if need be, and removing it
afterwards.

Funny thing noticed by tb@

ok tb@, sthen@


# 1.184 01-Nov-2022 espie

Have -S actually behave like the other introspection options, namely only
eschew building the package is -n is mentionned.

Document that -S -n is heavily optimized for speed since it's mostly used
by dpb -R to figure out what to rebuild.


# 1.183 01-Nov-2022 espie

fix a logic error from 2018: be silent if any of -S, -n, -q are mentioned.

The actual bug reverted in 1.128 was from "make print-plist-libs"
which would invoke pkg_create -n -Q and filter out the libs: but
in that case, pkg_create would not be silent, thus yielding
reading plist|-/usr/local/lib/libpython3.9.so.0.0
to filter, which obviously wouldn't work.

So, turn on silent mode for -Q as well.


Revision tags: OPENBSD_7_2_BASE
# 1.182 28-Jun-2022 espie

if we can't open the user db, don't try to read from a closed fh


# 1.181 28-Jun-2022 espie

some old signing code was still around


# 1.180 06-Jun-2022 espie

have compute_checksum return a status, so that we don't report similar
errors several times (for instance, if a file doesn't exist, its checksum
is not going to match, obviously)


# 1.179 28-May-2022 espie

have pkg_create generate the hash for always-update


# 1.178 15-May-2022 espie

clean up and document the LRU stuff better
- create a separate path when we don't want history
- add a dummy entry to see the threshold between changed and unchanged
in verbose mode
- document better the various stuff that gets separated
- error out in case we want history (by default) and anything goes wrong


# 1.177 15-May-2022 espie

remove the gzip chunk after CONTENTS, it was only needed back when
we signed the packing-list separately. Now that we use signify to
create the signature without decompressing anything, it's completely
irrelevant.


# 1.176 12-May-2022 espie

yet another stupid shadowed variable, thx sthen@


# 1.175 12-May-2022 espie

explicitly write LRU in a comment so that it's easier to find ;)


Revision tags: OPENBSD_7_1_BASE
# 1.174 13-Jan-2022 espie

allow disabling the @ts tweak, which may come in handy for new fw_update
that doesn't grok them.


# 1.173 09-Nov-2021 espie

fix typo (noticed by sthen@)


# 1.172 08-Nov-2021 espie

add extra support to pass REVISION, EPOCH, FLAVOR_LIST from the ports
infrastructure, so that pkg_create can catch some naming errors.


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.171 26-Jan-2021 espie

remove test that's now bogus, as fullpkgpath takes precedence.
thanks bluhm@


# 1.170 11-Jan-2021 espie

- grab fullpkgpath early (to decide: hard error if not provided) ?
- tweak the look-up mechanism for dependencies to NOT look at installed
packages for inter-dependencies between subpackages (and debug packages)
of the SAME pkgpath.

The rationale for looking at installed packages in the usual case
is that it's normally much faster rather than have the ports tree
spew out packing-lists.

In the case of multi-packages updates, the new version may have been built
successfully (and correctly) while the old version is still around.
However, if pkg_create looks at the installed version, it may fail to create
the package because the shared library versions will be different.


Revision tags: OPENBSD_6_8_BASE
# 1.169 25-Jul-2020 ajacoutot

More DESC -> DESCR; spotted by espie@


# 1.168 25-Jul-2020 ajacoutot

tyop: DESC -> DESCR

ok landry@ robert@


Revision tags: OPENBSD_6_7_BASE
# 1.167 26-Jan-2020 espie

give pkg_create knowledge of WRKOBJDIR, so it can error out if a symlink
points in there.

okay aja@ sthen@


# 1.166 13-Jan-2020 espie

nit, use "fatal" with parameters as intended


# 1.165 09-Jan-2020 espie

have ask_tree be more specific in its error reporting.
make sure the child has the same effective and real ids,
as perl interprets it as "setuid, refuse to debug"
go to the end of the pipe so the child doesn't exit
prematurely (didn't use to happen but now it does)

help from afresh1@ in diagnosing that one.


# 1.164 07-Nov-2019 espie

when asking the ports tree, we fork a child.
instead of ditching stderr entirely, keep it in a temp file, and if the
child exits with an error, we got something to display.
(note that returning and undef'd plist is enough of an error, just we
had no clue what went wrong previously)

aja@ ran into this a few weeks ago.


Revision tags: OPENBSD_6_6_BASE
# 1.163 21-Jul-2019 espie

start re-adding the non-broken changes:
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle


# 1.162 17-Jul-2019 sthen

backout previous commits for now; some of this is shared with dpb and
results in problems. hints from pvk@ about what introduced the breakage
we were seeing, who confirms that this backout fixes things; comitting
early to unbreak package builds.

====
a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...

Members:
OpenBSD/AddCreateDelete.pm:1.44->1.45
OpenBSD/AddDelete.pm:1.87->1.88
OpenBSD/Error.pm:1.33->1.34
OpenBSD/PackageRepository.pm:1.164->1.165
OpenBSD/PkgCreate.pm:1.160->1.161
OpenBSD/State.pm:1.58->1.59
OpenBSD/Temp.pm:1.34->1.35
====


# 1.161 14-Jul-2019 espie

a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...


# 1.160 11-Jul-2019 espie

move the display of cmd into fatal, and don't say it's a fatal error, it's
already obvious


# 1.159 11-Jul-2019 espie

tweak the way we report bugs
- the catch/catchall distinction is no longer relevant, strip some info
by default now
- use state->{cmd} to display the command name properly

This makes sure final displays show the command name.


# 1.158 10-Jul-2019 espie

make pkg_create fail properly (return 1 is useless there)

OpenBSD::Temp error handling as well


# 1.157 08-Jul-2019 espie

actually use error, we can delay fatal problems


# 1.156 08-Jul-2019 espie

check ::Temp creation


# 1.155 28-May-2019 espie

oops, let cdrom normalize if it's there.
Noticed by sthen@


# 1.154 28-May-2019 espie

make PERMIT_CDROM info optional
as discussed with sthen@, code slightly adjusted


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.153 03-Aug-2018 espie

actually heed localbase when looking for groff


# 1.152 03-Aug-2018 espie

reorg groff runner so that failures are handled better
do the logic for manpage formatting better, so that we can't miss things
simplify filenames, fullname always has a slash


# 1.151 26-Jun-2018 espie

kill the solve_tags part of pkg_create for now, as it doesn't work at all


# 1.150 24-Jun-2018 espie

get ready to reuse verify_tag


# 1.149 23-Jun-2018 espie

solve_tags not yet functional, I'll reactivate the checks during creation
when it's cleaned up


# 1.148 23-Jun-2018 espie

well, when we read the plist from the ports tree, we need to register
the tag info similarly to registering libraries


# 1.147 23-Jun-2018 espie

PkgCreate has no business knowing details of define-tag


# 1.146 23-Jun-2018 espie

do some more basic checking of tags vs define-tag so that parameter usage
is handled more gracefully


# 1.145 22-Jun-2018 espie

move the tag base code into SolverBase, and use it in PkgCreate, so that
we refuse to create packages with tags without reachable definitions


# 1.144 21-Jun-2018 espie

split the common half of dependencies handling into SolverBase, as PkgCreate
only uses that


# 1.143 18-Jun-2018 espie

kill Frag/NoFrag, they only make sense in update-plist, so they've been
moved there.


# 1.142 15-Jun-2018 espie

Add a -Dstub option to facilitate creating/adding/deleting "stubbed" packages
with just the packing and dependency info with none of the files.

(useful for debugging tricky cases that involve large packages)


# 1.141 06-Jun-2018 espie

if the parser can't find a starting line in user db, it won't look
at any line, so it won't error out.
Add logic to make it error out.


# 1.140 30-May-2018 espie

port -u userlist option from update-plist, as suggested by sthen@.
main differences:
- error out on a problem instead of warning
- always parse the userlist if the option is specified. Avoid ticking time
bomb effect on bulk builds, where packages would be fine until the first
@new(user|group) usage in case the user list got corrupted.

Note it's still an option, so if you're using pkg_create outside of the
ports tree, you can do whatever you want.


# 1.139 13-May-2018 espie

adjust highly misleading comment to match reality


# 1.138 09-May-2018 espie

on the other hand, commenting this out was involuntary.
ask_tree will often say fun things because of (say) pipe closes


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.184 01-Nov-2022 espie

Have -S actually behave like the other introspection options, namely only
eschew building the package is -n is mentionned.

Document that -S -n is heavily optimized for speed since it's mostly used
by dpb -R to figure out what to rebuild.


# 1.183 01-Nov-2022 espie

fix a logic error from 2018: be silent if any of -S, -n, -q are mentioned.

The actual bug reverted in 1.128 was from "make print-plist-libs"
which would invoke pkg_create -n -Q and filter out the libs: but
in that case, pkg_create would not be silent, thus yielding
reading plist|-/usr/local/lib/libpython3.9.so.0.0
to filter, which obviously wouldn't work.

So, turn on silent mode for -Q as well.


Revision tags: OPENBSD_7_2_BASE
# 1.182 28-Jun-2022 espie

if we can't open the user db, don't try to read from a closed fh


# 1.181 28-Jun-2022 espie

some old signing code was still around


# 1.180 06-Jun-2022 espie

have compute_checksum return a status, so that we don't report similar
errors several times (for instance, if a file doesn't exist, its checksum
is not going to match, obviously)


# 1.179 28-May-2022 espie

have pkg_create generate the hash for always-update


# 1.178 15-May-2022 espie

clean up and document the LRU stuff better
- create a separate path when we don't want history
- add a dummy entry to see the threshold between changed and unchanged
in verbose mode
- document better the various stuff that gets separated
- error out in case we want history (by default) and anything goes wrong


# 1.177 15-May-2022 espie

remove the gzip chunk after CONTENTS, it was only needed back when
we signed the packing-list separately. Now that we use signify to
create the signature without decompressing anything, it's completely
irrelevant.


# 1.176 12-May-2022 espie

yet another stupid shadowed variable, thx sthen@


# 1.175 12-May-2022 espie

explicitly write LRU in a comment so that it's easier to find ;)


Revision tags: OPENBSD_7_1_BASE
# 1.174 13-Jan-2022 espie

allow disabling the @ts tweak, which may come in handy for new fw_update
that doesn't grok them.


# 1.173 09-Nov-2021 espie

fix typo (noticed by sthen@)


# 1.172 08-Nov-2021 espie

add extra support to pass REVISION, EPOCH, FLAVOR_LIST from the ports
infrastructure, so that pkg_create can catch some naming errors.


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.171 26-Jan-2021 espie

remove test that's now bogus, as fullpkgpath takes precedence.
thanks bluhm@


# 1.170 11-Jan-2021 espie

- grab fullpkgpath early (to decide: hard error if not provided) ?
- tweak the look-up mechanism for dependencies to NOT look at installed
packages for inter-dependencies between subpackages (and debug packages)
of the SAME pkgpath.

The rationale for looking at installed packages in the usual case
is that it's normally much faster rather than have the ports tree
spew out packing-lists.

In the case of multi-packages updates, the new version may have been built
successfully (and correctly) while the old version is still around.
However, if pkg_create looks at the installed version, it may fail to create
the package because the shared library versions will be different.


Revision tags: OPENBSD_6_8_BASE
# 1.169 25-Jul-2020 ajacoutot

More DESC -> DESCR; spotted by espie@


# 1.168 25-Jul-2020 ajacoutot

tyop: DESC -> DESCR

ok landry@ robert@


Revision tags: OPENBSD_6_7_BASE
# 1.167 26-Jan-2020 espie

give pkg_create knowledge of WRKOBJDIR, so it can error out if a symlink
points in there.

okay aja@ sthen@


# 1.166 13-Jan-2020 espie

nit, use "fatal" with parameters as intended


# 1.165 09-Jan-2020 espie

have ask_tree be more specific in its error reporting.
make sure the child has the same effective and real ids,
as perl interprets it as "setuid, refuse to debug"
go to the end of the pipe so the child doesn't exit
prematurely (didn't use to happen but now it does)

help from afresh1@ in diagnosing that one.


# 1.164 07-Nov-2019 espie

when asking the ports tree, we fork a child.
instead of ditching stderr entirely, keep it in a temp file, and if the
child exits with an error, we got something to display.
(note that returning and undef'd plist is enough of an error, just we
had no clue what went wrong previously)

aja@ ran into this a few weeks ago.


Revision tags: OPENBSD_6_6_BASE
# 1.163 21-Jul-2019 espie

start re-adding the non-broken changes:
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle


# 1.162 17-Jul-2019 sthen

backout previous commits for now; some of this is shared with dpb and
results in problems. hints from pvk@ about what introduced the breakage
we were seeing, who confirms that this backout fixes things; comitting
early to unbreak package builds.

====
a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...

Members:
OpenBSD/AddCreateDelete.pm:1.44->1.45
OpenBSD/AddDelete.pm:1.87->1.88
OpenBSD/Error.pm:1.33->1.34
OpenBSD/PackageRepository.pm:1.164->1.165
OpenBSD/PkgCreate.pm:1.160->1.161
OpenBSD/State.pm:1.58->1.59
OpenBSD/Temp.pm:1.34->1.35
====


# 1.161 14-Jul-2019 espie

a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...


# 1.160 11-Jul-2019 espie

move the display of cmd into fatal, and don't say it's a fatal error, it's
already obvious


# 1.159 11-Jul-2019 espie

tweak the way we report bugs
- the catch/catchall distinction is no longer relevant, strip some info
by default now
- use state->{cmd} to display the command name properly

This makes sure final displays show the command name.


# 1.158 10-Jul-2019 espie

make pkg_create fail properly (return 1 is useless there)

OpenBSD::Temp error handling as well


# 1.157 08-Jul-2019 espie

actually use error, we can delay fatal problems


# 1.156 08-Jul-2019 espie

check ::Temp creation


# 1.155 28-May-2019 espie

oops, let cdrom normalize if it's there.
Noticed by sthen@


# 1.154 28-May-2019 espie

make PERMIT_CDROM info optional
as discussed with sthen@, code slightly adjusted


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.153 03-Aug-2018 espie

actually heed localbase when looking for groff


# 1.152 03-Aug-2018 espie

reorg groff runner so that failures are handled better
do the logic for manpage formatting better, so that we can't miss things
simplify filenames, fullname always has a slash


# 1.151 26-Jun-2018 espie

kill the solve_tags part of pkg_create for now, as it doesn't work at all


# 1.150 24-Jun-2018 espie

get ready to reuse verify_tag


# 1.149 23-Jun-2018 espie

solve_tags not yet functional, I'll reactivate the checks during creation
when it's cleaned up


# 1.148 23-Jun-2018 espie

well, when we read the plist from the ports tree, we need to register
the tag info similarly to registering libraries


# 1.147 23-Jun-2018 espie

PkgCreate has no business knowing details of define-tag


# 1.146 23-Jun-2018 espie

do some more basic checking of tags vs define-tag so that parameter usage
is handled more gracefully


# 1.145 22-Jun-2018 espie

move the tag base code into SolverBase, and use it in PkgCreate, so that
we refuse to create packages with tags without reachable definitions


# 1.144 21-Jun-2018 espie

split the common half of dependencies handling into SolverBase, as PkgCreate
only uses that


# 1.143 18-Jun-2018 espie

kill Frag/NoFrag, they only make sense in update-plist, so they've been
moved there.


# 1.142 15-Jun-2018 espie

Add a -Dstub option to facilitate creating/adding/deleting "stubbed" packages
with just the packing and dependency info with none of the files.

(useful for debugging tricky cases that involve large packages)


# 1.141 06-Jun-2018 espie

if the parser can't find a starting line in user db, it won't look
at any line, so it won't error out.
Add logic to make it error out.


# 1.140 30-May-2018 espie

port -u userlist option from update-plist, as suggested by sthen@.
main differences:
- error out on a problem instead of warning
- always parse the userlist if the option is specified. Avoid ticking time
bomb effect on bulk builds, where packages would be fine until the first
@new(user|group) usage in case the user list got corrupted.

Note it's still an option, so if you're using pkg_create outside of the
ports tree, you can do whatever you want.


# 1.139 13-May-2018 espie

adjust highly misleading comment to match reality


# 1.138 09-May-2018 espie

on the other hand, commenting this out was involuntary.
ask_tree will often say fun things because of (say) pipe closes


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.182 28-Jun-2022 espie

if we can't open the user db, don't try to read from a closed fh


# 1.181 28-Jun-2022 espie

some old signing code was still around


# 1.180 06-Jun-2022 espie

have compute_checksum return a status, so that we don't report similar
errors several times (for instance, if a file doesn't exist, its checksum
is not going to match, obviously)


# 1.179 28-May-2022 espie

have pkg_create generate the hash for always-update


# 1.178 15-May-2022 espie

clean up and document the LRU stuff better
- create a separate path when we don't want history
- add a dummy entry to see the threshold between changed and unchanged
in verbose mode
- document better the various stuff that gets separated
- error out in case we want history (by default) and anything goes wrong


# 1.177 15-May-2022 espie

remove the gzip chunk after CONTENTS, it was only needed back when
we signed the packing-list separately. Now that we use signify to
create the signature without decompressing anything, it's completely
irrelevant.


# 1.176 12-May-2022 espie

yet another stupid shadowed variable, thx sthen@


# 1.175 12-May-2022 espie

explicitly write LRU in a comment so that it's easier to find ;)


Revision tags: OPENBSD_7_1_BASE
# 1.174 13-Jan-2022 espie

allow disabling the @ts tweak, which may come in handy for new fw_update
that doesn't grok them.


# 1.173 09-Nov-2021 espie

fix typo (noticed by sthen@)


# 1.172 08-Nov-2021 espie

add extra support to pass REVISION, EPOCH, FLAVOR_LIST from the ports
infrastructure, so that pkg_create can catch some naming errors.


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.171 26-Jan-2021 espie

remove test that's now bogus, as fullpkgpath takes precedence.
thanks bluhm@


# 1.170 11-Jan-2021 espie

- grab fullpkgpath early (to decide: hard error if not provided) ?
- tweak the look-up mechanism for dependencies to NOT look at installed
packages for inter-dependencies between subpackages (and debug packages)
of the SAME pkgpath.

The rationale for looking at installed packages in the usual case
is that it's normally much faster rather than have the ports tree
spew out packing-lists.

In the case of multi-packages updates, the new version may have been built
successfully (and correctly) while the old version is still around.
However, if pkg_create looks at the installed version, it may fail to create
the package because the shared library versions will be different.


Revision tags: OPENBSD_6_8_BASE
# 1.169 25-Jul-2020 ajacoutot

More DESC -> DESCR; spotted by espie@


# 1.168 25-Jul-2020 ajacoutot

tyop: DESC -> DESCR

ok landry@ robert@


Revision tags: OPENBSD_6_7_BASE
# 1.167 26-Jan-2020 espie

give pkg_create knowledge of WRKOBJDIR, so it can error out if a symlink
points in there.

okay aja@ sthen@


# 1.166 13-Jan-2020 espie

nit, use "fatal" with parameters as intended


# 1.165 09-Jan-2020 espie

have ask_tree be more specific in its error reporting.
make sure the child has the same effective and real ids,
as perl interprets it as "setuid, refuse to debug"
go to the end of the pipe so the child doesn't exit
prematurely (didn't use to happen but now it does)

help from afresh1@ in diagnosing that one.


# 1.164 07-Nov-2019 espie

when asking the ports tree, we fork a child.
instead of ditching stderr entirely, keep it in a temp file, and if the
child exits with an error, we got something to display.
(note that returning and undef'd plist is enough of an error, just we
had no clue what went wrong previously)

aja@ ran into this a few weeks ago.


Revision tags: OPENBSD_6_6_BASE
# 1.163 21-Jul-2019 espie

start re-adding the non-broken changes:
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle


# 1.162 17-Jul-2019 sthen

backout previous commits for now; some of this is shared with dpb and
results in problems. hints from pvk@ about what introduced the breakage
we were seeing, who confirms that this backout fixes things; comitting
early to unbreak package builds.

====
a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...

Members:
OpenBSD/AddCreateDelete.pm:1.44->1.45
OpenBSD/AddDelete.pm:1.87->1.88
OpenBSD/Error.pm:1.33->1.34
OpenBSD/PackageRepository.pm:1.164->1.165
OpenBSD/PkgCreate.pm:1.160->1.161
OpenBSD/State.pm:1.58->1.59
OpenBSD/Temp.pm:1.34->1.35
====


# 1.161 14-Jul-2019 espie

a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...


# 1.160 11-Jul-2019 espie

move the display of cmd into fatal, and don't say it's a fatal error, it's
already obvious


# 1.159 11-Jul-2019 espie

tweak the way we report bugs
- the catch/catchall distinction is no longer relevant, strip some info
by default now
- use state->{cmd} to display the command name properly

This makes sure final displays show the command name.


# 1.158 10-Jul-2019 espie

make pkg_create fail properly (return 1 is useless there)

OpenBSD::Temp error handling as well


# 1.157 08-Jul-2019 espie

actually use error, we can delay fatal problems


# 1.156 08-Jul-2019 espie

check ::Temp creation


# 1.155 28-May-2019 espie

oops, let cdrom normalize if it's there.
Noticed by sthen@


# 1.154 28-May-2019 espie

make PERMIT_CDROM info optional
as discussed with sthen@, code slightly adjusted


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.153 03-Aug-2018 espie

actually heed localbase when looking for groff


# 1.152 03-Aug-2018 espie

reorg groff runner so that failures are handled better
do the logic for manpage formatting better, so that we can't miss things
simplify filenames, fullname always has a slash


# 1.151 26-Jun-2018 espie

kill the solve_tags part of pkg_create for now, as it doesn't work at all


# 1.150 24-Jun-2018 espie

get ready to reuse verify_tag


# 1.149 23-Jun-2018 espie

solve_tags not yet functional, I'll reactivate the checks during creation
when it's cleaned up


# 1.148 23-Jun-2018 espie

well, when we read the plist from the ports tree, we need to register
the tag info similarly to registering libraries


# 1.147 23-Jun-2018 espie

PkgCreate has no business knowing details of define-tag


# 1.146 23-Jun-2018 espie

do some more basic checking of tags vs define-tag so that parameter usage
is handled more gracefully


# 1.145 22-Jun-2018 espie

move the tag base code into SolverBase, and use it in PkgCreate, so that
we refuse to create packages with tags without reachable definitions


# 1.144 21-Jun-2018 espie

split the common half of dependencies handling into SolverBase, as PkgCreate
only uses that


# 1.143 18-Jun-2018 espie

kill Frag/NoFrag, they only make sense in update-plist, so they've been
moved there.


# 1.142 15-Jun-2018 espie

Add a -Dstub option to facilitate creating/adding/deleting "stubbed" packages
with just the packing and dependency info with none of the files.

(useful for debugging tricky cases that involve large packages)


# 1.141 06-Jun-2018 espie

if the parser can't find a starting line in user db, it won't look
at any line, so it won't error out.
Add logic to make it error out.


# 1.140 30-May-2018 espie

port -u userlist option from update-plist, as suggested by sthen@.
main differences:
- error out on a problem instead of warning
- always parse the userlist if the option is specified. Avoid ticking time
bomb effect on bulk builds, where packages would be fine until the first
@new(user|group) usage in case the user list got corrupted.

Note it's still an option, so if you're using pkg_create outside of the
ports tree, you can do whatever you want.


# 1.139 13-May-2018 espie

adjust highly misleading comment to match reality


# 1.138 09-May-2018 espie

on the other hand, commenting this out was involuntary.
ask_tree will often say fun things because of (say) pipe closes


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.180 06-Jun-2022 espie

have compute_checksum return a status, so that we don't report similar
errors several times (for instance, if a file doesn't exist, its checksum
is not going to match, obviously)


# 1.179 28-May-2022 espie

have pkg_create generate the hash for always-update


# 1.178 15-May-2022 espie

clean up and document the LRU stuff better
- create a separate path when we don't want history
- add a dummy entry to see the threshold between changed and unchanged
in verbose mode
- document better the various stuff that gets separated
- error out in case we want history (by default) and anything goes wrong


# 1.177 15-May-2022 espie

remove the gzip chunk after CONTENTS, it was only needed back when
we signed the packing-list separately. Now that we use signify to
create the signature without decompressing anything, it's completely
irrelevant.


# 1.176 12-May-2022 espie

yet another stupid shadowed variable, thx sthen@


# 1.175 12-May-2022 espie

explicitly write LRU in a comment so that it's easier to find ;)


Revision tags: OPENBSD_7_1_BASE
# 1.174 13-Jan-2022 espie

allow disabling the @ts tweak, which may come in handy for new fw_update
that doesn't grok them.


# 1.173 09-Nov-2021 espie

fix typo (noticed by sthen@)


# 1.172 08-Nov-2021 espie

add extra support to pass REVISION, EPOCH, FLAVOR_LIST from the ports
infrastructure, so that pkg_create can catch some naming errors.


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.171 26-Jan-2021 espie

remove test that's now bogus, as fullpkgpath takes precedence.
thanks bluhm@


# 1.170 11-Jan-2021 espie

- grab fullpkgpath early (to decide: hard error if not provided) ?
- tweak the look-up mechanism for dependencies to NOT look at installed
packages for inter-dependencies between subpackages (and debug packages)
of the SAME pkgpath.

The rationale for looking at installed packages in the usual case
is that it's normally much faster rather than have the ports tree
spew out packing-lists.

In the case of multi-packages updates, the new version may have been built
successfully (and correctly) while the old version is still around.
However, if pkg_create looks at the installed version, it may fail to create
the package because the shared library versions will be different.


Revision tags: OPENBSD_6_8_BASE
# 1.169 25-Jul-2020 ajacoutot

More DESC -> DESCR; spotted by espie@


# 1.168 25-Jul-2020 ajacoutot

tyop: DESC -> DESCR

ok landry@ robert@


Revision tags: OPENBSD_6_7_BASE
# 1.167 26-Jan-2020 espie

give pkg_create knowledge of WRKOBJDIR, so it can error out if a symlink
points in there.

okay aja@ sthen@


# 1.166 13-Jan-2020 espie

nit, use "fatal" with parameters as intended


# 1.165 09-Jan-2020 espie

have ask_tree be more specific in its error reporting.
make sure the child has the same effective and real ids,
as perl interprets it as "setuid, refuse to debug"
go to the end of the pipe so the child doesn't exit
prematurely (didn't use to happen but now it does)

help from afresh1@ in diagnosing that one.


# 1.164 07-Nov-2019 espie

when asking the ports tree, we fork a child.
instead of ditching stderr entirely, keep it in a temp file, and if the
child exits with an error, we got something to display.
(note that returning and undef'd plist is enough of an error, just we
had no clue what went wrong previously)

aja@ ran into this a few weeks ago.


Revision tags: OPENBSD_6_6_BASE
# 1.163 21-Jul-2019 espie

start re-adding the non-broken changes:
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle


# 1.162 17-Jul-2019 sthen

backout previous commits for now; some of this is shared with dpb and
results in problems. hints from pvk@ about what introduced the breakage
we were seeing, who confirms that this backout fixes things; comitting
early to unbreak package builds.

====
a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...

Members:
OpenBSD/AddCreateDelete.pm:1.44->1.45
OpenBSD/AddDelete.pm:1.87->1.88
OpenBSD/Error.pm:1.33->1.34
OpenBSD/PackageRepository.pm:1.164->1.165
OpenBSD/PkgCreate.pm:1.160->1.161
OpenBSD/State.pm:1.58->1.59
OpenBSD/Temp.pm:1.34->1.35
====


# 1.161 14-Jul-2019 espie

a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...


# 1.160 11-Jul-2019 espie

move the display of cmd into fatal, and don't say it's a fatal error, it's
already obvious


# 1.159 11-Jul-2019 espie

tweak the way we report bugs
- the catch/catchall distinction is no longer relevant, strip some info
by default now
- use state->{cmd} to display the command name properly

This makes sure final displays show the command name.


# 1.158 10-Jul-2019 espie

make pkg_create fail properly (return 1 is useless there)

OpenBSD::Temp error handling as well


# 1.157 08-Jul-2019 espie

actually use error, we can delay fatal problems


# 1.156 08-Jul-2019 espie

check ::Temp creation


# 1.155 28-May-2019 espie

oops, let cdrom normalize if it's there.
Noticed by sthen@


# 1.154 28-May-2019 espie

make PERMIT_CDROM info optional
as discussed with sthen@, code slightly adjusted


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.153 03-Aug-2018 espie

actually heed localbase when looking for groff


# 1.152 03-Aug-2018 espie

reorg groff runner so that failures are handled better
do the logic for manpage formatting better, so that we can't miss things
simplify filenames, fullname always has a slash


# 1.151 26-Jun-2018 espie

kill the solve_tags part of pkg_create for now, as it doesn't work at all


# 1.150 24-Jun-2018 espie

get ready to reuse verify_tag


# 1.149 23-Jun-2018 espie

solve_tags not yet functional, I'll reactivate the checks during creation
when it's cleaned up


# 1.148 23-Jun-2018 espie

well, when we read the plist from the ports tree, we need to register
the tag info similarly to registering libraries


# 1.147 23-Jun-2018 espie

PkgCreate has no business knowing details of define-tag


# 1.146 23-Jun-2018 espie

do some more basic checking of tags vs define-tag so that parameter usage
is handled more gracefully


# 1.145 22-Jun-2018 espie

move the tag base code into SolverBase, and use it in PkgCreate, so that
we refuse to create packages with tags without reachable definitions


# 1.144 21-Jun-2018 espie

split the common half of dependencies handling into SolverBase, as PkgCreate
only uses that


# 1.143 18-Jun-2018 espie

kill Frag/NoFrag, they only make sense in update-plist, so they've been
moved there.


# 1.142 15-Jun-2018 espie

Add a -Dstub option to facilitate creating/adding/deleting "stubbed" packages
with just the packing and dependency info with none of the files.

(useful for debugging tricky cases that involve large packages)


# 1.141 06-Jun-2018 espie

if the parser can't find a starting line in user db, it won't look
at any line, so it won't error out.
Add logic to make it error out.


# 1.140 30-May-2018 espie

port -u userlist option from update-plist, as suggested by sthen@.
main differences:
- error out on a problem instead of warning
- always parse the userlist if the option is specified. Avoid ticking time
bomb effect on bulk builds, where packages would be fine until the first
@new(user|group) usage in case the user list got corrupted.

Note it's still an option, so if you're using pkg_create outside of the
ports tree, you can do whatever you want.


# 1.139 13-May-2018 espie

adjust highly misleading comment to match reality


# 1.138 09-May-2018 espie

on the other hand, commenting this out was involuntary.
ask_tree will often say fun things because of (say) pipe closes


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.179 28-May-2022 espie

have pkg_create generate the hash for always-update


# 1.178 15-May-2022 espie

clean up and document the LRU stuff better
- create a separate path when we don't want history
- add a dummy entry to see the threshold between changed and unchanged
in verbose mode
- document better the various stuff that gets separated
- error out in case we want history (by default) and anything goes wrong


# 1.177 15-May-2022 espie

remove the gzip chunk after CONTENTS, it was only needed back when
we signed the packing-list separately. Now that we use signify to
create the signature without decompressing anything, it's completely
irrelevant.


# 1.176 12-May-2022 espie

yet another stupid shadowed variable, thx sthen@


# 1.175 12-May-2022 espie

explicitly write LRU in a comment so that it's easier to find ;)


Revision tags: OPENBSD_7_1_BASE
# 1.174 13-Jan-2022 espie

allow disabling the @ts tweak, which may come in handy for new fw_update
that doesn't grok them.


# 1.173 09-Nov-2021 espie

fix typo (noticed by sthen@)


# 1.172 08-Nov-2021 espie

add extra support to pass REVISION, EPOCH, FLAVOR_LIST from the ports
infrastructure, so that pkg_create can catch some naming errors.


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.171 26-Jan-2021 espie

remove test that's now bogus, as fullpkgpath takes precedence.
thanks bluhm@


# 1.170 11-Jan-2021 espie

- grab fullpkgpath early (to decide: hard error if not provided) ?
- tweak the look-up mechanism for dependencies to NOT look at installed
packages for inter-dependencies between subpackages (and debug packages)
of the SAME pkgpath.

The rationale for looking at installed packages in the usual case
is that it's normally much faster rather than have the ports tree
spew out packing-lists.

In the case of multi-packages updates, the new version may have been built
successfully (and correctly) while the old version is still around.
However, if pkg_create looks at the installed version, it may fail to create
the package because the shared library versions will be different.


Revision tags: OPENBSD_6_8_BASE
# 1.169 25-Jul-2020 ajacoutot

More DESC -> DESCR; spotted by espie@


# 1.168 25-Jul-2020 ajacoutot

tyop: DESC -> DESCR

ok landry@ robert@


Revision tags: OPENBSD_6_7_BASE
# 1.167 26-Jan-2020 espie

give pkg_create knowledge of WRKOBJDIR, so it can error out if a symlink
points in there.

okay aja@ sthen@


# 1.166 13-Jan-2020 espie

nit, use "fatal" with parameters as intended


# 1.165 09-Jan-2020 espie

have ask_tree be more specific in its error reporting.
make sure the child has the same effective and real ids,
as perl interprets it as "setuid, refuse to debug"
go to the end of the pipe so the child doesn't exit
prematurely (didn't use to happen but now it does)

help from afresh1@ in diagnosing that one.


# 1.164 07-Nov-2019 espie

when asking the ports tree, we fork a child.
instead of ditching stderr entirely, keep it in a temp file, and if the
child exits with an error, we got something to display.
(note that returning and undef'd plist is enough of an error, just we
had no clue what went wrong previously)

aja@ ran into this a few weeks ago.


Revision tags: OPENBSD_6_6_BASE
# 1.163 21-Jul-2019 espie

start re-adding the non-broken changes:
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle


# 1.162 17-Jul-2019 sthen

backout previous commits for now; some of this is shared with dpb and
results in problems. hints from pvk@ about what introduced the breakage
we were seeing, who confirms that this backout fixes things; comitting
early to unbreak package builds.

====
a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...

Members:
OpenBSD/AddCreateDelete.pm:1.44->1.45
OpenBSD/AddDelete.pm:1.87->1.88
OpenBSD/Error.pm:1.33->1.34
OpenBSD/PackageRepository.pm:1.164->1.165
OpenBSD/PkgCreate.pm:1.160->1.161
OpenBSD/State.pm:1.58->1.59
OpenBSD/Temp.pm:1.34->1.35
====


# 1.161 14-Jul-2019 espie

a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...


# 1.160 11-Jul-2019 espie

move the display of cmd into fatal, and don't say it's a fatal error, it's
already obvious


# 1.159 11-Jul-2019 espie

tweak the way we report bugs
- the catch/catchall distinction is no longer relevant, strip some info
by default now
- use state->{cmd} to display the command name properly

This makes sure final displays show the command name.


# 1.158 10-Jul-2019 espie

make pkg_create fail properly (return 1 is useless there)

OpenBSD::Temp error handling as well


# 1.157 08-Jul-2019 espie

actually use error, we can delay fatal problems


# 1.156 08-Jul-2019 espie

check ::Temp creation


# 1.155 28-May-2019 espie

oops, let cdrom normalize if it's there.
Noticed by sthen@


# 1.154 28-May-2019 espie

make PERMIT_CDROM info optional
as discussed with sthen@, code slightly adjusted


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.153 03-Aug-2018 espie

actually heed localbase when looking for groff


# 1.152 03-Aug-2018 espie

reorg groff runner so that failures are handled better
do the logic for manpage formatting better, so that we can't miss things
simplify filenames, fullname always has a slash


# 1.151 26-Jun-2018 espie

kill the solve_tags part of pkg_create for now, as it doesn't work at all


# 1.150 24-Jun-2018 espie

get ready to reuse verify_tag


# 1.149 23-Jun-2018 espie

solve_tags not yet functional, I'll reactivate the checks during creation
when it's cleaned up


# 1.148 23-Jun-2018 espie

well, when we read the plist from the ports tree, we need to register
the tag info similarly to registering libraries


# 1.147 23-Jun-2018 espie

PkgCreate has no business knowing details of define-tag


# 1.146 23-Jun-2018 espie

do some more basic checking of tags vs define-tag so that parameter usage
is handled more gracefully


# 1.145 22-Jun-2018 espie

move the tag base code into SolverBase, and use it in PkgCreate, so that
we refuse to create packages with tags without reachable definitions


# 1.144 21-Jun-2018 espie

split the common half of dependencies handling into SolverBase, as PkgCreate
only uses that


# 1.143 18-Jun-2018 espie

kill Frag/NoFrag, they only make sense in update-plist, so they've been
moved there.


# 1.142 15-Jun-2018 espie

Add a -Dstub option to facilitate creating/adding/deleting "stubbed" packages
with just the packing and dependency info with none of the files.

(useful for debugging tricky cases that involve large packages)


# 1.141 06-Jun-2018 espie

if the parser can't find a starting line in user db, it won't look
at any line, so it won't error out.
Add logic to make it error out.


# 1.140 30-May-2018 espie

port -u userlist option from update-plist, as suggested by sthen@.
main differences:
- error out on a problem instead of warning
- always parse the userlist if the option is specified. Avoid ticking time
bomb effect on bulk builds, where packages would be fine until the first
@new(user|group) usage in case the user list got corrupted.

Note it's still an option, so if you're using pkg_create outside of the
ports tree, you can do whatever you want.


# 1.139 13-May-2018 espie

adjust highly misleading comment to match reality


# 1.138 09-May-2018 espie

on the other hand, commenting this out was involuntary.
ask_tree will often say fun things because of (say) pipe closes


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.178 15-May-2022 espie

clean up and document the LRU stuff better
- create a separate path when we don't want history
- add a dummy entry to see the threshold between changed and unchanged
in verbose mode
- document better the various stuff that gets separated
- error out in case we want history (by default) and anything goes wrong


# 1.177 15-May-2022 espie

remove the gzip chunk after CONTENTS, it was only needed back when
we signed the packing-list separately. Now that we use signify to
create the signature without decompressing anything, it's completely
irrelevant.


# 1.176 12-May-2022 espie

yet another stupid shadowed variable, thx sthen@


# 1.175 12-May-2022 espie

explicitly write LRU in a comment so that it's easier to find ;)


Revision tags: OPENBSD_7_1_BASE
# 1.174 13-Jan-2022 espie

allow disabling the @ts tweak, which may come in handy for new fw_update
that doesn't grok them.


# 1.173 09-Nov-2021 espie

fix typo (noticed by sthen@)


# 1.172 08-Nov-2021 espie

add extra support to pass REVISION, EPOCH, FLAVOR_LIST from the ports
infrastructure, so that pkg_create can catch some naming errors.


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.171 26-Jan-2021 espie

remove test that's now bogus, as fullpkgpath takes precedence.
thanks bluhm@


# 1.170 11-Jan-2021 espie

- grab fullpkgpath early (to decide: hard error if not provided) ?
- tweak the look-up mechanism for dependencies to NOT look at installed
packages for inter-dependencies between subpackages (and debug packages)
of the SAME pkgpath.

The rationale for looking at installed packages in the usual case
is that it's normally much faster rather than have the ports tree
spew out packing-lists.

In the case of multi-packages updates, the new version may have been built
successfully (and correctly) while the old version is still around.
However, if pkg_create looks at the installed version, it may fail to create
the package because the shared library versions will be different.


Revision tags: OPENBSD_6_8_BASE
# 1.169 25-Jul-2020 ajacoutot

More DESC -> DESCR; spotted by espie@


# 1.168 25-Jul-2020 ajacoutot

tyop: DESC -> DESCR

ok landry@ robert@


Revision tags: OPENBSD_6_7_BASE
# 1.167 26-Jan-2020 espie

give pkg_create knowledge of WRKOBJDIR, so it can error out if a symlink
points in there.

okay aja@ sthen@


# 1.166 13-Jan-2020 espie

nit, use "fatal" with parameters as intended


# 1.165 09-Jan-2020 espie

have ask_tree be more specific in its error reporting.
make sure the child has the same effective and real ids,
as perl interprets it as "setuid, refuse to debug"
go to the end of the pipe so the child doesn't exit
prematurely (didn't use to happen but now it does)

help from afresh1@ in diagnosing that one.


# 1.164 07-Nov-2019 espie

when asking the ports tree, we fork a child.
instead of ditching stderr entirely, keep it in a temp file, and if the
child exits with an error, we got something to display.
(note that returning and undef'd plist is enough of an error, just we
had no clue what went wrong previously)

aja@ ran into this a few weeks ago.


Revision tags: OPENBSD_6_6_BASE
# 1.163 21-Jul-2019 espie

start re-adding the non-broken changes:
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle


# 1.162 17-Jul-2019 sthen

backout previous commits for now; some of this is shared with dpb and
results in problems. hints from pvk@ about what introduced the breakage
we were seeing, who confirms that this backout fixes things; comitting
early to unbreak package builds.

====
a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...

Members:
OpenBSD/AddCreateDelete.pm:1.44->1.45
OpenBSD/AddDelete.pm:1.87->1.88
OpenBSD/Error.pm:1.33->1.34
OpenBSD/PackageRepository.pm:1.164->1.165
OpenBSD/PkgCreate.pm:1.160->1.161
OpenBSD/State.pm:1.58->1.59
OpenBSD/Temp.pm:1.34->1.35
====


# 1.161 14-Jul-2019 espie

a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...


# 1.160 11-Jul-2019 espie

move the display of cmd into fatal, and don't say it's a fatal error, it's
already obvious


# 1.159 11-Jul-2019 espie

tweak the way we report bugs
- the catch/catchall distinction is no longer relevant, strip some info
by default now
- use state->{cmd} to display the command name properly

This makes sure final displays show the command name.


# 1.158 10-Jul-2019 espie

make pkg_create fail properly (return 1 is useless there)

OpenBSD::Temp error handling as well


# 1.157 08-Jul-2019 espie

actually use error, we can delay fatal problems


# 1.156 08-Jul-2019 espie

check ::Temp creation


# 1.155 28-May-2019 espie

oops, let cdrom normalize if it's there.
Noticed by sthen@


# 1.154 28-May-2019 espie

make PERMIT_CDROM info optional
as discussed with sthen@, code slightly adjusted


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.153 03-Aug-2018 espie

actually heed localbase when looking for groff


# 1.152 03-Aug-2018 espie

reorg groff runner so that failures are handled better
do the logic for manpage formatting better, so that we can't miss things
simplify filenames, fullname always has a slash


# 1.151 26-Jun-2018 espie

kill the solve_tags part of pkg_create for now, as it doesn't work at all


# 1.150 24-Jun-2018 espie

get ready to reuse verify_tag


# 1.149 23-Jun-2018 espie

solve_tags not yet functional, I'll reactivate the checks during creation
when it's cleaned up


# 1.148 23-Jun-2018 espie

well, when we read the plist from the ports tree, we need to register
the tag info similarly to registering libraries


# 1.147 23-Jun-2018 espie

PkgCreate has no business knowing details of define-tag


# 1.146 23-Jun-2018 espie

do some more basic checking of tags vs define-tag so that parameter usage
is handled more gracefully


# 1.145 22-Jun-2018 espie

move the tag base code into SolverBase, and use it in PkgCreate, so that
we refuse to create packages with tags without reachable definitions


# 1.144 21-Jun-2018 espie

split the common half of dependencies handling into SolverBase, as PkgCreate
only uses that


# 1.143 18-Jun-2018 espie

kill Frag/NoFrag, they only make sense in update-plist, so they've been
moved there.


# 1.142 15-Jun-2018 espie

Add a -Dstub option to facilitate creating/adding/deleting "stubbed" packages
with just the packing and dependency info with none of the files.

(useful for debugging tricky cases that involve large packages)


# 1.141 06-Jun-2018 espie

if the parser can't find a starting line in user db, it won't look
at any line, so it won't error out.
Add logic to make it error out.


# 1.140 30-May-2018 espie

port -u userlist option from update-plist, as suggested by sthen@.
main differences:
- error out on a problem instead of warning
- always parse the userlist if the option is specified. Avoid ticking time
bomb effect on bulk builds, where packages would be fine until the first
@new(user|group) usage in case the user list got corrupted.

Note it's still an option, so if you're using pkg_create outside of the
ports tree, you can do whatever you want.


# 1.139 13-May-2018 espie

adjust highly misleading comment to match reality


# 1.138 09-May-2018 espie

on the other hand, commenting this out was involuntary.
ask_tree will often say fun things because of (say) pipe closes


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.176 12-May-2022 espie

yet another stupid shadowed variable, thx sthen@


# 1.175 12-May-2022 espie

explicitly write LRU in a comment so that it's easier to find ;)


Revision tags: OPENBSD_7_1_BASE
# 1.174 13-Jan-2022 espie

allow disabling the @ts tweak, which may come in handy for new fw_update
that doesn't grok them.


# 1.173 09-Nov-2021 espie

fix typo (noticed by sthen@)


# 1.172 08-Nov-2021 espie

add extra support to pass REVISION, EPOCH, FLAVOR_LIST from the ports
infrastructure, so that pkg_create can catch some naming errors.


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.171 26-Jan-2021 espie

remove test that's now bogus, as fullpkgpath takes precedence.
thanks bluhm@


# 1.170 11-Jan-2021 espie

- grab fullpkgpath early (to decide: hard error if not provided) ?
- tweak the look-up mechanism for dependencies to NOT look at installed
packages for inter-dependencies between subpackages (and debug packages)
of the SAME pkgpath.

The rationale for looking at installed packages in the usual case
is that it's normally much faster rather than have the ports tree
spew out packing-lists.

In the case of multi-packages updates, the new version may have been built
successfully (and correctly) while the old version is still around.
However, if pkg_create looks at the installed version, it may fail to create
the package because the shared library versions will be different.


Revision tags: OPENBSD_6_8_BASE
# 1.169 25-Jul-2020 ajacoutot

More DESC -> DESCR; spotted by espie@


# 1.168 25-Jul-2020 ajacoutot

tyop: DESC -> DESCR

ok landry@ robert@


Revision tags: OPENBSD_6_7_BASE
# 1.167 26-Jan-2020 espie

give pkg_create knowledge of WRKOBJDIR, so it can error out if a symlink
points in there.

okay aja@ sthen@


# 1.166 13-Jan-2020 espie

nit, use "fatal" with parameters as intended


# 1.165 09-Jan-2020 espie

have ask_tree be more specific in its error reporting.
make sure the child has the same effective and real ids,
as perl interprets it as "setuid, refuse to debug"
go to the end of the pipe so the child doesn't exit
prematurely (didn't use to happen but now it does)

help from afresh1@ in diagnosing that one.


# 1.164 07-Nov-2019 espie

when asking the ports tree, we fork a child.
instead of ditching stderr entirely, keep it in a temp file, and if the
child exits with an error, we got something to display.
(note that returning and undef'd plist is enough of an error, just we
had no clue what went wrong previously)

aja@ ran into this a few weeks ago.


Revision tags: OPENBSD_6_6_BASE
# 1.163 21-Jul-2019 espie

start re-adding the non-broken changes:
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle


# 1.162 17-Jul-2019 sthen

backout previous commits for now; some of this is shared with dpb and
results in problems. hints from pvk@ about what introduced the breakage
we were seeing, who confirms that this backout fixes things; comitting
early to unbreak package builds.

====
a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...

Members:
OpenBSD/AddCreateDelete.pm:1.44->1.45
OpenBSD/AddDelete.pm:1.87->1.88
OpenBSD/Error.pm:1.33->1.34
OpenBSD/PackageRepository.pm:1.164->1.165
OpenBSD/PkgCreate.pm:1.160->1.161
OpenBSD/State.pm:1.58->1.59
OpenBSD/Temp.pm:1.34->1.35
====


# 1.161 14-Jul-2019 espie

a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...


# 1.160 11-Jul-2019 espie

move the display of cmd into fatal, and don't say it's a fatal error, it's
already obvious


# 1.159 11-Jul-2019 espie

tweak the way we report bugs
- the catch/catchall distinction is no longer relevant, strip some info
by default now
- use state->{cmd} to display the command name properly

This makes sure final displays show the command name.


# 1.158 10-Jul-2019 espie

make pkg_create fail properly (return 1 is useless there)

OpenBSD::Temp error handling as well


# 1.157 08-Jul-2019 espie

actually use error, we can delay fatal problems


# 1.156 08-Jul-2019 espie

check ::Temp creation


# 1.155 28-May-2019 espie

oops, let cdrom normalize if it's there.
Noticed by sthen@


# 1.154 28-May-2019 espie

make PERMIT_CDROM info optional
as discussed with sthen@, code slightly adjusted


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.153 03-Aug-2018 espie

actually heed localbase when looking for groff


# 1.152 03-Aug-2018 espie

reorg groff runner so that failures are handled better
do the logic for manpage formatting better, so that we can't miss things
simplify filenames, fullname always has a slash


# 1.151 26-Jun-2018 espie

kill the solve_tags part of pkg_create for now, as it doesn't work at all


# 1.150 24-Jun-2018 espie

get ready to reuse verify_tag


# 1.149 23-Jun-2018 espie

solve_tags not yet functional, I'll reactivate the checks during creation
when it's cleaned up


# 1.148 23-Jun-2018 espie

well, when we read the plist from the ports tree, we need to register
the tag info similarly to registering libraries


# 1.147 23-Jun-2018 espie

PkgCreate has no business knowing details of define-tag


# 1.146 23-Jun-2018 espie

do some more basic checking of tags vs define-tag so that parameter usage
is handled more gracefully


# 1.145 22-Jun-2018 espie

move the tag base code into SolverBase, and use it in PkgCreate, so that
we refuse to create packages with tags without reachable definitions


# 1.144 21-Jun-2018 espie

split the common half of dependencies handling into SolverBase, as PkgCreate
only uses that


# 1.143 18-Jun-2018 espie

kill Frag/NoFrag, they only make sense in update-plist, so they've been
moved there.


# 1.142 15-Jun-2018 espie

Add a -Dstub option to facilitate creating/adding/deleting "stubbed" packages
with just the packing and dependency info with none of the files.

(useful for debugging tricky cases that involve large packages)


# 1.141 06-Jun-2018 espie

if the parser can't find a starting line in user db, it won't look
at any line, so it won't error out.
Add logic to make it error out.


# 1.140 30-May-2018 espie

port -u userlist option from update-plist, as suggested by sthen@.
main differences:
- error out on a problem instead of warning
- always parse the userlist if the option is specified. Avoid ticking time
bomb effect on bulk builds, where packages would be fine until the first
@new(user|group) usage in case the user list got corrupted.

Note it's still an option, so if you're using pkg_create outside of the
ports tree, you can do whatever you want.


# 1.139 13-May-2018 espie

adjust highly misleading comment to match reality


# 1.138 09-May-2018 espie

on the other hand, commenting this out was involuntary.
ask_tree will often say fun things because of (say) pipe closes


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.174 13-Jan-2022 espie

allow disabling the @ts tweak, which may come in handy for new fw_update
that doesn't grok them.


# 1.173 09-Nov-2021 espie

fix typo (noticed by sthen@)


# 1.172 08-Nov-2021 espie

add extra support to pass REVISION, EPOCH, FLAVOR_LIST from the ports
infrastructure, so that pkg_create can catch some naming errors.


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.171 26-Jan-2021 espie

remove test that's now bogus, as fullpkgpath takes precedence.
thanks bluhm@


# 1.170 11-Jan-2021 espie

- grab fullpkgpath early (to decide: hard error if not provided) ?
- tweak the look-up mechanism for dependencies to NOT look at installed
packages for inter-dependencies between subpackages (and debug packages)
of the SAME pkgpath.

The rationale for looking at installed packages in the usual case
is that it's normally much faster rather than have the ports tree
spew out packing-lists.

In the case of multi-packages updates, the new version may have been built
successfully (and correctly) while the old version is still around.
However, if pkg_create looks at the installed version, it may fail to create
the package because the shared library versions will be different.


Revision tags: OPENBSD_6_8_BASE
# 1.169 25-Jul-2020 ajacoutot

More DESC -> DESCR; spotted by espie@


# 1.168 25-Jul-2020 ajacoutot

tyop: DESC -> DESCR

ok landry@ robert@


Revision tags: OPENBSD_6_7_BASE
# 1.167 26-Jan-2020 espie

give pkg_create knowledge of WRKOBJDIR, so it can error out if a symlink
points in there.

okay aja@ sthen@


# 1.166 13-Jan-2020 espie

nit, use "fatal" with parameters as intended


# 1.165 09-Jan-2020 espie

have ask_tree be more specific in its error reporting.
make sure the child has the same effective and real ids,
as perl interprets it as "setuid, refuse to debug"
go to the end of the pipe so the child doesn't exit
prematurely (didn't use to happen but now it does)

help from afresh1@ in diagnosing that one.


# 1.164 07-Nov-2019 espie

when asking the ports tree, we fork a child.
instead of ditching stderr entirely, keep it in a temp file, and if the
child exits with an error, we got something to display.
(note that returning and undef'd plist is enough of an error, just we
had no clue what went wrong previously)

aja@ ran into this a few weeks ago.


Revision tags: OPENBSD_6_6_BASE
# 1.163 21-Jul-2019 espie

start re-adding the non-broken changes:
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle


# 1.162 17-Jul-2019 sthen

backout previous commits for now; some of this is shared with dpb and
results in problems. hints from pvk@ about what introduced the breakage
we were seeing, who confirms that this backout fixes things; comitting
early to unbreak package builds.

====
a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...

Members:
OpenBSD/AddCreateDelete.pm:1.44->1.45
OpenBSD/AddDelete.pm:1.87->1.88
OpenBSD/Error.pm:1.33->1.34
OpenBSD/PackageRepository.pm:1.164->1.165
OpenBSD/PkgCreate.pm:1.160->1.161
OpenBSD/State.pm:1.58->1.59
OpenBSD/Temp.pm:1.34->1.35
====


# 1.161 14-Jul-2019 espie

a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...


# 1.160 11-Jul-2019 espie

move the display of cmd into fatal, and don't say it's a fatal error, it's
already obvious


# 1.159 11-Jul-2019 espie

tweak the way we report bugs
- the catch/catchall distinction is no longer relevant, strip some info
by default now
- use state->{cmd} to display the command name properly

This makes sure final displays show the command name.


# 1.158 10-Jul-2019 espie

make pkg_create fail properly (return 1 is useless there)

OpenBSD::Temp error handling as well


# 1.157 08-Jul-2019 espie

actually use error, we can delay fatal problems


# 1.156 08-Jul-2019 espie

check ::Temp creation


# 1.155 28-May-2019 espie

oops, let cdrom normalize if it's there.
Noticed by sthen@


# 1.154 28-May-2019 espie

make PERMIT_CDROM info optional
as discussed with sthen@, code slightly adjusted


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.153 03-Aug-2018 espie

actually heed localbase when looking for groff


# 1.152 03-Aug-2018 espie

reorg groff runner so that failures are handled better
do the logic for manpage formatting better, so that we can't miss things
simplify filenames, fullname always has a slash


# 1.151 26-Jun-2018 espie

kill the solve_tags part of pkg_create for now, as it doesn't work at all


# 1.150 24-Jun-2018 espie

get ready to reuse verify_tag


# 1.149 23-Jun-2018 espie

solve_tags not yet functional, I'll reactivate the checks during creation
when it's cleaned up


# 1.148 23-Jun-2018 espie

well, when we read the plist from the ports tree, we need to register
the tag info similarly to registering libraries


# 1.147 23-Jun-2018 espie

PkgCreate has no business knowing details of define-tag


# 1.146 23-Jun-2018 espie

do some more basic checking of tags vs define-tag so that parameter usage
is handled more gracefully


# 1.145 22-Jun-2018 espie

move the tag base code into SolverBase, and use it in PkgCreate, so that
we refuse to create packages with tags without reachable definitions


# 1.144 21-Jun-2018 espie

split the common half of dependencies handling into SolverBase, as PkgCreate
only uses that


# 1.143 18-Jun-2018 espie

kill Frag/NoFrag, they only make sense in update-plist, so they've been
moved there.


# 1.142 15-Jun-2018 espie

Add a -Dstub option to facilitate creating/adding/deleting "stubbed" packages
with just the packing and dependency info with none of the files.

(useful for debugging tricky cases that involve large packages)


# 1.141 06-Jun-2018 espie

if the parser can't find a starting line in user db, it won't look
at any line, so it won't error out.
Add logic to make it error out.


# 1.140 30-May-2018 espie

port -u userlist option from update-plist, as suggested by sthen@.
main differences:
- error out on a problem instead of warning
- always parse the userlist if the option is specified. Avoid ticking time
bomb effect on bulk builds, where packages would be fine until the first
@new(user|group) usage in case the user list got corrupted.

Note it's still an option, so if you're using pkg_create outside of the
ports tree, you can do whatever you want.


# 1.139 13-May-2018 espie

adjust highly misleading comment to match reality


# 1.138 09-May-2018 espie

on the other hand, commenting this out was involuntary.
ask_tree will often say fun things because of (say) pipe closes


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.173 09-Nov-2021 espie

fix typo (noticed by sthen@)


# 1.172 08-Nov-2021 espie

add extra support to pass REVISION, EPOCH, FLAVOR_LIST from the ports
infrastructure, so that pkg_create can catch some naming errors.


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.171 26-Jan-2021 espie

remove test that's now bogus, as fullpkgpath takes precedence.
thanks bluhm@


# 1.170 11-Jan-2021 espie

- grab fullpkgpath early (to decide: hard error if not provided) ?
- tweak the look-up mechanism for dependencies to NOT look at installed
packages for inter-dependencies between subpackages (and debug packages)
of the SAME pkgpath.

The rationale for looking at installed packages in the usual case
is that it's normally much faster rather than have the ports tree
spew out packing-lists.

In the case of multi-packages updates, the new version may have been built
successfully (and correctly) while the old version is still around.
However, if pkg_create looks at the installed version, it may fail to create
the package because the shared library versions will be different.


Revision tags: OPENBSD_6_8_BASE
# 1.169 25-Jul-2020 ajacoutot

More DESC -> DESCR; spotted by espie@


# 1.168 25-Jul-2020 ajacoutot

tyop: DESC -> DESCR

ok landry@ robert@


Revision tags: OPENBSD_6_7_BASE
# 1.167 26-Jan-2020 espie

give pkg_create knowledge of WRKOBJDIR, so it can error out if a symlink
points in there.

okay aja@ sthen@


# 1.166 13-Jan-2020 espie

nit, use "fatal" with parameters as intended


# 1.165 09-Jan-2020 espie

have ask_tree be more specific in its error reporting.
make sure the child has the same effective and real ids,
as perl interprets it as "setuid, refuse to debug"
go to the end of the pipe so the child doesn't exit
prematurely (didn't use to happen but now it does)

help from afresh1@ in diagnosing that one.


# 1.164 07-Nov-2019 espie

when asking the ports tree, we fork a child.
instead of ditching stderr entirely, keep it in a temp file, and if the
child exits with an error, we got something to display.
(note that returning and undef'd plist is enough of an error, just we
had no clue what went wrong previously)

aja@ ran into this a few weeks ago.


Revision tags: OPENBSD_6_6_BASE
# 1.163 21-Jul-2019 espie

start re-adding the non-broken changes:
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle


# 1.162 17-Jul-2019 sthen

backout previous commits for now; some of this is shared with dpb and
results in problems. hints from pvk@ about what introduced the breakage
we were seeing, who confirms that this backout fixes things; comitting
early to unbreak package builds.

====
a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...

Members:
OpenBSD/AddCreateDelete.pm:1.44->1.45
OpenBSD/AddDelete.pm:1.87->1.88
OpenBSD/Error.pm:1.33->1.34
OpenBSD/PackageRepository.pm:1.164->1.165
OpenBSD/PkgCreate.pm:1.160->1.161
OpenBSD/State.pm:1.58->1.59
OpenBSD/Temp.pm:1.34->1.35
====


# 1.161 14-Jul-2019 espie

a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...


# 1.160 11-Jul-2019 espie

move the display of cmd into fatal, and don't say it's a fatal error, it's
already obvious


# 1.159 11-Jul-2019 espie

tweak the way we report bugs
- the catch/catchall distinction is no longer relevant, strip some info
by default now
- use state->{cmd} to display the command name properly

This makes sure final displays show the command name.


# 1.158 10-Jul-2019 espie

make pkg_create fail properly (return 1 is useless there)

OpenBSD::Temp error handling as well


# 1.157 08-Jul-2019 espie

actually use error, we can delay fatal problems


# 1.156 08-Jul-2019 espie

check ::Temp creation


# 1.155 28-May-2019 espie

oops, let cdrom normalize if it's there.
Noticed by sthen@


# 1.154 28-May-2019 espie

make PERMIT_CDROM info optional
as discussed with sthen@, code slightly adjusted


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.153 03-Aug-2018 espie

actually heed localbase when looking for groff


# 1.152 03-Aug-2018 espie

reorg groff runner so that failures are handled better
do the logic for manpage formatting better, so that we can't miss things
simplify filenames, fullname always has a slash


# 1.151 26-Jun-2018 espie

kill the solve_tags part of pkg_create for now, as it doesn't work at all


# 1.150 24-Jun-2018 espie

get ready to reuse verify_tag


# 1.149 23-Jun-2018 espie

solve_tags not yet functional, I'll reactivate the checks during creation
when it's cleaned up


# 1.148 23-Jun-2018 espie

well, when we read the plist from the ports tree, we need to register
the tag info similarly to registering libraries


# 1.147 23-Jun-2018 espie

PkgCreate has no business knowing details of define-tag


# 1.146 23-Jun-2018 espie

do some more basic checking of tags vs define-tag so that parameter usage
is handled more gracefully


# 1.145 22-Jun-2018 espie

move the tag base code into SolverBase, and use it in PkgCreate, so that
we refuse to create packages with tags without reachable definitions


# 1.144 21-Jun-2018 espie

split the common half of dependencies handling into SolverBase, as PkgCreate
only uses that


# 1.143 18-Jun-2018 espie

kill Frag/NoFrag, they only make sense in update-plist, so they've been
moved there.


# 1.142 15-Jun-2018 espie

Add a -Dstub option to facilitate creating/adding/deleting "stubbed" packages
with just the packing and dependency info with none of the files.

(useful for debugging tricky cases that involve large packages)


# 1.141 06-Jun-2018 espie

if the parser can't find a starting line in user db, it won't look
at any line, so it won't error out.
Add logic to make it error out.


# 1.140 30-May-2018 espie

port -u userlist option from update-plist, as suggested by sthen@.
main differences:
- error out on a problem instead of warning
- always parse the userlist if the option is specified. Avoid ticking time
bomb effect on bulk builds, where packages would be fine until the first
@new(user|group) usage in case the user list got corrupted.

Note it's still an option, so if you're using pkg_create outside of the
ports tree, you can do whatever you want.


# 1.139 13-May-2018 espie

adjust highly misleading comment to match reality


# 1.138 09-May-2018 espie

on the other hand, commenting this out was involuntary.
ask_tree will often say fun things because of (say) pipe closes


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.173 09-Nov-2021 espie

fix typo (noticed by sthen@)


# 1.172 08-Nov-2021 espie

add extra support to pass REVISION, EPOCH, FLAVOR_LIST from the ports
infrastructure, so that pkg_create can catch some naming errors.


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.171 26-Jan-2021 espie

remove test that's now bogus, as fullpkgpath takes precedence.
thanks bluhm@


# 1.170 11-Jan-2021 espie

- grab fullpkgpath early (to decide: hard error if not provided) ?
- tweak the look-up mechanism for dependencies to NOT look at installed
packages for inter-dependencies between subpackages (and debug packages)
of the SAME pkgpath.

The rationale for looking at installed packages in the usual case
is that it's normally much faster rather than have the ports tree
spew out packing-lists.

In the case of multi-packages updates, the new version may have been built
successfully (and correctly) while the old version is still around.
However, if pkg_create looks at the installed version, it may fail to create
the package because the shared library versions will be different.


Revision tags: OPENBSD_6_8_BASE
# 1.169 25-Jul-2020 ajacoutot

More DESC -> DESCR; spotted by espie@


# 1.168 25-Jul-2020 ajacoutot

tyop: DESC -> DESCR

ok landry@ robert@


Revision tags: OPENBSD_6_7_BASE
# 1.167 26-Jan-2020 espie

give pkg_create knowledge of WRKOBJDIR, so it can error out if a symlink
points in there.

okay aja@ sthen@


# 1.166 13-Jan-2020 espie

nit, use "fatal" with parameters as intended


# 1.165 09-Jan-2020 espie

have ask_tree be more specific in its error reporting.
make sure the child has the same effective and real ids,
as perl interprets it as "setuid, refuse to debug"
go to the end of the pipe so the child doesn't exit
prematurely (didn't use to happen but now it does)

help from afresh1@ in diagnosing that one.


# 1.164 07-Nov-2019 espie

when asking the ports tree, we fork a child.
instead of ditching stderr entirely, keep it in a temp file, and if the
child exits with an error, we got something to display.
(note that returning and undef'd plist is enough of an error, just we
had no clue what went wrong previously)

aja@ ran into this a few weeks ago.


Revision tags: OPENBSD_6_6_BASE
# 1.163 21-Jul-2019 espie

start re-adding the non-broken changes:
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle


# 1.162 17-Jul-2019 sthen

backout previous commits for now; some of this is shared with dpb and
results in problems. hints from pvk@ about what introduced the breakage
we were seeing, who confirms that this backout fixes things; comitting
early to unbreak package builds.

====
a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...

Members:
OpenBSD/AddCreateDelete.pm:1.44->1.45
OpenBSD/AddDelete.pm:1.87->1.88
OpenBSD/Error.pm:1.33->1.34
OpenBSD/PackageRepository.pm:1.164->1.165
OpenBSD/PkgCreate.pm:1.160->1.161
OpenBSD/State.pm:1.58->1.59
OpenBSD/Temp.pm:1.34->1.35
====


# 1.161 14-Jul-2019 espie

a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...


# 1.160 11-Jul-2019 espie

move the display of cmd into fatal, and don't say it's a fatal error, it's
already obvious


# 1.159 11-Jul-2019 espie

tweak the way we report bugs
- the catch/catchall distinction is no longer relevant, strip some info
by default now
- use state->{cmd} to display the command name properly

This makes sure final displays show the command name.


# 1.158 10-Jul-2019 espie

make pkg_create fail properly (return 1 is useless there)

OpenBSD::Temp error handling as well


# 1.157 08-Jul-2019 espie

actually use error, we can delay fatal problems


# 1.156 08-Jul-2019 espie

check ::Temp creation


# 1.155 28-May-2019 espie

oops, let cdrom normalize if it's there.
Noticed by sthen@


# 1.154 28-May-2019 espie

make PERMIT_CDROM info optional
as discussed with sthen@, code slightly adjusted


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.153 03-Aug-2018 espie

actually heed localbase when looking for groff


# 1.152 03-Aug-2018 espie

reorg groff runner so that failures are handled better
do the logic for manpage formatting better, so that we can't miss things
simplify filenames, fullname always has a slash


# 1.151 26-Jun-2018 espie

kill the solve_tags part of pkg_create for now, as it doesn't work at all


# 1.150 24-Jun-2018 espie

get ready to reuse verify_tag


# 1.149 23-Jun-2018 espie

solve_tags not yet functional, I'll reactivate the checks during creation
when it's cleaned up


# 1.148 23-Jun-2018 espie

well, when we read the plist from the ports tree, we need to register
the tag info similarly to registering libraries


# 1.147 23-Jun-2018 espie

PkgCreate has no business knowing details of define-tag


# 1.146 23-Jun-2018 espie

do some more basic checking of tags vs define-tag so that parameter usage
is handled more gracefully


# 1.145 22-Jun-2018 espie

move the tag base code into SolverBase, and use it in PkgCreate, so that
we refuse to create packages with tags without reachable definitions


# 1.144 21-Jun-2018 espie

split the common half of dependencies handling into SolverBase, as PkgCreate
only uses that


# 1.143 18-Jun-2018 espie

kill Frag/NoFrag, they only make sense in update-plist, so they've been
moved there.


# 1.142 15-Jun-2018 espie

Add a -Dstub option to facilitate creating/adding/deleting "stubbed" packages
with just the packing and dependency info with none of the files.

(useful for debugging tricky cases that involve large packages)


# 1.141 06-Jun-2018 espie

if the parser can't find a starting line in user db, it won't look
at any line, so it won't error out.
Add logic to make it error out.


# 1.140 30-May-2018 espie

port -u userlist option from update-plist, as suggested by sthen@.
main differences:
- error out on a problem instead of warning
- always parse the userlist if the option is specified. Avoid ticking time
bomb effect on bulk builds, where packages would be fine until the first
@new(user|group) usage in case the user list got corrupted.

Note it's still an option, so if you're using pkg_create outside of the
ports tree, you can do whatever you want.


# 1.139 13-May-2018 espie

adjust highly misleading comment to match reality


# 1.138 09-May-2018 espie

on the other hand, commenting this out was involuntary.
ask_tree will often say fun things because of (say) pipe closes


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.171 26-Jan-2021 espie

remove test that's now bogus, as fullpkgpath takes precedence.
thanks bluhm@


# 1.170 11-Jan-2021 espie

- grab fullpkgpath early (to decide: hard error if not provided) ?
- tweak the look-up mechanism for dependencies to NOT look at installed
packages for inter-dependencies between subpackages (and debug packages)
of the SAME pkgpath.

The rationale for looking at installed packages in the usual case
is that it's normally much faster rather than have the ports tree
spew out packing-lists.

In the case of multi-packages updates, the new version may have been built
successfully (and correctly) while the old version is still around.
However, if pkg_create looks at the installed version, it may fail to create
the package because the shared library versions will be different.


Revision tags: OPENBSD_6_8_BASE
# 1.169 25-Jul-2020 ajacoutot

More DESC -> DESCR; spotted by espie@


# 1.168 25-Jul-2020 ajacoutot

tyop: DESC -> DESCR

ok landry@ robert@


Revision tags: OPENBSD_6_7_BASE
# 1.167 26-Jan-2020 espie

give pkg_create knowledge of WRKOBJDIR, so it can error out if a symlink
points in there.

okay aja@ sthen@


# 1.166 13-Jan-2020 espie

nit, use "fatal" with parameters as intended


# 1.165 09-Jan-2020 espie

have ask_tree be more specific in its error reporting.
make sure the child has the same effective and real ids,
as perl interprets it as "setuid, refuse to debug"
go to the end of the pipe so the child doesn't exit
prematurely (didn't use to happen but now it does)

help from afresh1@ in diagnosing that one.


# 1.164 07-Nov-2019 espie

when asking the ports tree, we fork a child.
instead of ditching stderr entirely, keep it in a temp file, and if the
child exits with an error, we got something to display.
(note that returning and undef'd plist is enough of an error, just we
had no clue what went wrong previously)

aja@ ran into this a few weeks ago.


Revision tags: OPENBSD_6_6_BASE
# 1.163 21-Jul-2019 espie

start re-adding the non-broken changes:
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle


# 1.162 17-Jul-2019 sthen

backout previous commits for now; some of this is shared with dpb and
results in problems. hints from pvk@ about what introduced the breakage
we were seeing, who confirms that this backout fixes things; comitting
early to unbreak package builds.

====
a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...

Members:
OpenBSD/AddCreateDelete.pm:1.44->1.45
OpenBSD/AddDelete.pm:1.87->1.88
OpenBSD/Error.pm:1.33->1.34
OpenBSD/PackageRepository.pm:1.164->1.165
OpenBSD/PkgCreate.pm:1.160->1.161
OpenBSD/State.pm:1.58->1.59
OpenBSD/Temp.pm:1.34->1.35
====


# 1.161 14-Jul-2019 espie

a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...


# 1.160 11-Jul-2019 espie

move the display of cmd into fatal, and don't say it's a fatal error, it's
already obvious


# 1.159 11-Jul-2019 espie

tweak the way we report bugs
- the catch/catchall distinction is no longer relevant, strip some info
by default now
- use state->{cmd} to display the command name properly

This makes sure final displays show the command name.


# 1.158 10-Jul-2019 espie

make pkg_create fail properly (return 1 is useless there)

OpenBSD::Temp error handling as well


# 1.157 08-Jul-2019 espie

actually use error, we can delay fatal problems


# 1.156 08-Jul-2019 espie

check ::Temp creation


# 1.155 28-May-2019 espie

oops, let cdrom normalize if it's there.
Noticed by sthen@


# 1.154 28-May-2019 espie

make PERMIT_CDROM info optional
as discussed with sthen@, code slightly adjusted


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.153 03-Aug-2018 espie

actually heed localbase when looking for groff


# 1.152 03-Aug-2018 espie

reorg groff runner so that failures are handled better
do the logic for manpage formatting better, so that we can't miss things
simplify filenames, fullname always has a slash


# 1.151 26-Jun-2018 espie

kill the solve_tags part of pkg_create for now, as it doesn't work at all


# 1.150 24-Jun-2018 espie

get ready to reuse verify_tag


# 1.149 23-Jun-2018 espie

solve_tags not yet functional, I'll reactivate the checks during creation
when it's cleaned up


# 1.148 23-Jun-2018 espie

well, when we read the plist from the ports tree, we need to register
the tag info similarly to registering libraries


# 1.147 23-Jun-2018 espie

PkgCreate has no business knowing details of define-tag


# 1.146 23-Jun-2018 espie

do some more basic checking of tags vs define-tag so that parameter usage
is handled more gracefully


# 1.145 22-Jun-2018 espie

move the tag base code into SolverBase, and use it in PkgCreate, so that
we refuse to create packages with tags without reachable definitions


# 1.144 21-Jun-2018 espie

split the common half of dependencies handling into SolverBase, as PkgCreate
only uses that


# 1.143 18-Jun-2018 espie

kill Frag/NoFrag, they only make sense in update-plist, so they've been
moved there.


# 1.142 15-Jun-2018 espie

Add a -Dstub option to facilitate creating/adding/deleting "stubbed" packages
with just the packing and dependency info with none of the files.

(useful for debugging tricky cases that involve large packages)


# 1.141 06-Jun-2018 espie

if the parser can't find a starting line in user db, it won't look
at any line, so it won't error out.
Add logic to make it error out.


# 1.140 30-May-2018 espie

port -u userlist option from update-plist, as suggested by sthen@.
main differences:
- error out on a problem instead of warning
- always parse the userlist if the option is specified. Avoid ticking time
bomb effect on bulk builds, where packages would be fine until the first
@new(user|group) usage in case the user list got corrupted.

Note it's still an option, so if you're using pkg_create outside of the
ports tree, you can do whatever you want.


# 1.139 13-May-2018 espie

adjust highly misleading comment to match reality


# 1.138 09-May-2018 espie

on the other hand, commenting this out was involuntary.
ask_tree will often say fun things because of (say) pipe closes


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.170 11-Jan-2021 espie

- grab fullpkgpath early (to decide: hard error if not provided) ?
- tweak the look-up mechanism for dependencies to NOT look at installed
packages for inter-dependencies between subpackages (and debug packages)
of the SAME pkgpath.

The rationale for looking at installed packages in the usual case
is that it's normally much faster rather than have the ports tree
spew out packing-lists.

In the case of multi-packages updates, the new version may have been built
successfully (and correctly) while the old version is still around.
However, if pkg_create looks at the installed version, it may fail to create
the package because the shared library versions will be different.


Revision tags: OPENBSD_6_8_BASE
# 1.169 25-Jul-2020 ajacoutot

More DESC -> DESCR; spotted by espie@


# 1.168 25-Jul-2020 ajacoutot

tyop: DESC -> DESCR

ok landry@ robert@


Revision tags: OPENBSD_6_7_BASE
# 1.167 26-Jan-2020 espie

give pkg_create knowledge of WRKOBJDIR, so it can error out if a symlink
points in there.

okay aja@ sthen@


# 1.166 13-Jan-2020 espie

nit, use "fatal" with parameters as intended


# 1.165 09-Jan-2020 espie

have ask_tree be more specific in its error reporting.
make sure the child has the same effective and real ids,
as perl interprets it as "setuid, refuse to debug"
go to the end of the pipe so the child doesn't exit
prematurely (didn't use to happen but now it does)

help from afresh1@ in diagnosing that one.


# 1.164 07-Nov-2019 espie

when asking the ports tree, we fork a child.
instead of ditching stderr entirely, keep it in a temp file, and if the
child exits with an error, we got something to display.
(note that returning and undef'd plist is enough of an error, just we
had no clue what went wrong previously)

aja@ ran into this a few weeks ago.


Revision tags: OPENBSD_6_6_BASE
# 1.163 21-Jul-2019 espie

start re-adding the non-broken changes:
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle


# 1.162 17-Jul-2019 sthen

backout previous commits for now; some of this is shared with dpb and
results in problems. hints from pvk@ about what introduced the breakage
we were seeing, who confirms that this backout fixes things; comitting
early to unbreak package builds.

====
a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...

Members:
OpenBSD/AddCreateDelete.pm:1.44->1.45
OpenBSD/AddDelete.pm:1.87->1.88
OpenBSD/Error.pm:1.33->1.34
OpenBSD/PackageRepository.pm:1.164->1.165
OpenBSD/PkgCreate.pm:1.160->1.161
OpenBSD/State.pm:1.58->1.59
OpenBSD/Temp.pm:1.34->1.35
====


# 1.161 14-Jul-2019 espie

a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...


# 1.160 11-Jul-2019 espie

move the display of cmd into fatal, and don't say it's a fatal error, it's
already obvious


# 1.159 11-Jul-2019 espie

tweak the way we report bugs
- the catch/catchall distinction is no longer relevant, strip some info
by default now
- use state->{cmd} to display the command name properly

This makes sure final displays show the command name.


# 1.158 10-Jul-2019 espie

make pkg_create fail properly (return 1 is useless there)

OpenBSD::Temp error handling as well


# 1.157 08-Jul-2019 espie

actually use error, we can delay fatal problems


# 1.156 08-Jul-2019 espie

check ::Temp creation


# 1.155 28-May-2019 espie

oops, let cdrom normalize if it's there.
Noticed by sthen@


# 1.154 28-May-2019 espie

make PERMIT_CDROM info optional
as discussed with sthen@, code slightly adjusted


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.153 03-Aug-2018 espie

actually heed localbase when looking for groff


# 1.152 03-Aug-2018 espie

reorg groff runner so that failures are handled better
do the logic for manpage formatting better, so that we can't miss things
simplify filenames, fullname always has a slash


# 1.151 26-Jun-2018 espie

kill the solve_tags part of pkg_create for now, as it doesn't work at all


# 1.150 24-Jun-2018 espie

get ready to reuse verify_tag


# 1.149 23-Jun-2018 espie

solve_tags not yet functional, I'll reactivate the checks during creation
when it's cleaned up


# 1.148 23-Jun-2018 espie

well, when we read the plist from the ports tree, we need to register
the tag info similarly to registering libraries


# 1.147 23-Jun-2018 espie

PkgCreate has no business knowing details of define-tag


# 1.146 23-Jun-2018 espie

do some more basic checking of tags vs define-tag so that parameter usage
is handled more gracefully


# 1.145 22-Jun-2018 espie

move the tag base code into SolverBase, and use it in PkgCreate, so that
we refuse to create packages with tags without reachable definitions


# 1.144 21-Jun-2018 espie

split the common half of dependencies handling into SolverBase, as PkgCreate
only uses that


# 1.143 18-Jun-2018 espie

kill Frag/NoFrag, they only make sense in update-plist, so they've been
moved there.


# 1.142 15-Jun-2018 espie

Add a -Dstub option to facilitate creating/adding/deleting "stubbed" packages
with just the packing and dependency info with none of the files.

(useful for debugging tricky cases that involve large packages)


# 1.141 06-Jun-2018 espie

if the parser can't find a starting line in user db, it won't look
at any line, so it won't error out.
Add logic to make it error out.


# 1.140 30-May-2018 espie

port -u userlist option from update-plist, as suggested by sthen@.
main differences:
- error out on a problem instead of warning
- always parse the userlist if the option is specified. Avoid ticking time
bomb effect on bulk builds, where packages would be fine until the first
@new(user|group) usage in case the user list got corrupted.

Note it's still an option, so if you're using pkg_create outside of the
ports tree, you can do whatever you want.


# 1.139 13-May-2018 espie

adjust highly misleading comment to match reality


# 1.138 09-May-2018 espie

on the other hand, commenting this out was involuntary.
ask_tree will often say fun things because of (say) pipe closes


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.169 25-Jul-2020 ajacoutot

More DESC -> DESCR; spotted by espie@


# 1.168 25-Jul-2020 ajacoutot

tyop: DESC -> DESCR

ok landry@ robert@


Revision tags: OPENBSD_6_7_BASE
# 1.167 26-Jan-2020 espie

give pkg_create knowledge of WRKOBJDIR, so it can error out if a symlink
points in there.

okay aja@ sthen@


# 1.166 13-Jan-2020 espie

nit, use "fatal" with parameters as intended


# 1.165 09-Jan-2020 espie

have ask_tree be more specific in its error reporting.
make sure the child has the same effective and real ids,
as perl interprets it as "setuid, refuse to debug"
go to the end of the pipe so the child doesn't exit
prematurely (didn't use to happen but now it does)

help from afresh1@ in diagnosing that one.


# 1.164 07-Nov-2019 espie

when asking the ports tree, we fork a child.
instead of ditching stderr entirely, keep it in a temp file, and if the
child exits with an error, we got something to display.
(note that returning and undef'd plist is enough of an error, just we
had no clue what went wrong previously)

aja@ ran into this a few weeks ago.


Revision tags: OPENBSD_6_6_BASE
# 1.163 21-Jul-2019 espie

start re-adding the non-broken changes:
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle


# 1.162 17-Jul-2019 sthen

backout previous commits for now; some of this is shared with dpb and
results in problems. hints from pvk@ about what introduced the breakage
we were seeing, who confirms that this backout fixes things; comitting
early to unbreak package builds.

====
a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...

Members:
OpenBSD/AddCreateDelete.pm:1.44->1.45
OpenBSD/AddDelete.pm:1.87->1.88
OpenBSD/Error.pm:1.33->1.34
OpenBSD/PackageRepository.pm:1.164->1.165
OpenBSD/PkgCreate.pm:1.160->1.161
OpenBSD/State.pm:1.58->1.59
OpenBSD/Temp.pm:1.34->1.35
====


# 1.161 14-Jul-2019 espie

a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...


# 1.160 11-Jul-2019 espie

move the display of cmd into fatal, and don't say it's a fatal error, it's
already obvious


# 1.159 11-Jul-2019 espie

tweak the way we report bugs
- the catch/catchall distinction is no longer relevant, strip some info
by default now
- use state->{cmd} to display the command name properly

This makes sure final displays show the command name.


# 1.158 10-Jul-2019 espie

make pkg_create fail properly (return 1 is useless there)

OpenBSD::Temp error handling as well


# 1.157 08-Jul-2019 espie

actually use error, we can delay fatal problems


# 1.156 08-Jul-2019 espie

check ::Temp creation


# 1.155 28-May-2019 espie

oops, let cdrom normalize if it's there.
Noticed by sthen@


# 1.154 28-May-2019 espie

make PERMIT_CDROM info optional
as discussed with sthen@, code slightly adjusted


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.153 03-Aug-2018 espie

actually heed localbase when looking for groff


# 1.152 03-Aug-2018 espie

reorg groff runner so that failures are handled better
do the logic for manpage formatting better, so that we can't miss things
simplify filenames, fullname always has a slash


# 1.151 26-Jun-2018 espie

kill the solve_tags part of pkg_create for now, as it doesn't work at all


# 1.150 24-Jun-2018 espie

get ready to reuse verify_tag


# 1.149 23-Jun-2018 espie

solve_tags not yet functional, I'll reactivate the checks during creation
when it's cleaned up


# 1.148 23-Jun-2018 espie

well, when we read the plist from the ports tree, we need to register
the tag info similarly to registering libraries


# 1.147 23-Jun-2018 espie

PkgCreate has no business knowing details of define-tag


# 1.146 23-Jun-2018 espie

do some more basic checking of tags vs define-tag so that parameter usage
is handled more gracefully


# 1.145 22-Jun-2018 espie

move the tag base code into SolverBase, and use it in PkgCreate, so that
we refuse to create packages with tags without reachable definitions


# 1.144 21-Jun-2018 espie

split the common half of dependencies handling into SolverBase, as PkgCreate
only uses that


# 1.143 18-Jun-2018 espie

kill Frag/NoFrag, they only make sense in update-plist, so they've been
moved there.


# 1.142 15-Jun-2018 espie

Add a -Dstub option to facilitate creating/adding/deleting "stubbed" packages
with just the packing and dependency info with none of the files.

(useful for debugging tricky cases that involve large packages)


# 1.141 06-Jun-2018 espie

if the parser can't find a starting line in user db, it won't look
at any line, so it won't error out.
Add logic to make it error out.


# 1.140 30-May-2018 espie

port -u userlist option from update-plist, as suggested by sthen@.
main differences:
- error out on a problem instead of warning
- always parse the userlist if the option is specified. Avoid ticking time
bomb effect on bulk builds, where packages would be fine until the first
@new(user|group) usage in case the user list got corrupted.

Note it's still an option, so if you're using pkg_create outside of the
ports tree, you can do whatever you want.


# 1.139 13-May-2018 espie

adjust highly misleading comment to match reality


# 1.138 09-May-2018 espie

on the other hand, commenting this out was involuntary.
ask_tree will often say fun things because of (say) pipe closes


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.167 26-Jan-2020 espie

give pkg_create knowledge of WRKOBJDIR, so it can error out if a symlink
points in there.

okay aja@ sthen@


# 1.166 13-Jan-2020 espie

nit, use "fatal" with parameters as intended


# 1.165 09-Jan-2020 espie

have ask_tree be more specific in its error reporting.
make sure the child has the same effective and real ids,
as perl interprets it as "setuid, refuse to debug"
go to the end of the pipe so the child doesn't exit
prematurely (didn't use to happen but now it does)

help from afresh1@ in diagnosing that one.


# 1.164 07-Nov-2019 espie

when asking the ports tree, we fork a child.
instead of ditching stderr entirely, keep it in a temp file, and if the
child exits with an error, we got something to display.
(note that returning and undef'd plist is enough of an error, just we
had no clue what went wrong previously)

aja@ ran into this a few weeks ago.


Revision tags: OPENBSD_6_6_BASE
# 1.163 21-Jul-2019 espie

start re-adding the non-broken changes:
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle


# 1.162 17-Jul-2019 sthen

backout previous commits for now; some of this is shared with dpb and
results in problems. hints from pvk@ about what introduced the breakage
we were seeing, who confirms that this backout fixes things; comitting
early to unbreak package builds.

====
a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...

Members:
OpenBSD/AddCreateDelete.pm:1.44->1.45
OpenBSD/AddDelete.pm:1.87->1.88
OpenBSD/Error.pm:1.33->1.34
OpenBSD/PackageRepository.pm:1.164->1.165
OpenBSD/PkgCreate.pm:1.160->1.161
OpenBSD/State.pm:1.58->1.59
OpenBSD/Temp.pm:1.34->1.35
====


# 1.161 14-Jul-2019 espie

a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...


# 1.160 11-Jul-2019 espie

move the display of cmd into fatal, and don't say it's a fatal error, it's
already obvious


# 1.159 11-Jul-2019 espie

tweak the way we report bugs
- the catch/catchall distinction is no longer relevant, strip some info
by default now
- use state->{cmd} to display the command name properly

This makes sure final displays show the command name.


# 1.158 10-Jul-2019 espie

make pkg_create fail properly (return 1 is useless there)

OpenBSD::Temp error handling as well


# 1.157 08-Jul-2019 espie

actually use error, we can delay fatal problems


# 1.156 08-Jul-2019 espie

check ::Temp creation


# 1.155 28-May-2019 espie

oops, let cdrom normalize if it's there.
Noticed by sthen@


# 1.154 28-May-2019 espie

make PERMIT_CDROM info optional
as discussed with sthen@, code slightly adjusted


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.153 03-Aug-2018 espie

actually heed localbase when looking for groff


# 1.152 03-Aug-2018 espie

reorg groff runner so that failures are handled better
do the logic for manpage formatting better, so that we can't miss things
simplify filenames, fullname always has a slash


# 1.151 26-Jun-2018 espie

kill the solve_tags part of pkg_create for now, as it doesn't work at all


# 1.150 24-Jun-2018 espie

get ready to reuse verify_tag


# 1.149 23-Jun-2018 espie

solve_tags not yet functional, I'll reactivate the checks during creation
when it's cleaned up


# 1.148 23-Jun-2018 espie

well, when we read the plist from the ports tree, we need to register
the tag info similarly to registering libraries


# 1.147 23-Jun-2018 espie

PkgCreate has no business knowing details of define-tag


# 1.146 23-Jun-2018 espie

do some more basic checking of tags vs define-tag so that parameter usage
is handled more gracefully


# 1.145 22-Jun-2018 espie

move the tag base code into SolverBase, and use it in PkgCreate, so that
we refuse to create packages with tags without reachable definitions


# 1.144 21-Jun-2018 espie

split the common half of dependencies handling into SolverBase, as PkgCreate
only uses that


# 1.143 18-Jun-2018 espie

kill Frag/NoFrag, they only make sense in update-plist, so they've been
moved there.


# 1.142 15-Jun-2018 espie

Add a -Dstub option to facilitate creating/adding/deleting "stubbed" packages
with just the packing and dependency info with none of the files.

(useful for debugging tricky cases that involve large packages)


# 1.141 06-Jun-2018 espie

if the parser can't find a starting line in user db, it won't look
at any line, so it won't error out.
Add logic to make it error out.


# 1.140 30-May-2018 espie

port -u userlist option from update-plist, as suggested by sthen@.
main differences:
- error out on a problem instead of warning
- always parse the userlist if the option is specified. Avoid ticking time
bomb effect on bulk builds, where packages would be fine until the first
@new(user|group) usage in case the user list got corrupted.

Note it's still an option, so if you're using pkg_create outside of the
ports tree, you can do whatever you want.


# 1.139 13-May-2018 espie

adjust highly misleading comment to match reality


# 1.138 09-May-2018 espie

on the other hand, commenting this out was involuntary.
ask_tree will often say fun things because of (say) pipe closes


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.166 13-Jan-2020 espie

nit, use "fatal" with parameters as intended


# 1.165 09-Jan-2020 espie

have ask_tree be more specific in its error reporting.
make sure the child has the same effective and real ids,
as perl interprets it as "setuid, refuse to debug"
go to the end of the pipe so the child doesn't exit
prematurely (didn't use to happen but now it does)

help from afresh1@ in diagnosing that one.


# 1.164 07-Nov-2019 espie

when asking the ports tree, we fork a child.
instead of ditching stderr entirely, keep it in a temp file, and if the
child exits with an error, we got something to display.
(note that returning and undef'd plist is enough of an error, just we
had no clue what went wrong previously)

aja@ ran into this a few weeks ago.


Revision tags: OPENBSD_6_6_BASE
# 1.163 21-Jul-2019 espie

start re-adding the non-broken changes:
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle


# 1.162 17-Jul-2019 sthen

backout previous commits for now; some of this is shared with dpb and
results in problems. hints from pvk@ about what introduced the breakage
we were seeing, who confirms that this backout fixes things; comitting
early to unbreak package builds.

====
a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...

Members:
OpenBSD/AddCreateDelete.pm:1.44->1.45
OpenBSD/AddDelete.pm:1.87->1.88
OpenBSD/Error.pm:1.33->1.34
OpenBSD/PackageRepository.pm:1.164->1.165
OpenBSD/PkgCreate.pm:1.160->1.161
OpenBSD/State.pm:1.58->1.59
OpenBSD/Temp.pm:1.34->1.35
====


# 1.161 14-Jul-2019 espie

a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...


# 1.160 11-Jul-2019 espie

move the display of cmd into fatal, and don't say it's a fatal error, it's
already obvious


# 1.159 11-Jul-2019 espie

tweak the way we report bugs
- the catch/catchall distinction is no longer relevant, strip some info
by default now
- use state->{cmd} to display the command name properly

This makes sure final displays show the command name.


# 1.158 10-Jul-2019 espie

make pkg_create fail properly (return 1 is useless there)

OpenBSD::Temp error handling as well


# 1.157 08-Jul-2019 espie

actually use error, we can delay fatal problems


# 1.156 08-Jul-2019 espie

check ::Temp creation


# 1.155 28-May-2019 espie

oops, let cdrom normalize if it's there.
Noticed by sthen@


# 1.154 28-May-2019 espie

make PERMIT_CDROM info optional
as discussed with sthen@, code slightly adjusted


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.153 03-Aug-2018 espie

actually heed localbase when looking for groff


# 1.152 03-Aug-2018 espie

reorg groff runner so that failures are handled better
do the logic for manpage formatting better, so that we can't miss things
simplify filenames, fullname always has a slash


# 1.151 26-Jun-2018 espie

kill the solve_tags part of pkg_create for now, as it doesn't work at all


# 1.150 24-Jun-2018 espie

get ready to reuse verify_tag


# 1.149 23-Jun-2018 espie

solve_tags not yet functional, I'll reactivate the checks during creation
when it's cleaned up


# 1.148 23-Jun-2018 espie

well, when we read the plist from the ports tree, we need to register
the tag info similarly to registering libraries


# 1.147 23-Jun-2018 espie

PkgCreate has no business knowing details of define-tag


# 1.146 23-Jun-2018 espie

do some more basic checking of tags vs define-tag so that parameter usage
is handled more gracefully


# 1.145 22-Jun-2018 espie

move the tag base code into SolverBase, and use it in PkgCreate, so that
we refuse to create packages with tags without reachable definitions


# 1.144 21-Jun-2018 espie

split the common half of dependencies handling into SolverBase, as PkgCreate
only uses that


# 1.143 18-Jun-2018 espie

kill Frag/NoFrag, they only make sense in update-plist, so they've been
moved there.


# 1.142 15-Jun-2018 espie

Add a -Dstub option to facilitate creating/adding/deleting "stubbed" packages
with just the packing and dependency info with none of the files.

(useful for debugging tricky cases that involve large packages)


# 1.141 06-Jun-2018 espie

if the parser can't find a starting line in user db, it won't look
at any line, so it won't error out.
Add logic to make it error out.


# 1.140 30-May-2018 espie

port -u userlist option from update-plist, as suggested by sthen@.
main differences:
- error out on a problem instead of warning
- always parse the userlist if the option is specified. Avoid ticking time
bomb effect on bulk builds, where packages would be fine until the first
@new(user|group) usage in case the user list got corrupted.

Note it's still an option, so if you're using pkg_create outside of the
ports tree, you can do whatever you want.


# 1.139 13-May-2018 espie

adjust highly misleading comment to match reality


# 1.138 09-May-2018 espie

on the other hand, commenting this out was involuntary.
ask_tree will often say fun things because of (say) pipe closes


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.165 09-Jan-2020 espie

have ask_tree be more specific in its error reporting.
make sure the child has the same effective and real ids,
as perl interprets it as "setuid, refuse to debug"
go to the end of the pipe so the child doesn't exit
prematurely (didn't use to happen but now it does)

help from afresh1@ in diagnosing that one.


# 1.164 07-Nov-2019 espie

when asking the ports tree, we fork a child.
instead of ditching stderr entirely, keep it in a temp file, and if the
child exits with an error, we got something to display.
(note that returning and undef'd plist is enough of an error, just we
had no clue what went wrong previously)

aja@ ran into this a few weeks ago.


Revision tags: OPENBSD_6_6_BASE
# 1.163 21-Jul-2019 espie

start re-adding the non-broken changes:
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle


# 1.162 17-Jul-2019 sthen

backout previous commits for now; some of this is shared with dpb and
results in problems. hints from pvk@ about what introduced the breakage
we were seeing, who confirms that this backout fixes things; comitting
early to unbreak package builds.

====
a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...

Members:
OpenBSD/AddCreateDelete.pm:1.44->1.45
OpenBSD/AddDelete.pm:1.87->1.88
OpenBSD/Error.pm:1.33->1.34
OpenBSD/PackageRepository.pm:1.164->1.165
OpenBSD/PkgCreate.pm:1.160->1.161
OpenBSD/State.pm:1.58->1.59
OpenBSD/Temp.pm:1.34->1.35
====


# 1.161 14-Jul-2019 espie

a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...


# 1.160 11-Jul-2019 espie

move the display of cmd into fatal, and don't say it's a fatal error, it's
already obvious


# 1.159 11-Jul-2019 espie

tweak the way we report bugs
- the catch/catchall distinction is no longer relevant, strip some info
by default now
- use state->{cmd} to display the command name properly

This makes sure final displays show the command name.


# 1.158 10-Jul-2019 espie

make pkg_create fail properly (return 1 is useless there)

OpenBSD::Temp error handling as well


# 1.157 08-Jul-2019 espie

actually use error, we can delay fatal problems


# 1.156 08-Jul-2019 espie

check ::Temp creation


# 1.155 28-May-2019 espie

oops, let cdrom normalize if it's there.
Noticed by sthen@


# 1.154 28-May-2019 espie

make PERMIT_CDROM info optional
as discussed with sthen@, code slightly adjusted


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.153 03-Aug-2018 espie

actually heed localbase when looking for groff


# 1.152 03-Aug-2018 espie

reorg groff runner so that failures are handled better
do the logic for manpage formatting better, so that we can't miss things
simplify filenames, fullname always has a slash


# 1.151 26-Jun-2018 espie

kill the solve_tags part of pkg_create for now, as it doesn't work at all


# 1.150 24-Jun-2018 espie

get ready to reuse verify_tag


# 1.149 23-Jun-2018 espie

solve_tags not yet functional, I'll reactivate the checks during creation
when it's cleaned up


# 1.148 23-Jun-2018 espie

well, when we read the plist from the ports tree, we need to register
the tag info similarly to registering libraries


# 1.147 23-Jun-2018 espie

PkgCreate has no business knowing details of define-tag


# 1.146 23-Jun-2018 espie

do some more basic checking of tags vs define-tag so that parameter usage
is handled more gracefully


# 1.145 22-Jun-2018 espie

move the tag base code into SolverBase, and use it in PkgCreate, so that
we refuse to create packages with tags without reachable definitions


# 1.144 21-Jun-2018 espie

split the common half of dependencies handling into SolverBase, as PkgCreate
only uses that


# 1.143 18-Jun-2018 espie

kill Frag/NoFrag, they only make sense in update-plist, so they've been
moved there.


# 1.142 15-Jun-2018 espie

Add a -Dstub option to facilitate creating/adding/deleting "stubbed" packages
with just the packing and dependency info with none of the files.

(useful for debugging tricky cases that involve large packages)


# 1.141 06-Jun-2018 espie

if the parser can't find a starting line in user db, it won't look
at any line, so it won't error out.
Add logic to make it error out.


# 1.140 30-May-2018 espie

port -u userlist option from update-plist, as suggested by sthen@.
main differences:
- error out on a problem instead of warning
- always parse the userlist if the option is specified. Avoid ticking time
bomb effect on bulk builds, where packages would be fine until the first
@new(user|group) usage in case the user list got corrupted.

Note it's still an option, so if you're using pkg_create outside of the
ports tree, you can do whatever you want.


# 1.139 13-May-2018 espie

adjust highly misleading comment to match reality


# 1.138 09-May-2018 espie

on the other hand, commenting this out was involuntary.
ask_tree will often say fun things because of (say) pipe closes


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.164 07-Nov-2019 espie

when asking the ports tree, we fork a child.
instead of ditching stderr entirely, keep it in a temp file, and if the
child exits with an error, we got something to display.
(note that returning and undef'd plist is enough of an error, just we
had no clue what went wrong previously)

aja@ ran into this a few weeks ago.


Revision tags: OPENBSD_6_6_BASE
# 1.163 21-Jul-2019 espie

start re-adding the non-broken changes:
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle


# 1.162 17-Jul-2019 sthen

backout previous commits for now; some of this is shared with dpb and
results in problems. hints from pvk@ about what introduced the breakage
we were seeing, who confirms that this backout fixes things; comitting
early to unbreak package builds.

====
a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...

Members:
OpenBSD/AddCreateDelete.pm:1.44->1.45
OpenBSD/AddDelete.pm:1.87->1.88
OpenBSD/Error.pm:1.33->1.34
OpenBSD/PackageRepository.pm:1.164->1.165
OpenBSD/PkgCreate.pm:1.160->1.161
OpenBSD/State.pm:1.58->1.59
OpenBSD/Temp.pm:1.34->1.35
====


# 1.161 14-Jul-2019 espie

a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...


# 1.160 11-Jul-2019 espie

move the display of cmd into fatal, and don't say it's a fatal error, it's
already obvious


# 1.159 11-Jul-2019 espie

tweak the way we report bugs
- the catch/catchall distinction is no longer relevant, strip some info
by default now
- use state->{cmd} to display the command name properly

This makes sure final displays show the command name.


# 1.158 10-Jul-2019 espie

make pkg_create fail properly (return 1 is useless there)

OpenBSD::Temp error handling as well


# 1.157 08-Jul-2019 espie

actually use error, we can delay fatal problems


# 1.156 08-Jul-2019 espie

check ::Temp creation


# 1.155 28-May-2019 espie

oops, let cdrom normalize if it's there.
Noticed by sthen@


# 1.154 28-May-2019 espie

make PERMIT_CDROM info optional
as discussed with sthen@, code slightly adjusted


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.153 03-Aug-2018 espie

actually heed localbase when looking for groff


# 1.152 03-Aug-2018 espie

reorg groff runner so that failures are handled better
do the logic for manpage formatting better, so that we can't miss things
simplify filenames, fullname always has a slash


# 1.151 26-Jun-2018 espie

kill the solve_tags part of pkg_create for now, as it doesn't work at all


# 1.150 24-Jun-2018 espie

get ready to reuse verify_tag


# 1.149 23-Jun-2018 espie

solve_tags not yet functional, I'll reactivate the checks during creation
when it's cleaned up


# 1.148 23-Jun-2018 espie

well, when we read the plist from the ports tree, we need to register
the tag info similarly to registering libraries


# 1.147 23-Jun-2018 espie

PkgCreate has no business knowing details of define-tag


# 1.146 23-Jun-2018 espie

do some more basic checking of tags vs define-tag so that parameter usage
is handled more gracefully


# 1.145 22-Jun-2018 espie

move the tag base code into SolverBase, and use it in PkgCreate, so that
we refuse to create packages with tags without reachable definitions


# 1.144 21-Jun-2018 espie

split the common half of dependencies handling into SolverBase, as PkgCreate
only uses that


# 1.143 18-Jun-2018 espie

kill Frag/NoFrag, they only make sense in update-plist, so they've been
moved there.


# 1.142 15-Jun-2018 espie

Add a -Dstub option to facilitate creating/adding/deleting "stubbed" packages
with just the packing and dependency info with none of the files.

(useful for debugging tricky cases that involve large packages)


# 1.141 06-Jun-2018 espie

if the parser can't find a starting line in user db, it won't look
at any line, so it won't error out.
Add logic to make it error out.


# 1.140 30-May-2018 espie

port -u userlist option from update-plist, as suggested by sthen@.
main differences:
- error out on a problem instead of warning
- always parse the userlist if the option is specified. Avoid ticking time
bomb effect on bulk builds, where packages would be fine until the first
@new(user|group) usage in case the user list got corrupted.

Note it's still an option, so if you're using pkg_create outside of the
ports tree, you can do whatever you want.


# 1.139 13-May-2018 espie

adjust highly misleading comment to match reality


# 1.138 09-May-2018 espie

on the other hand, commenting this out was involuntary.
ask_tree will often say fun things because of (say) pipe closes


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.163 21-Jul-2019 espie

start re-adding the non-broken changes:
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle


# 1.162 17-Jul-2019 sthen

backout previous commits for now; some of this is shared with dpb and
results in problems. hints from pvk@ about what introduced the breakage
we were seeing, who confirms that this backout fixes things; comitting
early to unbreak package builds.

====
a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...

Members:
OpenBSD/AddCreateDelete.pm:1.44->1.45
OpenBSD/AddDelete.pm:1.87->1.88
OpenBSD/Error.pm:1.33->1.34
OpenBSD/PackageRepository.pm:1.164->1.165
OpenBSD/PkgCreate.pm:1.160->1.161
OpenBSD/State.pm:1.58->1.59
OpenBSD/Temp.pm:1.34->1.35
====


# 1.161 14-Jul-2019 espie

a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...


# 1.160 11-Jul-2019 espie

move the display of cmd into fatal, and don't say it's a fatal error, it's
already obvious


# 1.159 11-Jul-2019 espie

tweak the way we report bugs
- the catch/catchall distinction is no longer relevant, strip some info
by default now
- use state->{cmd} to display the command name properly

This makes sure final displays show the command name.


# 1.158 10-Jul-2019 espie

make pkg_create fail properly (return 1 is useless there)

OpenBSD::Temp error handling as well


# 1.157 08-Jul-2019 espie

actually use error, we can delay fatal problems


# 1.156 08-Jul-2019 espie

check ::Temp creation


# 1.155 28-May-2019 espie

oops, let cdrom normalize if it's there.
Noticed by sthen@


# 1.154 28-May-2019 espie

make PERMIT_CDROM info optional
as discussed with sthen@, code slightly adjusted


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.153 03-Aug-2018 espie

actually heed localbase when looking for groff


# 1.152 03-Aug-2018 espie

reorg groff runner so that failures are handled better
do the logic for manpage formatting better, so that we can't miss things
simplify filenames, fullname always has a slash


# 1.151 26-Jun-2018 espie

kill the solve_tags part of pkg_create for now, as it doesn't work at all


# 1.150 24-Jun-2018 espie

get ready to reuse verify_tag


# 1.149 23-Jun-2018 espie

solve_tags not yet functional, I'll reactivate the checks during creation
when it's cleaned up


# 1.148 23-Jun-2018 espie

well, when we read the plist from the ports tree, we need to register
the tag info similarly to registering libraries


# 1.147 23-Jun-2018 espie

PkgCreate has no business knowing details of define-tag


# 1.146 23-Jun-2018 espie

do some more basic checking of tags vs define-tag so that parameter usage
is handled more gracefully


# 1.145 22-Jun-2018 espie

move the tag base code into SolverBase, and use it in PkgCreate, so that
we refuse to create packages with tags without reachable definitions


# 1.144 21-Jun-2018 espie

split the common half of dependencies handling into SolverBase, as PkgCreate
only uses that


# 1.143 18-Jun-2018 espie

kill Frag/NoFrag, they only make sense in update-plist, so they've been
moved there.


# 1.142 15-Jun-2018 espie

Add a -Dstub option to facilitate creating/adding/deleting "stubbed" packages
with just the packing and dependency info with none of the files.

(useful for debugging tricky cases that involve large packages)


# 1.141 06-Jun-2018 espie

if the parser can't find a starting line in user db, it won't look
at any line, so it won't error out.
Add logic to make it error out.


# 1.140 30-May-2018 espie

port -u userlist option from update-plist, as suggested by sthen@.
main differences:
- error out on a problem instead of warning
- always parse the userlist if the option is specified. Avoid ticking time
bomb effect on bulk builds, where packages would be fine until the first
@new(user|group) usage in case the user list got corrupted.

Note it's still an option, so if you're using pkg_create outside of the
ports tree, you can do whatever you want.


# 1.139 13-May-2018 espie

adjust highly misleading comment to match reality


# 1.138 09-May-2018 espie

on the other hand, commenting this out was involuntary.
ask_tree will often say fun things because of (say) pipe closes


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.162 17-Jul-2019 sthen

backout previous commits for now; some of this is shared with dpb and
results in problems. hints from pvk@ about what introduced the breakage
we were seeing, who confirms that this backout fixes things; comitting
early to unbreak package builds.

====
a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...

Members:
OpenBSD/AddCreateDelete.pm:1.44->1.45
OpenBSD/AddDelete.pm:1.87->1.88
OpenBSD/Error.pm:1.33->1.34
OpenBSD/PackageRepository.pm:1.164->1.165
OpenBSD/PkgCreate.pm:1.160->1.161
OpenBSD/State.pm:1.58->1.59
OpenBSD/Temp.pm:1.34->1.35
====


# 1.161 14-Jul-2019 espie

a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...


# 1.160 11-Jul-2019 espie

move the display of cmd into fatal, and don't say it's a fatal error, it's
already obvious


# 1.159 11-Jul-2019 espie

tweak the way we report bugs
- the catch/catchall distinction is no longer relevant, strip some info
by default now
- use state->{cmd} to display the command name properly

This makes sure final displays show the command name.


# 1.158 10-Jul-2019 espie

make pkg_create fail properly (return 1 is useless there)

OpenBSD::Temp error handling as well


# 1.157 08-Jul-2019 espie

actually use error, we can delay fatal problems


# 1.156 08-Jul-2019 espie

check ::Temp creation


# 1.155 28-May-2019 espie

oops, let cdrom normalize if it's there.
Noticed by sthen@


# 1.154 28-May-2019 espie

make PERMIT_CDROM info optional
as discussed with sthen@, code slightly adjusted


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.153 03-Aug-2018 espie

actually heed localbase when looking for groff


# 1.152 03-Aug-2018 espie

reorg groff runner so that failures are handled better
do the logic for manpage formatting better, so that we can't miss things
simplify filenames, fullname always has a slash


# 1.151 26-Jun-2018 espie

kill the solve_tags part of pkg_create for now, as it doesn't work at all


# 1.150 24-Jun-2018 espie

get ready to reuse verify_tag


# 1.149 23-Jun-2018 espie

solve_tags not yet functional, I'll reactivate the checks during creation
when it's cleaned up


# 1.148 23-Jun-2018 espie

well, when we read the plist from the ports tree, we need to register
the tag info similarly to registering libraries


# 1.147 23-Jun-2018 espie

PkgCreate has no business knowing details of define-tag


# 1.146 23-Jun-2018 espie

do some more basic checking of tags vs define-tag so that parameter usage
is handled more gracefully


# 1.145 22-Jun-2018 espie

move the tag base code into SolverBase, and use it in PkgCreate, so that
we refuse to create packages with tags without reachable definitions


# 1.144 21-Jun-2018 espie

split the common half of dependencies handling into SolverBase, as PkgCreate
only uses that


# 1.143 18-Jun-2018 espie

kill Frag/NoFrag, they only make sense in update-plist, so they've been
moved there.


# 1.142 15-Jun-2018 espie

Add a -Dstub option to facilitate creating/adding/deleting "stubbed" packages
with just the packing and dependency info with none of the files.

(useful for debugging tricky cases that involve large packages)


# 1.141 06-Jun-2018 espie

if the parser can't find a starting line in user db, it won't look
at any line, so it won't error out.
Add logic to make it error out.


# 1.140 30-May-2018 espie

port -u userlist option from update-plist, as suggested by sthen@.
main differences:
- error out on a problem instead of warning
- always parse the userlist if the option is specified. Avoid ticking time
bomb effect on bulk builds, where packages would be fine until the first
@new(user|group) usage in case the user list got corrupted.

Note it's still an option, so if you're using pkg_create outside of the
ports tree, you can do whatever you want.


# 1.139 13-May-2018 espie

adjust highly misleading comment to match reality


# 1.138 09-May-2018 espie

on the other hand, commenting this out was involuntary.
ask_tree will often say fun things because of (say) pipe closes


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.161 14-Jul-2019 espie

a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that
individual packages don't have to, and explain the issue
- kill old Unlink/Copy code that migrated to State years ago
- commonalize try{} catch {} for pkg_add/delete and pkg_create, so that
debug works the same way in both.
- switch printing command name to the catch handler, so that exceptions
are simpler to handle

and a few comments for the hairy parts...


# 1.160 11-Jul-2019 espie

move the display of cmd into fatal, and don't say it's a fatal error, it's
already obvious


# 1.159 11-Jul-2019 espie

tweak the way we report bugs
- the catch/catchall distinction is no longer relevant, strip some info
by default now
- use state->{cmd} to display the command name properly

This makes sure final displays show the command name.


# 1.158 10-Jul-2019 espie

make pkg_create fail properly (return 1 is useless there)

OpenBSD::Temp error handling as well


# 1.157 08-Jul-2019 espie

actually use error, we can delay fatal problems


# 1.156 08-Jul-2019 espie

check ::Temp creation


# 1.155 28-May-2019 espie

oops, let cdrom normalize if it's there.
Noticed by sthen@


# 1.154 28-May-2019 espie

make PERMIT_CDROM info optional
as discussed with sthen@, code slightly adjusted


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.153 03-Aug-2018 espie

actually heed localbase when looking for groff


# 1.152 03-Aug-2018 espie

reorg groff runner so that failures are handled better
do the logic for manpage formatting better, so that we can't miss things
simplify filenames, fullname always has a slash


# 1.151 26-Jun-2018 espie

kill the solve_tags part of pkg_create for now, as it doesn't work at all


# 1.150 24-Jun-2018 espie

get ready to reuse verify_tag


# 1.149 23-Jun-2018 espie

solve_tags not yet functional, I'll reactivate the checks during creation
when it's cleaned up


# 1.148 23-Jun-2018 espie

well, when we read the plist from the ports tree, we need to register
the tag info similarly to registering libraries


# 1.147 23-Jun-2018 espie

PkgCreate has no business knowing details of define-tag


# 1.146 23-Jun-2018 espie

do some more basic checking of tags vs define-tag so that parameter usage
is handled more gracefully


# 1.145 22-Jun-2018 espie

move the tag base code into SolverBase, and use it in PkgCreate, so that
we refuse to create packages with tags without reachable definitions


# 1.144 21-Jun-2018 espie

split the common half of dependencies handling into SolverBase, as PkgCreate
only uses that


# 1.143 18-Jun-2018 espie

kill Frag/NoFrag, they only make sense in update-plist, so they've been
moved there.


# 1.142 15-Jun-2018 espie

Add a -Dstub option to facilitate creating/adding/deleting "stubbed" packages
with just the packing and dependency info with none of the files.

(useful for debugging tricky cases that involve large packages)


# 1.141 06-Jun-2018 espie

if the parser can't find a starting line in user db, it won't look
at any line, so it won't error out.
Add logic to make it error out.


# 1.140 30-May-2018 espie

port -u userlist option from update-plist, as suggested by sthen@.
main differences:
- error out on a problem instead of warning
- always parse the userlist if the option is specified. Avoid ticking time
bomb effect on bulk builds, where packages would be fine until the first
@new(user|group) usage in case the user list got corrupted.

Note it's still an option, so if you're using pkg_create outside of the
ports tree, you can do whatever you want.


# 1.139 13-May-2018 espie

adjust highly misleading comment to match reality


# 1.138 09-May-2018 espie

on the other hand, commenting this out was involuntary.
ask_tree will often say fun things because of (say) pipe closes


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.160 11-Jul-2019 espie

move the display of cmd into fatal, and don't say it's a fatal error, it's
already obvious


# 1.159 11-Jul-2019 espie

tweak the way we report bugs
- the catch/catchall distinction is no longer relevant, strip some info
by default now
- use state->{cmd} to display the command name properly

This makes sure final displays show the command name.


# 1.158 10-Jul-2019 espie

make pkg_create fail properly (return 1 is useless there)

OpenBSD::Temp error handling as well


# 1.157 08-Jul-2019 espie

actually use error, we can delay fatal problems


# 1.156 08-Jul-2019 espie

check ::Temp creation


# 1.155 28-May-2019 espie

oops, let cdrom normalize if it's there.
Noticed by sthen@


# 1.154 28-May-2019 espie

make PERMIT_CDROM info optional
as discussed with sthen@, code slightly adjusted


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.153 03-Aug-2018 espie

actually heed localbase when looking for groff


# 1.152 03-Aug-2018 espie

reorg groff runner so that failures are handled better
do the logic for manpage formatting better, so that we can't miss things
simplify filenames, fullname always has a slash


# 1.151 26-Jun-2018 espie

kill the solve_tags part of pkg_create for now, as it doesn't work at all


# 1.150 24-Jun-2018 espie

get ready to reuse verify_tag


# 1.149 23-Jun-2018 espie

solve_tags not yet functional, I'll reactivate the checks during creation
when it's cleaned up


# 1.148 23-Jun-2018 espie

well, when we read the plist from the ports tree, we need to register
the tag info similarly to registering libraries


# 1.147 23-Jun-2018 espie

PkgCreate has no business knowing details of define-tag


# 1.146 23-Jun-2018 espie

do some more basic checking of tags vs define-tag so that parameter usage
is handled more gracefully


# 1.145 22-Jun-2018 espie

move the tag base code into SolverBase, and use it in PkgCreate, so that
we refuse to create packages with tags without reachable definitions


# 1.144 21-Jun-2018 espie

split the common half of dependencies handling into SolverBase, as PkgCreate
only uses that


# 1.143 18-Jun-2018 espie

kill Frag/NoFrag, they only make sense in update-plist, so they've been
moved there.


# 1.142 15-Jun-2018 espie

Add a -Dstub option to facilitate creating/adding/deleting "stubbed" packages
with just the packing and dependency info with none of the files.

(useful for debugging tricky cases that involve large packages)


# 1.141 06-Jun-2018 espie

if the parser can't find a starting line in user db, it won't look
at any line, so it won't error out.
Add logic to make it error out.


# 1.140 30-May-2018 espie

port -u userlist option from update-plist, as suggested by sthen@.
main differences:
- error out on a problem instead of warning
- always parse the userlist if the option is specified. Avoid ticking time
bomb effect on bulk builds, where packages would be fine until the first
@new(user|group) usage in case the user list got corrupted.

Note it's still an option, so if you're using pkg_create outside of the
ports tree, you can do whatever you want.


# 1.139 13-May-2018 espie

adjust highly misleading comment to match reality


# 1.138 09-May-2018 espie

on the other hand, commenting this out was involuntary.
ask_tree will often say fun things because of (say) pipe closes


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.158 10-Jul-2019 espie

make pkg_create fail properly (return 1 is useless there)

OpenBSD::Temp error handling as well


# 1.157 08-Jul-2019 espie

actually use error, we can delay fatal problems


# 1.156 08-Jul-2019 espie

check ::Temp creation


# 1.155 28-May-2019 espie

oops, let cdrom normalize if it's there.
Noticed by sthen@


# 1.154 28-May-2019 espie

make PERMIT_CDROM info optional
as discussed with sthen@, code slightly adjusted


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.153 03-Aug-2018 espie

actually heed localbase when looking for groff


# 1.152 03-Aug-2018 espie

reorg groff runner so that failures are handled better
do the logic for manpage formatting better, so that we can't miss things
simplify filenames, fullname always has a slash


# 1.151 26-Jun-2018 espie

kill the solve_tags part of pkg_create for now, as it doesn't work at all


# 1.150 24-Jun-2018 espie

get ready to reuse verify_tag


# 1.149 23-Jun-2018 espie

solve_tags not yet functional, I'll reactivate the checks during creation
when it's cleaned up


# 1.148 23-Jun-2018 espie

well, when we read the plist from the ports tree, we need to register
the tag info similarly to registering libraries


# 1.147 23-Jun-2018 espie

PkgCreate has no business knowing details of define-tag


# 1.146 23-Jun-2018 espie

do some more basic checking of tags vs define-tag so that parameter usage
is handled more gracefully


# 1.145 22-Jun-2018 espie

move the tag base code into SolverBase, and use it in PkgCreate, so that
we refuse to create packages with tags without reachable definitions


# 1.144 21-Jun-2018 espie

split the common half of dependencies handling into SolverBase, as PkgCreate
only uses that


# 1.143 18-Jun-2018 espie

kill Frag/NoFrag, they only make sense in update-plist, so they've been
moved there.


# 1.142 15-Jun-2018 espie

Add a -Dstub option to facilitate creating/adding/deleting "stubbed" packages
with just the packing and dependency info with none of the files.

(useful for debugging tricky cases that involve large packages)


# 1.141 06-Jun-2018 espie

if the parser can't find a starting line in user db, it won't look
at any line, so it won't error out.
Add logic to make it error out.


# 1.140 30-May-2018 espie

port -u userlist option from update-plist, as suggested by sthen@.
main differences:
- error out on a problem instead of warning
- always parse the userlist if the option is specified. Avoid ticking time
bomb effect on bulk builds, where packages would be fine until the first
@new(user|group) usage in case the user list got corrupted.

Note it's still an option, so if you're using pkg_create outside of the
ports tree, you can do whatever you want.


# 1.139 13-May-2018 espie

adjust highly misleading comment to match reality


# 1.138 09-May-2018 espie

on the other hand, commenting this out was involuntary.
ask_tree will often say fun things because of (say) pipe closes


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.157 08-Jul-2019 espie

actually use error, we can delay fatal problems


# 1.156 08-Jul-2019 espie

check ::Temp creation


# 1.155 28-May-2019 espie

oops, let cdrom normalize if it's there.
Noticed by sthen@


# 1.154 28-May-2019 espie

make PERMIT_CDROM info optional
as discussed with sthen@, code slightly adjusted


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.153 03-Aug-2018 espie

actually heed localbase when looking for groff


# 1.152 03-Aug-2018 espie

reorg groff runner so that failures are handled better
do the logic for manpage formatting better, so that we can't miss things
simplify filenames, fullname always has a slash


# 1.151 26-Jun-2018 espie

kill the solve_tags part of pkg_create for now, as it doesn't work at all


# 1.150 24-Jun-2018 espie

get ready to reuse verify_tag


# 1.149 23-Jun-2018 espie

solve_tags not yet functional, I'll reactivate the checks during creation
when it's cleaned up


# 1.148 23-Jun-2018 espie

well, when we read the plist from the ports tree, we need to register
the tag info similarly to registering libraries


# 1.147 23-Jun-2018 espie

PkgCreate has no business knowing details of define-tag


# 1.146 23-Jun-2018 espie

do some more basic checking of tags vs define-tag so that parameter usage
is handled more gracefully


# 1.145 22-Jun-2018 espie

move the tag base code into SolverBase, and use it in PkgCreate, so that
we refuse to create packages with tags without reachable definitions


# 1.144 21-Jun-2018 espie

split the common half of dependencies handling into SolverBase, as PkgCreate
only uses that


# 1.143 18-Jun-2018 espie

kill Frag/NoFrag, they only make sense in update-plist, so they've been
moved there.


# 1.142 15-Jun-2018 espie

Add a -Dstub option to facilitate creating/adding/deleting "stubbed" packages
with just the packing and dependency info with none of the files.

(useful for debugging tricky cases that involve large packages)


# 1.141 06-Jun-2018 espie

if the parser can't find a starting line in user db, it won't look
at any line, so it won't error out.
Add logic to make it error out.


# 1.140 30-May-2018 espie

port -u userlist option from update-plist, as suggested by sthen@.
main differences:
- error out on a problem instead of warning
- always parse the userlist if the option is specified. Avoid ticking time
bomb effect on bulk builds, where packages would be fine until the first
@new(user|group) usage in case the user list got corrupted.

Note it's still an option, so if you're using pkg_create outside of the
ports tree, you can do whatever you want.


# 1.139 13-May-2018 espie

adjust highly misleading comment to match reality


# 1.138 09-May-2018 espie

on the other hand, commenting this out was involuntary.
ask_tree will often say fun things because of (say) pipe closes


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.155 28-May-2019 espie

oops, let cdrom normalize if it's there.
Noticed by sthen@


# 1.154 28-May-2019 espie

make PERMIT_CDROM info optional
as discussed with sthen@, code slightly adjusted


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.153 03-Aug-2018 espie

actually heed localbase when looking for groff


# 1.152 03-Aug-2018 espie

reorg groff runner so that failures are handled better
do the logic for manpage formatting better, so that we can't miss things
simplify filenames, fullname always has a slash


# 1.151 26-Jun-2018 espie

kill the solve_tags part of pkg_create for now, as it doesn't work at all


# 1.150 24-Jun-2018 espie

get ready to reuse verify_tag


# 1.149 23-Jun-2018 espie

solve_tags not yet functional, I'll reactivate the checks during creation
when it's cleaned up


# 1.148 23-Jun-2018 espie

well, when we read the plist from the ports tree, we need to register
the tag info similarly to registering libraries


# 1.147 23-Jun-2018 espie

PkgCreate has no business knowing details of define-tag


# 1.146 23-Jun-2018 espie

do some more basic checking of tags vs define-tag so that parameter usage
is handled more gracefully


# 1.145 22-Jun-2018 espie

move the tag base code into SolverBase, and use it in PkgCreate, so that
we refuse to create packages with tags without reachable definitions


# 1.144 21-Jun-2018 espie

split the common half of dependencies handling into SolverBase, as PkgCreate
only uses that


# 1.143 18-Jun-2018 espie

kill Frag/NoFrag, they only make sense in update-plist, so they've been
moved there.


# 1.142 15-Jun-2018 espie

Add a -Dstub option to facilitate creating/adding/deleting "stubbed" packages
with just the packing and dependency info with none of the files.

(useful for debugging tricky cases that involve large packages)


# 1.141 06-Jun-2018 espie

if the parser can't find a starting line in user db, it won't look
at any line, so it won't error out.
Add logic to make it error out.


# 1.140 30-May-2018 espie

port -u userlist option from update-plist, as suggested by sthen@.
main differences:
- error out on a problem instead of warning
- always parse the userlist if the option is specified. Avoid ticking time
bomb effect on bulk builds, where packages would be fine until the first
@new(user|group) usage in case the user list got corrupted.

Note it's still an option, so if you're using pkg_create outside of the
ports tree, you can do whatever you want.


# 1.139 13-May-2018 espie

adjust highly misleading comment to match reality


# 1.138 09-May-2018 espie

on the other hand, commenting this out was involuntary.
ask_tree will often say fun things because of (say) pipe closes


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.153 03-Aug-2018 espie

actually heed localbase when looking for groff


# 1.152 03-Aug-2018 espie

reorg groff runner so that failures are handled better
do the logic for manpage formatting better, so that we can't miss things
simplify filenames, fullname always has a slash


# 1.151 26-Jun-2018 espie

kill the solve_tags part of pkg_create for now, as it doesn't work at all


# 1.150 24-Jun-2018 espie

get ready to reuse verify_tag


# 1.149 23-Jun-2018 espie

solve_tags not yet functional, I'll reactivate the checks during creation
when it's cleaned up


# 1.148 23-Jun-2018 espie

well, when we read the plist from the ports tree, we need to register
the tag info similarly to registering libraries


# 1.147 23-Jun-2018 espie

PkgCreate has no business knowing details of define-tag


# 1.146 23-Jun-2018 espie

do some more basic checking of tags vs define-tag so that parameter usage
is handled more gracefully


# 1.145 22-Jun-2018 espie

move the tag base code into SolverBase, and use it in PkgCreate, so that
we refuse to create packages with tags without reachable definitions


# 1.144 21-Jun-2018 espie

split the common half of dependencies handling into SolverBase, as PkgCreate
only uses that


# 1.143 18-Jun-2018 espie

kill Frag/NoFrag, they only make sense in update-plist, so they've been
moved there.


# 1.142 15-Jun-2018 espie

Add a -Dstub option to facilitate creating/adding/deleting "stubbed" packages
with just the packing and dependency info with none of the files.

(useful for debugging tricky cases that involve large packages)


# 1.141 06-Jun-2018 espie

if the parser can't find a starting line in user db, it won't look
at any line, so it won't error out.
Add logic to make it error out.


# 1.140 30-May-2018 espie

port -u userlist option from update-plist, as suggested by sthen@.
main differences:
- error out on a problem instead of warning
- always parse the userlist if the option is specified. Avoid ticking time
bomb effect on bulk builds, where packages would be fine until the first
@new(user|group) usage in case the user list got corrupted.

Note it's still an option, so if you're using pkg_create outside of the
ports tree, you can do whatever you want.


# 1.139 13-May-2018 espie

adjust highly misleading comment to match reality


# 1.138 09-May-2018 espie

on the other hand, commenting this out was involuntary.
ask_tree will often say fun things because of (say) pipe closes


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.151 26-Jun-2018 espie

kill the solve_tags part of pkg_create for now, as it doesn't work at all


# 1.150 24-Jun-2018 espie

get ready to reuse verify_tag


# 1.149 23-Jun-2018 espie

solve_tags not yet functional, I'll reactivate the checks during creation
when it's cleaned up


# 1.148 23-Jun-2018 espie

well, when we read the plist from the ports tree, we need to register
the tag info similarly to registering libraries


# 1.147 23-Jun-2018 espie

PkgCreate has no business knowing details of define-tag


# 1.146 23-Jun-2018 espie

do some more basic checking of tags vs define-tag so that parameter usage
is handled more gracefully


# 1.145 22-Jun-2018 espie

move the tag base code into SolverBase, and use it in PkgCreate, so that
we refuse to create packages with tags without reachable definitions


# 1.144 21-Jun-2018 espie

split the common half of dependencies handling into SolverBase, as PkgCreate
only uses that


# 1.143 18-Jun-2018 espie

kill Frag/NoFrag, they only make sense in update-plist, so they've been
moved there.


# 1.142 15-Jun-2018 espie

Add a -Dstub option to facilitate creating/adding/deleting "stubbed" packages
with just the packing and dependency info with none of the files.

(useful for debugging tricky cases that involve large packages)


# 1.141 06-Jun-2018 espie

if the parser can't find a starting line in user db, it won't look
at any line, so it won't error out.
Add logic to make it error out.


# 1.140 30-May-2018 espie

port -u userlist option from update-plist, as suggested by sthen@.
main differences:
- error out on a problem instead of warning
- always parse the userlist if the option is specified. Avoid ticking time
bomb effect on bulk builds, where packages would be fine until the first
@new(user|group) usage in case the user list got corrupted.

Note it's still an option, so if you're using pkg_create outside of the
ports tree, you can do whatever you want.


# 1.139 13-May-2018 espie

adjust highly misleading comment to match reality


# 1.138 09-May-2018 espie

on the other hand, commenting this out was involuntary.
ask_tree will often say fun things because of (say) pipe closes


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.137 04-May-2018 espie

the perl debugger tells you everything a perl process exits.
this child is irrelevant, tell the debugger (if present) to not stop


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.136 29-Apr-2018 espie

if we create fragments, we must know which files they come from


# 1.135 28-Apr-2018 espie

update-plist wants to ask the ports tree as well, so refactor so that
it can reused that code


# 1.134 28-Apr-2018 espie

need instrumentation for fragments


# 1.133 26-Apr-2018 espie

reorg error handling so it's always passed to class methods that can
be overridden. Useful for nextgen update-plist


Revision tags: OPENBSD_6_3_BASE
# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.132 27-Feb-2018 espie

sanitize say/print output further
- have confirm go thru f() every time (adding
confirm_defaults_to_no/confirm_defaults_to_yes apis... verbose but effective)
- check DESCR in pkg_create, as suggested by sthen@
- don't do the whole safe dance when not needed (optimization)
- misnamed allowed -> forbidden (schwarze@)

This effectively prevents DESCR from using diacritics. Sorry!
Ingo makes a compelling argument that using UTF8 while installing a new
box is currently fairly dangerous, considering tty setups.

This affects about 10 ports at the moment, all of which were fixed before
this commit.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.131 24-Jan-2018 espie

add the glue to generate future libset, which are currently 100% unused


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.


# 1.130 05-Jan-2018 espie

@libset is going to be part of the dependency information.


# 1.129 02-Dec-2017 espie

switching to _pbuild is tricky, you can't take it back.
in particular, disable future PORTS_PRIVSEP mechanisms under
pkg_create, because we should already be running as _pbuild
by this point.


# 1.128 07-Nov-2017 ajacoutot

Revert previous, it breaks ports/infrastructure/bin/resolve-lib (I think)
with at least python and ruby.

ok naddy@


# 1.127 06-Nov-2017 espie

typo, surprised nobody noticed yet


# 1.126 10-Oct-2017 espie

clean-up option handling slightly, some more to be done.

Add a -S option that computes signatures, so that we may remove
code from bsd.port.mk that does the exact same thing, and no longer
work since the addition of @version.

For now, -S is exclusive of other package creation options, as it exits
as soon as it computes what it needs.


Revision tags: OPENBSD_6_2_BASE
# 1.125 18-Sep-2017 espie

better diagnostics


# 1.124 18-Sep-2017 espie

-V option for pkg_create and incorporate version into signatures.


Revision tags: OPENBSD_6_1_BASE
# 1.123 03-Oct-2016 espie

kill creating old signatures.


# 1.122 06-Sep-2016 espie

remove code that allows pkg_create to sign


Revision tags: OPENBSD_6_0_BASE
# 1.121 21-Jun-2016 espie

pass file name thru to Subst for better error messages.
reported by Adam Wolk


# 1.120 25-Apr-2016 espie

kill remnants of non shared arches


# 1.119 02-Apr-2016 espie

streamline the code that checks meta information before extracting files
- verify_modes should only verify modes
- put the whole checking code in one single routine in validate_meta, makes
the size checking code more obvious
- document what's going on
- prevent PkgCreate from creating impossible packages, only a few Ustar
objects are actually usable.


Revision tags: OPENBSD_5_9_BASE
# 1.118 06-Nov-2015 espie

the Solver uses kept_names, so we need these there too
found by aja@


# 1.117 13-Aug-2015 espie

let pkg_create recreate all packages correctly, again.


Revision tags: OPENBSD_5_8_BASE
# 1.116 18-May-2015 espie

simplify progressmeter calls to visit_and: we retrieve the state from the
progressmeter object


# 1.115 18-May-2015 espie

have visit_with_count and visit_with_size use the same parameter conventions.
In particular, pass state before the other method parameters.


Revision tags: OPENBSD_5_7_BASE
# 1.114 22-Dec-2014 espie

when we run into real errors, the progress meter is distracting, so have
a method ->disable that does something nice to the display, and stops
the progress meter right before we display our first real error.


# 1.113 21-Sep-2014 espie

final bulk shows chunking to happen in all the right places, and signing
works correctly as well. So activate this.

This basically makes package snapshots rsync-friendly with a low-tech
approach. Instead of having a patched gzip, we borrow from other archive
formats, and cut the archive every few files. Since the files are already
sorted in order of date of modification, packages that don't change tend
to end with identical gzip archives.

Note that this will still work when/if we transition to bzip2/xz packages...


# 1.112 20-Sep-2014 espie

need meta stuff that tells me those are "real files" to not create extra
chunks at the beginning of the package...
Also, be very verbose about everything.


# 1.111 19-Sep-2014 espie

.py files no longer need to be special, as the timestamps are stored in
the plist itself, so there's no longer any worry of the timestamp not
getting updated and python throwing a fit.


# 1.110 16-Sep-2014 espie

fix display of comments to use "say" properly.
Prepare scaffolding to be able to chunk archives


# 1.109 16-Sep-2014 espie

store explicit timestamps in generated plists.
this prevents updates from fucking up mtime of new file, thus the
"python exception" no longer prevents python files from being reordered.

Note that this requires newish scaffolding in pkg_add proper. That
scaffolding was committed prior to 5.6, in preparation for this change.


Revision tags: OPENBSD_5_6_BASE
# 1.108 10-Jul-2014 espie

prevent users from adding timestamp themselves


# 1.107 01-Jul-2014 espie

activate "out-of-order" archives based on history
things to watch out for:
- correct handling of multiple files with the same sha
- cwd handling. This is already destated, so we can call set_destdir on
each entry's cwd, instead of relying on @cwd being in the "right" location
as that's no longer the case...


# 1.106 20-May-2014 espie

makewhatis being now external, it no longer requires picky/test/check_dir.
It also can't handle too many manpages at once (shell limit) so hand-feed
it (problem spotted by landry@).

Some tests by schwarze@.


# 1.105 18-Apr-2014 schwarze

Switch to the new makewhatis(8)/apropos(1)/whatis(1) combo.
"commit the switch now" espie@ "go for it" deraadt@

See the apropos(1) manual for a description of what's new.
On machines where you want the full functionality,
run "sudo makewhatis" and put "MAKEWHATISARGS=' '" into weekly.local(8).
Otherwise, when upgrading via source, run "sudo makewhatis -Q".


# 1.104 18-Mar-2014 espie

don't use $_ as "throw-away" variable, proper idiom is "undef"
(and if you're wondering about the unused extra parameter, this is
designed to allow a new makewhatis that shares more code with pkg_create)


# 1.103 18-Mar-2014 espie

remove $_ usage that warns under perl 5.18


# 1.102 05-Mar-2014 espie

refactor solve_from_ports a bit.

do the write to cache thru a temp file, so the end result is atomic,
to be used to enable a global depends cache for parallel building in
the near future.


Revision tags: OPENBSD_5_5_BASE
# 1.101 02-Feb-2014 espie

pseudo handle needs dependency_info too, forgot that one.


# 1.100 23-Jan-2014 espie

tweak the way we create and sign packages significantly:

all modern compression formats support multi-stream archives.
Store the packing-list as a separate stream, and note where the
first stream ends when reading back the packing list.

When pkg_sign sees a split-stream archive, it does not need to unpack/repack
the whole archive: it can just sign the packing-list, close the stream, and
copy the next stream(s) from the source archive verbatim.

This is perfectly transparent to pkg_add, but abuses IO::Uncompress::Gunzip
internals slightly (to be solved with cpan).

also adds explicit option -C for generating a SHA256 list of all packages.

and okay naddy@


# 1.99 23-Jan-2014 espie

clean-up synopsis


# 1.98 23-Jan-2014 espie

zap the sign-only part (moved to PkgSign.pm).
reuse the signer part (move to Signer.pm)


# 1.97 20-Jan-2014 naddy

for the SHA256 file, output checksums in base64; ok espie@


# 1.96 18-Jan-2014 espie

involuntary sneak preview, revert


# 1.95 18-Jan-2014 espie

...and sort SHA256 properly


# 1.94 17-Jan-2014 espie

tweak the interface to generating signatures yet again.
- assume key names match, deduce signer from sec key.
e.g., -s signify -s 55pkg.sec
will set signer to 55pkg and look for a pubkey named 55pkg.pub,
either besides 55pkg.sec or in /etc/signify.
- verify there's no mismatch, if possible, by verifying the first package
signed.

- also build a SHA256 on the fly while signing.


# 1.93 13-Jan-2014 espie

say something if we sign an empty repository
tweak mode on tmp signed file


# 1.92 09-Jan-2014 espie

bump copyright to 2014


# 1.91 09-Jan-2014 espie

if we're re-signing, check old sig first. shouldn't sign stuff we don't
trust.


# 1.90 09-Jan-2014 espie

@signer makes sense only for signify, so move it there.


# 1.89 09-Jan-2014 espie

simplify a bit: pass the first SIGNER for @signer.


# 1.88 09-Jan-2014 espie

switch to internal gzip/gunzip.
reduces the number of external processes and the complexity of the code.

tested on a few select arches by tobiasu, naddy. If it breaks somewhere,
tough. This one is simple to revert.


# 1.87 09-Jan-2014 espie

tweak signing yet again. Have pkg_create automatically add signing
identities every time, and make matching identities mandatory.
e.g., pkg_create and pkg_add must have matching -DSIGNER.
by default, signer is derived from uname -r and role (pkg_add/fw_update),
e.g., 54pkg, 54fw...


# 1.86 07-Jan-2014 espie

integrate signer logic and fix resign with -DSIGNER


# 1.85 07-Jan-2014 espie

if HISTORY_DIR is defined, create a new "permanent" file during build.
this file records the sha256 of all elements in the archive, and keeps
track of changes (quite simply: sha256 that were already present end
up at the end of the file).

Start recording these *now*, so that we have enough info to shuffle
packages later.


# 1.84 07-Jan-2014 espie

allow processing of package lists in parallel.
Turns out re-gzipping a signed package is really expensive, so turn
it into several jobs with a -j option.


# 1.83 04-Jan-2014 espie

more forbidden elements


# 1.82 04-Jan-2014 espie

vendor->signer
shorten pubkey -> pub (naddy@)
\\ -> \e (jmc@)


# 1.81 03-Jan-2014 espie

make sure elements are not set manually, namely forbid
@depend (use -P)
@wantlib (use -W)
@name (duh)
@arch
@localbase
@option manual-installation
@comment pkgpath=...
(some of this is actually redundant, but will give more explicit error
messages)


# 1.80 02-Jan-2014 espie

simplify handling of special files some more, that stuff has fixed names
anyways


# 1.79 02-Jan-2014 espie

make the special file creation more explicit, so that the order actually
doesn't matter


# 1.78 02-Jan-2014 espie

be more explicit in why we don't write DESC
return early instead of adding an extra level of test.


# 1.77 02-Jan-2014 espie

zap PKG_PREFIX (undocumented and unused, now)
okay landry@


# 1.76 31-Dec-2013 espie

signify support


# 1.75 30-Dec-2013 espie

@vendor annotation


# 1.74 29-Dec-2013 espie

fix sign-while-creating mode


# 1.73 25-Dec-2013 espie

sign package thru a signer object, instead of hardcoding signature parameters


# 1.72 23-Dec-2013 espie

move ntogo code, so it can be used while copying packages in pkg_create.
add the few lines necessary for that to work.


# 1.71 23-Dec-2013 espie

get rid of "copy_long", we don't really need to recheck names while copying
a package contents.

Allow -o/-S for output/signature dirs for batch operations.
Fix copying of packages while signing, add progressmeter.


# 1.70 15-Oct-2013 schwarze

If the fake target of a port installed an empty (0-byte) file as a
manual page, pkg_create(1) asked groff to process the empty file,
which failed, and then decided to install the empty file as a source
manual page, which later caused mandoc(1) called from man(1) to
complain to the end-user. Instead, detect the emptiness in time,
skip the formatting attempt, skip the file, process the packing
list to its end, then abort pkg_create(1) unsuccessfully such that
the porter sees the problem and can fix whatever the root cause is.

Problem reported by naddy@ as seen in p5-Carp-Datum during a bulk build,
solution is joint work with espie@, again tested in a bulk by naddy@;
"please commit" espie@.


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.69 31-Dec-2012 espie

simple optimization: if we're already erroring out, there's totally no
need to compute those pesky checksums.


Revision tags: OPENBSD_5_2_BASE
# 1.68 08-Jun-2012 espie

activate new pkg_create magic.
Note that, in most cases, PFRAG.shared are probably no longer needed...


# 1.67 24-May-2012 espie

put possible fragments in there.
fix buglet in parsing libraries


# 1.66 15-May-2012 espie

supplementary magic code, not active yet


# 1.65 15-May-2012 espie

less hackish test for LIB*VERSION: after building the element,
redo a check based on the non-subst version, so we can:
- actually parse the library name
- check we depend upon the right variable


# 1.64 07-May-2012 espie

well pkg_create itself doesn't care, but a custom ->annotate will get
very confused


# 1.63 01-May-2012 espie

make fragment handling yet more customizable


# 1.62 30-Apr-2012 espie

allow a subclass to override that specific error


# 1.61 30-Apr-2012 espie

make the reading of packing-lists amenable to further annotations, such as
those that will be required for update-plist


# 1.60 30-Apr-2012 espie

move code around a bit more


# 1.59 30-Apr-2012 espie

more refactor


# 1.58 30-Apr-2012 espie

just a bit of refactoring, make sure option handling is done in state,
as should be, so we can reuse it without needing to duplicate all of
pkg_create code.


# 1.57 13-Feb-2012 espie

warn when @option no-default-conflict and not explicit @conflict.
(very seldom correct, mostly used for autoconf/automake)


Revision tags: OPENBSD_5_1_BASE
# 1.56 21-Jan-2012 espie

sanitize stuff a bit more...


# 1.55 16-Jan-2012 schwarze

Backout activation of the new apropos(1)/whatis(1)/makewhatis(8).
In its current state, it causes too much slowdown, in particular
during system builds, and there are other regressions.
That cannot be fixed quickly while it's enabled.

Problems pointed out by espie@, backout requested by deraadt@,
diff "looks good" to espie@.


# 1.54 05-Jan-2012 schwarze

Enable the new apropos(1), whatis(1), and makewhatis(8).
Unlink the old apropos(1), whatis(1), and makewhatis(8) from the build.
Call the new tools from pkg_create(1) and pkg_add(1).
"Please enable it now." deraadt@


# 1.53 16-Nov-2011 espie

if the portstree gives us a cache directory, use it.
in lots of multi-packages scenarios that all depend on the main package,
this speeds things *a lot*.
case in point: in php 5.2, make package goes down from 1mn40 to 53s.


# 1.52 14-Nov-2011 espie

much better solver: don't try to solve every library, but just the ones
we have in the package we're trying to create.

So, solve one level, and keep solving until we have what we need or we
run out of level. Any package without @wantlib and lots of runtime depends
will build MUCH faster. Other packages MAY build faster.


# 1.51 14-Nov-2011 espie

use print-plist-libs-with-depends (and make sure it does not skip depends)


# 1.50 21-Oct-2011 espie

small optimization: tell pkg_create to skip !libs if LIBS_ONLY (to be
used in make print-plist-libs)


# 1.49 25-Sep-2011 espie

remove hack, ask for SUBDIRs with FULLPATH set


# 1.48 17-Sep-2011 espie

work-around for default vs. no flavor


Revision tags: OPENBSD_5_0_BASE
# 1.47 24-Jun-2011 espie

speed up dependency checking:
- if the ports tree is -current, do not compute
@wantlib during dependencies.

- add an extra cache. The solver caches "exact" depends, we can also cache
pkgpaths when we go to the ports tree.

- make the checking computation progress message less painful by adding the
pkgpath currently investigated...


# 1.46 20-Jun-2011 espie

zap extra try that's no longer needed: print-plist-with-depends should
always succeed since it only depends on the ports tree itself.


# 1.45 15-Jun-2011 espie

change yet again how we handle transparent formatting of manpages.
simplify: actually create a tmp directory hierarchy that exactly mimics
what fake contains. This avoids trouble with makewhatis checks.
Don't even try to remember what files are there, just wipe it all with
rmtree.


# 1.44 25-Apr-2011 espie

don't erase 1st manpage in case two manpages have the first name.
as noticed on texlive, among a host of other issues...


# 1.43 19-Mar-2011 espie

I can remove duplicate flag since that's handled upwards.


# 1.42 07-Mar-2011 espie

run makewhatis during pkg_create in verbose mode.
tweak temp manpage generation a bit, so that it has correct names in its
own directory, because makewhatis will be really pissed off otherwise.


Revision tags: OPENBSD_4_9_BASE
# 1.41 09-Jan-2011 espie

add yet another check: obviously in a @depend line, if the def part doesn't
match the pattern, the package has something wrong.

prevents some bogus tk LIB_DEPENDS from even packaging.


# 1.40 04-Jan-2011 espie

go all the way, put temp pages in /tmp


# 1.39 04-Jan-2011 espie

create tempfile directly under fake, no need to go down.


# 1.38 02-Jan-2011 espie

create formatted manpages as temporary files we remove after the fact.


# 1.37 24-Dec-2010 espie

handle failures from ports tree with more care.
this does avoid infinite loops in case of wrong plists.
necessary since print-plist-with-depends CAN fail...


# 1.36 22-Dec-2010 espie

simplify some more: if it's not installed, ask the ports tree, who knows,
we will catch more mismatches between spec and actual packagenames ?

set status during dependency check

don't check when simply printing the plist, this 'fixes' a bit of
port-lib-depends-check

don't fatal(), error() allows for more stuff to show up


# 1.35 22-Dec-2010 espie

once we read the list, make sure it matches the dependency.
Otherwise, this WILL turn into an infinite loop indeed !


# 1.34 21-Dec-2010 espie

simplify a bit:
- make find_dep_in_installed more regular
- zap the {more} entry, add_dep is okay for that purpose
- don't special case installed_list, provide older_names instead
- make PseudoSets slightly less hackish
- don't read full packinglist, prelinkstuff is exactly what we need


# 1.33 20-Dec-2010 espie

use a better strategy: ask the ports tree for the plist for packages with
the same pkgpath. Thus, PseudoSets need to have a real list, and
pkgcreate needs to loop to solve those depends.

reactivate the check


# 1.32 20-Dec-2010 espie

disable temporarily


# 1.31 20-Dec-2010 espie

new check in pkg_create: walk the dependency tree for @wantlib, thus
preventing packages that won't install (much easier to fix that when
you still have the fake tree around !)

specifically, look into depend that are installed, and possibly in the
fake tree: if the package does build, it requires the libraries to be
around anyways, so pure RUN_DEPENDS are not an issue (and avoid old libraries,
if we find wantlib only in .lib, something really fishy is going on).

Reuse the Dependencies class, so we're sure to have the exact same way
to find libraries.

Also fix exit codes from pkg_create...


# 1.30 20-Dec-2010 espie

use state->defines


# 1.29 05-Dec-2010 espie

tweak the framework so that individual modules don't exist and return
the exit code upstream instead.
this simplifies the task of people who want to reuse it, as noted by
landry@


# 1.28 27-Nov-2010 espie

minor fix for ports which install manpages in other directories: keep
track of all known directories, so when we generate a manpage in a new
catN directory, we add the entry and it gets deleted properly.
-> requires a bump to affected packages.


# 1.27 27-Oct-2010 espie

initial scaffolding for @rcscript: for now, acts like normal files,
but allow absolute pathnames (treat that as an implicit @cwd).


# 1.26 25-Oct-2010 espie

@symlink/@size/@link are generated automatically, make pkg_create(1) error
out if we create them manually, instead of erroring later during pkg_add.


# 1.25 25-Oct-2010 espie

just bail out of producing empty files.
*this will become an error eventually, please fix those*


# 1.24 24-Oct-2010 espie

use newer system for more efficient redirection, and chdir the way man(1)
does, so groff is happier with .so.
(agreed by ingo)


# 1.23 02-Oct-2010 espie

whitespace


Revision tags: OPENBSD_4_8_BASE
# 1.22 28-Jul-2010 espie

pass state to Ustar objects, use it to display those pesky error and
fatal messages.

zap $opt_x from pkg_mklocated, do things like other commands do.


# 1.21 09-Jul-2010 espie

fix pkg_mklocatedb


# 1.20 03-Jul-2010 espie

we can't checksum directories either, so give a better error message


# 1.19 30-Jun-2010 espie

allow say and errsay to work without parameters, as it's ways common.
create verbose_system up in state, because it makes sense without verbose.


# 1.18 30-Jun-2010 espie

whitespace cleanup


# 1.17 30-Jun-2010 espie

pass state along when signing packages, uses repo and fatal directly


# 1.16 25-Jun-2010 espie

use locator object.
rework options into state


# 1.15 20-Jun-2010 espie

display bad symlinks by destination


# 1.14 14-Jun-2010 espie

zap empty message...


# 1.13 11-Jun-2010 espie

don't call working() in -q mode.


# 1.12 09-Jun-2010 espie

no need to fatal(), we can error() and keep going.


# 1.11 09-Jun-2010 espie

warns if packages contain symlinks that point to non-existent places.
actually error out if a symlink points to itself.
this breaks evolution, until someone fixes the bogus symlinks.


# 1.10 09-Jun-2010 espie

make error messages more consistent. Add an extra sanity check which
shouldn't trigger for special files


# 1.9 09-Jun-2010 espie

ui changes: go thru a state object for most printouts


# 1.8 08-Jun-2010 espie

tweak tweak so it works


# 1.7 08-Jun-2010 espie

tweak fragment handling a bit more. In particular, protest when we can't
get a fragment, regardless of whether or not we're going to use it.


# 1.6 07-Jun-2010 espie

display "switching to" with ->set_status


# 1.5 06-Jun-2010 espie

clean-up into smaller functions


# 1.4 05-Jun-2010 espie

add working cartwheel


# 1.3 05-Jun-2010 espie

move use to common part


# 1.2 04-Jun-2010 espie

add ->spec to Conflict and use the same check as for depend during pkg_create.


# 1.1 04-Jun-2010 espie

move code around, so that commands can be used as modules.
pkg becomes the start hub, which does nothing except require the
correct module.
Saner code wrt Add/Delete, and more sharing.