From 78786e09d40b8c8aa27f08226e96f58cc8f305f4 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 10 Jul 2018 17:11:46 +0700 Subject: [PATCH] Initialize env_node from Super_context.create Signed-off-by: Rudi Grinberg --- src/super_context.ml | 29 ++++++++++++------- .../test-cases/workspaces/run.t | 4 +++ .../test-cases/workspaces/workspace-env/dune | 0 .../workspaces/workspace-env/dune-project | 1 + .../workspaces/workspace-env/dune-workspace | 7 +++++ 5 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 test/blackbox-tests/test-cases/workspaces/workspace-env/dune create mode 100644 test/blackbox-tests/test-cases/workspaces/workspace-env/dune-project create mode 100644 test/blackbox-tests/test-cases/workspaces/workspace-env/dune-workspace diff --git a/src/super_context.ml b/src/super_context.ml index ed8aa288..816ccd74 100644 --- a/src/super_context.ml +++ b/src/super_context.ml @@ -612,33 +612,40 @@ let create ; env = Hashtbl.create 128 } in + let context_env_node = lazy ( + let config = + match context.env_node with + | Some s -> s + | None -> { loc = Loc.none; rules = [] } + in + { Env_node. + dir = context.build_dir + ; inherit_from = None + ; scope = Scope.DB.find_by_dir scopes context.build_dir + ; config + ; ocaml_flags = None + } + ) in List.iter stanzas ~f:(fun { Dir_with_jbuild. ctx_dir; scope; stanzas; _ } -> List.iter stanzas ~f:(function | Env config -> let inherit_from = if ctx_dir = Scope.root scope then - None + context_env_node else - Some (lazy (Env.get t ~dir:(Path.parent_exn ctx_dir))) + lazy (Env.get t ~dir:(Path.parent_exn ctx_dir)) in Hashtbl.add t.env ctx_dir { dir = ctx_dir - ; inherit_from + ; inherit_from = Some inherit_from ; scope = scope ; config = config ; ocaml_flags = None } | _ -> ())); if not (Hashtbl.mem t.env context.build_dir) then - Hashtbl.add t.env context.build_dir - { Env_node. - dir = context.build_dir - ; inherit_from = None - ; scope = Scope.DB.find_by_dir scopes context.build_dir - ; config = { loc = Loc.none; rules = [] } - ; ocaml_flags = None - }; + Hashtbl.add t.env context.build_dir (Lazy.force context_env_node); t module Libs = struct open Build.O diff --git a/test/blackbox-tests/test-cases/workspaces/run.t b/test/blackbox-tests/test-cases/workspaces/run.t index e33d288a..bafc3847 100644 --- a/test/blackbox-tests/test-cases/workspaces/run.t +++ b/test/blackbox-tests/test-cases/workspaces/run.t @@ -47,3 +47,7 @@ see how we can set a "native" target. Which is the default. Entering directory 'targets-native' Entering directory 'targets-native' message from targets-native test + +Workspaces also allow you to set the env for a context: + + $ dune printenv --root workspace-env --profile default \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/workspaces/workspace-env/dune b/test/blackbox-tests/test-cases/workspaces/workspace-env/dune new file mode 100644 index 00000000..e69de29b diff --git a/test/blackbox-tests/test-cases/workspaces/workspace-env/dune-project b/test/blackbox-tests/test-cases/workspaces/workspace-env/dune-project new file mode 100644 index 00000000..b2559fa0 --- /dev/null +++ b/test/blackbox-tests/test-cases/workspaces/workspace-env/dune-project @@ -0,0 +1 @@ +(lang dune 1.0) \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/workspaces/workspace-env/dune-workspace b/test/blackbox-tests/test-cases/workspaces/workspace-env/dune-workspace new file mode 100644 index 00000000..30a26e35 --- /dev/null +++ b/test/blackbox-tests/test-cases/workspaces/workspace-env/dune-workspace @@ -0,0 +1,7 @@ +(lang dune 1.0) + +(context + (default + (env + (default + (flags (:standard -machin)))))) \ No newline at end of file