Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Use pkg config udevdir #4126

Merged
merged 3 commits into from
Jul 29, 2021
Merged

Use pkg config udevdir #4126

merged 3 commits into from
Jul 29, 2021

Conversation

daschuer
Copy link
Member

This PR implement the suggestions by @dvzrv #4114 to make use of pk-config to install the udev rules file in the correct location.

@github-actions github-actions bot added the build label Jul 20, 2021
@daschuer
Copy link
Member Author

This is not yet tested widely. Please let confirm that it does not break existing packaging and does the right thing.

CMakeLists.txt Outdated
if(INSTALL_USER_UDEV_RULES)
set(MIXXX_UDEVDIR "${MIXXX_INSTALL_DATADIR}/udev")
if (CMAKE_INSTALL_PREFIX STREQUAL "/usr")
message(FATAL_ERROR "Bla")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

???

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ups, a debug left over.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rebased out

Comment on lines +1386 to +1387
if(PKGCONFIG_UDEVDIR)
file(TO_CMAKE_PATH "${PKGCONFIG_UDEVDIR}" MIXXX_UDEVDIR)
endif()
Copy link
Member

@Holzhaus Holzhaus Jul 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that PKGCONFIG_UDEVDIR is not an absolute path outside CMAKE_INSTALL_PREFIX? Mixxx mustn't install anything outside the chosen prefix under any circumstances.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not:

-- Installing: /home/be/local/share/mixxx/udev/rules.d/mixxx-usb-uaccess.rules

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this is certainly the case on all systems? So returning a relative path instead of an absolute one is guaranteed by pkg-config?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that PKGCONFIG_UDEVDIR is not an absolute path outside CMAKE_INSTALL_PREFIX? Mixxx mustn't install anything outside the chosen prefix under any circumstances.

In case of udevdir it is an exception. The rules files have to be installed at the common folder returned by pkg-config IF Mixxx is installed in the system location "/usr". This should happens only in the packaging case.

In all other case the udevdir is useless and the rules file is installed under our fall back location .../share/mixxx/udev/rules.d/mixxx-usb-uaccess.rules as before.

This should make all hacks in the packaging scripts obsolete.

Do we know a distro where this assumption is void?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be wrong for Ubuntu sorry

What would be wrong? Have you read the special case section at: https://cmake.org/cmake/help/v3.15/module/GNUInstallDirs.html?highlight=gnuinstalldirs#special-cases

The following values of CMAKE_INSTALL_PREFIX are special:

  • /
    For <dir> other than the SYSCONFDIR, LOCALSTATEDIR and RUNSTATEDIR, the value of CMAKE_INSTALL_<dir> is prefixed with usr/ if it is not user-specified as an absolute path. For example, the INCLUDEDIR value include becomes usr/include. This is required by the GNU Coding Standards, which state:
    When building the complete GNU system, the prefix will be empty and /usr will be a symbolic link to /.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah Ok, so we need to check how debuild uses CMake

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does PC return for udevdir on arch?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ pkgconf --variable=udevdir udev
/usr/lib/udev

Arch does not use /lib or /lib64 (it is symlinked to /usr/lib), as well as we also don't do /usr/sbin or /bin or /sbin (it is symlinked to /usr/bin): https://www.freedesktop.org/wiki/Software/systemd/TheCaseForTheUsrMerge/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, so it should work for all major distros at least

