Skip to content

Commit

Permalink
Merge pull request #81 from mgreter/feature/query-compiled-versions
Browse files Browse the repository at this point in the history
Implement API to fetch compiled version
  • Loading branch information
mgreter committed Dec 8, 2014
2 parents 9bdb4df + 6b33441 commit bbbac5d
Show file tree
Hide file tree
Showing 6 changed files with 240 additions and 19 deletions.
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ compiler:
env:
- AUTOTOOLS=no BUILD=shared
- AUTOTOOLS=no BUILD=static
- AUTOTOOLS=yes BUILD=shared
- AUTOTOOLS=yes BUILD=static

before_install:
- gem install sass
Expand All @@ -15,4 +17,8 @@ before_install:
- export SASS_LIBSASS_PATH=libsass

script:
- make test
- ./script/ci-build-libsass

after_success:
- ./bin/sassc -v
- ldd ./bin/sassc
66 changes: 51 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,32 +1,67 @@
CC ?= gcc
CFLAGS = -Wall -O2 -I $(SASS_LIBSASS_PATH) $(EXTRA_CFLAGS)
LDFLAGS = -O2 $(EXTRA_LDFLAGS)
CC ?= cc
CXX ?= g++
RM ?= rm -f
MKDIR ?= mkdir -p
CFLAGS ?= -Wall -fPIC -O2
CXXFLAGS ?= -Wall -fPIC -O2
LDFLAGS ?= -Wall -fPIC -O2

ifeq "$(SASSC_VERSION)" ""
ifneq "$(wildcard ./.git/ )" ""
SASSC_VERSION = $(shell git describe --abbrev=4 --dirty --always --tags)
endif
endif

ifneq "$(SASSC_VERSION)" ""
CFLAGS += -DSASSC_VERSION="\"$(SASSC_VERSION)\""
CXXFLAGS += -DSASSC_VERSION="\"$(SASSC_VERSION)\""
endif

# enable mandatory flag
CXXFLAGS += -std=c++0x
LDFLAGS += -std=c++0x

ifneq "$(SASS_LIBSASS_PATH)" ""
CFLAGS += -I $(SASS_LIBSASS_PATH)
CXXFLAGS += -I $(SASS_LIBSASS_PATH)
endif

ifneq "$(EXTRA_CFLAGS)" ""
CFLAGS += $(EXTRA_CFLAGS)
endif
ifneq "$(EXTRA_CXXFLAGS)" ""
CXXFLAGS += $(EXTRA_CXXFLAGS)
endif
ifneq "$(EXTRA_LDFLAGS)" ""
LDFLAGS += $(EXTRA_LDFLAGS)
endif

ifneq (,$(findstring /cygdrive/,$(PATH)))
UNAME := Cygwin
else
ifneq (,$(findstring WINDOWS,$(PATH)))
UNAME := Windows
else
UNAME := $(shell uname -s)
endif
ifneq (,$(findstring WINDOWS,$(PATH)))
UNAME := Windows
else
UNAME := $(shell uname -s)
endif
endif

LDLIBS = -lstdc++ -lm
ifeq ($(UNAME),Darwin)
LDLIBS = -lstdc++ -lm -stdlib=libc++
else
LDLIBS = -lstdc++ -lm
CFLAGS += -stdlib=libc++
CXXFLAGS += -stdlib=libc++
LDFLAGS += -stdlib=libc++
endif

ifneq ($(BUILD), shared)
BUILD = static
endif

SOURCES = sassc.c
OBJECTS = $(SOURCES:.c=.o)
TARGET = bin/sassc
SPEC_PATH = $(SASS_SPEC_PATH)

ifneq ($(BUILD), shared)
BUILD = static
endif

all: libsass $(TARGET)

$(TARGET): build-$(BUILD)
Expand Down Expand Up @@ -61,6 +96,7 @@ endif

test: all
bin/sassc -h
bin/sassc -v

clean:
rm -f $(OBJECTS) $(TARGET)
Expand Down
25 changes: 23 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
ACLOCAL_AMFLAGS = -I m4

AM_LDFLAGS =
AM_CFLAGS = -Wall -fPIC
AM_CXXFLAGS = -Wall -fPIC
AM_CFLAGS += -DSASSC_VERSION="\"$(SASSC_VERSION)\""
AM_CXXFLAGS += -DSASSC_VERSION="\"$(SASSC_VERSION)\""

