JSDOC/ScopeParser.js
[gnome.introspection-doc-generator] / jhbuild.js
1 //<script type="text/javascript">
2
3
4 /** NOT CURRENTLY BEING WORKED ON !!! */
5
6
7 GLib= imports.gi.GLib;
8 Gio = imports.gi.Gio;
9
10
11 File = imports.File.File;
12 console = imports.console.console;
13
14 Seed.include('Date.js');
15  
16 //DateExtra = imports.DateExtra.DateExtra;
17
18  
19
20 // these should come from args
21 var SRC='/disk2/checkout/gnome2/';
22
23 // perhaps we can just do a simple make for building the girs - no make install etc.?
24 var UPDATE_SOURCES = false;
25
26
27
28 var LOGFILE = "jhbuild-" + (new Date()).format("Y-m-d-H") + '.log';
29
30
31 // change src & deleteGirs when you add / remove girs..
32 /*
33
34 USAGE:
35 screen -d -m seed jhbuild.js
36 tail /tmp/builder.log
37
38 TODO:
39 continue - do not trash gir's...
40 use this to diff changes when we fix gobject introspection..
41 git diff on directories..
42 email me the results.
43 run the doc tool as well.
44
45
46 patching
47 --- before jhbuild..
48 --- git diff (current to /SRC/package-DATE.diff)
49 --- see if we have a patch list
50 --- if so: git reset --hard
51 ---    apply patch..
52 --- run jhbuild.
53
54 to add:
55 avahi + core.
56 babl
57 dbus
58  
59
60 sqlite3
61 libbonbo
62
63 to fix: - see the list of modules commented out.
64
65 */
66
67
68
69 var deleteGirs = [
70         'atk/atk/Atk-1.0.gir',
71     'clutter/clutter/json/ClutterJson-1.0.gir',
72         'clutter/clutter/cogl/Cogl-1.0.gir',
73         'clutter/clutter/Clutter-1.0.gir',
74         'clutter/clutter/Cogl-1.0.gir',
75         'clutter/clutter/ClutterJson-1.0.gir',
76     'epiphany/src/Epiphany-2.29.gir',
77     'libgda/libgda/Gda-4.0.gir',
78         'libgda/libgda-ui/Gdaui-4.0.gir',
79     'libgsf/gsf/Gsf-1.gir',
80     'gobject-introspection/gir/libxml2-2.0.gir', // needed!
81         'gobject-introspection/gir/Gio-2.0.gir',
82         'gobject-introspection/gir/GModule-2.0.gir',
83         'gobject-introspection/gir/GLib-2.0.gir',
84         'gobject-introspection/gir/GIRepository-2.0.gir',
85         'gobject-introspection/gir/GObject-2.0.gir',
86         
87         'gtk+/gdk-pixbuf/GdkPixbuf-2.0.gir',
88         'gtk+/gtk/Gtk-2.0.gir',
89         'gtk+/gdk/Gdk-2.0.gir',
90     'clutter-gtk/clutter-gtk/GtkClutter-0.10.gir',
91     'gconf/GConf-2.0.gir',
92     'gtksourceview/gtksourceview/GtkSource-2.0.gir',
93         'gstreamer/gst/Gst-0.10.gir',
94         'gstreamer/libs/gst/check/GstCheck-0.10.gir',
95         'gstreamer/libs/gst/net/GstNet-0.10.gir',
96         'gstreamer/libs/gst/controller/GstController-0.10.gir',
97         'gstreamer/libs/gst/base/GstBase-0.10.gir',
98     'gst-plugins-base/gst-libs/gst/video/GstVideo-0.10.gir',
99         'gst-plugins-base/gst-libs/gst/tag/GstTag-0.10.gir',
100         'gst-plugins-base/gst-libs/gst/interfaces/GstInterfaces-0.10.gir',
101         'gst-plugins-base/gst-libs/gst/pbutils/GstPbutils-0.10.gir',
102         'gst-plugins-base/gst-libs/gst/netbuffer/GstNetbuffer-0.10.gir',
103         'gst-plugins-base/gst-libs/gst/riff/GstRiff-0.10.gir',
104         'gst-plugins-base/gst-libs/gst/audio/GstAudio-0.10.gir',
105         'gst-plugins-base/gst-libs/gst/fft/GstFft-0.10.gir',
106         'gst-plugins-base/gst-libs/gst/rtsp/GstRtsp-0.10.gir',
107         'gst-plugins-base/gst-libs/gst/app/GstApp-0.10.gir',
108         'gst-plugins-base/gst-libs/gst/sdp/GstSdp-0.10.gir',
109         'gst-plugins-base/gst-libs/gst/rtp/GstRtp-0.10.gir',
110
111     'gssdp/libgssdp/GSSDP-1.0.gir',
112         'gdome2/libgdome/Gdome-2.0.gir',
113     'gnome-menus/libmenu/GMenu-2.0.gir',
114         
115         
116     
117         'pango/pango/PangoFT2-1.0.gir',
118         'pango/pango/PangoCairo-1.0.gir',
119         'pango/pango/PangoXft-1.0.gir',
120         'pango/pango/Pango-1.0.gir',
121         'PolicyKit/src/polkit/Polkit-1.0.gir',    
122         'unique/unique/Unique-1.0.gir',
123     'vte/src/Vte-0.gir',
124         
125         'WebKit/WebKit-1.0.gir',
126         //'WebKit/WebKit/gtk/JSCore-1.0.gir', -- not a generated file!
127         
128
129 ];
130
131 var all = {
132     
133     // package : directory
134     'atk' : 'atk',
135     'clutter': 'clutter', 
136         'clutter-gtk' :'clutter-gtk', 
137     'eggdbus' : 'eggdbus',
138         'glib' : 'glib' ,   
139         'epiphany' : 'epiphany',
140         'gtk+' : 'gtk+',
141         'gobject-introspection' : 'gobject-introspection',
142          
143         'gstreamer' : 'gstreamer',
144         'gst-plugins-base' : 'gst-plugins-base',
145         'gtksourceview' : 'gtksourceview',
146     'gnome-menus' :     'gnome-menus',
147     'gssdp' :'gssdp',
148         'libgda'  :'libgda',
149         'libgsf' :'libgsf',
150         'libunique' :'unique', 
151     'libsoup' : 'libsoup',
152         'pango' : 'pango',
153     'polkit' : 'PolicyKit', 
154         'vte' : 'vte',
155         'WebKit' :'WebKit',
156     'gconf' : 'gconf',
157     
158     //'gtop',
159     //'panelapplet',
160     //'epiphany'
161     
162     
163     
164     //'gupnp', -- needs patch
165         // 'gnome-keyring' -- ndeds patch
166     // gnome-vfs -- needs patch
167     // 'goocanvas' -- needs patch
168     //'libnotify' -- needs patch
169     // 'poppler' --- 
170     
171 };
172
173 // we dont use these at present..
174 var patches = {
175     'gconf' : [
176        'http://bugzilla-attachments.gnome.org/attachment.cgi?id=156459',
177        'http://bugzilla-attachments.gnome.org/attachment.cgi?id=156457',
178     ],
179     'gnome-keyring' : [
180         // not valid - against release..
181         //'http://bugzilla-attachments.gnome.org/attachment.cgi?id=145422'
182     ],
183     'gtksouceview' : [
184         'http://bugzilla-attachments.gnome.org/attachment.cgi?id=153062',
185     ],
186     'avahi' : [
187        'http://www.akbkhome.com/svn/seed/gir/avahi.diff',
188     ]
189 };
190 /**
191  * 
192  * spawnlog:
193  * spawn process, and print/monitor output.
194  * 
195  * usage scenarios:
196  *  - global log.. -> our global log just indicates what was done and what was the result?
197  *  - build log for a specific package?
198  *  - return data? - 
199  * 
200  * @arg string cwd working directory.
201  * @arg array  args 
202  * @
203  * 
204  */
205 var streams  = { };
206   
207 function  write(fn, str) {
208     if (!str) {
209         return;
210     }
211     
212     if (!fn) {
213         return;
214     }
215     console.log(str.replace(/\n/,''));
216     
217     if (typeof(streams[fn])=='undefined') {
218         GLib.unlink(fn);
219         var f = Gio.file_new_for_path(String(fn));
220         streams[fn] = new Gio.DataOutputStream({
221                 base_stream: f.replace(null, false, Gio.FileCreateFlags.REPLACE_DESTINATION, null)
222             });
223     }
224     streams[fn].put_string(str, null);
225 }
226 function  close(fn) {
227     if (!fn || typeof(streams[fn])=='undefined') {
228         return;
229     }
230     streams[fn].close(null);
231     delete streams[fn];
232 }
233
234
235 function spawnlog (cwd, s, outfile, errfile) {
236     var ret = { };
237     var retval =  { output: '' , error : '', cmd : s.join(' ') , done : false};
238     console.log(retval.cmd);
239     GLib.spawn_async_with_pipes(cwd, s, null, 
240         GLib.SpawnFlags.DO_NOT_REAP_CHILD + GLib.SpawnFlags.SEARCH_PATH , 
241         null, null, ret);
242         
243     var ctx = new GLib.MainLoop.c_new (null, false);
244     var started = false;
245     
246     GLib.child_watch_add(GLib.PRIORITY_DEFAULT, ret.child_pid, function(pid, status) {
247         console.log("GOT STATUS:" + status);
248         retval.status = status;
249         retval.done = true;
250         if (started) {
251             console.log("Ending LOOP");
252             ctx.quit();
253         }
254         
255     });
256    //console.dump(ret);
257
258     var in_ch = GLib.io_channel_unix_new(ret.standard_input);
259     var out_ch = GLib.io_channel_unix_new(ret.standard_output);
260     var err_ch = GLib.io_channel_unix_new(ret.standard_error);
261     
262     function readstr(ch, fn, prop) {
263         
264         while (true) {
265             
266             var x = new GLib.String();
267             
268             
269             var cstatus = ch.get_buffer_condition();
270             cstatus = ch.get_flags (ch)
271             
272
273             //Seed.print("WAITING INPUT?" + prop+':'+cstatus);
274             //var status = GLib.io_channel_read_line_string (ch, x, null);
275             
276                
277             var status = ch.read_line_string (x);
278             
279             //Seed.print(prop + ":INPUT:" + status);
280         
281             switch(status) {
282                 case GLib.IOStatus.NORMAL:
283                     write(fn, x.str);
284                     retval[prop] += x.str;
285                    continue
286                 case GLib.IOStatus.AGAIN:   
287                     break;
288                 case GLib.IOStatus.ERROR:    
289                 case GLib.IOStatus.EOF:   
290                    break;
291                 
292             }
293             break;
294         }
295     }
296     
297     
298     
299     GLib.io_add_watch(in_ch, GLib.PRIORITY_DEFAULT, 
300         GLib.IOCondition.OUT + GLib.IOCondition.IN  + GLib.IOCondition.PRI, function()
301     {
302         //Seed.print("GOT INOUT ON IN");
303         readstr(out_ch, outfile, 'output');
304         
305     });
306     GLib.io_add_watch(err_ch, GLib.PRIORITY_DEFAULT, 
307         GLib.IOCondition.ERR + GLib.IOCondition.IN + GLib.IOCondition.PRI + GLib.IOCondition.OUT, 
308         function()
309     {
310         // Seed.print("GOT INOUT ON ERR");
311          readstr(er_ch, errfile, 'error');
312          
313     });
314     // let's just write some data... 
315     //var x = new GLib.String();
316     //var status = GLib.io_channel_write (out_ch, "\n", 1);
317     
318     //while (!retval.done) {
319             
320      
321     //}
322  
323     // do we need this?
324     if (!retval.done) {
325         started = true;
326         console.log("STARTING LOOP");
327         ctx.run(); // wait fore exit?
328     }
329     readstr(out_ch, outfile, 'output');
330     readstr(err_ch, errfile, 'error');
331      
332     
333     
334     
335     close(outfile);
336     close(errfile);
337     
338     //GLib.spawn_close_pid(ret.child_pid);
339     return retval;
340     
341
342 }
343   
344
345 function log(res) {
346     if (typeof(res) == 'string') {
347         if (!res.length) { // skip blan.
348             return;
349         }
350         
351         
352         write(SRC + LOGFILE, '[' + (new Date()).format("Y-m-d H:i:s") + '] ' + res);
353         return;
354     }
355     log("CMD:" + res.cmd +"\n");
356     log("RETURN:" + (res.status ? res.status : "OK")+"\n");
357     log(res.output ? "---OUT---\n" + res.output + "\n" : '');
358     log(res.error ? " ---ERROR---\n" + res.error + "\n" : '');
359    
360 }
361 function logresult(res) {
362    log("CMD: " + res.cmd +"\n");
363    log((res.status ? "RETURN: " + res.status : 'BUILD OK') +"\n");
364     if (res.status != 0 ) {
365        log(res.error ? "---ERROR---\n" + res.error + "\n" : '');
366     }
367      
368 }
369
370 var nojhbuild = {
371         gdome  : [ 'git', 'clean', 'make' , 'install' ], // fixme..
372          
373     
374     
375 }
376
377 function main() {
378         // delete old..
379     deleteGirs.map( function(g) {
380         try {
381             console.log("DELETE" + SRC + g);
382             GLib.unlink(SRC+g);
383         } catch(e) {
384             console.log(e);
385         }
386         
387     });
388
389     
390     
391     
392     var pkgs = [];
393     var cline = [];
394     for(var i in all) {
395         pkgs.push(i);
396         cline.push(i);
397     }
398     cline.unshift('list');
399     cline.unshift('jhbuild');
400     var order = spawnlog('/tmp', cline).output.split("\n");
401     // push introspection first...!!!
402     
403  
404     var buildorder = [];
405     for (var i=0; i < order.length; i++) {
406         if (!order[i].length || pkgs.indexOf(order[i]) < 0) {
407             //console.log("SKIP (not related to gir) " + order[i] );
408             log("SKIP (not related to gir) " + order[i] +"\n");
409             continue;    
410         }
411         
412         // special cases:
413         // just for our reference..
414         spawnlog('/tmp', ['jhbuild','info', order[i]]);
415         // add -a -c for a clean build..
416         
417         if (!UPDATE_SOURCES) {
418             // quick rebuild - probably to check introspection change results.
419             log("MAKE INSTALL: " + order[i] + "\n");
420             var res = spawnlog(
421                     SRC+all[order[i]], ['bash' , '-c' ,'make install 2>&1'],
422                     SRC+all[order[i]]+'/jhbuild.log', 
423                     SRC+all[order[i]]+'/jhbuild.err'
424             );
425             logresult(res); 
426             continue;
427             
428         }
429         
430         
431         // for git.. - do a diff before we start, and store it..
432         // just in case..
433         if (File.exists(SRC+all[order[i]]+'/.git')) {
434              
435             var gitres = spawnlog( SRC + all[order[i]], [ 'git', 'diff' ]);
436             
437             var fn = false;
438             if (gitres.output.length) {
439                 fn = SRC+all[order[i]]+'-' + (new Date()).format('Y-m-d-H') + '.diff';
440                 log("DIFF STORED: "+ fn+"\n");
441                 write(fn, gitres.output);
442                 close(fn);
443             }
444             log("RESET GIT / PULL\n");
445             spawnlog( SRC + all[order[i]], [ 'git', 'reset', '--hard' ]);
446             spawnlog( SRC + all[order[i]], [ 'git', 'pull' ]);
447             if (fn) {
448                 log("RE-APPLING DIFF\n");
449                 spawnlog( SRC + all[order[i]], [ 'patch', '-p1', '-i',  fn ]);
450             }
451             // we should apply patches here..
452             
453         }
454         
455         
456         
457         while(true) {
458             
459                
460             log("BUILDING : " + order[i] + "\n");
461             var res = spawnlog(
462                     '/tmp', ['jhbuild', '--no-interact', 'buildone',order[i]],
463                     SRC+all[order[i]]+'/jhbuild.log', 
464                     SRC+all[order[i]]+'/jhbuild.err'
465             );
466             logresult(res);
467             if (res.status == 256 && res.error.match(/The remote end hung up unexpectedly/)) {
468                 // try again - git connection failed..
469                 continue;
470             }
471             break;
472         }
473        
474    
475         
476         
477     }
478     close(SRC + LOGFILE);
479         
480         
481 }
482
483  
484 main();
485 // specials..
486 //polkit  -> PolicyKit
487 //WebKit -> svn 
488 //gdome -> manual..
489 //libxml2 -> last! and must manual..
490
491 // refresh build...
492 // we can just trash the gir's..
493 // usefull for checking changes in introspection..
494 // then run make on the whole lot..
495
496
497 // special treatment
498 //libxml (must be after introspecton)
499
500
501
502
503
504 // full build - needs jhbuild really...
505 // ideally:
506 // -- will not build stuff that's not changed.. (we need to store checkout id's to make this work..)
507 // otherwise do a -a -c 
508
509
510
511 // what this has to do.. (similar to jhbuild...?? why not use it???
512