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 "context" flag in _tags for multi-directories projects #6161

Closed
vicuna opened this issue Sep 5, 2013 · 4 comments
Closed

add "context" flag in _tags for multi-directories projects #6161

vicuna opened this issue Sep 5, 2013 · 4 comments

Comments

@vicuna
Copy link

vicuna commented Sep 5, 2013

Original bug ID: 6161
Reporter: daweil
Status: resolved (set by @damiendoligez on 2017-03-01T15:05:43Z)
Resolution: suspended
Priority: normal
Severity: feature
Version: 4.00.1
Category: -for ocamlbuild use https://github.com/ocaml/ocamlbuild/issues
Monitored by: @hcarty

Bug description

I propose to add a "context" flag in the _tags file.
The syntax would be something like:
: context (dirA,dirB)

and would have the same effects this in myocamlbuild.ml:
Pathname.define_context mysubdir ["dirA";"dirB"]

This is much better that using the "include" tag which include a directory everywhere and is not very clean in many cases!

@vicuna
Copy link
Author

vicuna commented Sep 5, 2013

Comment author: @gasche

There is some pressure to add a lot of things in _tags because editing that file is more convenient than adding stuff to myocamlbuild.ml. Some of those ideas are good, some of those ideas are bad, and some feels like "may be nice, but may turn out to be a mistake in a few months".

For now, my personal filter is "does it respect the existing semantics of _tags file?". Now there are several non-conflicting interpretations of what this existing semantics may be -- in decreasing order of strictness:

(1) A way to attach tags to an arbitrary subset of the ocamlbuild targets matching some predicate
(2) A way to influence manipulation (but not necessarily through the tagset->flag mapping machinery) of the ocamlbuild targets matching some predicate
(3) A general way to configure ocamlbuild's behavior, restricted by a bizarre syntax

Option (1) is the strictest and consistent with almost all tags existing today. Option (2) is supported by the "traverse", "include" and "non_hygienic"/"precious". Option (3) is what led to horrible hacks such as "true: use_menhir".

A feature that falls into use-case (1) and has a clear utility is immediately confirmed: yes, we want that and feel free to help us by providing a patch. A feature that falls into use-case (3) is highly suspect -- my current entirely personal opinion is that it is a bad idea. A feature falling into use-case (2) is on hold: it may be a good idea, but it could also lead us down the slope, into the junkyard were no sane design is possible anymore.

Yours falls into case (2). It is a reasonable extension of the "include" and "traverse" mechanism, but it's still not the core purpose of the _tags file. I will happily accept a good patch that does this, but will concentrate my own contribution time on things that feel more convincing.

@vicuna
Copy link
Author

vicuna commented Sep 6, 2013

Comment author: daweil

I agree with your position and actually, the semantic of the "include" is very bizarre : if you add " : include" in some _tags file, it will add "-I xxx/A" in all your project !
(where "xxx" is the relative path from the _tags file to the ocamlbuild root directory).

Usually, this is not what we need : we want to express the fact that "a given set of files need to add "-I A" options to the ocaml compilers.
This is very similar to the "package" parametric tags, so my wish fall more in Option (1) than Option (2).

I tried to write a plugin inspired from the package plugin as described on http://brion.inria.fr/gallium/index.php/Using_ocamlfind_with_ocamlbuild. I added the following code in the dispatch function/section After_rules:
let list_subdirs dir =
let rec list_dirs dirs dir =
if Sys.is_directory dir then (
(* printf "dir = %s, context = %a @." dir (print_list pp_print_string) context; *)
let dirs = dir::dirs in
Array.fold_left (fun dirs d -> list_dirs dirs (dir ^ "/" ^ d)) dirs (Sys.readdir dir)
) else dirs in
List.fold_left list_dirs [] (List.filter (fun d -> d <> "build") & Array.to_list & Sys.readdir ".")
in
List.iter begin fun dir ->
flag ["ocaml"; "compile"; "context
"^dir] & S[A"-I"; A dir];
flag ["ocaml"; "ocamldep"; "context_"^dir] & S[A"-I"; A dir];
flag ["ocaml"; "doc"; "context_"^dir] & S[A"-I"; A dir];
end (list_subdirs ())

It almost works except but fail when calling the "menhir" command because the menhir rule add the "--ocamlc" options only the include dirs obtained from the include flag (cf ocamlbuild/ocaml_tools.ml).

@vicuna
Copy link
Author

vicuna commented Sep 6, 2013

Comment author: @gasche

That's a good point.

@vicuna
Copy link
Author

vicuna commented Mar 1, 2017

Comment author: @damiendoligez

ocamlbuild is now a separate project that lives on GitHub.
PR transferred to ocaml/ocamlbuild#188

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant