Skip to content

Commit

Permalink
Merge c8c4170 into 7c9bc66
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed Apr 10, 2019
2 parents 7c9bc66 + c8c4170 commit 2e3cc2f
Show file tree
Hide file tree
Showing 11 changed files with 1,099 additions and 622 deletions.
14 changes: 14 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
CSS::Sass (3.4.12)

* Maintenance release (no libsass upgrade)
* Add unit tests for included plugins
* Add initial appveyor config and badge to readme
* Implement support for HRX spec tests
* Fix issue with newer ExtUtils::CppGuess
* Upgrade ppport.h and adjust makefile
* Add loading of alternate spec output file names
* Fix spec test by trimming trailing white-space
* Update img-size plugin to latest version

-- Marcel Greter <perl-libsass@ocbnet.ch> Thu, 10 Apr 2019 01:44:42 +0100

CSS::Sass (3.4.11)

* Bumped libsass version to latest 3.4 stable branch (3.4.9)
Expand Down
40 changes: 17 additions & 23 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,15 @@ my $orig = \&ExtUtils::MM_Unix::c_o;
*ExtUtils::MM_Unix::c_o = sub {
my @rv = &{$orig};
foreach (@rv) {
# ExtUtils::CppGuess sometimes calls gcc and
# sometimes g++, thus we need to force the
# compiler to compile in the specific language
# fixes https://github.com/sass/perl-libsass/issues/38
s/\$\*\.c\s*(?=\n|\r|\Z)/-xc \$\*\.c/g;
s/\$\*\.c(pp|xx)\s*(?=\n|\r|\Z)/-xc++ \$\*\.c$1/g;
# add c++0x flag only for cpp files
# otherwise XS perl handshake fails
s/\$\*\.c(pp|xx)\s*(?=\n|\r|\Z)/-xc++ -std=c++0x \$\*\.c$1/g
s/\$\*\.c(pp|xx)\s*(?=\n|\r|\Z)/-std=c++0x \$\*\.c$1/g
}
return @rv;
};
Expand All @@ -353,7 +359,7 @@ push @flags, '-o $*.o' if ($guess->is_gcc);
# push @flags, '-stdlib=libstdc++' if ($guess->is_gcc);

# create compile flags to include the libsass version
push @defs, qq( LIBSASS_VERSION=\\"$libsass_version\\");
push @defs, qq(LIBSASS_VERSION=\\"$libsass_version\\");

