From 16e82ffb481fb81ef70828facb1731bc07b82b97 Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Tue, 12 Dec 2023 16:47:33 +0100 Subject: [PATCH] allow the empty noop job (as observed in https://github.com/mirage/mirage-www/pull/815#issuecomment-1852273411) --- lib/functoria/impl.ml | 3 + test/mirage/query/config_noop.ml | 7 ++ test/mirage/query/dune | 7 +- test/mirage/query/run-noop.t | 138 +++++++++++++++++++++++++++++++ 4 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 test/mirage/query/config_noop.ml create mode 100644 test/mirage/query/run-noop.t diff --git a/lib/functoria/impl.ml b/lib/functoria/impl.ml index 309624a44..55b2cdeaf 100644 --- a/lib/functoria/impl.ml +++ b/lib/functoria/impl.ml @@ -44,6 +44,9 @@ let abstract t = Abstract t let rec app_has_no_arguments = function | App { args = Cons _; _ } | Dev { args = Cons _; _ } -> false + | Dev { dev ; _ } when String.equal (Device.module_name dev) "Unit" -> + (* special hack for Job.noop *) + false | App _ | Dev _ -> true | If { cond = _; branches; default } -> app_has_no_arguments default diff --git a/test/mirage/query/config_noop.ml b/test/mirage/query/config_noop.ml new file mode 100644 index 000000000..4f9195e4e --- /dev/null +++ b/test/mirage/query/config_noop.ml @@ -0,0 +1,7 @@ +open Mirage + +let key = + let doc = Key.Arg.info ~doc:"How to say hello." [ "hello" ] in + Key.(create "hello" Arg.(opt string "Hello World!" doc)) + +let () = register ~keys:[ Key.v key ] ~src:`None "noop" [ noop ] diff --git a/test/mirage/query/dune b/test/mirage/query/dune index 676ec2f63..3a8450d10 100644 --- a/test/mirage/query/dune +++ b/test/mirage/query/dune @@ -8,6 +8,11 @@ (modules config_dash_in_name) (libraries mirage)) +(executable + (name config_noop) + (modules config_noop) + (libraries mirage)) + (cram (package mirage) - (deps config.exe config_dash_in_name.exe)) + (deps config.exe config_noop.exe config_dash_in_name.exe)) diff --git a/test/mirage/query/run-noop.t b/test/mirage/query/run-noop.t new file mode 100644 index 000000000..fcd041436 --- /dev/null +++ b/test/mirage/query/run-noop.t @@ -0,0 +1,138 @@ +Query unikernel dune + $ ./config_noop.exe query dune.build + (copy_files ./config/*) + + (rule + (target noop) + (enabled_if (= %{context_name} "default")) + (deps main.exe) + (action + (copy main.exe %{target}))) + + (executable + (name main) + (libraries duration lwt mirage-bootvar-unix mirage-clock-unix mirage-logs + mirage-runtime mirage-unix) + (link_flags (-thread)) + (modules (:standard \ config)) + (flags :standard -w -70) + (enabled_if (= %{context_name} "default")) + ) + +Query dist dune + $ ./config_noop.exe query dune.dist + (rule + (mode (promote (until-clean))) + (target noop) + (enabled_if (= %{context_name} "default")) + (action + (copy ../noop %{target})) + ) + +Query makefile + $ ./config_noop.exe query Makefile --target unix + -include Makefile.user + BUILD_DIR = ./ + MIRAGE_DIR = ./mirage + UNIKERNEL_NAME = noop-unix + OPAM = opam + + all:: + @$(MAKE) --no-print-directory depends + @$(MAKE) --no-print-directory build + + .PHONY: all lock install-switch pull clean depend depends build repo-add repo-rm depext-lockfile + + repo-add: + @printf "\033[2musing overlay repository mirage: [opam-overlays, mirage-overlays] \033[0m\n" + $(OPAM) repo add opam-overlays https://github.com/dune-universe/opam-overlays.git || $(OPAM) repo set-url opam-overlays https://github.com/dune-universe/opam-overlays.git + $(OPAM) repo add mirage-overlays https://github.com/dune-universe/mirage-opam-overlays.git || $(OPAM) repo set-url mirage-overlays https://github.com/dune-universe/mirage-opam-overlays.git + + + repo-rm: + @printf "\033[2mremoving overlay repository [opam-overlays, mirage-overlays]\033[0m\n" + $(OPAM) repo remove opam-overlays https://github.com/dune-universe/opam-overlays.git + $(OPAM) repo remove mirage-overlays https://github.com/dune-universe/mirage-opam-overlays.git + + + + depext-lockfile: $(MIRAGE_DIR)/$(UNIKERNEL_NAME).opam.locked + echo " ↳ install external dependencies for monorepo" + env OPAMVAR_monorepo="opam-monorepo" $(OPAM) monorepo depext -y -l $< + + + $(MIRAGE_DIR)/$(UNIKERNEL_NAME).opam.locked: $(MIRAGE_DIR)/$(UNIKERNEL_NAME).opam + @$(MAKE) -s repo-add + @echo " ↳ generate lockfile for monorepo dependencies" + @env OPAMVAR_monorepo="opam-monorepo" $(OPAM) monorepo lock --require-cross-compile --build-only $(UNIKERNEL_NAME) -l $@ --ocaml-version $(shell ocamlc --version); (ret=$$?; $(MAKE) -s repo-rm && exit $$ret) + + lock:: + @$(MAKE) -B $(MIRAGE_DIR)/$(UNIKERNEL_NAME).opam.locked + + pull:: $(MIRAGE_DIR)/$(UNIKERNEL_NAME).opam.locked + @echo " ↳ fetch monorepo dependencies in the duniverse folder" + @env OPAMVAR_monorepo="opam-monorepo" $(OPAM) monorepo pull -l $< -r $(abspath $(BUILD_DIR)) + + install-switch:: $(MIRAGE_DIR)/$(UNIKERNEL_NAME).opam + @echo " ↳ opam install switch dependencies" + @$(OPAM) install $< --deps-only --yes + @$(MAKE) -s depext-lockfile + + depends depend:: + @$(MAKE) --no-print-directory lock + @$(MAKE) --no-print-directory install-switch + @$(MAKE) --no-print-directory pull + + build:: + mirage build -f config.ml + + clean:: + mirage clean + +... + +Query dune-project + $ ./config_noop.exe query dune-project --target unix + (lang dune 2.7) + + (name noop-unix) + + (implicit_transitive_deps true) + +Query unikernel dune (hvt) + $ ./config_noop.exe query --target hvt dune.build + (copy_files ./config/*) + + (executable + (enabled_if (= %{context_name} "solo5")) + (name main) + (modes (native exe)) + (libraries duration lwt mirage-bootvar-solo5 mirage-clock-solo5 mirage-logs + mirage-runtime mirage-solo5) + (link_flags :standard -w -70 -cclib "-z solo5-abi=hvt") + (modules (:standard \ config manifest)) + (foreign_stubs (language c) (names manifest)) + ) + + (rule + (targets manifest.c) + (deps manifest.json) + (action + (run solo5-elftool gen-manifest manifest.json manifest.c))) + + (rule + (target noop.hvt) + (enabled_if (= %{context_name} "solo5")) + (deps main.exe) + (action + (copy main.exe %{target}))) + +Query dist dune (hvt) + $ ./config_noop.exe query --target hvt dune.dist + (rule + (mode (promote (until-clean))) + (target noop.hvt) + (enabled_if (= %{context_name} "solo5")) + (action + (copy ../noop.hvt %{target})) + )