Commit Graph

209 Commits

Author SHA1 Message Date
Panu Matilainen d16b082354 Only calculate buildhost and buildtime during an actual build
Commit fa303d5ba6 moved buildhost and
buildtime calculation out of the package generation to early spec
initialization, but this broke reproducable builds: if buildtime is
to be set from changelog, changelog needs to be parsed first.

So either we need to do it twice or we need to do it right, and
besides avoiding duplication, conceptually these values are only
meaningful during a build and not a parse, so this restores that part
of the original code while keeping things thread-safe.

Fixes: #932
2019-11-11 15:11:27 +02:00
Panu Matilainen ac096e43fc Don't provide rpmlib(DynamicBuildRequires) in source packages
Packages can never provide rpmlib() capabilities, don't pollute the
namespace with invalid (if mostly harmless) data. The use-case of
identifying whether there are dynamically generated buildrequires in
an src.rpm is satisfied by looking for RPMSENSE_FIND_REQUIRES type
requires as of commit bee5dc94cf.
2019-10-28 15:29:50 +02:00
Panu Matilainen 35fb5d7367 Stop on invalid dynamic buildrequires 2019-10-09 14:21:51 +02:00
Panu Matilainen bee5dc94cf Mark dynamically generated buildrequires autogenerated
This makes them in line with regular auto-generated dependencies and allows
them to be easily identified. It also makes parseRCPOT() error reporting
do the right thing: generated dependencies do not relate to spec lines.