AM_CXXFLAGS += -std=c++0x
AM_LDFLAGS += -std=c++0x

LDLIBS = -lstdc++ -lm

if ENABLE_COVERAGE
AM_CFLAGS += -O0 --coverage
AM_CXXFLAGS += -O0 --coverage
AM_LDFLAGS += -O0 --coverage -lgcov
else
AM_CFLAGS += -O2
AM_CXXFLAGS += -O2
endif

bin_PROGRAMS = sassc
sassc_SOURCES = sassc.c
sassc_CPPFLAGS = $(LIBSASS_CFLAGS)
sassc_LDFLAGS= $(LIBSASS_LIBS)
sassc_CFLAGS = $(AM_CFLAGS) $(LIBSASS_CFLAGS)
sassc_CXXFLAGS = $(AM_CXXFLAGS) $(LIBSASS_CFLAGS)
sassc_LDFLAGS= $(AM_LDFLAGS) $(LIBSASS_LIBS) $(LDLIBS)
53 changes: 53 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,59 @@ AC_SUBST([LIBSASS_LIBS])

LT_INIT
AC_PROG_CXX

AC_CHECK_HEADERS([sass.h])
AC_CHECK_HEADERS([sass2scss.h])
AC_CHECK_HEADERS([sass_values.h])
AC_CHECK_HEADERS([sass_context.h])
AC_CHECK_HEADERS([sass_functions.h])
AC_CHECK_HEADERS([sass_interface.h])

AC_ARG_ENABLE([coverage],
[AS_HELP_STRING([--enable-coverage],
[enable coverage report for test suite])],
[enable_cov=$enableval],
[enable_cov=no])

if test "x$enable_cov" = "xyes"; then

AC_CHECK_PROG(GCOV, gcov, gcov)

# Remove all optimization flags from C[XX]FLAGS
changequote({,})
CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'`
CXXFLAGS=`echo "$CXXFLAGS" | $SED -e 's/-O[0-9]*//g'`
changequote([,])

AC_SUBST(GCOV)
fi

AM_CONDITIONAL(ENABLE_COVERAGE, test "x$enable_cov" = "xyes")

AC_ARG_VAR(SASSC_VERSION, libsass version)
if test "x$SASSC_VERSION" = "x"; then
AC_CHECK_PROG(GIT, git, git)
if test "x$GIT" = "x"; then
AC_MSG_ERROR([Unable to find git binary to query version.
You can solve this by setting SASSC_VERSION:
# export SASSC_VERSION="x.y.z"
])
else
AC_CHECK_FILE(.git/config, [], [
AC_MSG_ERROR([Unable to find .git directory to query version.
You can solve this by setting SASSC_VERSION:
# export SASSC_VERSION="x.y.z"
])
])
SASSC_VERSION=`$GIT describe --abbrev=4 --dirty --always --tags`
fi
if test "x$SASSC_VERSION" = "x"; then
AC_MSG_ERROR([SASSC_VERSION not defined.
You can solve this by setting SASSC_VERSION:
# export SASSC_VERSION="x.y.z"
])
fi
fi

AC_CONFIG_FILES([Makefile])
AC_OUTPUT
18 changes: 17 additions & 1 deletion sassc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
#include <string.h>
#include <stdlib.h>
#include <getopt.h>
#include <sass2scss.h>
#include <sass_interface.h>

#ifndef SASSC_VERSION
#define SASSC_VERSION "[NA]"
#endif

#define BUFSIZE 512
#ifdef _WIN32
#define PATH_SEP ';'
Expand Down Expand Up @@ -120,6 +125,12 @@ struct
#define NUM_STYLE_OPTION_STRINGS \
sizeof(style_option_strings) / sizeof(style_option_strings[0])

void print_version(char* argv0) {
printf("sassc: %s\n", SASSC_VERSION);
printf("libsass: %s\n", libsass_version());
printf("sass2scss: %s\n", sass2scss_version());
}

