From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: joaotavora@gmail.com (=?utf-8?B?Sm/Do28gVMOhdm9yYQ==?=) Newsgroups: gmane.emacs.devel Subject: Re: New Flymake rewrite in emacs-26 Date: Wed, 11 Oct 2017 01:07:19 +0100 Message-ID: <87a80y8s3s.fsf@gmail.com> References: <8760bwz5qf.fsf@gmail.com> <83infw1dkz.fsf@gnu.org> <87efqbb35x.fsf@gmail.com> <831smbqe70.fsf@gnu.org> <87tvz79h0s.fsf@gmail.com> <83wp43ov7s.fsf@gnu.org> <87bmlf9dh3.fsf@gmail.com> <83tvz7ot1o.fsf@gnu.org> <87y3oj7x60.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1507680460 25760 195.159.176.226 (11 Oct 2017 00:07:40 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 11 Oct 2017 00:07:40 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.60 (gnu/linux) Cc: Lele Gaifax , Emacs developers , Mark Oteiza , Stefan Monnier , Eli Zaretskii , Leo Liu To: Noam Postavsky Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Oct 11 02:07:36 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e24Yf-0005nf-MA for ged-emacs-devel@m.gmane.org; Wed, 11 Oct 2017 02:07:33 +0200 Original-Received: from localhost ([::1]:37896 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e24Yl-00040A-BP for ged-emacs-devel@m.gmane.org; Tue, 10 Oct 2017 20:07:39 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47579) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e24Ya-0003yx-P9 for emacs-devel@gnu.org; Tue, 10 Oct 2017 20:07:29 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e24YW-0004v7-Ge for emacs-devel@gnu.org; Tue, 10 Oct 2017 20:07:28 -0400 Original-Received: from mail-wr0-x22f.google.com ([2a00:1450:400c:c0c::22f]:51217) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e24YW-0004ug-63; Tue, 10 Oct 2017 20:07:24 -0400 Original-Received: by mail-wr0-x22f.google.com with SMTP id j14so16212wre.8; Tue, 10 Oct 2017 17:07:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=pyms/A1TKhh9AGEw3C9zp8avaf09vuiRoHieNs6J/70=; b=Pq/iiOlJ35LXOsj39VSXizUU958dPsmv9ghX4lhpr3WkjG/t6h00H4J/mU5XbNdnNp n4gxvVSNOq4BtlLDf2LY7mO3Nscj42V37h7ejRZ9HcmwW7EcKwqzl8Ax0VPQoNiI5L80 OfRUNtPpU1tGBGm5G4ZCq9fmiXloxsj3bikQiVqRer+mScgyEjABk2i5KRdjBF4UAfUV 4ifPz57KHNCBzqEb4LnGhqPR8C8/GsUHJYGNVT7RBwktJo20hqJRtmrOM55xxoh3k0Nb mRqaYO+9Qvtrq3sUPZsGI0BpgzyC+gu9M8h6L8qcem94DxJa0b/stmUoMSOGjWbU4oKP Hkgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=pyms/A1TKhh9AGEw3C9zp8avaf09vuiRoHieNs6J/70=; b=B3erc4K3inHQGzYQ7OBtpb2tI82NbpPBNwEUhuMBnP6UiARMy4k5YjgGSviBzt/CZJ 06Yg2uJ339CwHPQtclZTAZbE2YmuLygH5O8lIC9Jlrd4wO/3EnxTJlHdp+2pJlxoO6gI r08OfhSoNFVRfFv0o6Rw5vMPyF7lZ1lSdQ/oZRZJVmJjbEvFQsVrfUXR/DsBGWQ1WYbU 63slVyNV3Jk9Q1jCAeXVqc30LAHP/Rs6tfpuE2Y3rxyIS6pfANVE3ITiUF1v0+SeBpSf GuzmlPjzNIj5gkG8d9oZ9sKgZR1zkNJT5nVe9JxFPUVVIejE+BaGYSefXVr9+C65WG7a n+Fw== X-Gm-Message-State: AMCzsaUHrcrYu+gpVqDbHRQ0hK/zZWpWes0/sHZzNZ7cM0FKC51y5zDL 480HlkqX6e/hC5ep9yXTOP097nNnMqI= X-Google-Smtp-Source: AOwi7QBtW3lFQ3kWOrSjB1neRVumKx3gxCZE0GRsvMUv6DmITHXsDEUvGYEMuUf4j40fwNgNCfp/XA== X-Received: by 10.223.138.231 with SMTP id z36mr8947916wrz.154.1507680442850; Tue, 10 Oct 2017 17:07:22 -0700 (PDT) Original-Received: from lolita.yourcompany.com (188.139.62.94.rev.vodafone.pt. [94.62.139.188]) by smtp.gmail.com with ESMTPSA id w14sm7042536wmf.13.2017.10.10.17.07.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Oct 2017 17:07:21 -0700 (PDT) In-Reply-To: (Noam Postavsky's message of "Tue, 10 Oct 2017 13:20:33 -0400") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22f X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:219364 Archived-At: Noam Postavsky writes: > I've also hardly ever used flymake, so this may be nonsense, but maybe > you could run 'make --just-print foo.o' to get the exact shell > commands for compiling foo.c. This would bypass any need to know > details of compilation beyond figuring out the target name from the > source. Thanks for the idea. Certainly not nonsense, but also not a silver bullet, since Makefiles can invoke gcc in arbitrary ways that fool a guesser. Still, it=E2=80=99s probably decent in a fair amount of cases, and= I=E2=80=99m giving it a go to see if it works with Emacs sources and perhaps some other GNU projects. I attach my flag-guessing function at the end. First, my idea is to cache the result of these flags contingent on the Makefile=E2=80=99s location and mtime. This, I think, is doable. Then I use= a regexp to extract the gcc invocation from the output. The regexp is very poor but does the job. For the src/fringe.c file the regexp is "gcc[[:space:]]+\\(\\(?:-.*\\)*\\)/path/to/fringe.c" This indeed matches Make=E2=80=99s output and gets me something like this f= or the match group 1 -c -Demacs -I. -I. -I../lib -I../lib -isystem /usr/include/freetype2 -isystem /usr/include/alsa -pthread -isystem /usr/include/librsvg-2.0 -isystem /usr/include/gdk-pixbuf-2.0 -isystem /usr/include/libpng16 -isystem /usr/include/cairo -isystem /usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -isystem /usr/include/pixman-1 -isystem /usr/include/freetype2 -isystem /usr/include/libpng16 -isystem /usr/include/libpng16 -isystem /usr/include/libxml2 -isystem /usr/include/dbus-1.0 -isystem /usr/lib/x86_64-linux-gnu/dbus-1.0/include -pthread -isystem /usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -isystem /usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -isystem /usr/include/freetype2 -isystem /usr/include/freetype2 -isystem /usr/include/freetype2 -MMD -MF deps//home/capitaomorte/Source/Emacs/emacs-26/src/fringe.d -MP -isystem /usr/include/p11-kit-1 -fno-common -W -Wabi -Waddress [... elided many many -W flags] -Wno-type-limits -Wno-unused-parameter -Wno-format-nonliteral -g3 -O2 Unfortunately, not all flags make sense for flymake, like the -M family of flags. Ideally, i=E2=80=99d need a way to parse this big string of flags= back into, say, an alist, and cherry pick the -I, -D, and -W flags from that set. But I=E2=80=99m afraid split-string will insufficiently deal with esca= ped spaces in the output. Any ideas? Jo=C3=A3o PS: My WIP follows (defvar-local flymake--gcc-cached-flags nil) (defun flymake-gcc-guess-gcc-flags (&optional trash-cache) (interactive "P") (unless (executable-find "make") (error "Cannot find a suitable make")) (when trash-cache (setq flymake--gcc-cached-flags nil)) (catch 'retval (when-let* ((makefile-dir (locate-dominating-file default-directory "Makefile")) (makefile (expand-file-name "Makefile" makefile-dir)) (mtime (file-attribute-modification-time (file-attributes makefile)))) (cond ((equal (list makefile mtime) (cdr flymake--gcc-cached-flags)) (when (called-interactively-p 'interactive) (message "cached hit for flags for this buffer: %s" (car flymake--gcc-cached-flags))) (throw 'retval (car flymake--gcc-cached-flags))) (t (when-let* ((blob (shell-command-to-string (format "make -B -C %s -f %s --just-print %s.o" makefile-dir makefile (file-name-sans-extension (buffer-file-name))))) (match (string-match (format "gcc[[:space:]]+\\(\\(?:-.*\\)*\\)%s" (buffer-file-name)) blob)) (flags (split-string (match-string 1 blob) nil t "[[:space:]]"= ))) (setq flymake--gcc-cached-flags (list flags makefile mtime)) (when (called-interactively-p 'interactive) (message "cached miss for flags for this buffer: %s" flags)) (throw 'retval flags)))) (when (called-interactively-p 'interactive) (message "Couldn=E2=80=99t guess flags for this buffer :-(")))))