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

installed headers don't compile #4798

Draft
wants to merge 27 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5ef48b0
auth.h: installed headers can't #include "lib/..."
elliefm Jan 23, 2024
7cf07a7
Makefile.am: install xsha1.h
elliefm Jan 23, 2024
ddca47c
WIP Makefile.am: noinst_HEADERS is contagious
elliefm Jan 29, 2024
eb93d39
tok.h: remove unused config.h
elliefm Jan 29, 2024
fa62b3e
xsha1.h: protect inclusion of config.h
elliefm Jan 29, 2024
3032a1a
example_libcyrus_min.c: exercise funcs from most libcyrus_min modules
elliefm Jan 31, 2024
043e890
Instance: always set LD_LIBRARY_PATH and PKG_CONFIG_PATH in child pro…
elliefm Jan 29, 2024
b35bff9
LibCyrus: automatic testing of all libcyrus examples
elliefm Jan 31, 2024
2ddc704
Instance: make valgrind setup reusable
elliefm Jan 31, 2024
7349e27
LibCyrus: run examples under valgrind when requested
elliefm Jan 31, 2024
ba1e15e
xsha1: always include internal impls in libcyrus_min
elliefm Feb 2, 2024
b99867d
example_libcyrus_min.c: exercise xsha1 funcs
elliefm Feb 2, 2024
f3b1f75
LibCyrus: get make, pkg-config paths from cassini
elliefm Jan 31, 2024
fa42a41
LibCyrus: catch diagnostic colors from build failures
elliefm Feb 4, 2024
3473afc
bitvector.h: remove unused includes
elliefm Feb 4, 2024
de27be6
WIP command.h: remove unused config.h (but still bad)
elliefm Feb 4, 2024
704f581
cyr_qsort_r: move config.h from header to source
elliefm Feb 4, 2024
d85f37c
glob: hide struct internals from header
elliefm Feb 4, 2024
3324c05
procinfo.h: remove unused config.h
elliefm Feb 4, 2024
6112252
libcyrus.pc.in: needs path variables
elliefm Feb 5, 2024
1525a87
WIP libcyrus.pc.in: needs -lcyrus_min
elliefm Feb 5, 2024
00fe3a8
Makefile.am: don't install auth_pts.h
elliefm Feb 5, 2024
6c0e686
WIP Makefile.am: don't install chartable.h
elliefm Feb 5, 2024
c45aff5
procinfo: need config.h
elliefm Feb 5, 2024
4eba9aa
WIP example_libcyrus.c
elliefm Feb 4, 2024
90a805a
LibCyrus: extract deps from file contents
elliefm Feb 21, 2024
0afca14
WIP imclient notes
elliefm Feb 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ cunit/unit
debian/
depcomp
doc/examples/imapd_conf/imapd.conf.sample
doc/examples/libcyrus/example_libcyrus_min
doc/html/
doc/legacy/murder.png
doc/legacy/netnews.png
Expand Down
14 changes: 6 additions & 8 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -771,13 +771,10 @@ include_HEADERS = \
lib/arrayu64.h \
lib/assert.h \
lib/auth.h \
lib/auth_pts.h \
lib/bitvector.h \
lib/bloom.h \
lib/bsearch.h \
lib/bufarray.h \
lib/charset.h \
lib/chartable.h \
lib/command.h \
lib/crc32.h \
lib/cyr_lock.h \
Expand Down Expand Up @@ -816,9 +813,9 @@ include_HEADERS = \
lib/stristr.h \
lib/times.h \
lib/tok.h \
lib/vparse.h \
lib/wildmat.h \
lib/xmalloc.h \
lib/xsha1.h \
lib/xunlink.h

nodist_include_HEADERS = \
Expand All @@ -828,6 +825,7 @@ nobase_include_HEADERS = sieve/sieve_interface.h
nobase_nodist_include_HEADERS = sieve/sieve_err.h

noinst_HEADERS += \
lib/bufarray.h \
lib/byteorder.h \
lib/gai.h \
lib/libconfig.h \
Expand All @@ -836,7 +834,7 @@ noinst_HEADERS += \
lib/ptrarray.h \
lib/slowio.h \
lib/util.h \
lib/xsha1.h \
lib/vparse.h \
lib/xstrlcat.h \
lib/xstrlcpy.h \
lib/xstrnchr.h
Expand Down Expand Up @@ -1514,11 +1512,13 @@ lib_libcyrus_la_SOURCES = \
lib/auth_krb5.c \
lib/auth_mboxgroups.c \
lib/auth_pts.c \
lib/auth_pts.h \
lib/auth_unix.c \
lib/bitvector.c \
lib/bloom.c \
lib/bsearch.c \
lib/charset.c \
lib/chartable.h \
lib/command.c \
lib/cyr_qsort_r.c \
lib/cyrusdb.c \
Expand Down Expand Up @@ -1604,13 +1604,11 @@ lib_libcyrus_min_la_SOURCES = \
lib/util.c \
lib/vparse.c \
lib/xmalloc.c \
lib/xsha1.c \
lib/xstrlcat.c \
lib/xstrlcpy.c \
lib/xstrnchr.c \
lib/xunlink.c
if !HAVE_SSL
lib_libcyrus_min_la_SOURCES += lib/xsha1.c
endif
if IPV6_noGETADDRINFO
lib_libcyrus_min_la_SOURCES += lib/getaddrinfo.c
endif
Expand Down
235 changes: 235 additions & 0 deletions cassandane/Cassandane/Cyrus/LibCyrus.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
#!/usr/bin/perl
#
# Copyright (c) 2011-2024 FastMail Pty Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# 3. The name "Fastmail Pty Ltd" must not be used to
# endorse or promote products derived from this software without
# prior written permission. For permission or any legal
# details, please contact
# FastMail Pty Ltd
# PO Box 234
# Collins St West 8007
# Victoria
# Australia
#
# 4. Redistributions of any form whatsoever must retain the following
# acknowledgment:
# "This product includes software developed by Fastmail Pty. Ltd."
#
# FASTMAIL PTY LTD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
# EVENT SHALL OPERA SOFTWARE AUSTRALIA BE LIABLE FOR ANY SPECIAL, INDIRECT
# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
# USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
# OF THIS SOFTWARE.
#

package Cassandane::Cyrus::LibCyrus;
use strict;
use warnings;
use v5.010;
use Cwd qw(abs_path);
use Data::Dumper;
use DateTime;
use File::Copy;
use File::Find;

use lib '.';
use base qw(Cassandane::Cyrus::TestCase);
use Cassandane::Util::Log;
use Cassandane::Util::Slurp;

$Data::Dumper::Sortkeys = 1;

my $examples_dir = abs_path('../doc/examples/libcyrus');

sub new
{
my $class = shift;
return $class->SUPER::new({}, @_);
}

sub set_up
{
my ($self) = @_;
$self->SUPER::set_up();
}

sub tear_down
{
my ($self) = @_;
$self->SUPER::tear_down();
}

sub run_pkgconfig
{
my ($self, %params) = @_;
state $counter = 0;

$counter++;

my $outfname = $self->{instance}->{basedir} . "/pkg-config$counter.out";
my $errfname = $self->{instance}->{basedir} . "/pkg-config$counter.err";

my $cassini = Cassandane::Cassini->instance();
my $pkgconfig = $cassini->val('paths', 'pkg-config', '/usr/bin/pkg-config');

$self->{instance}->run_command({
cyrus => 0,
redirects => {
stdout => $outfname,
stderr => $errfname,
},
},
$pkgconfig, @{$params{options}}, @{$params{packages}},
);

my $val = slurp_file($outfname);
chomp $val;

return $val;
}

sub find_tests
{
my ($dir) = @_;

my @tests;

find(
sub {
my $file = $File::Find::name;

return unless $file =~ s/\.c$//;
return unless -f "$file.c";
$file =~ s/^$dir\/?//;
push @tests, "test_$file";
},
$dir,
);

return @tests;
}

sub list_tests
{
my @tests;

@tests = find_tests($examples_dir);

return @tests;
}

sub find_deps
{
my ($source) = @_;
my @deps;

open my $fh, '<', $source or die "read $source: $!";
while (<$fh>) {
if (m/\bDEPS:([-\sA-Za-z_]+)/) {
if (get_verbose() > 1) {
xlog "found DEPS at line $.: $_";
}
push @deps, split(q{ }, $1);
}
}
close $fh;

if (get_verbose() > 1) {
xlog "parsed dependencies: " . Dumper \@deps;
}
return @deps;
}

