3 public class AppSettings : Object
8 // what are we going to have as settings?
9 public string roo_html_dir { get; set; }
13 this.notify.connect(() => {
18 public static AppSettings factory()
21 var setting_file = BuilderApplication.configDirectory() + "/builder.settings";
23 if (!FileUtils.test(setting_file, FileTest.EXISTS)) {
24 return new AppSettings();
27 FileUtils.get_contents(setting_file, out data);
28 return Json.gobject_from_data (typeof (AppSettings), data) as AppSettings;
32 var dirname = GLib.Environment.get_home_dir() + "/.Builder";
33 var setting_file = dirname + "/builder.settings";
34 string data = Json.gobject_to_data (this, null);
35 print("saving application settings\n");
36 FileUtils.set_contents(setting_file, data);
43 public static BuilderApplication application = null;
45 public class BuilderApplication : Gtk.Application
48 // options - used when builder is run as a compiler
49 // we have to spawn ourself as a compiler as just running libvala
50 // as a task to check syntax causes memory leakage..
52 const OptionEntry[] options = {
55 { "project", 0, 0, OptionArg.STRING, ref opt_compile_project, "Compile a project", null },
56 { "target", 0, 0, OptionArg.STRING, ref opt_compile_target, "Target to build", null },
57 { "skip-file", 0, 0, OptionArg.STRING, ref opt_compile_skip ,"For test compiles do not add this (usually used in conjunction with add-file ", null },
58 { "add-file", 0, 0, OptionArg.STRING, ref opt_compile_add, "Add this file to compile list", null },
59 { "output", 0, 0, OptionArg.STRING, ref opt_compile_output, "output binary file path", null },
60 { "debug", 0, 0, OptionArg.NONE, ref opt_debug, "Show debug messages", null },
61 { "pull-resources", 0, 0, OptionArg.NONE, ref opt_pull_resources, "Fetch the online resources", null },
64 { "list-projects", 0, 0, OptionArg.NONE, ref opt_list_projects, "List Projects", null },
65 { "list-files", 0, 0, OptionArg.NONE, ref opt_list_files, "List Files (in a project", null},
66 { "bjs", 0, 0, OptionArg.STRING, ref opt_bjs_compile, "convert bjs file (use all to convert all of them and compare output)", null },
67 { "bjs-glade", 0, 0, OptionArg.NONE, ref opt_bjs_compile_glade, "output glade", null },
68 { "bjs-test-all", 0, 0, OptionArg.NONE, ref opt_bjs_test, "Test all the BJS files to see if the new parser/writer would change anything", null },
69 { "bjs-target", 0, 0, OptionArg.STRING, ref opt_bjs_compile_target, "convert bjs file to tareet : vala / js", null },
70 { "test", 0, 0, OptionArg.STRING, ref opt_test, "run a test use 'help' to list the available tests", null },
74 public static string opt_compile_project;
75 public static string opt_compile_target;
76 public static string opt_compile_skip;
77 public static string opt_compile_add;
78 public static string opt_compile_output;
79 public static string opt_bjs_compile;
81 public static string opt_bjs_compile_target;
82 public static string opt_test;
83 public static bool opt_debug = false;
84 public static bool opt_list_projects = false;
85 public static bool opt_list_files = false;
86 public static bool opt_pull_resources = false;
87 public static bool opt_bjs_compile_glade = false;
88 public static bool opt_bjs_test = false;
89 public static string _self;
98 public const Gtk.TargetEntry[] targetList = {
99 { "INTEGER", 0, Target.INT32 },
100 { "STRING", 0, Target.STRING },
101 { "application/json", 0, Target.STRING },
102 { "text/plain", 0, Target.STRING },
103 { "application/x-rootwindow-drop", 0, Target.ROOTWIN }
105 public AppSettings settings = null;
108 public BuilderApplication ( string[] args)
111 _self = FileUtils.read_link("/proc/self/exe");
112 GLib.debug("SELF = %s", _self);
115 application_id: "org.roojs.app-builder",
116 flags: ApplicationFlags.FLAGS_NONE
120 this.settings = AppSettings.factory();
121 var opt_context = new OptionContext ("Application Builder");
124 opt_context.set_help_enabled (true);
125 opt_context.add_main_entries (options, null);
126 opt_context.parse (ref args);
129 } catch (OptionError e) {
130 stdout.printf ("error: %s\n", e.message);
131 stdout.printf ("Run '%s --help' to see a full list of available command line options.\n %s",
132 args[0], opt_context.get_help(true,null));
133 GLib.Process.exit(Posix.EXIT_FAILURE);
138 this.pullResources();
140 Project.Project.loadAll();
142 var cur_project = this.compileProject();
143 this.listFiles(cur_project);
144 this.testBjs(cur_project);
145 this.compileBjs(cur_project);
152 public static BuilderApplication singleton( string[] args)
154 if (application==null) {
155 application = new BuilderApplication( args);
163 public static string configDirectory()
165 var dirname = GLib.Environment.get_home_dir() + "/.Builder";
167 if (!FileUtils.test(dirname,FileTest.IS_DIR)) {
168 var dir = File.new_for_path(dirname);
169 dir.make_directory();
171 if (!FileUtils.test(dirname + "/resources",FileTest.IS_DIR)) {
172 var dir = File.new_for_path(dirname + "/resources");
173 dir.make_directory();
181 // --------------- non static...
186 if (BuilderApplication.opt_debug || BuilderApplication.opt_compile_project == null) {
187 GLib.Log.set_handler(null,
188 GLib.LogLevelFlags.LEVEL_DEBUG | GLib.LogLevelFlags.LEVEL_WARNING,
190 print("%s: %s\n", dom, msg);
198 if (!BuilderApplication.opt_list_projects) {
201 print("Projects\n %s\n", Project.Project.listAllToString());
202 GLib.Process.exit(Posix.EXIT_SUCCESS);
205 Project.Project? compileProject()
208 if (BuilderApplication.opt_compile_project == null) {
211 Project.Project cur_project = null;
212 cur_project = Project.Project.getProjectByHash( BuilderApplication.opt_compile_project);
214 if (cur_project == null) {
215 GLib.error("invalid project %s, use --list-projects to show project ids",BuilderApplication.opt_compile_project);
217 cur_project.scanDirs();
222 void listFiles(Project.Project? cur_project)
224 if (!BuilderApplication.opt_list_files) {
227 if (cur_project == null) {
228 GLib.error("missing project, use --project to select which project");
230 print("Files for %s\n %s\n", cur_project.name, cur_project.listAllFilesToString());
231 GLib.Process.exit(Posix.EXIT_SUCCESS);
236 Test to see if the internal BJS reader/writer still outputs the same files.
237 -- probably need this for the generator as well.
240 void testBjs(Project.Project? cur_project)
242 if (!BuilderApplication.opt_bjs_test) {
245 if (cur_project == null) {
246 GLib.error("missing project, use --project to select which project");
248 print("Checking files\n");
249 var ar = cur_project.sortedFiles();
250 foreach(var file in ar) {
254 GLib.FileUtils.get_contents(file.path, out oldstr);
255 var outstr = file.toJsonString();
256 if (outstr != oldstr) {
258 GLib.FileUtils.set_contents("/tmp/" + file.name , outstr);
259 print("meld %s /tmp/%s\n", file.path, file.name);
260 //GLib.Process.exit(Posix.EXIT_SUCCESS);
262 print("# Files match %s\n", file.name);
266 print("All files pass");
267 GLib.Process.exit(Posix.EXIT_SUCCESS);
270 void compileBjs(Project.Project? cur_project)
272 if (BuilderApplication.opt_bjs_compile == null) {
275 if (cur_project == null) {
276 GLib.error("missing project, use --project to select which project");
279 if (BuilderApplication.opt_bjs_compile == "all") {
280 var ar = cur_project.sortedFiles();
281 foreach(var file in ar) {
285 var oldfn = file.targetName();
286 GLib.FileUtils.get_contents(oldfn, out oldstr);
288 var outstr = file.toSourceCode();
289 if (outstr != oldstr) {
291 GLib.FileUtils.set_contents("/tmp/" + file.name + ".out", outstr);
292 print("meld %s /tmp/%s\n", oldfn, file.name + ".out");
293 //GLib.Process.exit(Posix.EXIT_SUCCESS);
295 print("# Files match %s\n", file.name);
298 GLib.Process.exit(Posix.EXIT_SUCCESS);
304 var file = cur_project.getByName(BuilderApplication.opt_bjs_compile);
306 // then compile them all, and compare them...
313 GLib.error("missing file %s in project %s", BuilderApplication.opt_bjs_compile, cur_project.name);
317 if (BuilderApplication.opt_bjs_compile_glade) {
318 var str = file.toGlade();
320 GLib.Process.exit(Posix.EXIT_SUCCESS);
323 //BuilderApplication.compileBjs();
325 var str = file.toSourceCode();
328 if (!BuilderApplication.opt_debug) {
330 GLib.Process.exit(Posix.EXIT_SUCCESS);
333 // dump the node tree
334 file.tree.dumpProps();
340 var str_ar = str.split("\n");
341 for(var i =0;i<str_ar.length;i++) {
342 var node = file.tree.lineToNode(i+1);
343 var prop = node == null ? null : node.lineToProp(i+1);
344 print("%d: %s : %s\n",
346 node == null ? "......" : (prop == null ? "????????" : prop),
351 GLib.Process.exit(Posix.EXIT_SUCCESS);
356 if (BuilderApplication.opt_compile_target == null) {
359 Palete.ValaSourceCompiler.buildApplication();
361 GLib.Process.exit(Posix.EXIT_SUCCESS);
366 if (!opt_pull_resources) {
369 var loop = new MainLoop();
370 Resources.singleton().updateProgress.connect((p,t) => {
371 print("Got %d/%d", (int) p,(int)t);
376 Resources.singleton().fetchStart();
378 GLib.Process.exit(Posix.EXIT_SUCCESS);
384 if (opt_test == null) {
390 help - list available tests
391 flutter-project - create a flutter project in /tmp/test-flutter
394 case "flutter-project":
395 Project.Project.loadAll();
396 var p = Project.Project.factory("Flutter", "/tmp/test-flutter");
397 /*var pa = p.palete as Palete.Flutter;
399 var ar = pa.getChildList("material.Scaffold");
400 GLib.debug("childlist for material.Scaffold is %s",
401 string.joinv( "\n-- ", ar)
403 ar = pa.getDropList("material.MaterialApp");
404 GLib.debug("droplist for material.MaterialApp is %s",
405 string.joinv( "\n-- ", ar)
411 print("Invalid test\n");
416 GLib.Process.exit(Posix.EXIT_SUCCESS);