Skip to content
This repository
Newer
Older
100755 135 lines (118 sloc) 4.512 kb
b4918986 » dizzyd
2009-12-04 Refactor rebar to build a self-contained script
1 #!/usr/bin/env escript
c466076f » tuncer
2011-01-31 Clean up emacs file local variables
2 %% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
fa4b2ee7 » tuncer
2010-02-11 Add emacs and vim file local variables
3 %% ex: ft=erlang ts=4 sw=4 et
b4918986 » dizzyd
2009-12-04 Refactor rebar to build a self-contained script
4
5 main(Args) ->
ffa0cda4 » dizzyd
2009-12-07 Updating bootstrap to embed the build time into a macro that we can p…
6 %% Get a string repr of build time
7 Built = build_time(),
8
27f638b4 » dizzyd
2010-07-28 Add support for embedding git version; make sure to always rebuild re…
9 %% Get a string repr of first matching VCS changeset
e34b7024 » tuncer
2012-08-12 bootstrap: fix and enhance VCS_INFO handling
10 VcsInfo = vcs_info([{hg, ".hg", "hg identify -i", "hg status"},
11 {git, ".git", "git describe --always --tags",
12 "git status -s"}]),
02bc52fc » dizzyd
2010-06-22 Add support for embedding VCS info into the version data
13
ffa0cda4 » dizzyd
2009-12-07 Updating bootstrap to embed the build time into a macro that we can p…
14 %% Check for force=1 flag to force a rebuild
15 case lists:member("force=1", Args) of
16 true ->
8a5eea5e » juranki
2010-08-02 add bat scripts for bootstrap and rebat (windows doesn't understand s…
17 rm("ebin/*.beam");
ffa0cda4 » dizzyd
2009-12-07 Updating bootstrap to embed the build time into a macro that we can p…
18 false ->
e34b7024 » tuncer
2012-08-12 bootstrap: fix and enhance VCS_INFO handling
19 rm("ebin/rebar.beam")
ffa0cda4 » dizzyd
2009-12-07 Updating bootstrap to embed the build time into a macro that we can p…
20 end,
1ea7065b » dizzyd
2010-01-08 Rework how the escript is built so that we can inclue templates
21
465af362 » dizzyd
2010-10-07 Add debug flag to make it easier to get a debug version of rebar
22 %% Add check for debug flag
27019e28 » tuncer
2011-01-10 Fix code clarity in bootstrap
23 DebugFlag = case lists:member("debug", Args) of
24 true -> debug_info;
25 false -> undefined
26 end,
465af362 » dizzyd
2010-10-07 Add debug flag to make it easier to get a debug version of rebar
27
0f24d932 » dizzyd
2012-06-04 Move to major.minor.patch release version; add OTP build version
28 %% Extract the system info of the version of OTP we use to compile rebar
29 OtpInfo = string:strip(erlang:system_info(otp_release), both, $\n),
30
4de9ea55 » matwey
2014-06-05 Add namespaced_types to bootstrap script.
31 %% Types dict:dict() and digraph:digraph() have been introduced in Erlang 17.
32 %% At the same time, their counterparts dict() and digraph() are to be deprecated
33 %% in Erlang 18. namespaced_types option is used to select proper type name
34 %% depending of the OTP version used.
35 NamespacedTypes = case is_otp(OtpInfo, "^[0-9]+") of
36 true -> {d, namespaced_types};
37 false -> undefined
38 end,
39
b4918986 » dizzyd
2009-12-04 Refactor rebar to build a self-contained script
40 %% Compile all src/*.erl to ebin
461335ac » tuncer
2011-08-16 Reformat bootstrap
41 case make:files(filelib:wildcard("src/*.erl"),
42 [{outdir, "ebin"}, {i, "include"},
43 DebugFlag,
4de9ea55 » matwey
2014-06-05 Add namespaced_types to bootstrap script.
44 NamespacedTypes,
461335ac » tuncer
2011-08-16 Reformat bootstrap
45 {d, 'BUILD_TIME', Built},
0f24d932 » dizzyd
2012-06-04 Move to major.minor.patch release version; add OTP build version
46 {d, 'VCS_INFO', VcsInfo},
47 {d, 'OTP_INFO', OtpInfo}]) of
b4918986 » dizzyd
2009-12-04 Refactor rebar to build a self-contained script
48 up_to_date ->
49 ok;
50 error ->
51 io:format("Failed to compile rebar files!\n"),
52 halt(1)
53 end,
54
55 %% Make sure file:consult can parse the .app file
56 case file:consult("ebin/rebar.app") of
57 {ok, _} ->
58 ok;
59 {error, Reason} ->
60 io:format("Invalid syntax in ebin/rebar.app: ~p\n", [Reason]),
61 halt(1)
62 end,
63
64 %% Add ebin/ to our path
65 true = code:add_path("ebin"),
66
1e980859 » tuncer
2012-05-18 Extend escriptize and reuse in bootstrap
67 %% Run rebar compile to do proper .app validation etc.
68 %% and rebar escriptize to create the rebar script
af305f24 » tuncer
2013-12-14 bootstrap: avoid trying to run 'debug' command
69 RebarArgs = Args -- ["debug"], %% Avoid trying to run 'debug' command
70 rebar:main(["compile", "escriptize"] ++ RebarArgs),
b4918986 » dizzyd
2009-12-04 Refactor rebar to build a self-contained script
71
8c01734e » xenolinguist
2011-12-21 bootstrap: generate windows scripts
72 %% Finally, update executable perms for our script on *nix,
73 %% or write out script files on win32.
8a5eea5e » juranki
2010-08-02 add bat scripts for bootstrap and rebat (windows doesn't understand s…
74 case os:type() of
75 {unix,_} ->
76 [] = os:cmd("chmod u+x rebar"),
77 ok;
8c01734e » xenolinguist
2011-12-21 bootstrap: generate windows scripts
78 {win32,_} ->
79 write_windows_scripts(),
80 ok;
8a5eea5e » juranki
2010-08-02 add bat scripts for bootstrap and rebat (windows doesn't understand s…
81 _ ->
82 ok
83 end,
2911d48f » tuncer
2011-08-08 Remove trailing whitespace
84
01684ff0 » dizzyd
2009-12-04 Add a nice message
85 %% Add a helpful message
461335ac » tuncer
2011-08-16 Reformat bootstrap
86 io:format("Congratulations! You now have a self-contained script called"
87 " \"rebar\" in\n"
88 "your current working directory. "
89 "Place this script anywhere in your path\n"
01684ff0 » dizzyd
2009-12-04 Add a nice message
90 "and you can use rebar to build OTP-compliant apps.\n").
91
4de9ea55 » matwey
2014-06-05 Add namespaced_types to bootstrap script.
92 is_otp(OtpInfo, Regex) ->
93 case re:run(OtpInfo, Regex, [{capture, none}]) of
94 match -> true;
95 nomatch -> false
96 end.
97
8a5eea5e » juranki
2010-08-02 add bat scripts for bootstrap and rebat (windows doesn't understand s…
98 rm(Path) ->
2911d48f » tuncer
2011-08-08 Remove trailing whitespace
99 NativePath = filename:nativename(Path),
8a5eea5e » juranki
2010-08-02 add bat scripts for bootstrap and rebat (windows doesn't understand s…
100 Cmd = case os:type() of
101 {unix,_} -> "rm -f ";
102 {win32,_} -> "del /q "
103 end,
2911d48f » tuncer
2011-08-08 Remove trailing whitespace
104 [] = os:cmd(Cmd ++ NativePath),
8a5eea5e » juranki
2010-08-02 add bat scripts for bootstrap and rebat (windows doesn't understand s…
105 ok.
1ea7065b » dizzyd
2010-01-08 Rework how the escript is built so that we can inclue templates
106
ffa0cda4 » dizzyd
2009-12-07 Updating bootstrap to embed the build time into a macro that we can p…
107 build_time() ->
108 {{Y, M, D}, {H, Min, S}} = calendar:now_to_universal_time(now()),
461335ac » tuncer
2011-08-16 Reformat bootstrap
109 lists:flatten(io_lib:format("~4..0w~2..0w~2..0w_~2..0w~2..0w~2..0w",
110 [Y, M, D, H, Min, S])).
b4918986 » dizzyd
2009-12-04 Refactor rebar to build a self-contained script
111
27f638b4 » dizzyd
2010-07-28 Add support for embedding git version; make sure to always rebuild re…
112 vcs_info([]) ->
113 "No VCS info available.";
e34b7024 » tuncer
2012-08-12 bootstrap: fix and enhance VCS_INFO handling
114 vcs_info([{Id, Dir, VsnCmd, StatusCmd} | Rest]) ->
27f638b4 » dizzyd
2010-07-28 Add support for embedding git version; make sure to always rebuild re…
115 case filelib:is_dir(Dir) of
116 true ->
e34b7024 » tuncer
2012-08-12 bootstrap: fix and enhance VCS_INFO handling
117 Vsn = string:strip(os:cmd(VsnCmd), both, $\n),
118 Status = case string:strip(os:cmd(StatusCmd), both, $\n) of
119 [] ->
120 "";
121 _ ->
122 "-dirty"
123 end,
124 lists:concat([Id, " ", Vsn, Status]);
27f638b4 » dizzyd
2010-07-28 Add support for embedding git version; make sure to always rebuild re…
125 false ->
126 vcs_info(Rest)
127 end.
8c01734e » xenolinguist
2011-12-21 bootstrap: generate windows scripts
128
129 write_windows_scripts() ->
130 CmdScript=
131 "@echo off\r\n"
132 "setlocal\r\n"
133 "set rebarscript=%~f0\r\n"
fa3dab30 » Mike Lazar
2012-01-10 Fix typos in generated cmd script in bootstrap
134 "escript.exe \"%rebarscript:.cmd=%\" %*\r\n",
cbfabd60 » Mike Lazar
2012-01-10 Remove generation of ps1 script (no longer needed)
135 ok = file:write_file("rebar.cmd", CmdScript).
Something went wrong with that request. Please try again.