Merge: doc: fixed some typos and other misc. corrections
[nit.git] / src / nitpackage.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # Helpful features about packages
16 module nitpackage
17
18 import frontend
19 import doc::commands::commands_main
20
21 redef class ToolContext
22
23 # nitpackage phase
24 var nitpackage_phase: Phase = new NitPackagePhase(self, null)
25
26 # --expand
27 var opt_expand = new OptionBool("Move singleton packages to their own directory", "--expand")
28
29 # --check-ini
30 var opt_check_ini = new OptionBool("Check package.ini files", "--check-ini")
31
32 # --gen-ini
33 var opt_gen_ini = new OptionBool("Generate package.ini files", "--gen-ini")
34
35 # --force
36 var opt_force = new OptionBool("Force update of existing files", "-f", "--force")
37
38 # --check-makefile
39 var opt_check_makefile = new OptionBool("Check Makefile files", "--check-makefile")
40
41 # --gen-makefile
42 var opt_gen_makefile = new OptionBool("Generate Makefile files", "--gen-makefile")
43
44 # --check-man
45 var opt_check_man = new OptionBool("Check manpages files", "--check-man")
46
47 # --gen-man
48 var opt_gen_man = new OptionBool("Generate manpages files", "--gen-man")
49
50 # --check-readme
51 var opt_check_readme = new OptionBool("Check README.md files", "--check-readme")
52
53 redef init do
54 super
55 option_context.add_option(opt_expand, opt_force)
56 option_context.add_option(opt_check_ini, opt_gen_ini)
57 option_context.add_option(opt_check_makefile, opt_gen_makefile)
58 option_context.add_option(opt_check_man, opt_gen_man)
59 option_context.add_option(opt_check_readme)
60 end
61 end
62
63 private class NitPackagePhase
64 super Phase
65
66 redef fun process_mainmodule(mainmodule, mmodules) do
67 var mpackages = extract_mpackages(mmodules)
68 for mpackage in mpackages do
69
70 # Fictive and buggy packages are ignored
71 if not mpackage.has_source then
72 toolcontext.warning(mpackage.location, "no-source",
73 "Warning: `{mpackage}` has no source file")
74 continue
75 end
76
77 # Check package INI files
78 if toolcontext.opt_check_ini.value then
79 mpackage.check_ini(toolcontext)
80 continue
81 end
82
83 # Check package Makefiles
84 if toolcontext.opt_check_makefile.value then
85 mpackage.check_makefile(toolcontext, mainmodule)
86 continue
87 end
88
89 # Check manpages
90 if toolcontext.opt_check_man.value then
91 mpackage.check_man(toolcontext, mainmodule)
92 continue
93 end
94
95 # Check README.md
96 if toolcontext.opt_check_readme.value then
97 mpackage.check_readme(toolcontext)
98 continue
99 end
100
101 # Expand packages
102 if toolcontext.opt_expand.value and not mpackage.is_expanded then
103 var path = mpackage.expand
104 toolcontext.info("{mpackage} moved to {path}", 0)
105 end
106 if not mpackage.is_expanded then
107 toolcontext.warning(mpackage.location, "no-dir",
108 "Warning: `{mpackage}` has no package directory")
109 continue
110 end
111
112 # Create INI file
113 if toolcontext.opt_gen_ini.value then
114 if not mpackage.has_ini or toolcontext.opt_force.value then
115 var path = mpackage.gen_ini
116 toolcontext.info("generated INI file `{path}`", 0)
117 end
118 end
119
120 # Create Makefile
121 if toolcontext.opt_gen_makefile.value then
122 if not mpackage.has_makefile or toolcontext.opt_force.value then
123 var path = mpackage.gen_makefile(toolcontext.modelbuilder.model, mainmodule)
124 if path != null then
125 toolcontext.info("generated Makefile `{path}`", 0)
126 end
127 end
128 end
129
130 # Create manpages
131 if toolcontext.opt_gen_man.value then
132 mpackage.gen_man(toolcontext, mainmodule)
133 end
134 end
135 end
136
137 # Extract the list of packages from the mmodules passed as arguments
138 fun extract_mpackages(mmodules: Collection[MModule]): Collection[MPackage] do
139 var mpackages = new ArraySet[MPackage]
140 for mmodule in mmodules do
141 var mpackage = mmodule.mpackage
142 if mpackage == null then continue
143 mpackages.add mpackage
144 end
145 return mpackages.to_a
146 end
147 end
148
149 redef class MPackage
150
151 # Expand `self` in its own directory
152 private fun expand: String do
153 assert not is_expanded
154
155 var ori_path = package_path.as(not null)
156 var new_path = ori_path.dirname / name
157
158 new_path.mkdir
159 sys.system "mv {ori_path} {new_path / name}.nit"
160
161 var ini_file = "{new_path}.ini"
162 if ini_file.file_exists then
163 sys.system "mv {new_path}.ini {new_path}/package.ini"
164 end
165
166 return new_path
167 end
168
169 private var maintainer: nullable String is lazy do
170 return git_exec("git shortlog -esn . | head -n 1 | sed 's/\\s*[0-9]*\\s*//'")
171 end
172
173 private var contributors: Array[String] is lazy do
174 var contribs = git_exec("git shortlog -esn . | head -n -1 | " +
175 "sed 's/\\s*[0-9]*\\s*//'")
176 if contribs == null then return new Array[String]
177 return contribs.split("\n")
178 end
179
180 private var git_url: nullable String is lazy do
181 var git = git_exec("git remote get-url origin")
182 if git == null then return null
183 git = git.replace("git@github.com:", "https://github.com/")
184 git = git.replace("git@gitlab.com:", "https://gitlab.com/")
185 return git
186 end
187
188 private var git_dir: nullable String is lazy do
189 return git_exec("git rev-parse --show-prefix")
190 end
191
192 private var browse_url: nullable String is lazy do
193 var git = git_url
194 if git == null then return null
195 var browse = git.replace(".git", "")
196 var dir = git_dir
197 if dir == null or dir.is_empty then return browse
198 return "{browse}/tree/master/{dir}"
199 end
200
201 private var homepage_url: nullable String is lazy do
202 var git = git_url
203 if git == null then return null
204 # Special case for nit files
205 if git.has_suffix("/nit.git") then
206 return "http://nitlanguage.org"
207 end
208 return git.replace(".git", "")
209 end
210
211 private var issues_url: nullable String is lazy do
212 var git = git_url
213 if git == null then return null
214 return "{git.replace(".git", "")}/issues"
215 end
216
217 private var license: nullable String is lazy do
218 var git = git_url
219 if git == null then return null
220 # Special case for nit files
221 if git.has_suffix("/nit.git") then
222 return "Apache-2.0"
223 end
224 return null
225 end
226
227 private fun git_exec(cmd: String): nullable String do
228 var path = package_path
229 if path == null then return null
230 if not is_expanded then path = path.dirname
231 with pr = new ProcessReader("sh", "-c", "cd {path} && {cmd}") do
232 return pr.read_all.trim
233 end
234 end
235
236 private var allowed_ini_keys = [
237 "package.name", "package.desc", "package.tags", "package.license",
238 "package.maintainer", "package.more_contributors",
239 "upstream.browse", "upstream.git", "upstream.git.directory",
240 "upstream.homepage", "upstream.issues", "upstream.apk", "upstream.tryit",
241 "source.exclude"
242 ]
243
244 private fun check_ini(toolcontext: ToolContext) do
245 if not has_ini then
246 toolcontext.error(location, "No `package.ini` file for `{name}`")
247 return
248 end
249
250 var pkg_path = package_path
251 if pkg_path == null then return
252
253 var ini_path = ini_path
254 if ini_path == null then return
255
256 var ini = new IniFile.from_file(ini_path)
257
258 ini.check_key(ini_path, toolcontext, self, "package.name", name)
259 ini.check_key(ini_path, toolcontext, self, "package.desc")
260 ini.check_key(ini_path, toolcontext, self, "package.tags")
261
262 # FIXME since `git reflog --follow` seems bugged
263 ini.check_key(ini_path, toolcontext, self, "package.maintainer")
264 # var maint = mpackage.maintainer
265 # if maint != null then
266 # ini.check_key(toolcontext, self, "package.maintainer", maint)
267 # end
268
269 # FIXME since `git reflog --follow` seems bugged
270 # var contribs = mpackage.contributors
271 # if contribs.not_empty then
272 # ini.check_key(toolcontext, self, "package.more_contributors", contribs.join(", "))
273 # end
274
275 ini.check_key(ini_path, toolcontext, self, "package.license", license)
276 ini.check_key(ini_path, toolcontext, self, "upstream.browse", browse_url)
277 ini.check_key(ini_path, toolcontext, self, "upstream.git", git_url)
278 ini.check_key(ini_path, toolcontext, self, "upstream.git.directory", git_dir)
279 ini.check_key(ini_path, toolcontext, self, "upstream.homepage", homepage_url)
280 ini.check_key(ini_path, toolcontext, self, "upstream.issues", issues_url)
281
282 for key in ini.flatten.keys do
283 if not allowed_ini_keys.has(key) then
284 toolcontext.warning(location, "unknown-ini-key",
285 "Warning: ignoring unknown `{key}` key in `{ini_path}`")
286 end
287 end
288 end
289
290 private fun gen_ini: String do
291 var ini_path = self.ini_path.as(not null)
292 var ini = new IniFile.from_file(ini_path)
293
294 ini.update_value("package.name", name)
295 ini.update_value("package.desc", "")
296 ini.update_value("package.tags", "")
297 ini.update_value("package.maintainer", maintainer)
298 ini.update_value("package.more_contributors", contributors.join(","))
299 ini.update_value("package.license", license or else "")
300
301 ini.update_value("upstream.browse", browse_url)
302 ini.update_value("upstream.git", git_url)
303 ini.update_value("upstream.git.directory", git_dir)
304 ini.update_value("upstream.homepage", homepage_url)
305 ini.update_value("upstream.issues", issues_url)
306
307 ini.write_to_file(ini_path)
308 return ini_path
309 end
310
311 # Makefile
312
313 # The path to `self` Makefile
314 fun makefile_path: nullable String do
315 var path = package_path
316 if path == null then return null
317 if not is_expanded then return null
318 return path / "Makefile"
319 end
320
321 # Does `self` have a Makefile?
322 fun has_makefile: Bool do
323 var makefile_path = self.makefile_path
324 if makefile_path == null then return false
325 return makefile_path.file_exists
326 end
327
328 private fun check_makefile(toolcontext: ToolContext, mainmodule: MModule) do
329 var model = toolcontext.modelbuilder.model
330 var filter = new ModelFilter(accept_example = false, accept_test = false)
331
332 var cmd_bin = new CmdMains(model, filter, mentity = self)
333 var res_bin = cmd_bin.init_command
334 if not res_bin isa CmdSuccess then return
335
336 for mmodule in cmd_bin.results.as(not null) do
337 if not mmodule isa MModule then continue
338
339 if mmodule.makefile_path == null then
340 toolcontext.warning(location, "missing-makefile",
341 "Warning: no Makefile for executable module `{mmodule.full_name}`")
342 end
343 end
344 end
345
346 private fun gen_makefile(model: Model, mainmodule: MModule): nullable String do
347 var filter = new ModelFilter(accept_example = false, accept_test = false)
348
349 var pkg_path = package_path.as(not null)
350 var makefile_path = makefile_path.as(not null)
351
352 var bins = new Array[String]
353 var cmd_bin = new CmdMains(model, filter, mentity = self)
354 var res_bin = cmd_bin.init_command
355 if res_bin isa CmdSuccess then
356 for mmodule in cmd_bin.results.as(not null) do
357 if not mmodule isa MModule then continue
358 var mmodule_makefile = mmodule.makefile_path
359 if mmodule_makefile != null and mmodule_makefile != makefile_path then continue
360
361 var file = mmodule.location.file
362 if file == null then continue
363 # Remove package path prefix
364 var bin_path = file.filename
365 if pkg_path.has_suffix("/") then
366 bin_path = bin_path.replace(pkg_path, "")
367 else
368 bin_path = bin_path.replace("{pkg_path}/", "")
369 end
370 bins.add bin_path
371 end
372 end
373
374 if bins.is_empty then return null
375
376 var make = new NitMakefile(bins)
377 make.render.write_to_file(makefile_path)
378 return makefile_path
379 end
380
381 # Manpages
382
383 # The path to `self` manpage files
384 private fun man_path: nullable String do
385 var path = package_path
386 if path == null then return null
387 if not is_expanded then return null
388 return path / "man"
389 end
390
391 # Does `self` have a manpage files?
392 private fun has_man: Bool do
393 var man_path = self.man_path
394 if man_path == null then return false
395 return man_path.file_exists
396 end
397
398 private fun check_man(toolcontext: ToolContext, mainmodule: MModule) do
399 var model = toolcontext.modelbuilder.model
400 var filter = new ModelFilter(accept_example = false, accept_test = false)
401 var cmd = new CmdMains(model, filter, mentity = self)
402 var res = cmd.init_command
403 if not res isa CmdSuccess then return
404
405 for mmodule in cmd.results.as(not null) do
406 if not mmodule isa MModule then continue
407 mmodule.check_man(toolcontext)
408 end
409 end
410
411 private fun gen_man(toolcontext: ToolContext, mainmodule: MModule) do
412 var model = toolcontext.modelbuilder.model
413 var filter = new ModelFilter(accept_example = false, accept_test = false)
414 var cmd = new CmdMains(model, filter, mentity = self)
415 var res = cmd.init_command
416 if not res isa CmdSuccess then return
417
418 var pkg_man = man_path.as(not null)
419 for mmodule in cmd.results.as(not null) do
420 if not mmodule isa MModule then continue
421 if not has_man then pkg_man.mkdir
422 mmodule.gen_man(toolcontext)
423 end
424 end
425
426 # README
427
428 private fun check_readme(toolcontext: ToolContext) do
429 if not has_readme then
430 toolcontext.error(location, "No `README.md` file for `{name}`")
431 return
432 end
433 end
434 end
435
436 redef class MModule
437 private fun makefile_path: nullable String do
438 var file = location.file
439 if file == null then return null
440
441 var dir = file.filename.dirname
442 var makefile = (dir / "Makefile")
443 if not makefile.file_exists then return null
444
445 for line in makefile.to_path.read_lines do
446 if line.has_prefix("{name}:") then return makefile
447 end
448 return null
449 end
450
451 private fun man_path: nullable String do
452 var mpackage = self.mpackage
453 if mpackage == null then return null
454 var path = mpackage.man_path
455 if path == null then return null
456 return path / "{name}.man"
457 end
458
459 # Does `self` have a manpage?
460 private fun has_man: Bool do
461 var man_path = self.man_path
462 if man_path == null then return false
463 return man_path.file_exists
464 end
465
466 private fun make_module(toolcontext: ToolContext): Bool do
467 var mpackage = self.mpackage
468 if mpackage == null then return false
469 if not mpackage.is_expanded then return false
470
471 var pkg_path = mpackage.package_path
472 if pkg_path == null then return false
473
474 var pr = new ProcessReader("sh", "-c", "cd {pkg_path} && make -Bs bin/{name}")
475 var out = pr.read_all.trim
476 pr.close
477 pr.wait
478 if pr.status > 0 then
479 toolcontext.error(location, "unable to compile `{name}`")
480 print out
481 return false
482 end
483 return true
484 end
485
486 private fun stub_man(toolcontext: ToolContext): nullable String do
487 if not make_module(toolcontext) then return null
488 var mpackage = self.mpackage
489 if mpackage == null then return null
490 if not mpackage.is_expanded then return null
491
492 var pkg_path = mpackage.package_path
493 if pkg_path == null then return null
494
495 var pr = new ProcessReader("{pkg_path}/bin/{name}", "--stub-man")
496 var man = pr.read_all.trim
497 pr.close
498 pr.wait
499 if pr.status > 0 then
500 toolcontext.error(location, "unable to run `{pkg_path}/bin/{name} --stub-man`")
501 print man
502 return null
503 end
504 return man
505 end
506
507 private fun check_man(toolcontext: ToolContext) do
508 if not has_man then
509 toolcontext.error(location, "No manpage for bin {full_name}")
510 return
511 end
512 var man_path = self.man_path.as(not null)
513 var man = stub_man(toolcontext)
514 if man == null or man.is_empty then return
515
516 var old_man = new ManPage.from_file(self, man_path)
517 var new_man = new ManPage.from_string(self, man)
518 old_man.diff(toolcontext, new_man)
519 end
520
521 private fun gen_man(toolcontext: ToolContext) do
522 var man = stub_man(toolcontext)
523 if man == null or man.is_empty then return
524 var man_path = self.man_path
525 if man_path == null then return
526 man.write_to_file(man_path)
527 toolcontext.info("created manpage `{man_path}`", 0)
528 end
529 end
530
531 redef class IniFile
532 private fun check_key(ini_file: String, toolcontext: ToolContext, mpackage: MPackage, key: String, value: nullable String) do
533 if not has_key(key) then
534 toolcontext.warning(mpackage.location, "missing-ini-key",
535 "Warning: missing `{key}` key in `{ini_file}`")
536 return
537 end
538 if self[key].as(not null).is_empty then
539 toolcontext.warning(mpackage.location, "missing-ini-value",
540 "Warning: empty `{key}` key in `{ini_file}`")
541 return
542 end
543 if value != null and self[key] != value then
544 toolcontext.warning(mpackage.location, "wrong-ini-value",
545 "Warning: wrong value for `{key}` in `{ini_file}`. " +
546 "Expected `{value}`, got `{self[key] or else ""}`")
547 end
548 end
549
550 private fun update_value(key: String, value: nullable String) do
551 if value == null then return
552 if not has_key(key) then
553 self[key] = value
554 else
555 var old_value = self[key]
556 if not value.is_empty and old_value != value then
557 self[key] = value
558 end
559 end
560 end
561 end
562
563 # A Makefile for the Nit project
564 class NitMakefile
565
566 # Nit files to compile
567 var nit_files: Array[String]
568
569 # List of rules to add in the Makefile
570 fun rules: Array[MakeRule] do
571 var rules = new Array[MakeRule]
572
573 var rule_all = new MakeRule("all", is_phony = true)
574 rules.add rule_all
575
576 for file in nit_files do
577 var bin = file.basename.strip_extension
578
579 rule_all.deps.add "bin/{bin}"
580
581 var rule = new MakeRule("bin/{bin}")
582 rule.deps.add "$(shell $(NITLS) -M {file})"
583 rule.lines.add "mkdir -p bin/"
584 rule.lines.add "$(NITC) {file} -o bin/{bin}"
585 rules.add rule
586 end
587
588 var rule_check = new MakeRule("check", is_phony = true)
589 rule_check.lines.add "$(NITUNIT) ."
590 rules.add rule_check
591
592 var rule_doc = new MakeRule("doc", is_phony = true)
593 rule_doc.lines.add "$(NITDOC) . -o doc/"
594 rules.add rule_doc
595
596 var rule_clean = new MakeRule("clean", is_phony = true)
597 if nit_files.not_empty then
598 rule_clean.lines.add "rm -rf bin/"
599 end
600 rule_clean.lines.add "rm -rf doc/"
601 rules.add rule_clean
602
603 return rules
604 end
605
606 # Render `self`
607 fun render: Writable do
608 var tpl = new Template
609 tpl.addn """
610 # This file is part of NIT ( http://www.nitlanguage.org ).
611 #
612 # Licensed under the Apache License, Version 2.0 (the "License");
613 # you may not use this file except in compliance with the License.
614 # You may obtain a copy of the License at
615 #
616 # http://www.apache.org/licenses/LICENSE-2.0
617 #
618 # Unless required by applicable law or agreed to in writing, software
619 # distributed under the License is distributed on an "AS IS" BASIS,
620 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
621 # See the License for the specific language governing permissions and
622 # limitations under the License.\n"""
623
624 if nit_files.not_empty then
625 tpl.addn "NITC ?= nitc"
626 tpl.addn "NITLS ?= nitls"
627 end
628 tpl.addn "NITUNIT ?= nitunit"
629 tpl.addn "NITDOC ?= nitdoc"
630
631 for rule in rules do
632 tpl.add "\n{rule.render.write_to_string}"
633 end
634
635 return tpl
636 end
637 end
638
639 # A rule that goes into a Makefile
640 class MakeRule
641
642 # Rule name
643 var name: String
644
645 # Is this rule a `.PHONY` one?
646 var is_phony: Bool = false is optional
647
648 # Rule dependencies
649 var deps = new Array[String]
650
651 # Rule lines
652 var lines = new Array[String]
653
654 # Render `self`
655 fun render: Writable do
656 var tpl = new Template
657 if is_phony then
658 tpl.addn ".PHONY: {name}"
659 end
660 tpl.add "{name}:"
661 if deps.not_empty then
662 tpl.add " {deps.join(" ")}"
663 end
664 tpl.add "\n"
665 for line in lines do
666 tpl.addn "\t{line}"
667 end
668 return tpl
669 end
670 end
671
672 private class ManPage
673 var mmodule: MModule
674 var name: nullable String is noinit
675 var synopsis: nullable String is noinit
676 var options = new HashMap[Array[String], String]
677
678 init from_file(mmodule: MModule, file: String) do
679 from_lines(mmodule, file.to_path.read_lines)
680 end
681
682 init from_string(mmodule: MModule, string: String) do
683 from_lines(mmodule, string.split("\n"))
684 end
685
686 init from_lines(mmodule: MModule, lines: Array[String]) do
687 init mmodule
688
689 var section = null
690 for i in [0..lines.length[ do
691 var line = lines[i]
692 if line.is_empty then continue
693
694 if line == "# NAME" then
695 section = "name"
696 continue
697 end
698 if line == "# SYNOPSIS" then
699 section = "synopsis"
700 continue
701 end
702 if line == "# OPTIONS" then
703 section = "options"
704 continue
705 end
706
707 if section == "name" and name == null then
708 name = line.trim
709 end
710 if section == "synopsis" and synopsis == null then
711 synopsis = line.trim
712 end
713 if section == "options" and line.has_prefix("###") then
714 var opts = new Array[String]
715 for opt in line.substring(3, line.length).trim.replace("`", "").split(",") do
716 opts.add opt.trim
717 end
718 var desc = ""
719 if i < lines.length - 1 then
720 desc = lines[i + 1].trim
721 end
722 options[opts] = desc
723 end
724 end
725 end
726
727 fun diff(toolcontext: ToolContext, ref: ManPage) do
728 if name != ref.name then
729 toolcontext.warning(mmodule.location, "diff-man",
730 "Warning: outdated man description. " +
731 "Expected `{ref.name or else ""}` got `{name or else ""}`.")
732 end
733 if synopsis != ref.synopsis then
734 toolcontext.warning(mmodule.location, "diff-man",
735 "Warning: outdated man synopsis. " +
736 "Expected `{ref.synopsis or else ""}` got `{synopsis or else ""}`.")
737 end
738 for name, desc in options do
739 if not ref.options.has_key(name) then
740 toolcontext.warning(mmodule.location, "diff-man",
741 "Warning: unknown man option `{name}`.`")
742 continue
743 end
744 var ref_desc = ref.options[name]
745 if desc != ref_desc then
746 toolcontext.warning(mmodule.location, "diff-man",
747 "Warning: outdated man option description. Expected `{ref_desc}` got `{desc}`.")
748 end
749 end
750 for ref_name, ref_desc in ref.options do
751 if not options.has_key(ref_name) then
752 toolcontext.warning(mmodule.location, "diff-man",
753 "Warning: missing man option `{ref_name}`.`")
754 end
755 end
756 end
757
758 redef fun to_s do
759 var tpl = new Template
760 tpl.addn "# NAME"
761 tpl.addn name or else ""
762 tpl.addn "# SYNOPSIS"
763 tpl.addn synopsis or else ""
764 tpl.addn "# OPTIONS"
765 for name, desc in options do
766 tpl.addn " * {name}: {desc}"
767 end
768 return tpl.write_to_string
769 end
770 end
771
772 # build toolcontext
773 var toolcontext = new ToolContext
774 var tpl = new Template
775 tpl.add "Usage: nitpackage [OPTION]... <file.nit>...\n"
776 tpl.add "Helpful features about packages."
777 toolcontext.tooldescription = tpl.write_to_string
778
779 # process options
780 toolcontext.process_options(args)
781 var arguments = toolcontext.option_context.rest
782
783 # build model
784 var model = new Model
785 var mbuilder = new ModelBuilder(model, toolcontext)
786 var mmodules = mbuilder.parse_full(arguments)
787
788 # process
789 if mmodules.is_empty then return
790 mbuilder.run_phases
791 toolcontext.run_global_phases(mmodules)