Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Set compilation flags automatically according to OTP version

  • Loading branch information...
commit b831cbd6f2b0fa550e08eee44c6be28223520244 1 parent 1118a4f
@manopapad authored
View
1  .gitignore
@@ -8,5 +8,6 @@ doc/*.html
doc/*.css
doc/*.png
doc/edoc-info
+include/compile_flags.hrl
.directory
.eunit
View
27 Makefile
@@ -20,29 +20,25 @@
# Author: Manolis Papadakis
# Description: Instructions for make
-.PHONY: default all compile dialyze check_scripts tests doc clean distclean rebuild retest
+.PHONY: default all compile dialyze check_escripts tests doc clean distclean rebuild retest
default: compile
all: compile doc
-compile:
+include/compile_flags.hrl:
+ ./write_compile_flags $@
+
+compile: include/compile_flags.hrl
./rebar compile
dialyze: compile
./rebar dialyze
-check_scripts:
- @> make_doc.erl
- @echo "-module(make_doc)." >> make_doc.erl
- @echo "-export([main/1])." >> make_doc.erl
- @echo -n "%" >> make_doc.erl
- @cat make_doc >> make_doc.erl
- erlc +debug_info make_doc.erl; true
- dialyzer -Wunmatched_returns make_doc.beam; true
- @rm -f make_doc.erl make_doc.beam
-
-tests:
+check_escripts:
+ ./check_escripts.sh make_doc write_compile_flags
+
+tests: compile
./rebar eunit
doc:
@@ -54,10 +50,9 @@ clean:
distclean: clean
./rebar clean
-rebuild:
- ./rebar clean
+rebuild: distclean include/compile_flags.hrl
./rebar compile
-retest:
+retest: compile
rm -rf .eunit
./rebar eunit
View
9 README.md
@@ -119,15 +119,6 @@ The main issue is that both systems define a `?LET` macro. To avoid a potential
clash, simply include PropEr's header file before EUnit's. That way, any
instance of `?LET` will count as a PropEr `?LET`.
-### Using PropEr under Erlang/OTP R13B03 or older
-
-PropEr makes heavy use of recursive types, which are unsupported on versions of
-the Erlang/OTP distribution prior to R13B04. To compile PropEr on such a system,
-add `{d,'NO_TYPES'}` to the `erl_opts` option inside `rebar.config`. This
-enables the spec+type-stripping parse transform included in PropEr, which fixes
-the problem by stripping all type information from PropEr's source files during
-compilation.
-
Incompatibilities with QuviQ's QuickCheck
-----------------------------------------
View
36 check_escripts.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+
+# Copyright 2010-2011 Manolis Papadakis <manopapad@gmail.com>,
+# Eirini Arvaniti <eirinibob@gmail.com>
+# and Kostis Sagonas <kostis@cs.ntua.gr>
+#
+# This file is part of PropEr.
+#
+# PropEr is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# PropEr is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with PropEr. If not, see <http://www.gnu.org/licenses/>.
+
+# Author: Manolis Papadakis
+# Description: Script for testing the validity of escript files
+
+for ESCRIPT_NAME in "$@"; do
+ SRC_FILE="$ESCRIPT_NAME".erl
+ BIN_FILE="$ESCRIPT_NAME".beam
+ > $SRC_FILE
+ echo "-module($ESCRIPT_NAME)." >> $SRC_FILE
+ echo "-export([main/1])." >> $SRC_FILE
+ echo -n "%" >> $SRC_FILE
+ cat $ESCRIPT_NAME >> $SRC_FILE
+ erlc +debug_info $SRC_FILE; true
+ dialyzer -Wunmatched_returns $BIN_FILE; true
+ rm -f $SRC_FILE $BIN_FILE
+done
View
2  clean_doc.sh
@@ -1,4 +1,4 @@
-#! /bin/sh
+#!/bin/sh
# Copyright 2010-2011 Manolis Papadakis <manopapad@gmail.com>,
# Eirini Arvaniti <eirinibob@gmail.com>
View
8 clean_temp.sh
@@ -1,4 +1,4 @@
-#! /bin/sh
+#!/bin/sh
# Copyright 2010-2011 Manolis Papadakis <manopapad@gmail.com>,
# Eirini Arvaniti <eirinibob@gmail.com>
@@ -22,8 +22,4 @@
# Author: Manolis Papadakis
# Description: Cleanup script for temporary files
-DIRS=.\ `ls -l | grep '^d' | awk '{print $8}'`
-
-for d in $DIRS; do
- rm -f $d/*~ $d/#*# $d/*.dump
-done
+find . \( -name '*~' -or -name '#*#' -or -name '*.dump' \) -delete
View
1  include/proper_internal.hrl
@@ -23,6 +23,7 @@
%%% @doc Internal header file: This header is included in all PropEr source
%%% files.
+-include("compile_flags.hrl").
-include("proper_common.hrl").
View
1  make_doc
@@ -1,4 +1,5 @@
#!/usr/bin/env escript
+
%%% Copyright 2010-2011 Manolis Papadakis <manopapad@gmail.com>,
%%% Eirini Arvaniti <eirinibob@gmail.com>
%%% and Kostis Sagonas <kostis@cs.ntua.gr>
View
3  rebar.config
@@ -23,9 +23,6 @@
%% WARNING: Our version of rebar doesn't automatically report warnings,
%% nor does it add erl_opts to eunit_compile_opts.
-%% WARNING: To compile on versions of Erlang/OTP older than R13B4, add
-%% {d,'NO_TYPES'} to erl_opts.
-
{erl_first_files, ["src/strip_types.erl", "src/vararg.erl"]}.
{eunit_first_files, ["src/strip_types.erl", "src/vararg.erl",
"src/proper_transformer.erl",
View
27 src/proper.erl
@@ -507,11 +507,12 @@
-type exc_kind() :: 'throw' | 'error' | 'exit'.
-type exc_reason() :: term().
-type stacktrace() :: [call_record()].
--type call_record() :: %% prior to R15B:
- {mod_name(),fun_name(),arity() | list()}
- %% R15B onwards:
- | {mod_name(),fun_name(),arity() | list(),location()}.
+-ifdef(OLD_STACKTRACE_FORMAT).
+-type call_record() :: {mod_name(),fun_name(),arity() | list()}.
+-else.
+-type call_record() :: {mod_name(),fun_name(),arity() | list(),location()}.
-type location() :: [{atom(),term()}].
+-endif.
-type error_reason() :: 'arity_limit' | 'cant_generate' | 'cant_satisfy'
| 'non_boolean_result' | 'rejected' | 'too_many_instances'
| 'type_mismatch' | 'wrong_type' | {'typeserver',term()}
@@ -1362,10 +1363,13 @@ clear_mailbox() ->
end.
-spec threw_exception(function(), stacktrace()) -> boolean().
-threw_exception(Fun, [{TopMod,TopName,TopArgs} | _Rest]) -> % prior to R15B
- threw_exception_aux(Fun, TopMod, TopName, TopArgs);
-threw_exception(Fun, [{TopMod,TopName,TopArgs,_Location} | _Rest]) -> % R15B
+-ifdef(OLD_STACKTRACE_FORMAT).
+threw_exception(Fun, [{TopMod,TopName,TopArgs} | _Rest]) ->
threw_exception_aux(Fun, TopMod, TopName, TopArgs).
+-else.
+threw_exception(Fun, [{TopMod,TopName,TopArgs,_Location} | _Rest]) ->
+ threw_exception_aux(Fun, TopMod, TopName, TopArgs).
+-endif.
-spec threw_exception_aux(function(), mod_name(), fun_name(),
arity() | list()) -> boolean().
@@ -1385,10 +1389,13 @@ clean_stacktrace(RawTrace) ->
Trace.
-spec is_not_proper_call(call_record()) -> boolean().
-is_not_proper_call({Mod,_Fun,_Args}) -> % for versions prior to R15B
- not lists:prefix("proper", atom_to_list(Mod));
-is_not_proper_call({Mod,_Fun,_Args,_Location}) -> % R15B onwards
+-ifdef(OLD_STACKTRACE_FORMAT).
+is_not_proper_call({Mod,_Fun,_Args}) ->
+ not lists:prefix("proper", atom_to_list(Mod)).
+-else.
+is_not_proper_call({Mod,_Fun,_Args,_Location}) ->
not lists:prefix("proper", atom_to_list(Mod)).
+-endif.
-spec clean_testcase(imm_testcase()) -> counterexample().
clean_testcase(ImmTestCase) ->
View
49 write_compile_flags
@@ -0,0 +1,49 @@
+#!/usr/bin/env escript
+
+%%% Copyright 2010-2011 Manolis Papadakis <manopapad@gmail.com>,
+%%% Eirini Arvaniti <eirinibob@gmail.com>
+%%% and Kostis Sagonas <kostis@cs.ntua.gr>
+%%%
+%%% This file is part of PropEr.
+%%%
+%%% PropEr is free software: you can redistribute it and/or modify
+%%% it under the terms of the GNU General Public License as published by
+%%% the Free Software Foundation, either version 3 of the License, or
+%%% (at your option) any later version.
+%%%
+%%% PropEr is distributed in the hope that it will be useful,
+%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
+%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+%%% GNU General Public License for more details.
+%%%
+%%% You should have received a copy of the GNU General Public License
+%%% along with PropEr. If not, see <http://www.gnu.org/licenses/>.
+
+%%% Author: Manolis Papadakis
+%%% Description: Compilation environment setup script: This script computes and
+%%% prints out the correct set of compilation flags for the
+%%% currently running version of the OTP.
+
+-spec main([file:filename(),...]) -> 'ok'.
+main([OutFile]) ->
+ CurrVer = parse_version_string(erlang:system_info(version)),
+ {ok,Handle} = file:open(OutFile, [write]),
+ ToDefine =
+ %% older than R15B => no location information in stacktraces
+ case CurrVer < [5,9] of
+ true -> ["OLD_STACKTRACE_FORMAT"];
+ false -> []
+ end ++
+ %% older than R13B04 => can't handle recursive type declarations
+ case CurrVer < [5,7,5] of
+ true -> ["NO_TYPES"];
+ false -> []
+ end,
+ lists:foreach(fun(X) -> io:format(Handle, "-define(~s, 1).~n", [X]) end,
+ ToDefine),
+ ok = file:close(Handle),
+ ok.
+
+-spec parse_version_string(string()) -> [non_neg_integer()].
+parse_version_string(VerStr) ->
+ [list_to_integer(S) || S <- string:tokens(VerStr, ".")].
Please sign in to comment.
Something went wrong with that request. Please try again.