Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add autocompile support, controlled via --compile (default) and --no-compile #29

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions ocaml/cli.ml
Expand Up @@ -116,6 +116,8 @@ let generic_select_options : (_, _) opt_spec list = [
([ "--os"], 1, i_ "target operation system type", new one_arg OsType @@ fun o -> `Os o);
(["-r"; "--refresh"], 0, i_ "refresh all used interfaces", new ambiguous_no_arg `Refresh no_arg_reader);
(["-s"; "--source"], 0, i_ "select source code", new no_arg @@ `Source);
([ "--compile"], 0, i_ "compile implementations where no binary is available", new no_arg @@ `Autocompile true);
([ "--no-compile"], 0, i_ "only use prebuilt binaries", new no_arg @@ `Autocompile false);
([ "--version"], 1, i_ "specify version constraint (e.g. '3' or '3..')", new ambiguous_version_arg read_version_option);
([ "--version-for"], 2, i_ "set version constraints for a specific interface", parse_version_for);
]
Expand Down
2 changes: 1 addition & 1 deletion ocaml/gui_gtk/cache_explorer_box.ml
Expand Up @@ -353,7 +353,7 @@ let open_cache_explorer config =
Hashtbl.add impl_of_digest digest (feed, impl)
)
)
| `local_impl _ -> assert false
| `local_impl _ | `package_impl _ -> assert false
);
);

Expand Down
1 change: 1 addition & 0 deletions ocaml/options.mli
Expand Up @@ -31,6 +31,7 @@ type other_req_option = [
| `Cpu of string
| `Os of string
| `Source
| `Autocompile of bool
]

