Bug 1668512 - %cmake macro is broken without source/build directory
Summary: %cmake macro is broken without source/build directory
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: cmake
Version: 31
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Björn 'besser82' Esser
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2019-01-22 23:07 UTC by Elliott Sales de Andrade
Modified: 2020-08-10 01:03 UTC (History)
7 users (show)

Fixed In Version: cmake-3.17.4-1.fc32 cmake-3.17.4-1.fc31
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2020-08-10 01:03:54 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Elliott Sales de Andrade 2019-01-22 23:07:47 UTC
Almost all packages in this list appear to have been broken by the 3.13.2-1 -> 3.13.3-1 update:

https://apps.fedoraproject.org/koschei/affected-by/cmake?epoch1=0&version1=3.13.2&release1=1.fc30&epoch2=0&version2=3.13.3&release2=1.fc30&collection=f30

The result is:
BUILDSTDERR: CMake Error: No source or binary directory provided


I was trying to find a common thread, but not sure what it is. I thought perhaps it was because of passing parameters to the macro, but TeXmacs doesn't seem to do so.

The guidelines specify the current directory, so have these packages all been calling the macro incorrectly?


Version-Release number of selected component (if applicable):
3.13.3-1.fc30

Comment 1 Björn 'besser82' Esser 2019-01-23 08:44:39 UTC
I've appended an explicit curdir to the CMake invokation of the packages in the list you provided and triggered a build on Rawhide.  Packages should now build or be FTBFS for a different reason.

Comment 2 Björn 'besser82' Esser 2019-01-23 09:57:53 UTC
The following packages are still FTBFS, but not caused by the CMake update:

capnproto
ginac
libkml
mongo-cxx-driver
openvas-libraries

All of them have segfaulting tests on secondary arches, which seems (but is not neccessarily) to be related to GCC-9.

Comment 3 Michal Schorm 2019-06-04 10:54:00 UTC
I looked at: https://cmake.org/cmake/help/v3.13/release/3.13.html

| 3.13.3
| CMake now checks that at least one of the source or binary directory is specified when running CMake and issues an error if
| both are missing. This has always been a documented requirement, but the implementation previously accidentally accepted cases
| in which neither are specified so long as some other argument is given, and silently used the current working directory as the source and build tree.
|
| 3.13.4
| The error added by 3.13.3 in cases that neither a source or binary directory is specified has been downgraded to a warning.
| While this was never intended, documented, nor supported behavior, some projects relied on it. The error has been downgraded
| to a warning for the remainder of the 3.13.x release series to allow a transition period, but it may become a fatal error again
| in a later release. Scripts relying on the old behavior can be trivially fixed by specifying the path to the source tree
| (even if just .) explicitly and continue to work with all versions of CMake.
|

And I assume the: https://cmake.org/cmake/help/v3.14/manual/cmake.1.html

| Generate a Project Buildsystem
|  cmake [<options>] <path-to-source>
|  cmake [<options>] <path-to-existing-build>
|  cmake [<options>] -S <path-to-source> -B <path-to-build>

explains, why the syntax
# cmake . arg1 arg2 arg3
doesn't work, while
# cmake arg1 arg2 arg3 .
does

--------------------------

However I'm not sure if I'm correct with my above findings, because some packages, e.g. "mariadb" haven't been fixed:
  https://src.fedoraproject.org/rpms/mariadb/blob/master/f/mariadb.spec#_804
  https://src.fedoraproject.org/rpms/community-mysql/blob/master/f/community-mysql.spec#_399
  https://src.fedoraproject.org/rpms/mysql-connector-odbc/blob/master/f/mysql-connector-odbc.spec#_37
while others, e.g. "mariadb-connector-c" were:
  https://src.fedoraproject.org/rpms/mariadb-connector-odbc/c/967dcef5242221c63df2f523431ade9621861bb5?branch=master
  https://src.fedoraproject.org/rpms/mariadb-connector-odbc/c/967dcef5242221c63df2f523431ade9621861bb5?branch=master
can you explain this ^ to me?

--------------------------

What I see is:
* a pretty poorly performed proven-packager intervention
  * to a set of packages which was probabbly wrongly gathered (not all cases were found)
  * without a prior PR, notice or any kind of attemp to ask the maintainers to fix it themselves
  * adding whitespace errors
