Merge pull request #16122 from ericbmerritt/feature/beam-package-improvements

Feature/beam package improvements
This commit is contained in:
Joachim Fasting 2016-06-15 20:27:41 +02:00 committed by GitHub
commit 605c08d223
12 changed files with 15660 additions and 6055 deletions

View file

@ -1,4 +1,4 @@
{ stdenv, writeText, erlang, perl, which, gitMinimal, wget }:
{ stdenv, writeText, erlang, perl, which, gitMinimal, wget, lib }:
{ name, version
, src
@ -8,12 +8,17 @@
, postPatch ? ""
, compilePorts ? false
, installPhase ? null
, buildPhase ? null
, configurePhase ? null
, meta ? {}
, enableDebugInfo ? false
, ... }@attrs:
with stdenv.lib;
let
debugInfoFlag = lib.optionalString (enableDebugInfo || erlang.debugInfo) "+debug_info";
shell = drv: stdenv.mkDerivation {
name = "interactive-shell-${drv.name}";
buildInputs = [ drv ];
@ -37,7 +42,8 @@ let
buildInputs = [ erlang perl which gitMinimal wget ];
propagatedBuildInputs = beamDeps;
configurePhase = ''
configurePhase = if configurePhase == null
then ''
runHook preConfigure
# We shouldnt need to do this, but it seems at times there is a *.app in
@ -45,17 +51,21 @@ let
make SKIP_DEPS=1 clean
runHook postConfigure
'';
''
else configurePhase;
buildPhase = ''
buildPhase = if buildPhase == null
then ''
runHook preBuild
make SKIP_DEPS=1
make SKIP_DEPS=1 ERL_OPTS="$ERL_OPTS ${debugInfoFlag}"
runHook postBuild
'';
''
else buildPhase;
installPhase = ''
installPhase = if installPhase == null
then ''
runHook preInstall
mkdir -p $out/lib/erlang/lib/${name}
@ -75,7 +85,8 @@ let
fi
runHook postInstall
'';
''
else installPhase;
passthru = {
packageName = name;

View file

@ -1,4 +1,4 @@
{ stdenv, writeText, elixir, erlang, hexRegistrySnapshot, hex }:
{ stdenv, writeText, elixir, erlang, hexRegistrySnapshot, hex, lib }:
{ name
, version
@ -8,12 +8,19 @@
, beamDeps ? []
, postPatch ? ""
, compilePorts ? false
, installPhase ? null
, buildPhase ? null
, configurePhase ? null
, meta ? {}
, enableDebugInfo ? false
, ... }@attrs:
with stdenv.lib;
let
debugInfoFlag = lib.optionalString (enableDebugInfo || elixir.debugInfo) "--debug-info";
shell = drv: stdenv.mkDerivation {
name = "interactive-shell-${drv.name}";
buildInputs = [ drv ];
@ -38,25 +45,31 @@ let
inherit buildInputs;
propagatedBuildInputs = [ hexRegistrySnapshot hex elixir ] ++ beamDeps;
configurePhase = ''
configurePhase = if configurePhase == null
then ''
runHook preConfigure
${erlang}/bin/escript ${bootstrapper}
runHook postConfigure
'';
''
else configurePhase ;
buildPhase = ''
buildPhase = if buildPhase == null
then ''
runHook preBuild
export HEX_OFFLINE=1
export HEX_HOME=`pwd`
export MIX_ENV=prod
MIX_ENV=prod mix compile --debug-info --no-deps-check
MIX_ENV=prod mix compile ${debugInfoFlag} --no-deps-check
runHook postBuild
'';
''
else buildPhase;
installPhase = ''
installPhase = if installPhase == null
then ''
runHook preInstall
MIXENV=prod
@ -74,7 +87,8 @@ let
done
runHook postInstall
'';
''
else installPhase;
passthru = {
packageName = name;

View file

@ -1,5 +1,5 @@
{ stdenv, writeText, erlang, rebar3, openssl, libyaml,
pc, buildEnv }:
pc, buildEnv, lib }:
{ name, version
, src
@ -8,12 +8,17 @@
, postPatch ? ""
, compilePorts ? false
, installPhase ? null
, buildPhase ? null
, configurePhase ? null
, meta ? {}
, enableDebugInfo ? false
, ... }@attrs:
with stdenv.lib;
let
debugInfoFlag = lib.optionalString (enableDebugInfo || erlang.debugInfo) "debug-info";
ownPlugins = buildPlugins ++ (if compilePorts then [pc] else []);
shell = drv: stdenv.mkDerivation {
@ -46,20 +51,24 @@ let
rm -f rebar rebar3
'';
configurePhase = ''
configurePhase = if configurePhase == null
then ''
runHook preConfigure
${erlang}/bin/escript ${rebar3.bootstrapper}
${erlang}/bin/escript ${rebar3.bootstrapper} ${debugInfoFlag}
runHook postConfigure
'';
''
else configurePhase;
buildPhase = ''
buildPhase = if buildPhase == null
then ''
runHook preBuild
HOME=. rebar3 compile
${if compilePorts then ''
HOME=. rebar3 pc compile
'' else ''''}
runHook postBuild
'';
''
else installPhase;
installPhase = if installPhase == null
then ''

View file

@ -10,7 +10,7 @@ stdenv.mkDerivation ({
name = "hex-source-${pkg}-${version}";
src = fetchurl {
url = "https://s3.amazonaws.com/s3.hex.pm/tarballs/${pkg}-${version}.tar";
url = "https://repo.hex.pm/tarballs/${pkg}-${version}.tar";
inherit sha256;
};

File diff suppressed because it is too large Load diff

View file

@ -2,14 +2,14 @@
stdenv.mkDerivation rec {
name = "hex-registry";
rev = "59b836d";
rev = "d58a937";
version = "0.0.0+build.${rev}";
src = fetchFromGitHub {
owner = "erlang-nix";
repo = "hex-pm-registry-snapshots";
inherit rev;
sha256 = "1l8m6ckn5ivhfiv3k4dymi6b7wg511fwymnpxd6ymfd39dq0n5b0";
sha256 = "11ymmn75qjlhzf7aaza708gq0hqg55dzd3q13npgq43wg90rgpxy";
};
installPhase = ''

View file

@ -21,6 +21,8 @@ stdenv.mkDerivation rec {
setupHook = ./setup-hook.sh;
inherit debugInfo;
buildFlags = if debugInfo
then "ERL_COMPILER_OPTIONS=debug_info"
else "";

View file

@ -1,7 +1,8 @@
{ stdenv, fetchurl, perl, gnum4, ncurses, openssl
, gnused, gawk, makeWrapper
, odbcSupport ? false, unixODBC ? null
, wxSupport ? false, mesa ? null, wxGTK ? null, xorg ? null }:
, wxSupport ? false, mesa ? null, wxGTK ? null, xorg ? null
, enableDebugInfo ? false }:
assert wxSupport -> mesa != null && wxGTK != null && xorg != null;
assert odbcSupport -> unixODBC != null;
@ -17,6 +18,8 @@ stdenv.mkDerivation rec {
sha256 = "1rvyfh22g1fir1i4xn7v2md868wcmhajwhfsq97v7kn5kd2m7khp";
};
debugInfo = enableDebugInfo;
buildInputs =
[ perl gnum4 ncurses openssl makeWrapper
] ++ optional wxSupport [ mesa wxGTK xorg.libX11 ]

View file

@ -5,6 +5,7 @@
, wxSupport ? true, mesa ? null, wxGTK ? null, xorg ? null, wxmac ? null
, javacSupport ? false, openjdk ? null
, enableHipe ? true
, enableDebugInfo ? false
}:
assert wxSupport -> (if stdenv.isDarwin
@ -35,6 +36,8 @@ stdenv.mkDerivation rec {
patchPhase = '' sed -i "s@/bin/rm@rm@" lib/odbc/configure erts/configure '';
debugInfo = enableDebugInfo;
preConfigure = ''
export HOME=$PWD/../
sed -e s@/bin/pwd@pwd@g -i otp_build

View file

@ -5,6 +5,7 @@
, wxSupport ? true, mesa ? null, wxGTK ? null, xorg ? null, wxmac ? null
, javacSupport ? false, openjdk ? null
, enableHipe ? true
, enableDebugInfo ? false
}:
assert wxSupport -> (if stdenv.isDarwin
@ -33,6 +34,8 @@ stdenv.mkDerivation rec {
++ optional javacSupport openjdk
++ stdenv.lib.optionals stdenv.isDarwin [ Carbon Cocoa ];
debugInfo = enableDebugInfo;
patchPhase = '' sed -i "s@/bin/rm@rm@" lib/odbc/configure erts/configure '';
preConfigure = ''

View file

@ -26,6 +26,7 @@
-record(data, {version
, registry_only = false
, debug_info = false
, compile_ports
, erl_libs
, plugins
@ -54,21 +55,29 @@ do_the_bootstrap(RequiredData) ->
%% @doc
%% Argument parsing is super simple only because we want to keep the
%% dependencies minimal. For now there can be two entries on the
%% command line, "registery-only"
%% command line, "registery-only" and "debug-info"
-spec parse_args([string()]) -> #data{}.
parse_args(["registry-only"]) ->
{ok, #data{registry_only = true}};
parse_args([]) ->
{ok, #data{registry_only = false}};
parse_args(Args) ->
io:format("Unexpected command line arguments passed in: ~p~n", [Args]),
erlang:halt(120).
parse_args(Args0) ->
PossibleArgs = sets:from_list(["registry-only", "debug-info"]),
Args1 = sets:from_list(Args0),
Result = sets:subtract(Args1, PossibleArgs),
case sets:to_list(Result) of
[] ->
{ok, #data{registry_only = sets:is_element("registry-only", Args1),
debug_info = sets:is_element("debug-info", Args1)}};
UnknownArgs ->
io:format("Unexpected command line arguments passed in: ~p~n",
[UnknownArgs]),
erlang:halt(120)
end.
-spec bootstrap_configs(#data{}) -> ok.
bootstrap_configs(RequiredData)->
io:format("Boostrapping app and rebar configurations~n"),
ok = if_single_app_project_update_app_src_version(RequiredData),
ok = if_compile_ports_add_pc_plugin(RequiredData).
ok = if_compile_ports_add_pc_plugin(RequiredData),
ok = if_debug_info_add(RequiredData).
-spec bootstrap_plugins(#data{}) -> ok.
bootstrap_plugins(#data{plugins = Plugins}) ->
@ -198,6 +207,33 @@ guard_env(Name) ->
Variable
end.
%% @doc
%% If debug info is set we need to add debug info to the list of compile options
%%
-spec if_debug_info_add(#data{}) -> ok.
if_debug_info_add(#data{debug_info = true}) ->
ConfigTerms = add_debug_info(read_rebar_config()),
Text = lists:map(fun(Term) -> io_lib:format("~tp.~n", [Term]) end,
ConfigTerms),
file:write_file("rebar.config", Text);
if_debug_info_add(_) ->
ok.
-spec add_debug_info([term()]) -> [term()].
add_debug_info(Config) ->
ExistingOpts = case lists:keysearch(erl_opts, 1, Config) of
{value, {erl_opts, ExistingOptsList}} -> ExistingOptsList;
_ -> []
end,
case lists:member(debug_info, ExistingOpts) of
true ->
Config;
false ->
lists:keystore(erl_opts, 1, Config,
{erl_opts, [debug_info | ExistingOpts]})
end.
%% @doc
%% If the compile ports flag is set, rewrite the rebar config to
%% include the 'pc' plugin.
@ -213,7 +249,7 @@ if_compile_ports_add_pc_plugin(_) ->
-spec add_pc_to_plugins([term()]) -> [term()].
add_pc_to_plugins(Config) ->
PluginList = case lists:keysearch(plugins, 1, Config) of
{ok, {plugins, ExistingPluginList}} -> ExistingPluginList;
{value, {plugins, ExistingPluginList}} -> ExistingPluginList;
_ -> []
end,
lists:keystore(plugins, 1, Config, {plugins, [pc | PluginList]}).

View file

@ -1,23 +0,0 @@
{stdenv, writeText, fetchFromGitHub }:
stdenv.mkDerivation rec {
name = "hex-registry";
rev = "329ae2b";
version = "0.0.0+build.${rev}";
src = fetchFromGitHub {
owner = "erlang-nix";
repo = "hex-pm-registry-snapshots";
inherit rev;
sha256 = "1rs3z8psfvy10mzlfvkdzbflgikcnq08r38kfi0f8p5wvi8f8hmh";
};
installPhase = ''
mkdir -p "$out/var/hex"
zcat "registry.ets.gz" > "$out/var/hex/registry.ets"
'';
setupHook = writeText "setupHook.sh" ''
export HEX_REGISTRY_SNAPSHOT="$1/var/hex/registry.ets"
'';
}