haikuports / haikuporter

The tool that builds HaikuPorts recipes.
MIT License
41 stars 44 forks source link

fixCMake doesn't correctly fix $libDir to $developLibDir #301

Open mtl1979 opened 3 days ago

mtl1979 commented 3 days ago

CMake's configuration files use relative paths and thus trying to use full path of $libDir doesn't work...

One solution is to search for }/lib instead as that will catch relative paths where the base directory or "prefix" is a variable.

Begasus commented 3 days ago

This has always been an issue for packaging rizin (maybe still something could be fixed upstream), but so far this fixed (still checking) it for me, thanks on that pointer @mtl1979 :)

sed -i 's,\${PACKAGE_PREFIX_DIR}/lib,${PACKAGE_PREFIX_DIR}/develop/'${relativeLibDir}'',g \
    $libDir/cmake/rz_*/rz_*Config.cmake
mtl1979 commented 3 days ago

I counted 7 recipes having either uncommented or commented call to fixCMake... Some of them used sed in addition to fix what fixCMake skipped... I didn't count recipes that use sed only to fix any files generated by CMake...

mtl1979 commented 3 days ago

This has always been an issue for packaging rizin (maybe still something could be fixed upstream), but so far this fixed (still checking) it for me, thanks on that pointer @mtl1979 :)

sed -i 's,\${PACKAGE_PREFIX_DIR}/lib,${PACKAGE_PREFIX_DIR}/develop/'${relativeLibDir}'',g \
    $libDir/cmake/rz_*/rz_*Config.cmake

As pointed out on IRC, I think that the single quotes are in wrong places... I'm not sure why ${relativeLibDir} would need to be quoted if the whole string is already quoted... Also, the last single quote is too early...

Begasus commented 3 days ago

As pointed out on IRC, I think that the single quotes are in wrong places... I'm not sure why ${relativeLibDir} would need to be quoted if the whole string is already quoted... Also, the last single quote is too early...

Thought the relativeLibDir would be needed for 32bit, but that has already been taken care for, this works on 64bit and 32bit:

sed -i 's,\${PACKAGE_PREFIX_DIR}/lib,${PACKAGE_PREFIX_DIR}/develop/lib,g'
    $libDir/cmake/rz_*/rz_*Config.cmake
Begasus commented 3 days ago

Rizin is a bit different in this case, it uses meson/ninja as build system and some python scripts to fill in the paths in the cmake config files, I guess in most cases with cmake builds this will probably fine without any sed magic.

jmairboeck commented 3 days ago

What it really should do is replace $relativeLibDir with $relativeDevelopLibDir, but the problem is that $relativeLibDir is just lib on primary architectures, which is a bit short to match for.

Unfortunately, CMake files aren't as standardized as pkg-config files, so fixCmake will always have a harder time to replace things correctly than fixPkgconfig.

Maybe using sed in addition to or instead of fixCmake will still be the best solution for some recipes.

jmairboeck commented 3 days ago

As pointed out on IRC, I think that the single quotes are in wrong places... I'm not sure why ${relativeLibDir} would need to be quoted if the whole string is already quoted... Also, the last single quote is too early...

That is actually "de-quoting" ${relativeLibDir} (not quoting it again), i.e. it ends the quoted string, then comes the variable, then another quoted string starts (which is actually unneeded, because as it is written here, it is just empty, and the ,g doesn't need to be quoted because it contains no special characters). In single-quotes, shell variables aren't expanded, unlike with double quotes.

mtl1979 commented 3 days ago

That is actually "de-quoting" ${relativeLibDir} (not quoting it again), i.e. it ends the quoted string, then comes the variable, then another quoted string starts (which is actually unneeded, because as it is written here, it is just empty, and the ,g doesn't need to be quoted because it contains no special characters). In single-quotes, shell variables aren't expanded, unlike with double quotes.

I know what's the difference between single and double quotes... In this case double quotes might have been better choice as first $ is already escaped, so variable expansion doesn't happen.

mtl1979 commented 3 days ago

Maybe using sed in addition to or instead of fixCmake will still be the best solution for some recipes.

Some recipes are using sed in addition to fixCMake as fixCMake still works with fixing header paths... I didn't count how many recipes use sed without fixCMake as it would have taken more than just one use of "inrecipe" function.