From b1087617eac09217f0d0a705289d59bdc43bd5c7 Mon Sep 17 00:00:00 2001 From: Michael Herstine Date: Fri, 15 Sep 2023 20:12:06 -0400 Subject: [PATCH] Place scribbu types & functions in module `(scribbu)`, even when defined in C. This commit will place the snarfed functions provided by libscribbu.so into module `(scribbu)` and updates `scribbu.scm` to load the extension. This commit also changes the linking between `scribbu` and `libscribbu`. I have squashed a number of commits on master-- this is generally not a good idea, since I'm re-writing git history on a published branch. That said, this project is obscure enough that I very much doubt I'm inconveniencing anyone. --- .github/workflows/ci.yml | 43 ++++++++++++++++++++++----- NEWS | 1 + macros/ltoptions.m4 | 4 +-- macros/ltsugar.m4 | 2 +- macros/ltversion.m4 | 13 ++++---- macros/lt~obsolete.m4 | 4 +-- scheme/scribbu.scm | 4 +++ scribbu/Makefile.am | 21 ++++++++----- scribbu/scheme.cc | 33 ++++++++++++++++----- src/Makefile.am | 11 ++++--- test/Makefile.am | 7 +++-- test/id3v2.cc | 1 + test/test-fs-generator | 2 +- test/test-fs-generator.scm | 1 - test/test-snarfed-in-scribbu | 57 ++++++++++++++++++++++++++++++++++++ 15 files changed, 161 insertions(+), 43 deletions(-) create mode 100755 test/test-snarfed-in-scribbu diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1d1073a..10d7552 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,6 +4,12 @@ # The intent here is get as many lints & checks as possible out of my # personal checklist & into automation, being run every night. + +# Reference: +# +# - pwd +# - MacOS: /Users/runner/work/scribbu/scribbu +# - Ubuntu: /home/runner/work/scribbu/scribbu name: Continuous Integration on: workflow_dispatch: @@ -32,8 +38,8 @@ jobs: boost-dl: https://boostorg.jfrog.io/artifactory/main/release/1.74.0/source/boost_1_74_0.tar.bz2 - os: macos-12 boost: latest - boost-ver: 1_82_0 - boost-dl: https://boostorg.jfrog.io/artifactory/main/release/1.82.0/source/boost_1_82_0.tar.bz2 + boost-ver: 1_83_0 + boost-dl: https://boostorg.jfrog.io/artifactory/main/release/1.83.0/source/boost_1_83_0.tar.bz2 - os: ubuntu-22.04 boost: oldest boost-ver: 1_63_0 @@ -65,7 +71,6 @@ jobs: shell: bash run: | set -x - pwd version=`awk '/^AC_INIT/ {print substr($2, 2, length($2)-3)}' configure.ac` echo "Building scribbu version $version." echo "SCRIBBU_BUILD_NUMBER=${version}" >> $GITHUB_ENV @@ -75,7 +80,6 @@ jobs: shell: bash run: | set -x - pwd sudo apt-get update sudo apt-get install -y autoconf automake libtool openssl guile-3.0-dev doxygen flex bison graphviz libunistring-dev texlive tzdata locales @@ -87,7 +91,6 @@ jobs: # This seems wrong on multiple levels, but see here: # set +e - pwd brew cleanup # Will exit with non-zero status if it finds problems, but can be handy # for trouble-shooting: @@ -326,7 +329,19 @@ jobs: shell: bash run: | set -x - pwd + echo "====================================" + otool -L scribbu/.libs/libscribbu.dylib + echo "====================================" + there=$(cd boost_${{ matrix.boost-ver }}/installdir/lib; pwd) + echo "Changing the load location for boost libs to ${there}." + install_name_tool -change libboost_iostreams.dylib ${there}/libboost_iostreams.dylib scribbu/.libs/libscribbu.dylib + install_name_tool -change libboost_log.dylib ${there}/libboost_log.dylib scribbu/.libs/libscribbu.dylib + install_name_tool -change libboost_program_options.dylib ${there}/libboost_program_options.dylib scribbu/.libs/libscribbu.dylib + install_name_tool -change libboost_regex.dylib ${there}/libboost_regex.dylib scribbu/.libs/libscribbu.dylib + install_name_tool -change libboost_system.dylib ${there}/libboost_system.dylib scribbu/.libs/libscribbu.dylib + echo "====================================" + otool -L scribbu/.libs/libscribbu.dylib + echo "====================================" echo "====================================" otool -L src/.libs/scribbu echo "====================================" @@ -368,7 +383,19 @@ jobs: shell: bash run: | set -x - pwd + echo "====================================" + otool -L scribbu/.libs/libscribbu.dylib + echo "====================================" + there=$(cd boost_${{ matrix.boost-ver }}/installdir/lib; pwd) + echo "Changing the load location for boost libs to ${there}." + install_name_tool -change @rpath/libboost_iostreams.dylib ${there}/libboost_iostreams.dylib scribbu/.libs/libscribbu.dylib + install_name_tool -change @rpath/libboost_log.dylib ${there}/libboost_log.dylib scribbu/.libs/libscribbu.dylib + install_name_tool -change @rpath/libboost_program_options.dylib ${there}/libboost_program_options.dylib scribbu/.libs/libscribbu.dylib + install_name_tool -change @rpath/libboost_regex.dylib ${there}/libboost_regex.dylib scribbu/.libs/libscribbu.dylib + install_name_tool -change @rpath/libboost_system.dylib ${there}/libboost_system.dylib scribbu/.libs/libscribbu.dylib + echo "====================================" + otool -L scribbu/.libs/libscribbu.dylib + echo "====================================" echo "====================================" otool -L src/.libs/scribbu echo "====================================" @@ -412,6 +439,7 @@ jobs: set -x pwd here=$(pwd) + ldd scribbu/.libs/libscribbu.so find ${here}/boost_${{ matrix.boost-ver }}/installdir -iname '*.so' export LD_LIBRARY_PATH="${here}/boost_${{ matrix.boost-ver }}/installdir/lib:$LD_LIBRARY_PATH" pwd @@ -426,6 +454,7 @@ jobs: run: | set -x pwd + ldd scribbu/.libs/libscribbu.so if ! make check; then cat test/test-suite.log exit 1 diff --git a/NEWS b/NEWS index 644beb2..769a970 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,7 @@ scribbu News -- history of user-visible changes -*- outline -*- ** Bug Fixes +*** Scheme function & types defined in C are now in module (scribbu) *** fixed several bugs in `write_id3v1_tag` - Added a GOOPS type check ensuring the argument is truly an diff --git a/macros/ltoptions.m4 b/macros/ltoptions.m4 index b0b5e9c..94b0829 100644 --- a/macros/ltoptions.m4 +++ b/macros/ltoptions.m4 @@ -1,7 +1,7 @@ # Helper functions for option handling. -*- Autoconf -*- # -# Copyright (C) 2004-2005, 2007-2009, 2011-2019, 2021-2022 Free -# Software Foundation, Inc. +# Copyright (C) 2004-2005, 2007-2009, 2011-2015 Free Software +# Foundation, Inc. # Written by Gary V. Vaughan, 2004 # # This file is free software; the Free Software Foundation gives diff --git a/macros/ltsugar.m4 b/macros/ltsugar.m4 index 902508b..48bc934 100644 --- a/macros/ltsugar.m4 +++ b/macros/ltsugar.m4 @@ -1,6 +1,6 @@ # ltsugar.m4 -- libtool m4 base layer. -*-Autoconf-*- # -# Copyright (C) 2004-2005, 2007-2008, 2011-2019, 2021-2022 Free Software +# Copyright (C) 2004-2005, 2007-2008, 2011-2015 Free Software # Foundation, Inc. # Written by Gary V. Vaughan, 2004 # diff --git a/macros/ltversion.m4 b/macros/ltversion.m4 index 0026c21..fa04b52 100644 --- a/macros/ltversion.m4 +++ b/macros/ltversion.m4 @@ -1,7 +1,6 @@ # ltversion.m4 -- version numbers -*- Autoconf -*- # -# Copyright (C) 2004, 2011-2019, 2021-2022 Free Software Foundation, -# Inc. +# Copyright (C) 2004, 2011-2015 Free Software Foundation, Inc. # Written by Scott James Remnant, 2004 # # This file is free software; the Free Software Foundation gives @@ -10,15 +9,15 @@ # @configure_input@ -# serial 4249 ltversion.m4 +# serial 4179 ltversion.m4 # This file is part of GNU Libtool -m4_define([LT_PACKAGE_VERSION], [2.4.7.4-1ec8f-dirty]) -m4_define([LT_PACKAGE_REVISION], [2.4.7.4]) +m4_define([LT_PACKAGE_VERSION], [2.4.6]) +m4_define([LT_PACKAGE_REVISION], [2.4.6]) AC_DEFUN([LTVERSION_VERSION], -[macro_version='2.4.7.4-1ec8f-dirty' -macro_revision='2.4.7.4' +[macro_version='2.4.6' +macro_revision='2.4.6' _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) _LT_DECL(, macro_revision, 0) ]) diff --git a/macros/lt~obsolete.m4 b/macros/lt~obsolete.m4 index 0f7a875..c6b26f8 100644 --- a/macros/lt~obsolete.m4 +++ b/macros/lt~obsolete.m4 @@ -1,7 +1,7 @@ # lt~obsolete.m4 -- aclocal satisfying obsolete definitions. -*-Autoconf-*- # -# Copyright (C) 2004-2005, 2007, 2009, 2011-2019, 2021-2022 Free -# Software Foundation, Inc. +# Copyright (C) 2004-2005, 2007, 2009, 2011-2015 Free Software +# Foundation, Inc. # Written by Scott James Remnant, 2004. # # This file is free software; the Free Software Foundation gives diff --git a/scheme/scribbu.scm b/scheme/scribbu.scm index 760c897..0505b82 100644 --- a/scheme/scribbu.scm +++ b/scheme/scribbu.scm @@ -34,6 +34,10 @@ unknown-frame album-frame artist-frame has-frame? get-frames)) +;; Load the Scheme extension in `libscribbu.so` & invoke `init_scribbu()` therein to define types & +;; functions. Nb. These definitions will be in module `(scribbu)`. +(load-extension "libscribbu" "init_scribbu") + (use-modules (ice-9 ftw)) (use-modules (ice-9 match)) (use-modules (rnrs bytevectors)) diff --git a/scribbu/Makefile.am b/scribbu/Makefile.am index 703c190..cdc5220 100644 --- a/scribbu/Makefile.am +++ b/scribbu/Makefile.am @@ -1,12 +1,6 @@ # Tell automake that these two must be built first; we say how below BUILT_SOURCES = tbt-parser.hh tbt-lexer.hh scheme.x - -AM_YFLAGS = -d -AM_CPPFLAGS = -I$(srcdir)/.. $(BOOST_CPPFLAGS) $(OPENSSL_INCLUDES) $(GUILE_CFLAGS) -AM_CXXFLAGS = -std=c++17 -Wno-register $(GUILE_CFLAGS) - lib_LTLIBRARIES = libscribbu.la - libscribbu_la_SOURCES = tbt-parser.yy \ tbt-lexer.ll \ scribbu.cc \ @@ -58,7 +52,20 @@ pkginclude_HEADERS = scribbu.hh \ scheme-serde.hh \ winamp-genres.hh -libscribbu_la_LDFLAGS = -version-info 4:1:0 +AM_YFLAGS = -d +AM_CPPFLAGS = -I$(srcdir)/.. $(BOOST_CPPFLAGS) $(OPENSSL_INCLUDES) $(GUILE_CFLAGS) +AM_CXXFLAGS = -std=c++17 -Wno-register $(GUILE_CFLAGS) +AM_LDFLAGS = $(BOOST_LDFLAGS) $(LIBUNISTRING) + +libscribbu_la_LIBADD = $(GUILE_LIBS) \ + $(OPENSSL_LIBS) \ + $(BOOST_IOSTREAMS_LIB) \ + $(BOOST_FILESYSTEM_LIB) \ + $(BOOST_LOG_LIB) \ + $(BOOST_REGEX_LIB) \ + $(BOOST_SYSTEM_LIB) + +libscribbu_la_LDFLAGS = -version-info 4:1:0 $(BOOST_LDFLAGS) $(LIBUNISTRING) # automake will figure out how to make tbt-parser.hh, but we need to tell it how # to make tbt-lexer.h: diff --git a/scribbu/scheme.cc b/scribbu/scheme.cc index 2fc4947..944e265 100644 --- a/scribbu/scheme.cc +++ b/scribbu/scheme.cc @@ -758,6 +758,30 @@ extern "C" { } + /// Define our types & functions at the top level of the current module + void + init_scribbu() + { + + scribbu::init_symbols(); + +# ifndef SCM_MAGIC_SNARFER +# include "scheme.x" +# endif + + scm_c_export(READ_ID3V1_TAG, READ_TAGSET, WITH_TRACK_IN, WRITE_ID3V1_TAG, + WRITE_TAGSET, nullptr); + + } + + /// Define our types & functions in the current module-- this function is + /// just a shim to allow us to initialize this from either the Guile REPL or + /// when loading the extension from Scheme. + void + init_scribbu_shim(void*) { + init_scribbu(); + } + SCM get_version_variable(void*) { @@ -854,16 +878,11 @@ extern "C" { { const init_guile *pig = reinterpret_cast(praw); - scribbu::init_symbols(); - -# ifndef SCM_MAGIC_SNARFER -# include "scheme.x" -# endif - + // scm_c_define_module("scribbu-int", init_scribbu_shim, nullptr); customize_welcome(); customize_load_path(pig->datadir_); - return 0; + return nullptr; } } // End extern "C". diff --git a/src/Makefile.am b/src/Makefile.am index 50d860a..66d22d1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,16 +2,15 @@ bin_PROGRAMS = scribbu scribbu_SOURCES = scribbu.cc command-utilities.hh command-utilities.cc \ rename.cc report.cc split.cc dump.cc popm.cc xtag.cc text.cc \ genre.cc m3u.cc encodings.cc -# AM_CPPFLAGS = -I$(srcdir)/.. $(BOOST_CPPFLAGS) $(GUILE_CFLAGS) -DDATADIR=\"$(datadir)\" -DSCRIBBU_ALWAYS_DUMP_CORE -AM_CPPFLAGS = -I$(srcdir)/.. $(BOOST_CPPFLAGS) $(GUILE_CFLAGS) -DDATADIR=\"$(datadir)\" + +AM_CPPFLAGS = -I$(srcdir)/.. $(BOOST_CPPFLAGS) $(GUILE_CFLAGS) -DDATADIR=\"$(datadir)\" -DSCRIBBU_ALWAYS_DUMP_CORE +# AM_CPPFLAGS = -I$(srcdir)/.. $(BOOST_CPPFLAGS) $(GUILE_CFLAGS) -DDATADIR=\"$(datadir)\" + AM_CXXFLAGS = -std=c++17 $(GUILE_CFLAGS) AM_LDFLAGS = $(BOOST_LDFLAGS) $(LIBUNISTRING) scribbu_LDADD = ../scribbu/libscribbu.la \ $(GUILE_LIBS) \ - $(OPENSSL_LIBS) \ $(BOOST_IOSTREAMS_LIB) \ - $(BOOST_FILESYSTEM_LIB) \ - $(BOOST_LOG_LIB) \ $(BOOST_PROGRAM_OPTIONS_LIB) \ - $(BOOST_REGEX_LIB) \ + $(BOOST_REGEX_LIB) \ $(BOOST_SYSTEM_LIB) diff --git a/test/Makefile.am b/test/Makefile.am index 78a7776..332370c 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,3 +1,5 @@ +AM_TESTS_ENVIRONMENT = \ + abs_top_builddir=$(abs_top_builddir) check_PROGRAMS = unit SUBDIRS = data EXTRA_DIST = test-util test-split test-rename test-report test-report-tdf \ @@ -7,7 +9,7 @@ EXTRA_DIST = test-util test-split test-rename test-report test-report-tdf \ test-tagsets-from-scheme.scm test-tagsets-from-scheme \ test-frames-from-scheme.scm test-frames-from-scheme \ test-scripting test-options test-popm test-xtag test-text test-genre \ - test-m3u + test-m3u test-snarfed-in-scribbu CLEANFILES = id3v20B id3v21B report.last.csv report-tdf.last.tdf \ report.csv report-last.csv report-tdf.tdf \ id3v20A trackB id3v1A trackA \ @@ -34,7 +36,8 @@ TESTS = $(check_PROGRAMS) test-split test-rename test-report test-report-tdf \ test-dump test-with-track-in test-fs-generator \ test-cleanup-encoded-by test-cleanup-from-audacity \ test-tagsets-from-scheme test-frames-from-scheme test-scripting \ - test-options test-popm test-xtag test-text test-genre test-m3u + test-options test-popm test-xtag test-text test-genre test-m3u \ + test-snarfed-in-scribbu unit_SOURCES = unit.cc unit.hh charsets.cc ostream.cc id3v1.cc framesv2.cc \ framesv22.cc framesv23.cc framesv24.cc id3v2.cc id3v22.cc id3v23.cc \ id3v24.cc id3v2-utils.cc pprinter.cc csv-pprinter.cc mp3.cc tdf-pprinter.cc \ diff --git a/test/id3v2.cc b/test/id3v2.cc index fabeed2..f5d11d7 100644 --- a/test/id3v2.cc +++ b/test/id3v2.cc @@ -21,6 +21,7 @@ * */ +#include #include #include "unit.hh" diff --git a/test/test-fs-generator b/test/test-fs-generator index 4150d8e..8dfe1ac 100755 --- a/test/test-fs-generator +++ b/test/test-fs-generator @@ -2,4 +2,4 @@ testdir=/tmp/scribbu-test/scheme mkdir -p $testdir/a/b touch $testdir/foo $testdir/a/bar $testdir/a/b/splat -guile -L ${srcdir}/../scheme -s ${srcdir}/test-fs-generator.scm +LD_LIBRARY_PATH=${abs_top_builddir}/scribbu/.libs:$LD_LIBRARY_PATH DYLD_LIBRARY_PATH=${abs_top_builddir}/scribbu/.libs:$DYLD_LIBRARY_PATH guile -L ${srcdir}/../scheme -s ${srcdir}/test-fs-generator.scm diff --git a/test/test-fs-generator.scm b/test/test-fs-generator.scm index 8c19c27..9ee84af 100644 --- a/test/test-fs-generator.scm +++ b/test/test-fs-generator.scm @@ -20,7 +20,6 @@ ;;;; ;;;; - (use-modules (scribbu)) (define test-dir "/tmp/scribbu-test/scheme") (define G (fs-tree-generator test-dir)) diff --git a/test/test-snarfed-in-scribbu b/test/test-snarfed-in-scribbu new file mode 100755 index 0000000..c4561ae --- /dev/null +++ b/test/test-snarfed-in-scribbu @@ -0,0 +1,57 @@ +#!/usr/bin/env bash + +tmpfile=/tmp/test-scripting.scm +scribbu_dir=`cd ../src; pwd` +lib_dir=`cd ../scribbu; pwd` +case `uname` in + Linux) + echo "#!${scribbu_dir}/scribbu \\" > $tmpfile;; + Darwin) + # Workaround for MacOS-- should be; for some reason I don't + # understand (and don't care to debug), the `src/scribbu' + # libtool script doesn't work well with the extended #! line + # I use below. So, I call the MacOS binary directly, being careful + # to set DYLD_LIBRARY_PATH (like the libtool script would) + # so that we load the .so under test and not any previously installed + # version. + echo "#!${scribbu_dir}/.libs/scribbu \\" > $tmpfile; + export DYLD_LIBRARY_PATH=$lib_dir/.libs:$DYLD_LIBRARY_PATH;; + *) + echo "Unknown system" 2>&1; + exit 1;; +esac + +cat >> $tmpfile< >(t_err=$(cat); typeset -p t_err) \ + > >(t_std=$(cat); typeset -p t_std) )" +t_stat=$? +t_err=$(echo "$t_err" | grep -vE ';;; note: source file /tmp/test-scripting.scm' | grep -v 'newer than compiled') +if [ $t_stat -ne 0 ]; then + >&2 echo "Non-zero exit code ($t_stat)." + echo "stdout:" + echo "$t_std" + echo "stderr:" + echo "$t_err" + exit 1 +fi + +if [ "${t_err}" !~ "Unbound variable: read-id3v1-tag" ]; then + >&2 echo "Unexpected stderr" + echo "stdout:" + echo "$t_std" + echo "stderr:" + echo "$t_err" + exit 1 +fi