Fixes #801 (also reported as RhBug:1759100)
2019-10-09 14:21:51 +02:00
Panu Matilainen d472c20a5f Drop the no longer needed rpmfcExec() output duplication support
This effectively reverts commit 5fe8c9e6d5,
but no functional changes as nothing was using this anymore.
2019-08-21 14:23:26 +03:00
Panu Matilainen 3a51092644 Restore strict order of build scriptlet stdout/stderr output (#794)
Commit 18e8f4e9b2 and related changes
caused us to capture and re-emit stdout of all build scriptlets,
whether we actually use the output for anything or not. Besides doing
a whole bunch of work for nothing, this can disrupt the output of
build scriptlets by making the output jerky and out of order, at least
inside mock and other tools which in turn grab rpm output. This makes
troubleshooting failed builds unnecessarily hard for no good reason.

Handle the whole thing in a different way: on regular builds, don't
capture anything where we don't actually need to. This restores the
natural flow of output. We still need to somehow handle quiet builds
though, and we can't use redirect to /dev/null from %___build_pre like
we used to, because dynamic buildrequires need to provide output even
on quiet builds. So somewhat counter-intuitively, we need to capture
the output in order to discard it.

Closes: #794
2019-08-21 14:23:26 +03:00
Igor Gnatenko 077f4003ee rpmbuild: Generate buildreqs.nosrc.rpm even if no output
Fixes: https://github.com/rpm-software-management/rpm/issues/781
Reported-by: Michael Schroeder <mls@suse.de>
Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
2019-07-22 14:09:32 +02:00
Igor Gnatenko e672ec2ad8 rpmbuild: Generate src.rpm with dynamic BRs with --force
There is no way to get src.rpm with dynamic BuildRequires without
checking dependencies on the system. --nodeps always forces rpmbuild to
write buildreqs.nosrc.rpm, but in some cases it might be desired to get
src.rpm with dynamic BRs but without checking for dependencies.

Closes: https://github.com/rpm-software-management/rpm/issues/760
Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
2019-07-02 15:56:46 +02:00
Igor Gnatenko 0720d49a11 doScript: Restore good old message when scripts fail
Following snippet from buildlog is not helpful to user:

[…]
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.FqlMc8
[…]
+ exit 1
error: Exec of /var/tmp/rpm-tmp.FqlMc8 failed (%prep): No such file or directory

Previous rpmbuild versions returned:

[…]
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.epLFi2
[…]
+ exit 1
error: Bad exit status from /var/tmp/rpm-tmp.epLFi2 (%prep)

So let's restore good old version of a message.

References: https://github.com/rpm-software-management/rpm/issues/728
Fixes: 18e8f4e9b2
Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
2019-06-03 15:23:33 +03:00
Florian Festi 58dcfddc37 Add support for dynamic BuildRequires
Supports new %generate_buildrequires section in the spec file which is executed
after %prep. Stdout is captured and turned into BuildRequires. These are then
checked. If they cannot be fulfilled a source package is created with all
BuildRequires and the build is terminated after that.

rpmbuild has now the following new build modes -br, -tr, -rr and exits with 11
if build requirements are not met.

That means for users:
* No %generate_buildrequires
  * rpmbuild -br is equivalent to rpmbuild -bs
  * rpmbuild -br --nodeps is equivalent to rpmbuild -bs
* %generate_buildrequires
  * rpmbuild -br will check dynamic BuildRequires
    * Satisfied → src.rpm
    * Unsatisfied → buildreqs.nosrc.rpm
  * rpmbuild -br --nodeps will always generate buildreqs.nosrc.rpm

Source packages contain
Requires: rpmlib(DynamicBuildRequires) <= 4.15.0-1
if the spec contains a %generate_buildrequires section and
Provide: rpmlib(DynamicBuildRequires) = 4.15.0-1
if the results been added to the source package.

Co-authored-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
2019-05-28 09:24:01 +03:00
Igor Gnatenko d0754b4f2c Do not redirect command output to /dev/null in non-verbose mode
The output is going to be needed Dynamic BuildRequires.
Just do not duplicated to stdout if verbose mode is not enabled.

Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
2019-05-28 09:24:01 +03:00
Florian Festi 11c56d5aaa Move check for build dependencies out of rpmbuild.c and into build/build.c
Exit with return code 11 on missing build dependencies.
2019-05-28 09:24:01 +03:00
Florian Festi dd17c738c6 Pass rpmts object to rpmSpecBuild()
Add rpmtsFromPyObject
No functional change. Needed to move BuildRequires check to librpmbuild
2019-05-28 09:24:01 +03:00
Florian Festi 20437af6a2 doScript: Add sb_stdoutp param to allow getting the script output 2019-05-28 09:24:01 +03:00
Panu Matilainen 93604e2c3b Store source/patch/icon on-disk path in the source struct
Avoids having to reconstruct the path in multiple places all over.
No functional changes.
2019-04-25 10:40:31 +02:00
Panu Matilainen 18e8f4e9b2 Use rpmfcExec() for executing all build scripts to simplify code 2019-04-18 13:54:52 +03:00
Bernhard M. Wiedemann c33b41b2f1 build: Make sure SOURCE_DATE_EPOCH is in the past
otherwise, builds before noon will not have normalized mtimes
from %clamp_mtime_to_source_date_epoch

This also helps other programs like tar --clamp-mtime
2018-10-01 14:10:55 +02:00
Panu Matilainen f058b69a42 Fix an ancient leak and missing error logging on src.rpm create failure 2018-07-31 18:07:04 +03:00
Panu Matilainen ee33773218 Leave build scripts around in debug mode (#1442015)
We do this for install-time scripts too, so its only logical to do
so with build scripts as well.
Depends on commit 724830018a.
2017-08-23 11:52:50 +03:00
Panu Matilainen 585be2acf0 Stop NSPR from messing with our signals
For NSPR, (which NSS uses internally) being portable to Windows and
whatnot and centered around apps like Firefox, simply ignoring
SIGPIPE is probably a reasonable choice. Rpm however is an old school
unix cli piece where SIGPIPE is very much relevant and handled where
necessary. Besides we now have not just one but two other, less obnoxious
crypto backends which exhibit different core rpm behavior due to the
difference, not good.

Save and restore the SIGPIPE handler across NSS initialization,
and remove all the now redundant calls to reset it after forking.
Should've done this ages ago but better late than never, no?

Note that the install-time scriptlet thing is different since we set
SIGPIPE to SIG_IGN by ourselves there, add a comment.
2017-05-10 13:59:58 +03:00
Panu Matilainen c4b35c45ac Clean up doScript() a bit by assuming failure, no functional changes 2017-02-08 12:32:04 +02:00
Bernhard M. Wiedemann 0e87aed178 set SOURCE_DATE_EPOCH from changelog
if requested by macro
to allow for more reproducible builds of packages.

See https://reproducible-builds.org/ for why this is good
and https://reproducible-builds.org/specs/source-date-epoch/
for the definition of this variable.
2017-02-01 14:53:40 +01:00
Panu Matilainen a2d68d1ea3 If we need a FILE stream then get one...
- Replace the hysterical "lets see if the temp creation gave an fpio
  fd (it didn't), if not open another fd and then get its private
  FILE pointer" fiddling: since we need a FILE stream then open one
  with fdopen(), duh. Grabbing a rpmio fd to begin with is stupid enough
  when all we want is a stream, but wanting to use rpmMkTempFile()
  functionality...
- Also fixes an fd+mem leak in the unlikely but possible case that
  rpmMkTempFile() succeeds but fdopen() fails.
2011-07-08 10:15:58 +03:00
Panu Matilainen fb49951970 Remove pointless variable and a dead assignment to it 2011-05-28 11:34:51 +03:00
Panu Matilainen 786d7135dc Eliminate bunch of obvious dead NULL-assignments from build script code 2011-05-27 15:49:09 +03:00
Jindrich Novy 00274a017c Add missing exit status check for waitpid() while executing scriptlets 2011-03-04 04:43:32 +01:00
Panu Matilainen 6977e09556 Restore default SIGPIPE handling for build scriptlets (RhBug:651463) 2011-01-21 09:57:36 +02:00
Panu Matilainen a2d002a34b Unify the user+group caching between librpm and librpmbuild
- The build version has getUidS() and getGidS() for which there is
  no counterpart in the rpmug api but there's not much point to them:
  they check whether the user/groupname exists but return our own
  string back to us even if it doesn't.
- The build version also caches more than current rpmug, but has an ugly
  hardwired limit causing (in theory) errors that can't be nicely
  handled, and is the last piece relying on RPMLOG_CRIT actually
  terminating the process. The librpm version doesn't fail, in the
  worst case its just a bit slower. And that can be fixed anytime by
  making it to use hash tables for caching.
2010-12-15 09:30:56 +02:00
Panu Matilainen 3b99c79ef9 Pass the script to doScript() as const char *
- doScript() doesn't do anything special with the script buffer,
  this lets us use const for the argument.
2010-10-28 10:51:00 +03:00
Panu Matilainen 3f152a1312 Argument passing hysteria in doScript()
- Callers know perfectly well which part they're passing to doScript()
  so they can just as well pass in the name and the scriptlet to run,
  avoiding silly stuff in the switch-case
2010-10-28 10:45:35 +03:00
Panu Matilainen 4505fb312d Swap rpmSpecBuild() arguments for consistency with other APIs
- What we're building comes first, /how/ we're building comes second
- Update the sole caller, doesn't matter as this is a new interface...
2010-09-02 14:39:11 +03:00
Panu Matilainen 53385ee676 Eliminate _noDirTokens from librpmbuild API+ABI
- Add another flag set to control package generation, passing around
  as necessary. Use this to implement --nodirtokens functionality
  in a cleaner manner.
2010-09-02 12:12:46 +03:00
Panu Matilainen fb81dee4c6 Eliminate freeNames() from librpmbuild ABI
- Call freeNames() at end of buildSpec() instead of requiring API
  users to clean up after us. This does mean losing some of the
  supposed caching advantage when building on more than one spec,
  but hardly matters, one spec at a time is the typical build usage
  anyway.
2010-09-02 11:19:46 +03:00
Panu Matilainen 3c7d4f89bb Detect short-circuited build based on executed build steps from buildSpec()
- Avoids having to access rpmBTArgs from deep packageBinaries(),
  API changing is not an issue anymore...
2010-09-02 11:16:07 +03:00
Panu Matilainen 36f0c779d6 Handle --nobuild as another buildAmount flag 2010-09-02 10:23:57 +03:00
Panu Matilainen f9740318a8 Spec rootDir is only relevant for building, eliminate from parseSpec()
- The whole rootDir seems dubious for build purposes, but in any case its
  only relevant during the actual build process, not for spec parsing.
  Set spec->rootDir from buildSpec() for the duration of the
  build to avoid having to refactor doScript() and all right now.
2010-09-01 14:31:49 +03:00
Panu Matilainen 4acb8866ef Eliminate cookie from spec structure
- Cookies are not a property of spec but a given build, handle this
  internally to buildSpec() except for --rebuild which passes the
  srpm identifier cookie through buildArgs
2010-09-01 14:00:54 +03:00
Panu Matilainen 628de71cde Sanitize buildSpec() arguments a bit 2010-09-01 13:46:49 +03:00
Panu Matilainen bd9e1b9d9b Replace buildSpec() with a new interface in the API
- Accept the entire build arguments structure along with a spec, these
  contain everything that we'll need
- Just a convenience wrapper for buildSpec() for now, more things
  to follow...
- Update the sole existing caller accordingly
2010-09-01 13:37:37 +03:00
Panu Matilainen 76600e5389 Eliminate useless hardwired build debug foo 2010-09-01 10:48:02 +03:00
Steve Lawrence 383e275648 Add new %sepolicy section to the spec file format
The %sepolicy section is used to describe SELinux policy to be included
in a package. It's syntax is similar to other sections (%files, %pre,
%post, etc.) in that you can provide a string and -n after the
declaration to specify policy should be added to a subpackage.

For example:

%sepolicy
 # policy in this section will be added to the main package

%sepolicy foo
 # policy in this section will be added to the '<mainpackage>-foo' subpackage

%sepolicy -n bar
 # policy in this section will be added to the 'bar' subpackage

The %sepolicy section contains zero or more %semodule directives, with the
following format:

%semodule [OPTIONS] path/to/module.pp

The available options are:

-b, --base
	The module is a base module

-n, --name=NAME
	The name of the module. If not given, assumes the name is the basename of
	the module file with file extensions removed.

-t, --types=TYPES
	One or more comma-separated strings specifying which policy types the
	module can work with. To explicitly state that a module can work with any
	policy type, "default" can be specified as the value. If not specified,
	assumes the module can work with any policy type, and assigns the types as
	"default".

Below is an example of this new format:

  %sepolicy
  %semodule -n foo -t mls policy/foo.pp
  %semodule -n bar -t strict,targeted,mls -b policy/bar.pp

This also adds new header tags to store the new information:
 RPMTAG_POLICYNAMES        (string array)
 RPMTAG_POLICYTYPES        (string array)
 RPMTAG_POLICYTYPESINDEXES (uint32 array)
 RPMTAG_POLICYFLAGS        (uint32 array)

The index of NAMES and FLAGS maps directly to the index of RPMTAG_POLICIES.
However, because a single policy can have multiple types, the mapping for
TYPES is not direct. For this, the index maps to TYPESINDEXES, which
contains the index of the policy that the type maps to. This is similar to
how DIRINDEXES is used to map DIRNAMES and BASENAMES. As an example, the
previous %sepolicy section would have the following header tags:

RPMTAG_POLICIES:
 0: <foo.pp data, base64 encoded>
 1: <bar.pp data, base64 encoded>

RPMTAG_POLICYNAMES:
 0: foo
 1: bar

RPMTAG_POLICYFLAGS:
 0: 0
 1: 1	# assumes flag 1 == BASE

RPMTAG_POILCYTYPES:        RPMTAG_POLICYTYPESINDEXES:
 0: mls                     0: 0
 1: strict                  1: 1
 2: targeted                2: 1
 3: mls                     3: 1
2010-09-01 09:04:27 +03:00
Panu Matilainen 555f699f11 Mass eviction of remaining internal helpers in librpmbuild API
- Yank everything qualifying as "internal helper function" into
  internal-only headers, loosely grouped as follows:
  1) Everything involving spec-manipulation goes into rpmbuild_internal.h
  2) All other miscellaneous helpers go into rpmbuild_misc.h
