[gobject-introspection] giscanner: remove g_realpath



commit ebb80508d6959a0c94351e841c2cab6220602e62
Author: Dieter Verfaillie <dieterv optionexplicit be>
Date:   Thu Oct 17 17:43:48 2013 +0200

    giscanner: remove g_realpath
    
    giscannermodule expects file names to be canonicalized and
    symlinks to be resolved (most likely to support users of
    symlinked /usr/local). Instead of computing absolute and real
    paths all over the place, we can do this once on entry
    in SourceScanner().parse_files() and SourceScanner().parse_macros()
    and clean the rest a bit...
    
    https://bugzilla.gnome.org/show_bug.cgi?id=710320

 Makefile-giscanner.am       |    3 +-
 giscanner/giscannermodule.c |    5 +--
 giscanner/grealpath.h       |   64 -------------------------------------------
 giscanner/scannerlexer.l    |   11 +------
 giscanner/scannermain.py    |    4 +-
 giscanner/sourcescanner.py  |    8 +++---
 6 files changed, 11 insertions(+), 84 deletions(-)
---
diff --git a/Makefile-giscanner.am b/Makefile-giscanner.am
index 095bbd6..e3a934a 100644
--- a/Makefile-giscanner.am
+++ b/Makefile-giscanner.am
@@ -17,8 +17,7 @@ libgiscanner_la_SOURCES = \
        giscanner/sourcescanner.c                               \
        giscanner/sourcescanner.h                               \
        giscanner/scannerlexer.l                                \
-       giscanner/scannerparser.y                               \
-       giscanner/grealpath.h
+       giscanner/scannerparser.y
 libgiscanner_la_CPPFLAGS = -I$(top_srcdir)/girepository -I$(top_srcdir)/giscanner
 libgiscanner_la_LIBADD = $(GOBJECT_LIBS) $(GIO_LIBS)
 libgiscanner_la_CFLAGS = $(GOBJECT_CFLAGS) $(GIO_CFLAGS)
diff --git a/giscanner/giscannermodule.c b/giscanner/giscannermodule.c
index 2f4c0e8..2f413a0 100644
--- a/giscanner/giscannermodule.c
+++ b/giscanner/giscannermodule.c
@@ -28,7 +28,6 @@
 #ifdef G_OS_WIN32
 #define USE_WINDOWS
 #endif
-#include "grealpath.h"
 
 #ifdef _WIN32
 #include <fcntl.h>
@@ -361,7 +360,7 @@ pygi_source_scanner_append_filename (PyGISourceScanner *self,
   if (!PyArg_ParseTuple (args, "s:SourceScanner.append_filename", &filename))
     return NULL;
 
-  file = g_file_new_for_path (g_realpath (filename));
+  file = g_file_new_for_path (filename);
   g_hash_table_add (self->scanner->files, file);
 
   Py_INCREF (Py_None);
@@ -517,7 +516,7 @@ pygi_source_scanner_lex_filename (PyGISourceScanner *self,
   if (!PyArg_ParseTuple (args, "s:SourceScanner.lex_filename", &filename))
     return NULL;
 
-  self->scanner->current_file = g_file_new_for_path ( g_realpath (filename));
+  self->scanner->current_file = g_file_new_for_path (filename);
   if (!gi_source_scanner_lex_filename (self->scanner, filename))
     {
       g_print ("Something went wrong during lexing.\n");
diff --git a/giscanner/scannerlexer.l b/giscanner/scannerlexer.l
index 91f50cb..f30191d 100644
--- a/giscanner/scannerlexer.l
+++ b/giscanner/scannerlexer.l
@@ -35,7 +35,6 @@
 #include <glib.h>
 #include "sourcescanner.h"
 #include "scannerparser.h"
-#include "grealpath.h"
 
 int lineno;
 char linebuf[2000];
@@ -316,17 +315,11 @@ process_linemarks (GISourceScanner *scanner)
 {
        char escaped_filename[1025];
        char *filename;
-       char *real;
 
        sscanf(yytext, "# %d \"%1024[^\"]\"", &lineno, escaped_filename);
        filename = g_strcompress (escaped_filename);
-       real = g_realpath (filename);
-       if (real) {
-               g_object_unref (scanner->current_file);
-               scanner->current_file = g_file_new_for_path (real);
-       } else {
-               g_free (real);
-       }
+       g_object_unref (scanner->current_file);
+       scanner->current_file = g_file_new_for_path (filename);
        g_free (filename);
 }
 
diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py
index ab8f5bb..6ae2ded 100755
--- a/giscanner/scannermain.py
+++ b/giscanner/scannermain.py
@@ -267,7 +267,7 @@ def extract_filenames(args):
                 _error('%s: no such a file or directory' % (arg, ))
             # Make absolute, because we do comparisons inside scannerparser.c
             # against the absolute path that cpp will give us
-            filenames.append(os.path.abspath(arg))
+            filenames.append(arg)
     return filenames
 
 
@@ -289,7 +289,7 @@ def extract_filelist(options):
                 _error('%s: Invalid filelist entry-no such file or directory' % (line, ))
             # Make absolute, because we do comparisons inside scannerparser.c
             # against the absolute path that cpp will give us
-            filenames.append(os.path.abspath(filename))
+            filenames.append(filename)
     return filenames
 
 
diff --git a/giscanner/sourcescanner.py b/giscanner/sourcescanner.py
index d5c4392..3444445 100644
--- a/giscanner/sourcescanner.py
+++ b/giscanner/sourcescanner.py
@@ -237,14 +237,14 @@ class SourceScanner(object):
 
     def parse_files(self, filenames):
         for filename in filenames:
-            filename = os.path.abspath(filename)
+            # self._scanner expects file names to be canonicalized and symlinks to be resolved
+            filename = os.path.realpath(filename)
             self._scanner.append_filename(filename)
             self._filenames.append(filename)
 
         headers = []
         for filename in filenames:
             if os.path.splitext(filename)[1] in SOURCE_EXTS:
-                filename = os.path.abspath(filename)
                 self._scanner.lex_filename(filename)
             else:
                 headers.append(filename)
@@ -253,7 +253,8 @@ class SourceScanner(object):
 
     def parse_macros(self, filenames):
         self._scanner.set_macro_scan(True)
-        self._scanner.parse_macros(filenames)
+        # self._scanner expects file names to be canonicalized and symlinks to be resolved
+        self._scanner.parse_macros([os.path.realpath(f) for f in filenames])
         self._scanner.set_macro_scan(False)
 
     def get_symbols(self):
@@ -298,7 +299,6 @@ class SourceScanner(object):
         for undef in undefs:
             proc.stdin.write('#undef %s\n' % (undef, ))
         for filename in filenames:
-            filename = os.path.abspath(filename)
             proc.stdin.write('#include <%s>\n' % (filename, ))
         proc.stdin.close()
 


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