From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 854B17ED94 for ; Tue, 11 Mar 2014 13:19:55 +0100 (CET) X-IronPort-AV: E=Sophos;i="4.97,630,1389740400"; d="scan'208";a="62279144" Received: from tupi.irisa.fr (HELO [131.254.14.82]) ([131.254.14.82]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 11 Mar 2014 13:19:55 +0100 Message-ID: <531EFF6B.8090800@irisa.fr> Date: Tue, 11 Mar 2014 13:19:55 +0100 From: Andre OLIVEIRA MARONEZE User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: caml-list Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Subject: [Caml-list] Order of includes in Ocamlbuild I found a bug in one of my tools, which compiles using ocamlbuild, and I would like to avoid similar situations in the future. This bug is caused by having duplicate .ml files with the same name in different directories, which are both included via -I on the command line. An interesting aspect is that the bug is not trivial to reproduce, because the order seen by ocamlbuild depends on the order in which the directory nodes were created, not on their names. For instance, consider the following files, each containing a single line of code: a1/a.ml : let f = 1 a2/a.ml : let g = 1 main.ml : let _ = A.f File main.ml is the main file, and both subdirectories a1 and a2 contain a file with the same name, but each defines a different symbol. In my case, I hadn't noticed that a duplicate name existed, and I included both directories when running ocamlbuild: ocamlbuild -I a1,a2 main.native Note that the order of the includes in the command line is irrelevant to ocamlbuild; it chooses its own include order, which depends mainly on which subdirectory was created first. In some cases, ocamlbuild will include a1 before a2 and it will work, in other cases it will include a2 before a1 and fail ("Unbound value A.f"). By renaming directories (mv a1 tmp; mv a2 a1; mv tmp a2), or copying the directory structure to another disk partition, it is possible to invert the order seen by ocamlbuild and obtain surprising results. I have two questions concerning this behavior: 1) Is there a way to ask ocamlbuild to detect this dangerous situation (duplicate file names in included directories) and warn the user? 2) Is there a way to force the include order to depend on directory *names*, via the command line or some other mechanism? In case item 1 is not feasible, this would at least ensure stability once a working include order is found. Regards, André