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

ocamldep option to not include the current directory in the searched directories #6969

Closed
vicuna opened this issue Aug 25, 2015 · 12 comments
Closed

Comments

@vicuna
Copy link

vicuna commented Aug 25, 2015

Original bug ID: 6969
Reporter: @dbuenzli
Status: confirmed (set by @gasche on 2015-08-25T17:43:34Z)
Resolution: open
Priority: normal
Severity: feature
Version: 4.02.3
Category: tools (ocaml{lex,yacc,dep,debug,...})
Tags: junior_job
Monitored by: @gasche @diml

Bug description

By default ocamldep includes the cwd to the list of include directories. It would be nice to have an option to disable this. This can facilitate the operation of the tools in certain contexts.

See for example samoht/assemblage#83 (comment)

@vicuna
Copy link
Author

vicuna commented Dec 6, 2015

Comment author: @xavierleroy

Reclassifying as a feature wish. Proof-of-concept implementation is welcome.

@vicuna
Copy link
Author

vicuna commented Oct 17, 2016

Comment author: @bobzhang

This is useful for correct build, note that it is not just ocamldep, we wish to have no-implicit-include-current-dirs in all tools (ocamlc/ocamlopt/ocamldep etc)
other tickets which will help correct build: #7383
I will send a patch later

@muskangarg21
Copy link
Contributor

May I take this as my first contribution, I am an outreachy applicant and have gone through the CONTRIBUTION.md file.
@Octachron could you please guide me from where I should begin exploring the codebase for this issue.

@Octachron
Copy link
Member

I think it is a good idea as a first contribution. The logic for ocamldep's argument is defined in driver/makedepend.ml. Then it is a matter of finding when . is added to load_path.

@muskangarg21
Copy link
Contributor

@Octachron,

At Line 116 in driver/makedepend.ml
if dir = "." then truename else Filename.concat dir truename
seems to be the reason of this issue as this loads '.' in load_path making the ocamldep search in current directory, I also looked at the issue #83 mentioned in the top post.

P.s. - I am done with setting up of Ocaml on my system and started looking at the codebase in detail.

@gasche
Copy link
Member

gasche commented Mar 7, 2020

This was a reasonable guess, but I think that it is not the right candidate; what this line does it to compute a path of the form dirname/filename, except in the case where dir is the current directory, in which case it uses just filename instead of ./filename.

@muskangarg21
Copy link
Contributor

hi @gasche,

can we add a check in this line which when finds the current directory to be the root directory then it will not add that path to the load path. not sure though

This was a reasonable guess, but I think that it is not the right candidate; what this line does it to compute a path of the form dirname/filename, except in the case where dir is the current directory, in which case it uses just filename instead of ./filename.

@muskangarg21
Copy link
Contributor

Whenever we are calling the add_to_load_path function we are adding the directory without any checks to whether it is root directory or not, maybe we could add the check here. Again not sure,
please help.
Thanks

let add_to_load_path dir =
  try
    let dir = Misc.expand_directory Config.standard_library dir in
    let contents = readdir dir in
    add_to_list load_path (dir, contents)
  with Sys_error msg ->
    Format.fprintf Format.err_formatter "@[Bad -I option: %s@]@." msg;
    Error_occurred.set ()

@gasche
Copy link
Member

gasche commented Mar 8, 2020

Your proposal is to have add_to_load_path do an extra check that would not add the current directory to the load path, even if some other place calls add_to_load_path on the current directory (the current behavior, according to this issue). A nicer fix would be to not call add_to_load_path on the current directory at all; this is nicer because it results in simpler code (no call, no extra check to disable the code). This requires finding why/when the current directory gets added to the load path.

@muskangarg21
Copy link
Contributor

@gasche

Line 577: add_to_list first_include_dirs Filename.current_dir_name;

This seems to be the line where we add . to first_include_dirs then in Line 409-413

  List.iter add_to_load_path (
      (!Compenv.last_include_dirs @
       !Clflags.include_dirs @
       !Compenv.first_include_dirs
      ));

we add . to the load_path, could you please guide me if I am understanding something incorrectly here.
Thanks

@Octachron
Copy link
Member

You are right, the current directory is added at this line. So the next step is to not add the current directory conditionally if a flag is set. Once this is done, you would need to add a new argument to the list of arguments (which is also in driver/makedepend.ml).

@Octachron
Copy link
Member

Fixed by #9357 .

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

5 participants