Did you know ... Search Documentation:
Pack ninja -- prolog/ninja.pl
PublicShow source

This module contains helper dcg predicates to generate ninja build files akin to the ninja_syntax.py python module distributed by ninja. You can use these predicates if you want to generate your own build.ninja build file.

Example usage:

build_graph -->
  rule(cp, "cp $in $out"),
  build(["input.txt"], cp, ["output.txt"]).

main -->
  phrase(build_graph, L),
  open("build.ninja", write, Stream),
  string_codes(S, L),
  write(Stream, S),
  close(Stream).

Then build.ninja contains the following build specification:

rule cp
  command = cp $in $out

build input.txt: cp output.txt

See the ninja build format documentation for generating more complex build files.

author
- Kwon-Young Choi
license
- GPL
 variable(+Pair:pair)// is semidet
Generate a variable declaration from a pair Pair. The key can be an atom or a dcg, value should be a dcg. A variable definition always end with a new line.
?- phrase(variable(name-"Value"), L), format("~s", [L]).
name = Value
L = [110, 97, 109, 101, 32, 61, 32, 86, 97|...].
 variable(+Name:atom;dcg, +Value:dcg)// is semidet
Generate a variable declaration as a variable Name with value Value. The variable name can be an atom or a dcg, value should be a dcg. A variable definition always end with a new line.
?- phrase(variable(name, "Value"), L), format("~s", [L]).
name = Value
L = [110, 97, 109, 101, 32, 61, 32, 86, 97|...].
 rule(+Name:atom;dcg, +Command:dcg)// is semidet
Generate a rule declaration with no additional variables. The name can be an atom or a dcg, the command should be dcg.
?- phrase(rule(cp, "cp $in $out"), L), format("~s", [L]).
rule cp
  command = cp $in $out
L = [114, 117, 108, 101, 32, 99, 112, 10, 32|...].
 rule(+Name:atom;dcg, +Command:dcg, +Variables:list(pair))// is semidet
Generate a rule declaration with no additional variables. The name can be an atom or a dcg. The command should be dcg and describe the command to run. Variables is a list and will be generate using the variable//1 rule.
?- phrase(rule(cp, "cp $in $out"), L), format("~s", [L]).
rule cp
  command = cp $in $out
L = [114, 117, 108, 101, 32, 99, 112, 10, 32|...].
 build(+Outs:list(dcg), +Rule:atom;dcg, +Ins:list(dcg))// is semidet
Generate a build statement between input Ins and Output Outs with the rule Rule.
?- phrase(build(["input.txt"], cp, ["output.txt"]), L), format("~s", [L]).
build input.txt: cp output.txt
L = [98, 117, 105, 108, 100, 32, 105, 110, 112|...].
 build(+Outs:list(dcg), +Rule:atom;dcg, +Ins:list(dcg), +Options:list)// is semidet
Generate a build statement between input Ins and Output Outs with the rule Rule. Optional arguments can be specify in the option list Options. Valid options are:
implicit_ins(ImplicitIns:list(dcg))
List of implicit dependencies, as list of dcgs.
implicit_outs(ImplicitOuts:list(dcg))
List of implicit outputs, as list of dcgs.
orderonly_ins(OrderonlyIns:list(dcg))
List of order only dependencies, as list of dcgs.
validations(Validations:list(dcg))
List of validation targets, as list of dcgs.
variables(Variables:list(pair))
List of variables as pairs.
?- phrase(build(["input.txt"], cp, ["output.txt"],
     [implicit_outs(["implicit_out.txt"]),
      implicit_ins(["implicit_in.txt"]),
      orderonly_ins(["orderonly_in.txt"]),
      validations(["validation.txt"]),
      variables([name-"value"])]), L), format("~s", [L]).
build input.txt | implicit_out.txt: cp output.txt | implicit_in.txt || orderonly_in.txt |@ validation.txt
  name = value
L = `build input.txt | implici...alue\n`.
 deps(++Source:string)// is semidet
Generate a whitespace separated list of dependencies from prolog source file Source. It also include Source as a dependency.
?- phrase(deps("ninja.pl"), L), format("~s", [L]).
ninja.pl /usr/lib64/swipl-9.0.4/library/dcg/basics.pl /usr/lib64/swipl-9.0.4/library/dcg/high_order.pl /usr/lib64/swipl-9.0.4/library/option.pl /usr/lib64/swipl-9.0.4/library/error.pl
L = `ninja.pl /usr/lib64/swipl...or.pl`.