shogun: remove non-distributable SVMlight code

SVMlight uses a non-standard license [0] that doesn't allow distribution
without the author's permission:

> The software must not be modified and distributed without prior permission of the author.

So remove all code related to it when building the binary package.
Use upstream's own script to do it (which they use to create and
distribute their own Debian package), with a few fixes.

There is still the option of building from source with SVMlight enabled
with an override that sets the withSvmLight parameter.

If SVMlight is enabled set the license to unfree. Also fix the
deprecated gpl3 license to gpl3Plus.

[0]: https://github.com/shogun-toolbox/shogun/blob/shogun_6.1.4/doc/license/LICENSE_SVMlight.md

+96 -2
+20 -2
pkgs/applications/science/machine-learning/shogun/default.nix
··· 8 8 # extra support 9 9 , pythonSupport ? true, pythonPackages ? null 10 10 , opencvSupport ? false, opencv ? null 11 + , withSvmLight ? false 11 12 }: 12 13 13 14 assert pythonSupport -> pythonPackages != null; ··· 60 61 url = "https://github.com/awild82/shogun/commit/365ce4c4c700736d2eec8ba6c975327a5ac2cd9b.patch"; 61 62 sha256 = "158hqv4xzw648pmjbwrhxjp7qcppqa7kvriif87gn3zdn711c49s"; 62 63 }) 63 - ]; 64 + ] ++ lib.optional (!withSvmLight) ./svmlight-scrubber.patch; 64 65 65 66 CCACHE_DISABLE="1"; 66 67 CCACHE_DIR=".ccache"; ··· 86 87 (flag "CMAKE_VERBOSE_MAKEFILE:BOOL" doCheck) 87 88 (flag "PythonModular" pythonSupport) 88 89 (flag "OpenCV" opencvSupport) 90 + (flag "USE_SVMLIGHT" withSvmLight) 89 91 ]; 90 92 93 + postPatch = '' 94 + # Fix preprocessing SVMlight code 95 + sed -i \ 96 + -e 's@#ifdef SVMLIGHT@#ifdef USE_SVMLIGHT@' \ 97 + -e '/^#ifdef USE_SVMLIGHT/,/^#endif/ s@#endif@#endif //USE_SVMLIGHT@' \ 98 + src/shogun/kernel/string/CommUlongStringKernel.cpp 99 + sed -i -e 's/#if USE_SVMLIGHT/#ifdef USE_SVMLIGHT/' src/interfaces/swig/Machine.i 100 + sed -i -e 's@// USE_SVMLIGHT@//USE_SVMLIGHT@' src/interfaces/swig/Transfer.i 101 + sed -i -e 's@/\* USE_SVMLIGHT \*/@//USE_SVMLIGHT@' src/interfaces/swig/Transfer_includes.i 102 + '' + lib.optionalString (!withSvmLight) '' 103 + # Run SVMlight scrubber 104 + patchShebangs scripts/light-scrubber.sh 105 + echo "removing SVMlight code" 106 + ./scripts/light-scrubber.sh 107 + ''; 108 + 91 109 meta = with lib; { 92 110 description = "A toolbox which offers a wide range of efficient and unified machine learning methods"; 93 111 homepage = "http://shogun-toolbox.org/"; 94 - license = licenses.gpl3; 112 + license = if withSvmLight then licenses.unfree else licenses.gpl3Plus; 95 113 maintainers = with maintainers; [ edwtjo ]; 96 114 }; 97 115 }
+76
pkgs/applications/science/machine-learning/shogun/svmlight-scrubber.patch
··· 1 + From: Sebastián Mancilla <smancill@smancill.dev> 2 + Subject: Update SVMlight scrubber script 3 + 4 + This requires previously fixing a few wrong preprocessor directives that 5 + are supposed to fence code using SVMlight. 6 + 7 + - The script was too eager and removing *.light files in SVMlight format 8 + that are used by other tests. The code reading those files doesn't use 9 + any SVMlight code so it should be fine to keep it and run the tests. 10 + 11 + - The Python test *domainadaptationsvm.py was not removed because of 12 + wrong globbing. 13 + 14 + - Remove a couple of examples using SVMlight that were missed. 15 + 16 + - The script is actually modifying (and breaking) itself because the 17 + grep for the USE_SVMLIGHT macro is too eager again and matches itself 18 + (and the version stored in upstream's Debian package control tarball 19 + is broken because of it). Just fix it by grepping for preprocessor 20 + directives only. 21 + 22 + - No need to fix the Transfer_includes.i file in the script with a final 23 + %} when its preprocessor directives have been fixed. 24 + 25 + - The Swig files were moved to a new directory at some point but the 26 + script was not updated accordingly. 27 + --- 28 + scripts/light-scrubber.sh | 16 ++++++---------- 29 + 1 file changed, 6 insertions(+), 10 deletions(-) 30 + 31 + diff a/scripts/light-scrubber.sh b/scripts/light-scrubber.sh 32 + --- a/scripts/light-scrubber.sh 33 + +++ b/scripts/light-scrubber.sh 34 + @@ -26,14 +26,16 @@ 35 + # You should have received a copy of the GNU General Public License 36 + # along with this program. If not, see <http://www.gnu.org/licenses/>. 37 + # 38 + -rm -rf examples/*/*/{*light*,*_domainadaptationsvm_*} \ 39 + +rm -rf examples/*/*/{*light*.*,*domainadaptationsvm*} \ 40 + examples/undocumented/matlab_and_octave/tests/*light* \ 41 + + examples/undocumented/python/serialization_string_kernels.py \ 42 + + examples/undocumented/python/mkl_binclass.py \ 43 + src/shogun/classifier/svm/SVMLight.* \ 44 + src/shogun/classifier/svm/SVMLightOneClass.* \ 45 + src/shogun/regression/svr/SVRLight.* \ 46 + doc/md/LICENSE_SVMlight* 47 + 48 + -for _file in `grep -rl USE_SVMLIGHT .` 49 + +grep -rl '^#ifdef USE_SVMLIGHT' . | while read -r _file 50 + do 51 + sed -i.orig -e \ 52 + '/\#ifdef USE_SVMLIGHT/,/\#endif \/\/USE_SVMLIGHT/c \\' ${_file} && \ 53 + @@ -41,7 +43,7 @@ do 54 + rm -rf ${_file}.orig 55 + done 56 + 57 + -for _file in `find . -depth -name 'CMakeLists.txt'` 58 + +find . -depth -name 'CMakeLists.txt' | while read -r _file 59 + do 60 + sed -i.orig -e 's!.*_sv[mr]light_.*!!g' ${_file} && \ 61 + touch -r ${_file}.orig ${_file} && \ 62 + @@ -56,13 +58,7 @@ do 63 + rm -rf ${_file}.orig 64 + done 65 + 66 + -_file="src/interfaces/modular/Transfer_includes.i" && \ 67 + -cp -a ${_file} ${_file}.orig && \ 68 + -echo '%}' >> ${_file} && \ 69 + -touch -r ${_file}.orig ${_file} && \ 70 + -rm -rf ${_file}.orig 71 + - 72 + -_file="src/interfaces/modular/Machine.i" && \ 73 + +_file="src/interfaces/swig/Machine.i" && \ 74 + sed -i.orig -e '/.*CSVRLight.*/d' ${_file} && \ 75 + touch -r ${_file}.orig ${_file} && \ 76 + rm -rf ${_file}.orig