- This leaves us a rather minimal, and nearly useful API into librpmbuild:
  Users need to be able to parse a spec, query or build (parts of) it
  and free up the spec structure when done. This is what we have now,
  various still exposed structures not counting.
2010-08-25 15:41:09 +03:00
Panu Matilainen 9ed9daf93e Eliminate doRmSource() from librpmbuild API again
- buildSpec() is sufficient interface for accomplishing the same,
  avoid exposing internal helpers
2010-08-25 11:06:26 +03:00
Panu Matilainen dd58384ede Move <errno.h> include out of system.h to the places that need it 2010-01-05 15:25:31 +02:00
Panu Matilainen 2c6120755c Unconditionally include <sys/wait.h> where needed
- no point conditionalizing what we cant live without
2010-01-05 12:35:54 +02:00
Jindrich Novy e58db2eda1 Don't check package BuildRequires when doing --rmsource (rhbz#452477)
- export doRmSource() and make it more consistent with the API
2009-01-11 16:54:07 +01:00
Jindrich Novy 1909784075 Don't fail because of missing sources when only spec
removal is requested (rhbz #472427)
2009-01-11 15:23:59 +01:00
Jindrich Novy faaa0305f5 Return proper exit code when exec*() functions fail
- the correct exit code should be 127 accoring to bash(1),
  we want to keep the same exit code behaviour as bash for rpm
2008-11-04 10:09:31 +01:00
Panu Matilainen 0ee67fede8 Temp file handling tweaks
- rename rpmMkTemp() (back) to rpmMkTempFile()
- rpmMkTemp() is now a lower level thin wrapper around mkstemp()
2008-05-03 12:34:19 +03:00
Panu Matilainen fde961e25b Rewrite rpmMkTempFile() for sanity
- Actually use mkstemp() for creating the temp file and return a FD_t
  dupped from the file descriptor returned by mkstemp().
- Simplify the interface while at it.
- Change callers for the new interface.
- Yes we now require mkstemp() to work, mkstemp() is in POSIX.1-2001 and
  this is year 2008...
2008-04-11 09:05:05 +03:00