CMakeLists.txt Outdated
")
if(INSTALL_USER_UDEV_RULES)
set(MIXXX_UDEVDIR "${MIXXX_INSTALL_DATADIR}/udev")
if (CMAKE_INSTALL_PREFIX STREQUAL "/usr")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this will work on e.g. nixOS, as they have a very different directory structure as packages are installed to the /nix directory (but I also don't really know how they handle udev rule files, better ask someone who knows!).

Can we not check whether CMAKE_INSTALL_PREFIX does not match /usr/local instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The install prefix can also be
~/.local or /opt or wherever the user thinks it is correct.
So it is IMHO more reasonable to check for the system path that corospods to the system udev dir.
We can extend the list of suitable packaging install prefixes on demand.

@daschuer
Copy link
Member Author

daschuer commented Jul 21, 2021

debuild uses prefix /usr and requires the udevdir at /lib/udev
https://github.com/Debian/debhelper/blob/eb6e510ef52430c6edb96b28879fa4f64fbcafdb/Debian/Debhelper/Buildsystem/autoconf.pm#L34

If we want to install the rules automatically to the final location, we cannot enforce the rule "no file outside the install prefix" at the same time. Since pkg-config is telling us to violate the rule, it should be OK to follow.

Interestingly CMAKE_INSTALL_PREFIX "/" and "/usr" are treated as the same location:
https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html#special-cases
There are locations listed outside the /usr prefix which are used anyway.

So we can argue that we don't even voialate the rule, because "/usr" is actually "/" which allows any location.

I have added a comment, with some hints.

if (MIXXX_UDEVDIR STREQUAL "${MIXXX_INSTALL_DATADIR}/udev")
install(
FILES
"${CMAKE_CURRENT_SOURCE_DIR}/res/linux/mixxx-usb-uaccess.rules"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"${CMAKE_CURRENT_SOURCE_DIR}/res/linux/mixxx-usb-uaccess.rules"
"${CMAKE_CURRENT_SOURCE_DIR}/packaging/linux/69-mixxx-dj-hardware.rules"

This file needs to be renamed to have the correct priority.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the path where we install the file to the data directory. I have not renamed it to not break existing packaging scripts. To use the file the user can move and rename it as desired.

Copy link
Contributor

@Be-ing Be-ing Jul 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That defeats the purpose. The packager should not have to do anything besides the CMake install step.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we are in the branch that is not for packagers. In the packager's branch the file is renamed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unnecessarily complicated. Please simply rename the file. Packagers have already said that is not a problem. At most it is changing a single line of code for them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This place is not for packagers!

Copy link
Member

@Holzhaus Holzhaus Jul 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we just rename it in main? I think it's not really that important to change in 2.3 and packagers have already written packaging scripts with the old name for 2.3.0, so let's not break existing scripts in a point release.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this file even installed to somewhere it has no effect? I think we should just show a warning that the file has not been installed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense to have this file as part of the installer and move it yourself. FWIW it's actually a bit unexpected that just having mixxx installed messes around with your system permissions instead of copying the file yourself, but in this special case it's not an issue because the security implications of giving all users permission to access HID DJ controllers are small :D

@daschuer
Copy link
Member Author

This is IMHO in a mergeable state. @Holzhaus please have a look.

@daschuer daschuer requested a review from Holzhaus July 25, 2021 10:03
Copy link
Member

@Holzhaus Holzhaus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A simple test seems to work, make DESTDIR=/tmp/foo install seems to work correctly.

I'm still unsure if we actually need the pkgconfig magic instead of letting the packager take care of it. But I don't want to bikeshed over this. Would be good to get confirmation from @dvzrv and @PureTryOut though.

CMakeLists.txt Outdated Show resolved Hide resolved
if (MIXXX_UDEVDIR STREQUAL "${MIXXX_INSTALL_DATADIR}/udev")
install(
FILES
"${CMAKE_CURRENT_SOURCE_DIR}/res/linux/mixxx-usb-uaccess.rules"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense to have this file as part of the installer and move it yourself. FWIW it's actually a bit unexpected that just having mixxx installed messes around with your system permissions instead of copying the file yourself, but in this special case it's not an issue because the security implications of giving all users permission to access HID DJ controllers are small :D

")
if(INSTALL_USER_UDEV_RULES)
set(MIXXX_UDEVDIR "${MIXXX_INSTALL_DATADIR}/udev")
if (CMAKE_INSTALL_PREFIX STREQUAL "/usr" OR CMAKE_INSTALL_PREFIX STREQUAL "/" )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just an idea, maybe it's not better:

Suggested change
if (CMAKE_INSTALL_PREFIX STREQUAL "/usr" OR CMAKE_INSTALL_PREFIX STREQUAL "/" )
if (CMAKE_INSTALL_PREFIX IN_LIST "/;/usr" )

@PureTryOut
Copy link

Uh, I'm still unsure why #4114 didn't do the right thing and why this would be better. In the end both PR's achieve the same result (assuming packaging is done correctly, which it doesn't seem to be for Ubuntu currently as it doesn't set -DCMAKE_INSTALL_PREFIX to /usr) but this seems a way more complicated way to do it.

Why is making sure -DCMAKE_INSTALL_PREFIX is set correctly in packaging and then using ${CMAKE_INSTALL_LIBDIR}/udev/rules.d wrong? Why would this more complicated pkg-config stuff be preferable?

I'm still unsure if we actually need the pkgconfig magic instead of letting the packager take care of it.

I'm definitely against packagers having to do a mv <file> <new location> when CMake can install it to the right place in the first place.

Co-authored-by: Jan Holthuis <holthuis.jan@googlemail.com>
@daschuer
Copy link
Member Author

#4114 does not work for all, because it guesses the right udev location. This one does only install it when it is certain to be correct. That is an improvement.

In case of Ubuntu we use a manual install step using dh_installudev

dh_installudev --name=mixxx-usb-uaccess --priority 69

With this PR the packager can omit this step.

Why is making sure -DCMAKE_INSTALL_PREFIX is set correctly in packaging and then using ${CMAKE_INSTALL_LIBDIR}/udev/rules.d wrong? Why would this more complicated pkg-config stuff be preferable?

Two reasons:

  • With debuilder toolcahin CMAKE_INSTALL_PREFIX is set to /usr, but the correct install location is /lib/udev
  • If CMAKE_INSTALL_LIBDIR is not / or /usr the install location is wrong.

@PureTryOut
Copy link

With debuilder toolcahin CMAKE_INSTALL_PREFIX is set to /usr, but the correct install location is /lib/udev

So set it to / instead? Or does Ubuntu install some things to /usr and some things to /? That would be weird but I guess a valid reason not to use #4114. If it does not, this PR just seems a more complicated way to achieve the same result.

@daschuer
Copy link
Member Author

Yes right, on Ubuntu the default install prefix is /usr while the udev dir is /lib/udev.

@PureTryOut
Copy link

Weird... But ok, valid point then.

@daschuer
Copy link
Member Author

@Holzhaus merge?

@uklotzde uklotzde added this to the 2.3.1 milestone Jul 27, 2021
@Holzhaus Holzhaus merged commit ccfb894 into mixxxdj:2.3 Jul 29, 2021
@daschuer daschuer deleted the udev branch August 1, 2021 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants