Skip to content

Commit

Permalink
Merge pull request #4798 from elliefm/v311/installed-headers-lib-prefix
Browse files Browse the repository at this point in the history
installed headers don't compile
  • Loading branch information
elliefm authored Oct 20, 2024
2 parents 5bab038 + 86e0823 commit 29c9ff8
Show file tree
Hide file tree
Showing 22 changed files with 898 additions and 92 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,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 @@ -760,13 +760,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 @@ -805,9 +802,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 @@ -817,6 +814,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 @@ -825,7 +823,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 @@ -1459,11 +1457,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 @@ -1549,13 +1549,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 @@ -563,6 +563,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 @@ -577,19 +602,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 @@ -2003,6 +2016,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 @@ -2012,13 +2028,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

0 comments on commit 29c9ff8

Please sign in to comment.