type select_option = [
Expand Down
1 change: 1 addition & 0 deletions ocaml/req_options.ml
Expand Up @@ -67,6 +67,7 @@ let parse_update_options ?(update=true) options requirements =
| `Cpu v -> r := {!r with cpu = empty_to_opt v}
| `Os v -> r := {!r with os = empty_to_opt v}
| `SelectCommand v -> r := {!r with command = empty_to_opt v}
| `Autocompile v -> r := {!r with autocompile = Some v}
| `Source when not update -> r := {!r with source = true}
| `Source when !r.source -> ()
| `Source ->
Expand Down
38 changes: 37 additions & 1 deletion ocaml/run.ml
Expand Up @@ -40,6 +40,32 @@ let run_test options run_opts run_args sels =

result

let autocompile options sels reason =
(** if sels has any source impls, passes the entire selections document through `0compile autocompile`,
* which will compile all source impls. After that's done, we reselect and run the result *)

(*TODO: allow override with $ZI_0COMPILE_FEED or something? *)
log_debug "Getting 0compile selections...";
let compile_sels = Generic_select.handle options [`Autocompile false; `NotBefore "1.3-post"] "http://0install.net/2006/interfaces/0compile.xml" `Select_for_run in

let exec args ~env =
let tmp_filename, tmp_file = Filename.open_temp_file "0compile-sels-" ".xml" in
U.finally_do Unix.unlink tmp_filename (fun tmp_filename ->
U.finally_do close_out tmp_file (fun tmp_file ->
let xml_selections = Zeroinstall.Selections.as_xml sels in
Support.Qdom.output (Xmlm.make_output @@ `Channel tmp_file) xml_selections;
);
log_debug "Executing: %s" (String.concat " " args);
let child = options.config.system#create_process ~env (args@[tmp_filename]) Unix.stdin Unix.stdout Unix.stderr in
options.config.system#reap_child child
) in

begin
try Zeroinstall.Exec.execute_selections ~exec options.config compile_sels ["autocompile"; "--selections"]
with Safe_exception _ as ex -> reraise_with_context ex "... compiling sources for %s" reason
end;
()

let handle options flags args =
let run_opts = {
wrapper = None;
Expand All @@ -56,7 +82,17 @@ let handle options flags args =

match args with
| arg :: run_args -> (
let sels = Generic_select.handle options ~test_callback:(run_test options run_opts run_args) !select_opts arg `Select_for_run in
let do_select extra_opts =
Generic_select.handle options
~test_callback:(run_test options run_opts run_args) (!select_opts@extra_opts) arg `Select_for_run in
let sels = do_select [] in

let sels = if Zeroinstall.Selections.requires_compilation sels
then begin
autocompile options sels arg;
(* TODO: pin exact implementation IDs here, for efficiency? *)
do_select [`Autocompile false]
end else sels in

let exec args ~env =
options.config.system#exec args ~env in
Expand Down
1 change: 1 addition & 0 deletions ocaml/slave.ml
Expand Up @@ -101,6 +101,7 @@ let parse_requirements json_assoc =
os = pop "os" |> J.Util.to_string_option;
cpu = pop "cpu" |> J.Util.to_string_option;
message = pop "message" |> J.Util.to_string_option;
autocompile = pop "compile" |> J.Util.to_bool_option;
}) in
table |> Hashtbl.iter (fun name _ -> log_warning "Unexpected requirements field '%s'!" name);
reqs
Expand Down
72 changes: 36 additions & 36 deletions ocaml/tests/solves.xml
Expand Up @@ -7,7 +7,7 @@
</interface>
<requirements command='run' interface='http://example.com/prog.xml'/>
<selections source="false" command="run" interface="http://example.com/prog.xml">
<selection id='v1' interface='http://example.com/prog.xml' version='1'>
<selection id='v1' interface='http://example.com/prog.xml' mode='immediate' version='1'>
<command name="run" path="main"/>
</selection>
</selections>
Expand Down Expand Up @@ -35,9 +35,9 @@
</interface>
<requirements command='run' interface='http://example.com/prog.xml'/>
<selections source="false" command="run" interface="http://example.com/prog.xml">
<selection id='l1' interface='http://example.com/lib1.xml' version='1'/>
<selection id='l2' interface='http://example.com/lib2.xml' version='1'/>
<selection id='v1' interface='http://example.com/prog.xml' version='1'>
<selection id='l1' interface='http://example.com/lib1.xml' mode='immediate' version='1'/>
<selection id='l2' interface='http://example.com/lib2.xml' mode='immediate' version='1'/>
<selection id='v1' interface='http://example.com/prog.xml' mode='immediate' version='1'>
<command name="run" path="main">
<requires interface='http://example.com/lib1.xml'/>
<requires interface='http://example.com/lib2.xml'/>
Expand All @@ -57,7 +57,7 @@
</interface>
<requirements command='run' interface='http://example.com/prog.xml'/>
<selections source="false" command="run" interface="http://example.com/prog.xml">
<selection id='m3' interface='http://example.com/prog.xml' version='3'>
<selection id='m3' interface='http://example.com/prog.xml' mode='immediate' version='3'>
<command name="run" path="main"/>
</selection>
</selections>
Expand Down Expand Up @@ -105,22 +105,22 @@
</interface>
<requirements command='run' interface='http://example.com/prog.xml'/>
<selections source="false" command="run" interface="http://example.com/prog.xml">
<selection id='z2' interface='http://example.com/lib.xml' version='2'>
<selection id='z2' interface='http://example.com/lib.xml' mode='immediate' version='2'>
<command name='run' path='prog'/>
<command name='test' path='test-prog'>
<runner interface='http://example.com/tester.xml'/>
<requires interface='http://example.com/missing.xml' importance='recommended'/>
</command>
</selection>
<selection id='m3' interface='http://example.com/prog.xml' version='3'>
<selection id='m3' interface='http://example.com/prog.xml' mode='immediate' version='3'>
<command name="run" path="main"/>
<binding name='foo'/>
<requires interface='http://example.com/lib.xml'>
<executable-in-path name='lib' command='run'/>
<executable-in-path name='test-lib' command='test'/>
</requires>
</selection>
<selection id='t1' interface='http://example.com/tester.xml' version='1'>
<selection id='t1' interface='http://example.com/tester.xml' mode='immediate' version='1'>
<command name='run' path='tester'/>
</selection>
</selections>
Expand All @@ -142,7 +142,7 @@
</interface>
<requirements command='run' interface='http://example.com/prog.xml'/>
<selections source="false" command='run' interface="http://example.com/prog.xml">
<selection id='v1' interface='http://example.com/prog.xml' version='1'>
<selection id='v1' interface='http://example.com/prog.xml' mode='immediate' version='1'>
<command name='run'/>
</selection>
</selections>
Expand Down Expand Up @@ -178,8 +178,8 @@
</interface>
<requirements command='run' interface='http://example.com/prog.xml'/>
<selections source="false" command="run" interface="http://example.com/prog.xml">
<selection id='l2' interface='http://example.com/lib.xml' version='2'/>
<selection id='p2' interface='http://example.com/prog.xml' version='2'>
<selection id='l2' interface='http://example.com/lib.xml' mode='immediate' version='2'/>
<selection id='p2' interface='http://example.com/prog.xml' mode='immediate' version='2'>
<command name="run" path="main"/>
<requires interface='http://example.com/lib.xml' version='2..!3'/>
</selection>
Expand Down Expand Up @@ -261,7 +261,7 @@ Can't find all required implementations:
</interface>
<requirements command='run' interface='http://example.com/prog.xml'/>
<selections source="false" command="run" interface="http://example.com/prog.xml">
<selection id='v1' interface='http://example.com/prog.xml' version='1'>
<selection id='v1' interface='http://example.com/prog.xml' mode='immediate' version='1'>
<command name="run" path="new-path"/>
</selection>
</selections>
Expand All @@ -287,8 +287,8 @@ Can't find all required implementations:
</interface>
<requirements command='run' interface='http://example.com/prog.xml'/>
<selections source="false" command="run" interface="http://example.com/prog.xml">
<selection id='l2' interface='http://example.com/lib2.xml' version='1'/>
<selection id='v1' interface='http://example.com/prog.xml' version='1'>
<selection id='l2' interface='http://example.com/lib2.xml' mode='immediate' version='1'/>
<selection id='v1' interface='http://example.com/prog.xml' mode='immediate' version='1'>
<command name="run" path="main"/>
<requires interface='http://example.com/lib1.xml' distribution='foo' importance='recommended'/>
<requires interface='http://example.com/lib2.xml' distribution='foo 0install' importance='recommended'/>
Expand Down Expand Up @@ -329,9 +329,9 @@ Can't find all required implementations:
<requirements command='run' interface='http://example.com/prog.xml'/>

<selections source="false" command="run" interface="http://example.com/prog.xml">
<selection id='l12' interface='http://example.com/lib1.xml' version='2'/>
<selection id='l21' interface='http://example.com/lib2.xml' version='1'/>
<selection id='p1' interface='http://example.com/prog.xml' version='1'>
<selection id='l12' interface='http://example.com/lib1.xml' mode='immediate' version='2'/>
<selection id='l21' interface='http://example.com/lib2.xml' mode='immediate' version='1'/>
<selection id='p1' interface='http://example.com/prog.xml' mode='immediate' version='1'>
<command name="run" path="main"/>
<requires interface='http://example.com/lib1.xml'/>
<requires interface='http://example.com/lib2.xml'/>
Expand Down Expand Up @@ -729,11 +729,11 @@ Can't find all required implementations:

<selections source="false" interface="http://gfxmonk.net/dist/0install/watchdog.xml" command="test">
<selection id="sha1new=9e367bae00e50616d6b612e94713616a7fb5af4d"
interface="http://gfxmonk.net/dist/0install/nose.xml" released="2010-07-19" version="0.11.2">
interface="http://gfxmonk.net/dist/0install/nose.xml" released="2010-07-19" mode='immediate' version="0.11.2">
<command name="run" path="bin/nosetests"/>
</selection>
<selection id="sha1new=b6d40c5d38b58c1be359d879dadc90d212f9294c"
interface="http://gfxmonk.net/dist/0install/watchdog.xml" released="2011-02-09" version="0.5.3">
interface="http://gfxmonk.net/dist/0install/watchdog.xml" released="2011-02-09" mode='immediate' version="0.5.3">
<command name="test">
<runner interface="http://gfxmonk.net/dist/0install/nose.xml"/>
</command>
Expand Down Expand Up @@ -761,11 +761,11 @@ Can't find all required implementations:
<requirements interface='./OptionalMissing.xml'/>

<selections source="false" interface="/root/OptionalMissing.xml">
<selection id="a" interface="/root/OptionalMissing.xml" local-path="/root" version="0.1">
<selection id="a" interface="/root/OptionalMissing.xml" local-path="/root" mode='immediate' version="0.1">
<requires interface="http://localhost/Missing.xml" importance="recommended"/>
<requires interface="http://foo/Binary.xml"/>
</selection>
<selection id="sha1=3ce644dc725f1d21cfcf02562c76f375944b266a" interface="http://foo/Binary.xml" version="1.0"/>
<selection id="sha1=3ce644dc725f1d21cfcf02562c76f375944b266a" interface="http://foo/Binary.xml" mode='immediate' version="1.0"/>
</selections>

</test>
Expand All @@ -786,7 +786,7 @@ Can't find all required implementations:
<requirements interface='./OptionalMissing.xml'/>

<selections source="false" interface="/root/OptionalMissing.xml">
<selection id="a" interface="/root/OptionalMissing.xml" local-path="/root" version="0.1">
<selection id="a" interface="/root/OptionalMissing.xml" local-path="/root" mode='immediate' version="0.1">
<requires interface="http://localhost/Missing.xml" importance="recommended">
<executable-in-path name='missing'/>
</requires>
Expand All @@ -803,12 +803,12 @@ Can't find all required implementations:
<requirements interface='http://foo/Build.xml' command='run'/>

<selections source="false" interface='http://foo/Build.xml' command='run'>
<selection id="2" interface='http://foo/Build.xml' version='2'>
<selection id="2" interface='http://foo/Build.xml' mode='immediate' version='2'>
<command name="run" path="idontexist"/>
<requires interface="http://foo/Compiler-new.xml"/>
<manifest-digest sha256new="def"/>
</selection>
<selection from-feed="http://foo/Compiler.xml" id="sha1=999" interface="http://foo/Compiler-new.xml" version="5"/>
<selection from-feed="http://foo/Compiler.xml" id="sha1=999" interface="http://foo/Compiler-new.xml" mode='immediate' version="5"/>
</selections>
</test>

Expand All @@ -820,11 +820,11 @@ Can't find all required implementations:
<requirements interface='./ReplacedConflicts.xml' command='run'/>

<selections source="false" interface="/root/ReplacedConflicts.xml" command="run">
<selection id="b" interface="/root/ReplacedConflicts.xml" local-path="/root" version="2">
<selection id="b" interface="/root/ReplacedConflicts.xml" local-path="/root" mode='immediate' version="2">
<command name="run" path="missing"/>
<requires interface="http://localhost:8000/Hello"/>
</selection>
<selection id="sha1=3ce644dc725f1d21cfcf02562c76f375944b266a" interface="http://localhost:8000/Hello" version="1"/>
<selection id="sha1=3ce644dc725f1d21cfcf02562c76f375944b266a" interface="http://localhost:8000/Hello" mode='immediate' version="1"/>
</selections>
</test>

Expand All @@ -838,8 +838,8 @@ Can't find all required implementations:
</requirements>

<selections source="false" interface="/root/ReplacedConflicts.xml" command="run">
<selection id="." interface="/root/Replaced.xml" version="0" local-path='/root'/>
<selection id="a" interface="/root/ReplacedConflicts.xml" local-path="/root" version="1">
<selection id="." interface="/root/Replaced.xml" mode='immediate' version="0" local-path='/root'/>
<selection id="a" interface="/root/ReplacedConflicts.xml" local-path="/root" mode='immediate' version="1">
<command name="run" path="missing"/>
<requires interface="/root/Replaced.xml"/>
</selection>
Expand All @@ -866,8 +866,8 @@ Can't find all required implementations:
<requirements interface='./program.xml' command='compile' source='true'/>

<selections interface='/root/program.xml' command='compile' source='true'>
<selection id="lib-src" interface='/root/lib.xml' version='1.0' local-path='/root' arch='*-src'/>
<selection id="src" interface='/root/program.xml' version='2.0' local-path='/root' arch='*-src'>
<selection id="lib-src" interface='/root/lib.xml' mode='immediate' version='1.0' local-path='/root' arch='*-src'/>
<selection id="src" interface='/root/program.xml' mode='immediate' version='2.0' local-path='/root' arch='*-src'>
<command name="compile" path="build.sh"/>
<requires interface="/root/lib.xml" source='true'/>
</selection>
Expand All @@ -892,7 +892,7 @@ Can't find all required implementations:
<requirements interface='./prog.xml' command='test'/>

<selections source="false" interface="/root/prog.xml" command="test">
<selection interface="/root/prog.xml" version='1' id='.' local-path='/root'>
<selection interface="/root/prog.xml" mode='immediate' version='1' id='.' local-path='/root'>
<command name='foo' path='foo.py'/>
<command name='run' path='prog.py'/>
<command name="test">
Expand Down Expand Up @@ -941,9 +941,9 @@ Can't find all required implementations:
<requirements interface='./prog.xml' command='test'/>

<selections source="false" interface="/root/prog.xml" command="test">
<selection interface="/root/lib1.xml" version='2.0' id='new' local-path='/root'/>
<selection interface="/root/lib2.xml" version='2.0' id='new' local-path='/root'/>
<selection interface="/root/prog.xml" version='1' id='.' local-path='/root'>
<selection interface="/root/lib1.xml" mode='immediate' version='2.0' id='new' local-path='/root'/>
<selection interface="/root/lib2.xml" mode='immediate' version='2.0' id='new' local-path='/root'/>
<selection interface="/root/prog.xml" mode='immediate' version='1' id='.' local-path='/root'>
<command name='foo' path='foo.py'>
<requires interface="/root/lib2.xml" importance='recommended'/>
</command>
Expand Down Expand Up @@ -995,8 +995,8 @@ Can't find all required implementations:
<requirements interface='./Compiler.xml' command='compile' source='true'/>

<selections interface='/root/Compiler.xml' command='compile' source='true'>
<selection id="bin" interface='/root/Compiler.xml' version='1.0' local-path='/root'/>
<selection id="src" interface='/root/Compiler.xml' version='2.0' local-path='/root' arch='*-src'>
<selection id="bin" interface='/root/Compiler.xml' mode='immediate' version='1.0' local-path='/root'/>
<selection id="src" interface='/root/Compiler.xml' mode='immediate' version='2.0' local-path='/root' arch='*-src'>
<command name="compile" path="build.sh"/>
<requires interface="/root/Compiler.xml"/>
</selection>
Expand Down
1 change: 1 addition & 0 deletions ocaml/tests/test_distro.ml
Expand Up @@ -443,6 +443,7 @@ let suite = "distro">::: [
machine_ranks = StringMap.empty;
languages = Support.Locale.LangMap.empty;
allowed_uses = StringSet.empty;
autocompile = false;
} in
let impl_provider = new Impl_provider.default_impl_provider config (feed_provider :> Feed_provider.feed_provider) scope_filter in
let impls = impl_provider#get_implementations master_uri ~source:false in
Expand Down
1 change: 1 addition & 0 deletions ocaml/tests/test_fetch.ml
Expand Up @@ -38,6 +38,7 @@ let impl_template = Impl.({
digests = [("sha1", "123")];
retrieval_methods = [];
};
impl_mode = `immediate;
})

let parse_xml s =
Expand Down
3 changes: 2 additions & 1 deletion ocaml/tests/test_sat.ml
Expand Up @@ -37,7 +37,8 @@ class impl_provider =
stability = General.Stable;
os; machine;
parsed_version = Version.parse v;
impl_type = `local_impl "/"
impl_type = `local_impl "/";
impl_mode = `immediate;
}) in

object (_ : #I.impl_provider)
Expand Down