sub run_test
{
my ($self) = @_;

my $cassini = Cassandane::Cassini->instance();

my $name = $self->name();
$name =~ s/^test_//;

my $orig_source = "$examples_dir/$name.c";
copy($orig_source, $self->{instance}->{basedir})
or die "copy $orig_source: $!";

my @deps = find_deps($orig_source)
or die "couldn't determine libcyrus dependencies for test_$name";

my $cflags = $self->run_pkgconfig(packages => \@deps,
options => [ '--cflags' ]);
my $ldflags = $self->run_pkgconfig(packages => \@deps,
options => [ '--libs-only-L',
'--libs-only-other' ]);
my $ldlibs = $self->run_pkgconfig(packages => \@deps,
options => [ '--libs-only-l' ]);

my $makeerr = $self->{instance}->{basedir} . "/make.err";
my $make = $cassini->val('paths', 'make', '/usr/bin/make');

my $warnopts = '-Wall -Wextra -Werror';
my $otheropts = '-g -O0 -fdiagnostics-color=always';

eval {
$self->{instance}->run_command({
cyrus => 0,
redirects => {
stderr => $makeerr,
},
},
$make,
"CFLAGS=$warnopts $otheropts $cflags",
"LDFLAGS=$ldflags",
"LDLIBS=$ldlibs",
'-C', $self->{instance}->{basedir}, # n.b. not cyrus's -C
$name,
);
};
if ($@) {
xlog "make failed:\n" . slurp_file($makeerr);
die $@;
}

my $runerr = $self->{instance}->{basedir} . "/$name.err";

my @cmd;
if ($cassini->bool_val('valgrind', 'enabled')) {
push @cmd, $self->{instance}->_valgrind_setup($name);
}

push @cmd, $self->{instance}->{basedir} . "/$name",
'-C', $self->{instance}->_imapd_conf();

eval {
$self->{instance}->run_command({
cyrus => 0,
redirects => {
stderr => $runerr,
},
},
@cmd,
);
};
if ($@) {
xlog "$name failed:\n" . slurp_file($runerr);
die $@;
}

}

1;
53 changes: 33 additions & 20 deletions cassandane/Cassandane/Instance.pm
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,31 @@ sub _find_binary
die "Couldn't locate $name under $base";
}

sub _valgrind_setup
{
my ($self, $name) = @_;

my @cmd;

my $cassini = Cassandane::Cassini->instance();

my $arguments = '-q --tool=memcheck --leak-check=full --run-libc-freeres=no';
my $valgrind_logdir = $self->{basedir} . '/vglogs';
my $valgrind_suppressions =
abs_path($cassini->val('valgrind', 'suppression', 'vg.supp'));
mkpath $valgrind_logdir
unless ( -d $valgrind_logdir );
push(@cmd,
$cassini->val('valgrind', 'binary', '/usr/bin/valgrind'),
"--log-file=$valgrind_logdir/$name.%p",
"--suppressions=$valgrind_suppressions",
"--gen-suppressions=all",
split(/\s+/, $cassini->val('valgrind', 'arguments', $arguments))
);

return @cmd;
}

sub _binary
{
my ($self, $name) = @_;
Expand All @@ -575,19 +600,7 @@ sub _binary
!($name =~ m/\.pl$/) &&
!($name =~ m/^\//))
{
my $arguments = '-q --tool=memcheck --leak-check=full --run-libc-freeres=no';
my $valgrind_logdir = $self->{basedir} . '/vglogs';
my $valgrind_suppressions =
abs_path($cassini->val('valgrind', 'suppression', 'vg.supp'));
mkpath $valgrind_logdir
unless ( -d $valgrind_logdir );
push(@cmd,
$cassini->val('valgrind', 'binary', '/usr/bin/valgrind'),
"--log-file=$valgrind_logdir/$name.%p",
"--suppressions=$valgrind_suppressions",
"--gen-suppressions=all",
split(/\s+/, $cassini->val('valgrind', 'arguments', $arguments))
);
push @cmd, $self->_valgrind_setup($name);
$valground = 1;
}

Expand Down Expand Up @@ -2015,6 +2028,9 @@ sub _fork_command
$ENV{CASSANDANE_SYSLOG_FNAME} = abs_path($self->{syslog_fname});
$ENV{LD_PRELOAD} = abs_path('utils/syslog.so')
}
$ENV{PKG_CONFIG_PATH} = $self->{cyrus_destdir}
. $self->{cyrus_prefix}
. "/lib/pkgconfig";

# xlog "\$PERL5LIB is"; map { xlog " $_"; } split(/:/, $ENV{PERL5LIB});

Expand All @@ -2024,13 +2040,10 @@ sub _fork_command
# entirely clear how to detect that - we could use readelf -d
# on an executable to discover what it thinks it's RPATH ought
# to be, then prepend destdir to that.
if ($self->{cyrus_destdir} ne "")
{
$ENV{LD_LIBRARY_PATH} = join(':', (
$self->{cyrus_destdir} . $self->{cyrus_prefix} . "/lib",
split(/:/, $ENV{LD_LIBRARY_PATH} || "")
));
}
$ENV{LD_LIBRARY_PATH} = join(':', (
$self->{cyrus_destdir} . $self->{cyrus_prefix} . "/lib",
split(/:/, $ENV{LD_LIBRARY_PATH} || "")
));
# xlog "\$LD_LIBRARY_PATH is"; map { xlog " $_"; } split(/:/, $ENV{LD_LIBRARY_PATH});

my $cd = $options->{workingdir};
Expand Down
Loading