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", null },
67 { "bjs-target", 0, 0, OptionArg.STRING, ref opt_bjs_compile_target, "convert bjs file to tareet : vala / js", null },
68 { "test", 0, 0, OptionArg.STRING, ref opt_test, "run a test use 'help' to list the available tests", null },
72 public static string opt_compile_project;
73 public static string opt_compile_target;
74 public static string opt_compile_skip;
75 public static string opt_compile_add;
76 public static string opt_compile_output;
77 public static string opt_bjs_compile;
78 public static string opt_bjs_compile_target;
79 public static string opt_test;
80 public static bool opt_debug = false;
81 public static bool opt_list_projects = false;
82 public static bool opt_list_files = false;
83 public static bool opt_pull_resources = false;
85 public static string _self;
94 public const Gtk.TargetEntry[] targetList = {
95 { "INTEGER", 0, Target.INT32 },
96 { "STRING", 0, Target.STRING },
97 { "application/json", 0, Target.STRING },
98 { "text/plain", 0, Target.STRING },
99 { "application/x-rootwindow-drop", 0, Target.ROOTWIN }
101 public AppSettings settings = null;
104 public BuilderApplication ( string[] args)
107 _self = FileUtils.read_link("/proc/self/exe");
108 GLib.debug("SELF = %s", _self);
111 application_id: "org.roojs.app-builder",
112 flags: ApplicationFlags.FLAGS_NONE
116 this.settings = AppSettings.factory();
117 var opt_context = new OptionContext ("Application Builder");
120 opt_context.set_help_enabled (true);
121 opt_context.add_main_entries (options, null);
122 opt_context.parse (ref args);
125 } catch (OptionError e) {
126 stdout.printf ("error: %s\n", e.message);
127 stdout.printf ("Run '%s --help' to see a full list of available command line options.\n %s",
128 args[0], opt_context.get_help(true,null));
129 GLib.Process.exit(Posix.EXIT_FAILURE);
134 this.pullResources();
136 Project.Project.loadAll();
138 var cur_project = this.compileProject();
139 this.listFiles(cur_project);
140 this.compileBjs(cur_project);
147 public static BuilderApplication singleton( string[] args)
149 if (application==null) {
150 application = new BuilderApplication( args);
158 public static string configDirectory()
160 var dirname = GLib.Environment.get_home_dir() + "/.Builder";
162 if (!FileUtils.test(dirname,FileTest.IS_DIR)) {
163 var dir = File.new_for_path(dirname);
164 dir.make_directory();
166 if (!FileUtils.test(dirname + "/resources",FileTest.IS_DIR)) {
167 var dir = File.new_for_path(dirname + "/resources");
168 dir.make_directory();
176 // --------------- non static...
181 if (BuilderApplication.opt_debug || BuilderApplication.opt_compile_project == null) {
182 GLib.Log.set_handler(null,
183 GLib.LogLevelFlags.LEVEL_DEBUG | GLib.LogLevelFlags.LEVEL_WARNING,
185 print("%s: %s\n", dom, msg);
193 if (!BuilderApplication.opt_list_projects) {
196 print("Projects\n %s\n", Project.Project.listAllToString());
197 GLib.Process.exit(Posix.EXIT_SUCCESS);
200 Project.Project? compileProject()
203 if (BuilderApplication.opt_compile_project == null) {
206 Project.Project cur_project = null;
207 cur_project = Project.Project.getProjectByHash( BuilderApplication.opt_compile_project);
209 if (cur_project == null) {
210 GLib.error("invalid project %s, use --list-projects to show project ids",BuilderApplication.opt_compile_project);
212 cur_project.scanDirs();
217 void listFiles(Project.Project? cur_project)
219 if (!BuilderApplication.opt_list_files) {
222 if (cur_project == null) {
223 GLib.error("missing project, use --project to select which project");
225 print("Files for %s\n %s\n", cur_project.name, cur_project.listAllFilesToString());
226 GLib.Process.exit(Posix.EXIT_SUCCESS);
229 void compileBjs(Project.Project? cur_project)
231 if (BuilderApplication.opt_bjs_compile == null) {
234 if (cur_project == null) {
235 GLib.error("missing project, use --project to select which project");
237 var file = cur_project.getByName(BuilderApplication.opt_bjs_compile);
239 GLib.error("missing file %s in project %s", BuilderApplication.opt_bjs_compile, cur_project.name);
241 //BuilderApplication.compileBjs();
243 var str = file.toSourceCode();
246 if (!BuilderApplication.opt_debug) {
248 GLib.Process.exit(Posix.EXIT_SUCCESS);
251 // dump the node tree
252 file.tree.dumpProps();
255 var str_ar = str.split("\n");
256 for(var i =0;i<str_ar.length;i++) {
257 var node = file.tree.lineToNode(i+1);
258 var prop = node == null ? null : node.lineToProp(i+1);
259 print("%d: %s : %s\n",
261 node == null ? "......" : (prop == null ? "????????" : prop),
266 GLib.Process.exit(Posix.EXIT_SUCCESS);
271 if (BuilderApplication.opt_compile_target == null) {
274 Palete.ValaSourceCompiler.buildApplication();
276 GLib.Process.exit(Posix.EXIT_SUCCESS);
281 if (!opt_pull_resources) {
284 var loop = new MainLoop();
285 Resources.singleton().updateProgress.connect((p,t) => {
286 print("Got %d/%d", (int) p,(int)t);
291 Resources.singleton().fetchStart();
293 GLib.Process.exit(Posix.EXIT_SUCCESS);
299 if (opt_test == null) {
305 help - list available tests
306 flutter-project - create a flutter project in /tmp/test-flutter
309 case "flutter-project":
310 Project.Project.loadAll();
311 var p = Project.Project.factory("Flutter", "/tmp/test-flutter");
312 var pa = p.palete as Palete.Flutter;
314 var ar = pa.getChildList("material.Scaffold");
315 GLib.debug("childlist for material.Scaffold is %s",
316 string.joinv( "\n-- ", ar)
318 ar = pa.getDropList("material.MaterialApp");
319 GLib.debug("droplist for material.MaterialApp is %s",
320 string.joinv( "\n-- ", ar)
325 print("Invalid test\n");
330 GLib.Process.exit(Posix.EXIT_SUCCESS);