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

Environment & build profiles #419

Merged
3 commits merged into from May 4, 2018
Merged

Environment & build profiles #419

3 commits merged into from May 4, 2018

Conversation

ghost
Copy link

@ghost ghost commented Jan 16, 2018

Configuration:

(env
 (release
  (flags (:standard -O3)))
 (foo
  (flags (:standard -w +a))))

usage:

$ jbuilder build --profile foo

@bobot
Copy link
Collaborator

bobot commented Jan 17, 2018

What is an Env_node ?

@ghost
Copy link
Author

ghost commented Jan 18, 2018

It represent the environment in a given directory. I haven't written the details yet, but the idea an environment is attached to every directory. It is inherit from the parent up to the root of the current scope, where the global default environment is used. (env ...) stanzas are used to modify the environment.

To know the value of a variable, one must look at (env ...) stanzas in the current directory and parent directories up to the root of the current scope. I'm planning to add a jbuilder printenv <dir> command that will print the computed environment for a given directory.

@@ -22,7 +22,7 @@ let dev_mode_warnings =
])

let default_flags () =
if !Clflags.dev_mode then
if !Clflags.profile = "dev" then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have the dev_mode function now.

@ghost
Copy link
Author

ghost commented Jan 29, 2018

I'm wondering if this feature shouldn't be a bit more generic with just a toplevel set stanza:

(set flags (:standard -O3))

and to do different things according to the profile, we could have generic constructions:

(when (= ${profile} dev)
 (set flags (:standard -w +a)))

(unless (= ${profile} release)
 (set flags (:standard -w +a)))

(case ${profile)
 (dev ...)
 (release ...))

This could subsume #397:

(case ${os}
 (win32 (set backend windows) (set backend_lib foo))
 (_     (set backend other)   (set backend_lib bar)))

(rule (copy# file.${backend}.ml file.ml))

(library
 ((name blah)
  (libraries (a b ${backend_lib})))

@ghost ghost mentioned this pull request Jan 30, 2018
@rgrinberg
Copy link
Member

I like the more general approach here. How are profile will be different from any other variable then? Just the fact that we can set them in the command line?

@ghost
Copy link
Author

ghost commented Jan 31, 2018

Yh, also maybe we'll be able to set other things from the command line. We should probably disallow changing the profile in a dune file as well, otherwise it's going to be difficult to understand what's happening

bin/main.ml Outdated
| true , None -> `Ok (Some "dev")
| true , Some _ ->
`Error (true,
"Cannot use -dev and --profile simultaneously")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--dev missing a dash.


.. code:: scheme

(profile foo)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we select the build profile per context?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I started a patch for it, I'm not sure I pushed it though

@jberdine
Copy link
Contributor

jberdine commented May 2, 2018

Let me know at any point if you could use some alpha testing of this. (I tried from this branch, but it seems to have fallen a bit far behind.)

@ghost
Copy link
Author

ghost commented May 2, 2018

I think what stopped this feature was more a design question. However, it might take quite a lot more time to design and implement something better and not being able to change the defaults is quite annoying. I guess we could start with this PR since it solves the problem. It's simple so it shouldn't be too hard to be backward compatible if we decide to change the system later.

I'll rebase it, some testing would be welcome indeed.

@ghost
Copy link
Author

ghost commented May 2, 2018

I rebased and finished this PR.

@ghost ghost changed the title [WIP] environment & build profiles Environment & build profiles May 2, 2018
String.Map.map map ~f:snd
(String_map.map map ~f:(fun (module M : Gen) -> M.gen_rules));
String_map.iter map ~f:(fun (module M : Gen) -> M.init ());
String_map.map map ~f:(fun (module M : Gen) -> M.sctx)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if this is the result of a rebase accident.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is correct, basically for the printenv command we need to access the super context. So instead of keeping the stanzas, we just keep the whole super contexts now.

@rgrinberg
Copy link
Member

rgrinberg commented May 3, 2018 via email

@ghost
Copy link
Author

ghost commented May 3, 2018

Ah, I guess it's because there is still a String_map in import.ml so I didn't catch this error. I'm removing it.

@ghost
Copy link
Author

ghost commented May 3, 2018

Actually it's a bit annoying as it's still used by many pretty-printers.

I added a commit to make sure env doesn't appear more than once in a jbuild file

@jberdine
Copy link
Contributor

jberdine commented May 4, 2018

Nice, this is working for me. One step closer to being able to use sexp jbuild files!

I don't know if it's difficult or leads down the slippery slope to hard design questions, but I wanted to write:

(env
 (coverage
  (flags (-g -opaque))
  (preprocess (pps (bisect_ppx)))))

in order to eliminate code in jbuild that detects if bisect_ppx is installed.

@jberdine
Copy link
Contributor

jberdine commented May 4, 2018

Additionally, it would be useful to be able to use :include with env to avoid duplicating this configuration in every subdirectory's build file.

(env
 (:include "${SCOPE_ROOT}/dune-env"))

Or even allow including whole (lists of) stanzas:

(:include "${SCOPE_ROOT}/dune-common")

This is not a big deal, as it's not hard to cat some files together to generate the jbuild files, but direct support would make it tidier.

@ghost
Copy link
Author

ghost commented May 4, 2018

The environment is inherited from the parent directory, up to the root of the current scope (project). So you should only need to write it once in a toplevel jbuild file.

Regarding preprocess, that seems fine, I was thinking of adding something like this at some point. For the case of bisect in particular, we are also planning to have first class support (#616).

@ghost ghost merged commit 4d8ca48 into ocaml:master May 4, 2018
jberdine added a commit to ocaml-ppx/ocamlformat that referenced this pull request May 6, 2018
Preview of simplifications enabled by ocaml/dune#419
@ghost ghost mentioned this pull request Jun 2, 2018
@aantron aantron mentioned this pull request Aug 6, 2019
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants