Re: Re: Patch for generator - allow compiling against multiple gtk versions

From: Date: Wed, 31 Jan 2007 17:10:50 +0000
Subject: Re: Re: Patch for generator - allow compiling against multiple gtk versions
References: 1 2 3  Groups: php.gtk.dev 
Request: Send a blank email to php-gtk-dev+get-3652@lists.php.net to get a copy of this message
Looks fine. Please commit. -Andrei On Jan 30, 2007, at 12:24 PM, Elizabeth Smith wrote:
Here's the final version of the generator patch - this has no changes for the build system, it only alters files in the php-gtk/generator directory. It allows the ability to pass a gtk library version when calling the generator (using -v) version 2.6 is assumed if nothing is passed. The version is used only on include files, which can have a minimum version used after them include "myfile" 2.8 This will allow files to be merged together whenever the minimum version of gtk required changes without any messy copy/pasting. The patch also allows a restore keyword in overrides files to restore a method (thanks for the unignore array idea, Andrei, works great) This patch doesn't change anything in the current build system and you can compile as usual with it applied - changes to configure and def files would be required to actually get it to do anything special. Thanks, Elizabeth Smith Index: generator.php =================================================================== RCS file: /repository/php-gtk/generator/generator.php,v retrieving revision 1.118 diff -u -r1.118 generator.php --- generator.php 22 Jan 2007 14:27:32 -0000 1.118 +++ generator.php 30 Jan 2007 19:26:18 -0000 @@ -1406,23 +1406,24 @@ } -$result = Console_Getopt::getopt($argv, 'l:o:p:c:r:f:'); +$result = Console_Getopt::getopt($argv, 'l:o:p:c:r:f:v:'); if (!$result || count($result[1]) < 2)
-    die("usage: php generator.php [-l logfile] [-o overridesfile] [-p prefix] [-c functionclass ] [-r typesfile] [-f savefile] defsfile\n");
+    die("usage: php generator.php [-l logfile] [-o overridesfile] [-p prefix] [-c functionclass ] [-r typesfile] [-f savefile] [-v gtklibversion] defsfile\n");
list($opts, $argv) = $result; $prefix = 'Gtk'; $function_class = null; -$overrides = new Overrides(); +$overrides = null; $register_defs = array(); $savefile = 'php://stdout'; $logfile = 'php://stderr'; +$gtkversion = '2.6'; foreach ($opts as $opt) {
     list($opt_spec, $opt_arg) = $opt;
     if ($opt_spec == 'o') {
-        $overrides = new Overrides($opt_arg);
+        $overrides = $opt_arg;
     } else if ($opt_spec == 'p') {
         $prefix = $opt_arg;
     } else if ($opt_spec == 'c') {
@@ -1433,6 +1434,8 @@
         $savefile = $opt_arg;
     } else if ($opt_spec == 'l') {
         $logfile = $opt_arg;
+    } else if ($opt_spec == 'v') {
+        $gtkversion = $opt_arg;
     }
} @@ -1440,11 +1443,12 @@
     include(dirname($argv[1]) . '/arg_types.php');
} -$parser = new Defs_Parser($argv[1]); +$overrides = new Overrides($overrides, $gtkversion); +$parser = new Defs_Parser($argv[1], $gtkversion); $generator = new Generator($parser, $overrides, $prefix, $function_class); $generator->set_logfile($logfile); foreach ($register_defs as $defs) {
-    $type_parser = new Defs_Parser($defs);
+    $type_parser = new Defs_Parser($defs, $gtkversion);
     $type_parser->start_parsing();
     $generator->register_types($type_parser);
} @@ -1455,4 +1459,4 @@ error_reporting($old_error_reporting); /* vim: set et sts=4: */ -?> +?> \ No newline at end of file Index: override.php =================================================================== RCS file: /repository/php-gtk/generator/override.php,v retrieving revision 1.32 diff -u -r1.32 override.php --- override.php 27 Mar 2006 04:23:11 -0000 1.32 +++ override.php 30 Jan 2007 20:19:23 -0000 @@ -23,6 +23,7 @@ class Overrides {
     var $ignores              = array();
+    var $unignores            = array();
     var $glob_ignores         = array();
     var $overrides            = array();
     var $prop_overrides       = array();
@@ -37,9 +38,15 @@
     var $post_registration    = array();
     var $lineinfo             = array();
     var $top_dir              = '';
+    var $gtkversion           = null; // gtk lib version
-    function Overrides($file_name = null)
+    function Overrides($file_name = null, $gtkversion = null)
     {
+        if (version_compare($gtkversion, '2.6', '<'))
+        {
+            $gtkversion = '2.6';
+        }
+        $this->gtkversion = $gtkversion;
         if (!isset($file_name))
             return;
@@ -111,6 +118,13 @@
                     $this->ignores[$func] = true;
                 break;
+            case 'restore':
+                foreach ($words as $func)
+                    $this->unignores[$func] = true;
+                foreach (preg_split('!\s+!', $rest, -1, PREG_SPLIT_NO_EMPTY) as $func)
+                    $this->unignores[$func] = true;
+                break;
+
             case 'ignore-win32':
                 if (WIN_OS) {
                     foreach ($words as $func)
@@ -176,7 +190,11 @@
             case 'include':
                 $file_name = $words[0];
-                $this->read_file($file_name);
+                // check for gtk lib version
+                if (!isset($words[1]) || version_compare($words[1], $this->gtkversion, '<='))
+                {
+                    $this->read_file($file_name);
+                }
                 foreach (preg_split(',\s+,', $rest, -1, PREG_SPLIT_NO_EMPTY) as $file_name) {
                     $this->read_file($file_name);
                 }
@@ -227,6 +245,9 @@
     function is_ignored($name)
     {
+        if(isset($this->unignores[$name]))
+            return false;
+
         if (isset($this->ignores[$name]))
             return true;
Index: scheme.php =================================================================== RCS file: /repository/php-gtk/generator/scheme.php,v retrieving revision 1.28 diff -u -r1.28 scheme.php --- scheme.php 30 Mar 2005 18:34:09 -0000 1.28 +++ scheme.php 27 Jan 2007 16:20:19 -0000 @@ -110,9 +110,15 @@
     var $boxed          = array();  // boxed types
     var $pointers       = array();  // pointers
     var $c_name         = array();  // C names of entities
+    var $gtkversion     = null; // gtk lib version
-    function Defs_Parser($arg)
+    function Defs_Parser($arg, $gtkversion = 0)
     {
+        if (version_compare($gtkversion, '2.6', '<'))
+        {
+            $gtkversion = '2.6';
+        }
+        $this->gtkversion = $gtkversion;
         switch (gettype($arg)) {
             case 'string':
                 $this->_parse_or_load($arg);
@@ -415,9 +421,17 @@
     function handle_include($arg)
     {
         $include_file = $this->file_path . "/" . $arg[0];
-        error_log("Parsing file \"$include_file\".");
-        $include_tree = parse($include_file, 'r');
-        $this->start_parsing($include_tree);
+        // check for gtk lib version
+        if (isset($arg[1]) && version_compare($arg[1], $this->gtkversion, '<='))
+        {
+            error_log("Ignoring \"$include_file\". - needs version {$arg[1]}");
+        }
+        else
+        {
+            error_log("Parsing file \"$include_file\".");
+            $include_tree = parse($include_file, 'r');
+            $this->start_parsing($include_tree);
+        }
     }
     function handle_define_virtual($arg)
-- PHP-GTK Development Mailing List (http://gtk.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.gtk.dev (#3652) next »