[gnome-builder] meson: Get compile flags from compilable file for headers



commit 8b55f15b62d55ab2d22333a10faf69ca0d186881
Author: Patrick Griffis <tingping tingping se>
Date:   Fri Aug 4 17:39:29 2017 -0400

    meson: Get compile flags from compilable file for headers
    
    This is a bit of a hack but it will usually be an accurate way
    of getting compile flags that a header file would have.

 plugins/meson/meson_plugin/__init__.py |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
---
diff --git a/plugins/meson/meson_plugin/__init__.py b/plugins/meson/meson_plugin/__init__.py
index 73c98ab..352b0f1 100644
--- a/plugins/meson/meson_plugin/__init__.py
+++ b/plugins/meson/meson_plugin/__init__.py
@@ -121,9 +121,17 @@ class MesonBuildSystem(Ide.Object, Ide.BuildSystem, Gio.AsyncInitable):
                 return
 
             infile = task.ifile.get_path()
+            # If this is a header file we want the flags for a C/C++/Objc file.
+            # (Extensions Match GtkSourceViews list)
+            is_header = infile.endswith(('.h', '.hpp', '.hh', '.h++', '.hp'))
+            if is_header:
+                # So just try to find a compilable file with the same prefix as
+                # that is *probably* correct.
+                infile = infile.rpartition('.')[0] + '.'
             for c in commands:
                 filepath = path.normpath(path.join(c['directory'], c['file']))
-                if filepath == infile:
+                if (is_header is False and filepath == infile) or \
+                   (is_header is True and filepath.startswith(infile)):
                     try:
                         task.build_flags = extract_flags(c['command'], builddir)
                     except GLib.Error as e:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]