* which references / is based on a BZ which
  * does not properly explain the cause
  * nor the solution

Also, you Björn, could have re-assigned this BZ to you, when you were fixing it; so it owuld be clear, that you aren't just some random guy who came and fixed it, while the asignee haven't even reacted once.

(I'd prefer the objections above to be understood as a constructive critics.)

--------------------------

So, can you please verify my findings and explain why some packages was not affected, so we can correct this hotfix?

Comment 4 Michal Schorm 2019-06-04 10:56:37 UTC
Also following package wan't fixed.
https://src.fedoraproject.org/rpms/mariadb-connector-c/blob/master/f/mariadb-connector-c.spec#_75
And so far, I'm still speaking only of my packages.

Comment 5 Ben Cotton 2019-08-13 16:56:13 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 31 development cycle.
Changing version to '31'.

Comment 6 Ben Cotton 2019-08-13 19:16:09 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 31 development cycle.
Changing version to 31.

Comment 7 Fedora Update System 2020-08-01 12:50:41 UTC
FEDORA-2020-c0594f0f63 has been submitted as an update to Fedora 31. https://bodhi.fedoraproject.org/updates/FEDORA-2020-c0594f0f63

Comment 8 Fedora Update System 2020-08-01 12:52:36 UTC
FEDORA-2020-f67faa0089 has been submitted as an update to Fedora 32. https://bodhi.fedoraproject.org/updates/FEDORA-2020-f67faa0089

Comment 9 Fedora Update System 2020-08-02 01:42:11 UTC
FEDORA-2020-f67faa0089 has been pushed to the Fedora 32 testing repository.
In short time you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --advisory=FEDORA-2020-f67faa0089`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2020-f67faa0089

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 10 Fedora Update System 2020-08-02 02:01:21 UTC
FEDORA-2020-c0594f0f63 has been pushed to the Fedora 31 testing repository.
In short time you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --advisory=FEDORA-2020-c0594f0f63`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2020-c0594f0f63

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 11 Fedora Update System 2020-08-04 01:20:54 UTC
FEDORA-2020-f67faa0089 has been pushed to the Fedora 32 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 12 Michal Schorm 2020-08-04 09:25:16 UTC
Can you please clarify HOW the issue has been fixed and what's the current status now?

The release notes on this page: https://cmake.org/cmake/help/v3.17/release/3.17.html#updates
ends with 3.17.3 release so I don't know what's new in the 3.17.4.

I can see, that the "%cmake" RPM macro now expands on Rawhide to:
| ...
|   /usr/bin/cmake \
|         -S "." \
|         -B "x86_64-redhat-linux-gnu" \
| ...
so both the source dir and build dir are specified, but neither is specified on F31.

Comment 13 Rex Dieter 2020-08-04 21:01:40 UTC
Michal,

The difference is that macro __cmake_in_source_build is undefined by default on f33+, whereas it is defined by default on prior releases.

If you want behavior to be the same on all releases, you ought to add one of these your your .spec:
%undefine __cmake_in_source_build
or
%define __cmake_in_source_build 1

Comment 14 Michal Schorm 2020-08-05 09:09:35 UTC
Hi Rex,
I know about the change you are talking, (since it is making most of my pkgs FTBFS), but that is IMO irrelevant for this buzilla.

---

I'm not sure what was the original cause of this bug, however it made some packages FTBFS, when the package did not have specified the <path-to-source> on a correct location.
So a ProvenPackager (Björn) came along and fixed it.

But what triggered me was that he only made the change for *some* packages, which immediatelly raised questions like:
 - why is it needed in one, but not in very simmilar other ?
   - why is it needed at all when other packages can be beuilt without it.

So I started to look for answers, but did not get any. (Neither for commit message, changelog, bugzilla ticket nor CMake release notes)

I've never got any answer that would fully (not even partially) explain the need for such ProvenPackager intervention.

---

Now this Bugzilla against F31 was closed because of some change on F33 ?
I still don't see it fixed.
The macro is still expanded without "-S" "-B" on F31 & F32.
Thus the questions are still in place.

When I use any of: "%undefine __cmake_in_source_build", "%define __cmake_in_source_build 1", "%define __cmake_in_source_build 0", the result of "rpm -E %%cmake" is the same on F31.
(neither switch the behaviour to the one in current Rawhide)

---

Number of my packages utilizing CMake use the layout before the ProvenPackager intervention, number of them use the layout after it.
I don't know *which is correct* and *why*.

Comment 15 Rex Dieter 2020-08-05 14:30:57 UTC
I cannot reproduce your findings.  When I set 
%undefine __cmake_in_source_build
in a spec, I definitely *do* see -S -B options passed to cmake (I used mariadb-connector-c.spec for this example)

the intent is that if that macro is defined, cmake will revert to legacy behavior of not using -S -B

Comment 16 Michal Schorm 2020-08-07 09:40:17 UTC
Here's my minimal reproducer:
1/ Use mariadb-connector-c package (needed for sources)
2/ Replace it's content with:
_________________________________________________________________________________________________________________
%undefine __cmake_in_source_build

Name:           mariadb-connector-c
Version:        3.1.9
Release:        1
Summary:        XYZ
License:        XYZ
Source:         https://downloads.mariadb.org/interstitial/connector-c-%{version}/%{name}-%{version}-src.tar.gz

BuildRequires: cmake

%description
XYZ

%prep
%setup -q -n %{name}-%{version}-src

rpm -E %%cmake
exit 999

%build
%install
%files
%changelog
* Tue Aug 04 2020 Michal Schorm <mschorm> - 3.1.9-1
- XYZ
_________________________________________________________________________________________________________________

3/ run "fedpkg --release=f31 mockbuild" (or f32 mockbuild)

Now I see:
|  ...
|     /usr/bin/cmake \
|            \
|            \
|           -DCMAKE_C_FLAGS_RELEASE:STRING="-DNDEBUG" \
|  ...

Probabbly I'm doing something wrong. Can you spot it and correct me?

Comment 17 Rex Dieter 2020-08-07 19:33:55 UTC
I don't think running rpm inside the .spec is a good test-case.  I'll followup with what I see running rpmbuild -bb mariadb-connector-c.spec on my f31 host.

Comment 18 Rex Dieter 2020-08-07 19:44:32 UTC
Starting with what's currently latest in f31 branch, when I run rpmbuild -bb mariadb-connector-c.spec it shows output:

+ /usr/bin/cmake -DCMAKE_C_FLAGS_RELEASE:STRING=-DNDEBUG -DCMAKE_CXX_FLAGS_RELEASE:STRING=-DNDEBUG -DCMAKE_Fortran_FLAGS_RELEASE:STRING=-DNDEBUG -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DCMAKE_INSTALL_PREFIX:PATH=/usr -DINCLUDE_INSTALL_DIR:PATH=/usr/include -DLIB_INSTALL_DIR:PATH=/usr/lib64 -DSYSCONF_INSTALL_DIR:PATH=/etc -DSHARE_INSTALL_PREFIX:PATH=/usr/share -DLIB_SUFFIX=64 -DBUILD_SHARED_LIBS:BOOL=ON . -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_SYSTEM_PROCESSOR=x86_64 -DMARIADB_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMARIADB_PORT=3306 -DWITH_EXTERNAL_ZLIB=ON -DWITH_SSL=OPENSSL -DWITH_MYSQLCOMPAT=ON -DPLUGIN_CLIENT_ED25519=DYNAMIC -DINSTALL_LAYOUT=RPM -DINSTALL_BINDIR=bin -DINSTALL_LIBDIR=lib64 -DINSTALL_INCLUDEDIR=include/mysql -DINSTALL_PLUGINDIR=lib64/mariadb/plugin -DINSTALL_PCDIR=lib64/pkgconfig -DWITH_UNIT_TESTS=ON

with small modification:

$ git diff
diff --git a/mariadb-connector-c.spec b/mariadb-connector-c.spec
index 58f47c9..120c1ae 100644
--- a/mariadb-connector-c.spec
+++ b/mariadb-connector-c.spec
@@ -9,7 +9,7 @@
 #   The Change owners offered themselves to help fix the affected packages via ProvenPackager rights.
 #   I'm generally in favor of this change, however when I tried to adapt it, I encountered a number of issues.
 #   That's why I disabled it for now.
-%global __cmake_in_source_build 1
+%undefine __cmake_in_source_build
 #   Specifically, be aware that all subsequent call of CMake *MUST* be called with the specified builddir
 #   e.g. " cmake -B %%{__cmake_builddir} -LAH "
 #   Otherwise you will experience *really odd* behaviour. HOWEVER the "%%{__cmake_builddir}" is not suitable for use,
@@ -107,7 +107,7 @@ rm -r win win-iconv zlib examples
 # The INSTALL_* macros have to be specified relative to CMAKE_INSTALL_PREFIX
 # so we can't use %%{_datadir} and so forth here.
 
-%cmake . \
+%cmake \
        -DCMAKE_BUILD_TYPE="%{?with_debug:Debug}%{!?with_debug:RelWithDebInfo}" \
        -DCMAKE_SYSTEM_PROCESSOR="%{_arch}" \
 \

Now, rpmbuild output shows:

+ /usr/bin/cmake -S . -B x86_64-redhat-linux-gnu -DCMAKE_C_FLAGS_RELEASE:STRING=-DNDEBUG -DCMAKE_CXX_FLAGS_RELEASE:STRING=-DNDEBUG -DCMAKE_Fortran_FLAGS_RELEASE:STRING=-DNDEBUG -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DCMAKE_INSTALL_PREFIX:PATH=/usr -DINCLUDE_INSTALL_DIR:PATH=/usr/include -DLIB_INSTALL_DIR:PATH=/usr/lib64 -DSYSCONF_INSTALL_DIR:PATH=/etc -DSHARE_INSTALL_PREFIX:PATH=/usr/share -DLIB_SUFFIX=64 -DBUILD_SHARED_LIBS:BOOL=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_SYSTEM_PROCESSOR=x86_64 -DMARIADB_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMARIADB_PORT=3306 -DWITH_EXTERNAL_ZLIB=ON -DWITH_SSL=OPENSSL -DWITH_MYSQLCOMPAT=ON -DPLUGIN_CLIENT_ED25519=DYNAMIC -DINSTALL_LAYOUT=RPM -DINSTALL_BINDIR=bin -DINSTALL_LIBDIR=lib64 -DINSTALL_INCLUDEDIR=include/mysql -DINSTALL_PLUGINDIR=lib64/mariadb/plugin -DINSTALL_PCDIR=lib64/pkgconfig -DWITH_UNIT_TESTS=ON

Unfortunately, there appears to be at least one issue with this, the build eventually fails in %install:
CMake Error at x86_64-redhat-linux-gnu/unittest/libmariadb/cmake_install.cmake:481 (file):
  file INSTALL cannot find
  "/var/tmp/kdecache-rdieter/BUILDROOT/mariadb-connector-c-3.1.9-src/unittest/mytap/libcctap.so":
  No such file or directory.
Call Stack (most recent call first):
  x86_64-redhat-linux-gnu/cmake_install.cmake:158 (include)

Guessing one (or more) CmakeLists.txt is making an invalid assumption that src=build somewhere, should be fixable.

Regardless, you can keep this minor modification either way:
[rdieter@localhost mariadb-connector-c (f31)]$ git diff
diff --git a/mariadb-connector-c.spec b/mariadb-connector-c.spec
index 58f47c9..71f4350 100644
--- a/mariadb-connector-c.spec
+++ b/mariadb-connector-c.spec
@@ -107,7 +107,7 @@ rm -r win win-iconv zlib examples
 # The INSTALL_* macros have to be specified relative to CMAKE_INSTALL_PREFIX
 # so we can't use %%{_datadir} and so forth here.
 
-%cmake . \
+%cmake \
        -DCMAKE_BUILD_TYPE="%{?with_debug:Debug}%{!?with_debug:RelWithDebInfo}" \
        -DCMAKE_SYSTEM_PROCESSOR="%{_arch}" \
 \



Does that help?

Comment 19 Rex Dieter 2020-08-07 19:47:19 UTC
If you want a better test with pure rpm, try this instead:

rpm --undefine=__cmake_in_source_build --eval %cmake

compared to:
rpm --define="__cmake_in_source_build 1" --eval %cmake

Comment 20 Fedora Update System 2020-08-10 01:03:54 UTC
FEDORA-2020-c0594f0f63 has been pushed to the Fedora 31 stable repository.
If problem still persists, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.