# enable code profiling via gcov
$optimize = '-O1' if $profiling;
Expand Down Expand Up @@ -447,7 +453,7 @@ my %watchers = (
# check if dependency is wanted and/or available
if (exists $watchers{$^O} && ! $ENV{PERL_FNS_NO_OPT}) {
if ($native_watcher) { $watchdeps = $watchers{$^O}; }
elsif (!eval "require $watchers{$^O}->[0]; return 1;") {
elsif (!eval { require $watchers{$^O}->[0]; return 1; }) {
warn "Consider installing $watchers{$^O}->[0]\n";
warn "Or configure with `--native-watcher` option\n";
}
Expand Down Expand Up @@ -562,18 +568,6 @@ my @commands;
my $static = 0;
my $reported = 0;

# http://perldoc.perl.org/ExtUtils/MakeMaker.html#make-install
sub inst_lib {
my ($mm) = @_;
warn "Installing as a ", $mm->{INSTALLDIRS}, " module\n"
unless $reported; $reported = 1;
return '$(INSTALLARCHLIB)' if $mm->{INSTALLDIRS} eq "perl";
return '$(INSTALLSITEARCH)' if $mm->{INSTALLDIRS} eq "site";
return '$(INSTALLVENDORLIB)' if $mm->{INSTALLDIRS} eq "vendor";
die "invalid INSTALLDIRS setting, abort";
}


sub compile_lib {
my ($mm, $name) = @_;
my @args = (
Expand All @@ -591,7 +585,7 @@ sub compile_lib {
# add explicit path to libsass lib
# needed to resolve lib from plugins
unless ($^O eq 'MSWin32' && $Config{cc} =~ /^cl/) {
push @args, '-Wl,-rpath,' . inst_lib($mm);
push @args, '-Wl,-rpath,\\$$ORIGIN/../..';
}
# -static-libgcc -static-libstdc++
return join(' ', @args, @libs);
Expand All @@ -614,10 +608,10 @@ sub libsass_sassc
else {
# create the sassc executable by linking against sassc and libsass
push @ret, "\t" . '$(LD) -o $(SASSC_EXE) $(LDFLAGS) $(SASSC_OBJ) $(LIBS)'
. ' ' . ($static ? '$(LIBSASS_OBJ)' : '-L$(INST_ARCHLIB) -lsass')
. ' ' . ($static ? '$(LIBSASS_OBJ)' : '-L$(INST_ARCHAUTODIR) -lsass -lstdc++')
. ' $(OPTIMIZE) -lstdc++ -std=c++0x ' . join(" ", @libs)
. ($^O eq "linux" ? ' -ldl' : '')
. ' -Wl,-rpath,' . inst_lib($_[0]);
. ' -Wl,-rpath,$(INST_ARCHAUTODIR)';
}
# add target to virtual "pure_all"
push @cleanups, '$(SASSC_OBJ)';
Expand All @@ -632,7 +626,7 @@ sub libsass_lib
# register our source and object files
my @ret = 'LIBSASS_OBJ = ' . join(" ", @SOURCES);
# location of the created object
push @ret, 'LIBSASS_LIB = $(INST_ARCHLIB)/libsass.$(SO)';
push @ret, 'LIBSASS_LIB = $(INST_ARCHAUTODIR)/libsass.$(SO)';
# create the target for the makefile
push @ret, '$(LIBSASS_LIB): $(LIBSASS_OBJ)';
# create the libsass shared library by linking against all objects
Expand All @@ -656,7 +650,7 @@ sub libsass_plugin_math
push @ret, "\t" . '$(MKPATH) $(INST_ARCHAUTODIR)/plugins/math';
# create the libsass shared library by linking against all objects
push @ret, "\t" . compile_lib($_[0], '$(MATH_LIB)') . ' $(MATH_OBJ)'
. ' ' . ($static ? '$(LIBSASS_OBJ)' : '-L$(INST_ARCHLIB) -lsass');
. ' ' . ($static ? '$(LIBSASS_OBJ)' : '-L$(INST_ARCHAUTODIR) -lsass -lstdc++');
# add target to virtual "pure_all"
push @cleanups, '$(MATH_OBJ)';
push @cleanups, '$(MATH_LIB)';
Expand All @@ -676,7 +670,7 @@ sub libsass_plugin_img_size
push @ret, "\t" . '$(MKPATH) $(INST_ARCHAUTODIR)/plugins/img-size';
# create the libsass shared library by linking against all objects
push @ret, "\t" . compile_lib($_[0], '$(IMG_SIZE_LIB)') . ' $(IMG_SIZE_OBJ)'
. ' ' . ($static ? '$(LIBSASS_OBJ)' : '-L$(INST_ARCHLIB) -lsass');
. ' ' . ($static ? '$(LIBSASS_OBJ)' : '-L$(INST_ARCHAUTODIR) -lsass -lstdc++');
# add target to virtual "pure_all"
push @cleanups, '$(IMG_SIZE_OBJ)';
push @cleanups, '$(IMG_SIZE_LIB)';
Expand All @@ -701,7 +695,7 @@ sub libsass_plugin_digest
push @ret, "\t" . '$(MKPATH) $(INST_ARCHAUTODIR)/plugins/digest';
# create the libsass shared library by linking against all objects
push @ret, "\t" . compile_lib($_[0], '$(DIGEST_LIB)') . ' $(DIGEST_OBJ)'
. ' ' . ($static ? '$(LIBSASS_OBJ)' : '-L$(INST_ARCHLIB) -lsass');
. ' ' . ($static ? '$(LIBSASS_OBJ)' : '-L$(INST_ARCHAUTODIR) -lsass -lstdc++');
# add target to virtual "pure_all"
push @cleanups, '$(DIGEST_OBJ)';
push @cleanups, '$(DIGEST_LIB)';
Expand All @@ -726,7 +720,7 @@ sub libsass_plugin_glob
push @ret, "\t" . '$(MKPATH) $(INST_ARCHAUTODIR)/plugins/glob';
# create the libsass shared library by linking against all objects
push @ret, "\t" . compile_lib($_[0], '$(GLOB_LIB)') . ' $(GLOB_OBJ)'
. ' ' . ($static ? '$(LIBSASS_OBJ)' : '-L$(INST_ARCHLIB) -lsass');
. ' ' . ($static ? '$(LIBSASS_OBJ)' : '-L$(INST_ARCHAUTODIR) -lsass -lstdc++');
# add target to virtual "pure_all"
push @cleanups, '$(GLOB_OBJ)';
push @cleanups, '$(GLOB_LIB)';
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Installation
------------

[![Build Status](https://travis-ci.org/sass/perl-libsass.svg?branch=master)](https://travis-ci.org/sass/perl-libsass)
[![Build status](https://ci.appveyor.com/api/projects/status/wg7joe46resvh1ow/branch/master?svg=true)](https://ci.appveyor.com/project/sass/perl-libsass/branch/master)
[![Coverage Status](https://img.shields.io/coveralls/sass/perl-libsass.svg)](https://coveralls.io/r/sass/perl-libsass?branch=master)
[![CPAN version](https://badge.fury.io/pl/CSS-Sass.svg)](http://badge.fury.io/pl/CSS-Sass)

Expand Down
15 changes: 15 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cache:
- C:\strawberry

install:
- if not exist "C:\strawberry" choco install strawberryperl -y
- set PATH=C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\strawberry\perl\bin;%PATH%
- cd %APPVEYOR_BUILD_FOLDER%
- cpanm --quiet --installdeps --with-develop --notest .

build_script:
- perl Makefile.PL
- gmake

test_script:
- gmake test
40 changes: 33 additions & 7 deletions lib/CSS/Sass.pm
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ our $VERSION = "3.4.11";

require XSLoader;
XSLoader::load('CSS::Sass', $VERSION);
use CSS::Sass::Plugins qw(@ppaths);
require CSS::Sass::Value;

sub new
Expand Down Expand Up @@ -151,33 +152,56 @@ my $normalize_options = sub
return $options;
};

# install the fix right before calling libsass
# make sure you local'd the env variable before
my $fix_lib_loading = sub {
# only do work on windows
return if $^O ne 'MSWin32';
# get path to our own module file
# libsass will be near somewhere
my $rpath = $INC{"CSS/Sass.pm"};
die "Module path not found" unless $rpath;
# normalize all slashes
$rpath =~ s/[\\\/]+/\//g;
# remove our own file from path
$rpath =~ s/CSS\/Sass\.pm$//;
# remove perl path parts
$rpath =~ s/(?:b?lib\/+)+//g;
# remove trailing slash
$rpath =~ s/[\\\/]+$//g;
# find lib and add path for loader
map { $ENV{'PATH'} .= ';' . $_ }
grep { -f join '/', $_, 'libsass.dll' }
map { join '/', $rpath, $_, 'CSS/Sass' }
@ppaths; # imported from plugins module
};

sub sass_compile
{
local $ENV{'PATH'};
$fix_lib_loading->();
my ($sass_code, %options) = @_;
no warnings 'uninitialized';
$normalize_options->(\%options);
my $r = compile_sass($sass_code, \%options);
# decode the streams (maybe move directly to XS code)
#utf8::decode($r->{output_string}) if defined $r->{output_string};
#utf8::decode($r->{output_string}) if defined $r->{output_string};
#utf8::decode($r->{error_message}) if defined $r->{error_message};
wantarray ? ($r->{output_string}, $r->{error_message}, $r) : $r->{output_string}
}

sub sass_compile_file
{
local $ENV{'PATH'};
$fix_lib_loading->();
my ($input_path, %options) = @_;
no warnings 'uninitialized';
$normalize_options->(\%options);
my $r = compile_sass_file($input_path, \%options);
# decode the streams (maybe move directly to XS code)
#utf8::decode($r->{output_string}) if defined $r->{output_string};
#utf8::decode($r->{error_message}) if defined $r->{error_message};
wantarray ? ($r->{output_string}, $r->{error_message}, $r) : $r->{output_string}
}

sub compile
{
local $ENV{'PATH'};
$fix_lib_loading->();
my ($self, $sass_code) = @_;
my ($compiled, $stats);
($compiled, $self->{last_error}, $stats) = sass_compile($sass_code, %{$self->options});
Expand All @@ -187,6 +211,8 @@ sub compile

sub compile_file
{
local $ENV{'PATH'};
$fix_lib_loading->();
my ($self, $sass_file) = @_;
my ($compiled, $stats);
($compiled, $self->{last_error}, $stats) = sass_compile_file($sass_file, %{$self->options});
Expand Down
69 changes: 51 additions & 18 deletions lib/CSS/Sass/Plugins.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,61 @@ our $VERSION = "3.4.11";
# collect plugins
our %plugins;
################################################################################
# all plugin directory variants
# propably too many, check-a-lot
our @ppaths = (
'arch',
'arch/auto',
'arch/auto/lib',
'blib',
'blib/auto',
'blib/auto/arch',
'blib/arch',
'blib/arch/auto',
'blib/lib',
'blib/lib/arch',
'blib/lib/arch/auto',
'lib',
'lib/arch',
'lib/arch/auto',
'lib/auto',
);
################################################################################
use Exporter 'import'; # gives you Exporter's import() method directly
our @EXPORT = qw(%plugins); # symbols to export by default
our @EXPORT = qw(%plugins @ppaths); # symbols to export by default
################################################################################

# prefix to append to root path
my $path = '/auto/CSS/Sass/plugins/';
# get our own path for module file
# we asume plugin path from install
my $root = $INC{'CSS/Sass/Plugins.pm'};
die "Module path not found" unless $root;
# only interested in base path
$root = substr($root, 0, -20) . $path;
# silently ignore missing directory
return \%plugins unless -d $root;
# open plugins directory to query
opendir (my $dh, $root) or
die "error querying plugins";
while (my $item = readdir($dh)) {
next unless $item =~ m/^[a-zA-Z\-]+$/;
$plugins{$item} = $root . $item
foreach my $path (map {
$_ . '/CSS/Sass/plugins'
} @ppaths) {
# get our own path for module file
# we asume plugin path from install
my $rpath = $INC{'CSS/Sass/Plugins.pm'};
die "Module path not found" unless $rpath;
# normalize all slashes
$rpath =~ s/[\\\/]+/\//g;
# remove our own file from path
$rpath =~ s/CSS\/Plugins\.pm$//;
# remove perl path parts
$rpath =~ s/(?:b?lib\/+)+//g;
# remove trailing slash
$rpath =~ s/[\\\/]+$//g;
# only interested in base path
$rpath = $rpath . $path;
# silently ignore missing directory
next unless -d $rpath;
# open plugins directory to query
opendir (my $dh, $rpath) or
die "error querying plugins";
while (my $item = readdir($dh)) {
next unless $item =~ m/^[a-zA-Z\-]+$/;
$plugins{$item} = $rpath . $item
}

}

return \%plugins;

################################################################################
################################################################################
1;
1;
2 changes: 1 addition & 1 deletion plugins/img-size
Submodule img-size updated 2 files
+3 −3 README.md
+6 −2 src/img-size.cpp

0 comments on commit 2e3cc2f

Please sign in to comment.