void print_usage(char* argv0) {
int i;
printf("Usage: %s [options] [INPUT] [OUTPUT]\n\n", argv0);
Expand All @@ -136,6 +147,7 @@ void print_usage(char* argv0) {
printf(" -m, --sourcemap Emit source map.\n");
printf(" -M, --omit-map-comment Omits the source map url comment.\n");
printf(" -p, --precision Set the precision for numbers.\n");
printf(" -v, --version Display compiled versions.\n");
printf(" -h, --help Display this help message.\n");
printf("\n");
}
Expand Down Expand Up @@ -167,9 +179,10 @@ int main(int argc, char** argv) {
{ "sourcemap", no_argument, 0, 'm' },
{ "omit-map-comment", no_argument, 0, 'M' },
{ "precision", required_argument, 0, 'p' },
{ "version", no_argument, 0, 'v' },
{ "help", no_argument, 0, 'h' }
};
while ((c = getopt_long(argc, argv, "hslmMt:I:", long_options, &long_index)) != -1) {
while ((c = getopt_long(argc, argv, "vhslmMt:I:", long_options, &long_index)) != -1) {
switch (c) {
case 's':
from_stdin = 1;
Expand Down Expand Up @@ -213,6 +226,9 @@ int main(int argc, char** argv) {
options.precision = atoi(optarg); // TODO: make this more robust
if (options.precision < 0) options.precision = 5;
break;
case 'v':
print_version(argv[0]);
return 0;
case 'h':
print_usage(argv[0]);
return 0;
Expand Down
89 changes: 89 additions & 0 deletions script/ci-build-libsass
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/bin/bash

set -e

# script/bootstrap

# export this path right here (was in script/spec before)
export SASS_SASSC_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/../ && pwd )"

# use some defaults if not running under travis ci
if [ "x$TRAVIS_BUILD_DIR" == "x" ]; then export TRAVIS_BUILD_DIR=$(pwd)/build; fi
if [ "x$SASS_LIBSASS_PATH" == "x" ]; then export SASS_SASSC_PATH=$(pwd)/libsass; fi
if [ "x$SASS_SPEC_PATH" == "x" ]; then export SASS_SPEC_PATH=$(pwd)/sass-spec; fi

if [ "x$COVERAGE" == "xyes" ]; then
COVERAGE_OPT="--enable-coverage"
export EXTRA_CFLAGS="-O0 --coverage"
export EXTRA_CXXFLAGS="-O0 --coverage"
export EXTRA_LDFLAGS="-O0 --coverage"
else
COVERAGE_OPT="--disable-coverage"
fi

if [ "x$BUILD" == "xstatic" ]; then
SHARED_OPT="--disable-shared --enable-static"
MAKE_TARGET="static"
else
# Makefile of sassc wants to link to static
SHARED_OPT="--enable-shared --enable-static"
MAKE_TARGET="shared"
fi

MAKE_OPTS="$MAKE_OPTS -j3 V=1"

if [ "x$AUTOTOOLS" == "xyes" ]; then

pushd $SASS_LIBSASS_PATH
echo -en 'travis_fold:start:libsass\r'

autoreconf --force --install
./configure --disable-tests $COVERAGE_OPT \
--disable-silent-rules \
--prefix=$TRAVIS_BUILD_DIR \
${SHARED_OPT}

# always rebuild
make $MAKE_OPTS clean

# install the library
make $MAKE_OPTS install

echo -en 'travis_fold:end:libsass\r'
popd

echo -en 'travis_fold:start:configure\r'
autoreconf --force --install
./configure --enable-tests $COVERAGE_OPT \
--disable-silent-rules \
--with-libsass-include=$SASS_LIBSASS_PATH \
--with-libsass-lib=$TRAVIS_BUILD_DIR/lib \
--prefix=$TRAVIS_BUILD_DIR \
${SHARED_OPT}
echo -en 'travis_fold:end:configure\r'

# always rebuild
make $MAKE_OPTS clean
# does what $BUILD says
make $MAKE_OPTS all

mkdir -p bin
cp -af sassc bin

else

# always rebuild
make $MAKE_OPTS clean

# does what $BUILD says
make $MAKE_OPTS all

# sassc has static as dep
echo make $MAKE_OPTS $SASS_SASSC_PATH/bin/sassc

fi

echo successfully compiled sassc
echo AUTOTOOLS=$AUTOTOOLS COVERAGE=$COVERAGE BUILD=$BUILD

LD_LIBRARY_PATH="$TRAVIS_BUILD_DIR/lib" bin/sassc -v

0 comments on commit bbbac5d

Please sign in to comment.