Skip to content

Commit

Permalink
Better error for build system issues
Browse files Browse the repository at this point in the history
Give different errors depending on a build system not existing at all or
not be defined properly. This makes it easier to detect issues in the
build system declaration and no longer requires developers of new build
system macros to pass --verbose to get meaningful messages.

Resolves: #3190
  • Loading branch information
ffesti authored and dmnks committed Jul 12, 2024
1 parent ea06853 commit 184475d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 10 deletions.
30 changes: 20 additions & 10 deletions build/parseSpec.c
Original file line number Diff line number Diff line change
Expand Up @@ -958,21 +958,31 @@ int checkBuildsystem(rpmSpec spec, const char *name)
return -1;

int rc = 0;
for (struct sectname_s *sc = sectList; rc == 0 && sc->name; sc++) {
if (!sc->required)
continue;
int found = 0;
char * mmn = NULL;
for (struct sectname_s *sc = sectList; sc->name; sc++) {
char *mn = rstrscat(NULL, "buildsystem_", name, "_", sc->name, NULL);
if (!rpmMacroIsParametric(NULL, mn)) {
rpmlog(RPMLOG_DEBUG,
"required parametric macro %%%s not defined buildsystem %s\n",
mn, name);

rpmlog(RPMLOG_ERR, _("line %d: Unknown buildsystem: %s\n"),
spec->lineNum, name);
rc = -1;
if (sc->required) {
if (!mmn)
mmn = xstrdup(mn);
rc = -1;
}
} else {
found = 1;
}
free(mn);
}

if (!found) {
rpmlog(RPMLOG_ERR, _("line %d: Unknown buildsystem: %s\n"),
spec->lineNum, name);
} else if (mmn) {
rpmlog(RPMLOG_ERR,
_("line %d: Required parametric macro %%%s not defined for buildsystem %s\n"),
spec->lineNum, mmn, name);
}
free(mmn);
return rc;
}

Expand Down
1 change: 1 addition & 0 deletions tests/data/macros.buildsystem
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
%buildsystem_autotools_conf() %configure %*
%buildsystem_autotools_build() %make_build %*
%buildsystem_autotools_install() %make_install %*
%buildsystem_autotools_check() echo Not checking, sorry!

# Example buildsystem for cmake
%buildsystem_cmake_conf() cmake %* -B __rpmbuild -S .
Expand Down
36 changes: 36 additions & 0 deletions tests/rpmbuild.at
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,42 @@ runroot rpmbuild -bb \
[error: line 11: Unknown buildsystem: bogons
])

RPMTEST_CHECK([
runroot rpmbuild -bb \
--define 'buildsystem_autotools_conf %nil' \
--define 'buildsystem_autotools_build %nil' \
--define 'buildsystem_autotools_install %nil' \
--define 'buildsystem_autotools_check %nil' \
--quiet /data/SPECS/amhello.spec
],
[1],
[],
[error: line 11: Unknown buildsystem: autotools
])

RPMTEST_CHECK([
runroot rpmbuild -bb \
--define 'buildsystem_autotools_conf %nil' \
--define 'buildsystem_autotools_build %nil' \
--define 'buildsystem_autotools_install %nil' \
--quiet /data/SPECS/amhello.spec
],
[1],
[],
[error: line 11: Required parametric macro %buildsystem_autotools_conf not defined for buildsystem autotools
])

RPMTEST_CHECK([
runroot rpmbuild -bb \
--define 'buildsystem_autotools_build %nil' \
--define 'buildsystem_autotools_check %nil' \
--quiet /data/SPECS/amhello.spec
],
[1],
[],
[error: line 11: Required parametric macro %buildsystem_autotools_build not defined for buildsystem autotools
])

RPMTEST_CLEANUP

AT_SETUP([rpmbuild -b steps])
Expand Down

0 comments on commit 184475d

Please sign in to comment.