Skip to content

Commit

Permalink
Place scribbu types & functions in module (scribbu), even
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Michael Herstine committed Sep 17, 2023
1 parent e544648 commit b108761
Show file tree
Hide file tree
Showing 15 changed files with 161 additions and 43 deletions.
43 changes: 36 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -87,7 +91,6 @@ jobs:
# This seems wrong on multiple levels, but see here:
# <https://github.com/orgs/Homebrew/discussions/4612#discussioncomment-6339258>
set +e
pwd
brew cleanup
# Will exit with non-zero status if it finds problems, but can be handy
# for trouble-shooting:
Expand Down Expand Up @@ -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 "===================================="
Expand Down Expand Up @@ -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 "===================================="
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions macros/ltoptions.m4
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion macros/ltsugar.m4
Original file line number Diff line number Diff line change
@@ -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
#
Expand Down
13 changes: 6 additions & 7 deletions macros/ltversion.m4
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
])
4 changes: 2 additions & 2 deletions macros/lt~obsolete.m4
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions scheme/scribbu.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
21 changes: 14 additions & 7 deletions scribbu/Makefile.am
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down Expand Up @@ -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:
Expand Down
33 changes: 26 additions & 7 deletions scribbu/scheme.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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*)
{
Expand Down Expand Up @@ -854,16 +878,11 @@ extern "C" {
{
const init_guile *pig = reinterpret_cast<const init_guile*>(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".
Expand Down
11 changes: 5 additions & 6 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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)
7 changes: 5 additions & 2 deletions test/Makefile.am
Original file line number Diff line number Diff line change
@@ -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 \
Expand All @@ -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 \
Expand All @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions test/id3v2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*
*/

#include <boost/test/unit_test_suite.hpp>
#include <scribbu/id3v2-utils.hh>

#include "unit.hh"
Expand Down
2 changes: 1 addition & 1 deletion test/test-fs-generator
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion test/test-fs-generator.scm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
;;;;
;;;;


(use-modules (scribbu))
(define test-dir "/tmp/scribbu-test/scheme")
(define G (fs-tree-generator test-dir))
Expand Down
57 changes: 57 additions & 0 deletions test/test-snarfed-in-scribbu
Original file line number Diff line number Diff line change
@@ -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<<EOF
-e main -s
!#
;; Should fail
(set! x (read-id3v1-tag "data/id3v1.2.3.tag"))
EOF

chmod a+x $tmpfile
export GUILE_AUTO_COMPILE=0
cols=$(tput cols)
export GUILE_LOAD_PATH=${srcdir}/../scheme

eval "$($tmpfile \
2> >(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

0 comments on commit b108761

Please sign in to comment.