The code server can handle one "primary" archive. It is usually used to<br>load code from a running (active) escript but if the system has been<br>started in the classic way (without an escript) the primary archive<br>

mechanism could be used to load code from a passive escript instead.<br>See the example below.<br><br>The "primary archive" mechanism is however only intended to be used in<br>the context of one (active) escript. That's why code:set_primary_archive/3<br>

is undocumented and its parameters may look somewhat strange.<br><br>But if loading of code from passive escripts is something that is regarded<br>as useful enough, it would not be too hard to generalize the mechanism<br>

(in erl_prim_loader and code_server) with one single "primary archive" to<br>handle multiple "escript archives" instead.<br><br>It's just to contribute to the community...<br><br>/Håkan<br><br>Eshell V5.9.1  (abort with ^G)<br>

1> Mod = rebar.<br>rebar<br>2> code:wh<br>where_is_file/1  where_is_file/2  which/1          <br>2> code:which(Mod).<br>non_existing<br>3> Escript = "rebar".<br>"rebar"<br>4> {ok,Props} = escript:extract(Escript,[]).<br>

{ok,[{shebang,default},<br>     {comment,[]},<br>     {emu_args,"-noshell -noinput"},<br>     {archive,<<80,75,3,4,20,0,0,0,8,0,129,102,235,64,180,<br>                80,127,93,93,54,0,...>>}]}<br>5> Bin = proplists:get_value(archive,Props).<br>

<<80,75,3,4,20,0,0,0,8,0,129,102,235,64,180,80,127,93,93,<br>  54,0,0,228,65,0,0,11,0,0,...>><br>6> {ok, Info} = file:read_file_info(Escript).<br>{ok,{file_info,283118,regular,read_write,<br>               {{2012,7,11},{12,52,47}},<br>

               {{2012,7,11},{12,52,33}},<br>               {{2012,7,11},{12,52,33}},<br>               33277,1,2056,0,4853045,1000,1000}}<br>7> code:set_primary_archive(Escript, Bin, Info).<br>ok<br>8> code:which(Mod).<br>

"/home/hm/repos/rebar/rebar/rebar.beam"<br>9> <br><br><div class="gmail_quote">On Wed, Jul 11, 2012 at 10:35 AM, Siri Hansen <span dir="ltr"><<a href="mailto:erlangsiri@gmail.com" target="_blank">erlangsiri@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Geoff!<div><br></div><div>There is no good way to do this really. Since rebar is an escript, the code server can not read it as a general archive. The only option you have would be to extract the archive part from it, write it to a file with .ez extension and then add code path to it, e.g.</div>


<div><br></div><div><div>1> {ok,Stuff} = escript:extract("rebar",[]). </div><div>{ok,[{shebang,default},</div><div>     {comment,[]},</div><div>     {emu_args,"-noshell -noinput"},</div><div>     {archive,<<80,75,3,4,20,0,0,0,8,0,15,84,235,64,105,178,</div>


<div>                62,157,168,18,0,...>>}]}</div><div>2> </div><div>2> Bin = proplists:get_value(archive,Stuff).</div><div><<80,75,3,4,20,0,0,0,8,0,15,84,235,64,105,178,62,157,168,</div><div>  18,0,0,164,30,0,0,11,0,0,...>></div>


<div>3> file:write_file("rebar.ez",Bin).</div><div>ok</div><div>4> erl_prim_loader:list_dir("rebar.ez").</div><div>{ok,["priv","rebar_xref.beam","rebar_utils.beam",</div>


<div>     "rebar_upgrade.beam","rebar_templater.beam",</div><div>     "rebar_subdirs.beam","rebar_require_vsn.beam",</div><div>     "rebar_reltool.beam","rebar_rel_utils.beam",</div>


<div>     "rebar_protobuffs_compiler.beam","rebar_port_compiler.beam",</div><div>     "rebar_otp_app.beam","rebar_neotoma_compiler.beam",</div><div>     "rebar_log.beam","rebar_lfe_compiler.beam",</div>


<div>     "rebar_file_utils.beam","rebar_eunit.beam",</div><div>     "rebar_escripter.beam","rebar_erlydtl_compiler.beam",</div><div>     "rebar_erlc_compiler.beam","rebar_edoc.beam",</div>


<div>     "rebar_deps.beam","rebar_ct.beam","rebar_core.beam",</div><div>     "rebar_config.beam","rebar_cleaner.beam",</div><div>     [...]|...]}</div><div>5> code:which(rebar).</div>


<div>non_existing</div><div>6> code:add_path("rebar.ez").</div><div>true</div><div>7> code:which(rebar).        </div><div>"rebar.ez/rebar.beam"</div><div>8> </div><div><br></div><div><br></div>


<div>Regards</div><span><font color="#888888"><div>/siri</div></font></span><div><div><br><div class="gmail_quote">2012/7/10 Geoff Cant <span dir="ltr"><<a href="mailto:nem@erlang.geek.nz" target="_blank">nem@erlang.geek.nz</a>></span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Hi all, after looking for a while, I couldn't figure out how to tell<br>
ERTS or the code server that /some/path/rebar was a valid place to load<br>
modules from.<br>
<br>
Is there a magic function / command-line flag I can use to get the<br>
contents of this escript archive into the code path?<br>
<br>
Cheers,<br>
<span><font color="#888888">--<br>
Geoff Cant</font></span><br></blockquote></div></div></div></div></blockquote></div>