From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 98308 invoked by alias); 12 Nov 2018 21:01:22 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 98295 invoked by uid 89); 12 Nov 2018 21:01:21 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=collapsing X-HELO: mail-qk1-f194.google.com Received: from mail-qk1-f194.google.com (HELO mail-qk1-f194.google.com) (209.85.222.194) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 12 Nov 2018 21:01:19 +0000 Received: by mail-qk1-f194.google.com with SMTP id w204so15857687qka.2 for ; Mon, 12 Nov 2018 13:01:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=xzjNC+tJACNzJ5TS/fiGSdNq/f/6X7UgU02acZnygBU=; b=ZZT0YyT4l6PpdVxLLvvSgxvy3eoEdJFv2v1Y33qutg7uVKawPsrOJvHfE+ROIscp9P vyeu2MVXjxwDgQxpZ9/fWD6DV2kCSba/IUige/H2+axP2tKKktIZ50yGH5gFdeUR2lgD LL1gM3KNXwcWUFedDMEeJqdGfVFGYzUDAPKxVMd8A9hj0JrBYZzUvWsv5wrkwEzBK524 y0gzVk+v2qh2TYwvzbfJ6oj0aNM6Nq8rof5lMImqdHvezQi362UQIvoSFlKkg4rkwdGe GvOMAwXfmNb6KxTc2lpP4sACs7ZNZ+cUTEzQqZVXWea0Ocjy34BArEpT5aiWzA7ZsKEv zJ2A== Return-Path: Received: from localhost.localdomain (184-96-239-209.hlrn.qwest.net. [184.96.239.209]) by smtp.gmail.com with ESMTPSA id 46-v6sm12780272qtv.73.2018.11.12.13.01.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Nov 2018 13:01:16 -0800 (PST) Subject: Re: [PATCH] RFC: C/C++: print help when a header can't be found To: David Malcolm , gcc-patches@gcc.gnu.org References: <1541979208-37968-1-git-send-email-dmalcolm@redhat.com> From: Martin Sebor Message-ID: <57d84cfc-5aeb-5fc1-996e-d1aed976afcf@gmail.com> Date: Mon, 12 Nov 2018 21:01:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <1541979208-37968-1-git-send-email-dmalcolm@redhat.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2018-11/txt/msg00996.txt.bz2 On 11/11/2018 04:33 PM, David Malcolm wrote: > When gcc can't find a header file, it's a hard error that stops the build, > typically requiring the user to mess around with compile flags, Makefiles, > dependencies, and so forth. > > Often the exact search paths aren't obvious to the user. Consider the > case where the include paths are injected via a tool such as pkg-config, > such as e.g.: > > gcc $(pkg-config --cflags glib-2.0) demo.c > > This patch is an attempt at being more helpful for such cases. Given that > the user can't proceed until the issue is resolved, I think it's reasonable > to default to telling the user as much as possible about what happened. > This patch list all of the search paths, and any close matches (e.g. for > misspellings). > > Without the patch, the current behavior is: > > misspelled-header-1.c:1:10: fatal error: test-header.hpp: No such file or directory > 1 | #include "test-header.hpp" > | ^~~~~~~~~~~~~~~~~ > compilation terminated. > > With the patch, the user gets this output: > > misspelled-header-1.c:1:10: fatal error: test-header.hpp: No such file or directory > 1 | #include "test-header.hpp" > | ^~~~~~~~~~~~~~~~~ > misspelled-header-1.c:1:10: note: paths searched: > misspelled-header-1.c:1:10: note: path: '' > misspelled-header-1.c:1:10: note: not found: 'test-header.hpp' > misspelled-header-1.c:1:10: note: close match: 'test-header.h' > 1 | #include "test-header.hpp" > | ^~~~~~~~~~~~~~~~~ > | "test-header.h" > misspelled-header-1.c:1:10: note: path: '/usr/include/glib-2.0' (via '-I') > misspelled-header-1.c:1:10: note: not found: '/usr/include/glib-2.0/test-header.hpp' > misspelled-header-1.c:1:10: note: path: '/usr/lib64/glib-2.0/include' (via '-I') > misspelled-header-1.c:1:10: note: not found: '/usr/lib64/glib-2.0/include/test-header.hpp' > misspelled-header-1.c:1:10: note: path: './include' (system directory) > misspelled-header-1.c:1:10: note: not found: './include/test-header.hpp' > misspelled-header-1.c:1:10: note: path: './include-fixed' (system directory) > misspelled-header-1.c:1:10: note: not found: './include-fixed/test-header.hpp' > misspelled-header-1.c:1:10: note: path: '/usr/local/include' (system directory) > misspelled-header-1.c:1:10: note: not found: '/usr/local/include/test-header.hpp' > misspelled-header-1.c:1:10: note: path: '/usr/include' (system directory) > misspelled-header-1.c:1:10: note: not found: '/usr/include/test-header.hpp' > compilation terminated. > > showing the paths that were tried, and why (e.g. the -I paths injected by > the pkg-config invocation), and the .hpp vs .h issue (with a fix-it hint). > > It's verbose, but as I said above, the user can't proceed until they > resolve it, so I think being verbose is appropriate here. > > Thoughts? I think printing the directories and especially the near matches will be very helpful, especially for big projects with lots of -I options. The output could be made substantially shorter, less repetitive, and so easier to read -- basically cut in half -- by avoiding most of the duplication and collapsing two notes into one, e.g. like so: fatal error: test-header.hpp: No such file or directory 1 | #include "test-header.hpp" | ^~~~~~~~~~~~~~~~~ note: paths searched: note: -I '.' note: close match: 'test-header.h' 1 | #include "test-header.hpp" | ^~~~~~~~~~~~~~~~~ | "test-header.h" note: -I '/usr/include/glib-2.0' note: -I '/usr/lib64/glib-2.0/include' note: -isystem './include' note: -isystem './include-fixed' note: -isystem '/usr/local/include' note: -isystem '/usr/include' or by printing the directories in sections: note: -I paths searched: note: '.' note: close match: 'test-header.h' 1 | #include "test-header.hpp" | ^~~~~~~~~~~~~~~~~ | "test-header.h" note: '/usr/include/glib-2.0' note: '/usr/lib64/glib-2.0/include' note: -isystem paths searched: note: './include' note: './include-fixed' note: '/usr/local/include' note: '/usr/include' Martin