AlloyTools / org.alloytools.alloy

Alloy is a language for describing structures and a tool for exploring them. It has been used in a wide range of applications from finding holes in security mechanisms to designing telephone switching networks. This repository contains the code for the tool.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JSON output mixed with other output

awwaiid opened this issue · comments

When trying the new -t json output, I noticed that the STDOUT has more than JSON. Ideally this output method would output machine-readable JSON to STDOUT, so that you could do things like:

alloy simple.als | jq '.[].instances[].values'

and get a lovely list of instance values. However, the STDOUT result right now ALSO includes some general output. To illustrate, here is a session (going off of #249 PR):

awwaiid@vorm:~/projects/recurse/org.alloytools.alloy$ cat simple.als                                                                                                         [nmacedo/master]
sig Thing {} run { one Thing }
awwaiid@vorm:~/projects/recurse/org.alloytools.alloy$ java -jar org.alloytools.alloy.dist/target/org.alloytools.alloy.dist.jar exec -t json simple.als 2>errors.txt >output.txt
awwaiid@vorm:~/projects/recurse/org.alloytools.alloy$ cat errors.txt                                                                                                         [nmacedo/master]
[main] INFO kodkod.engine.config.Reporter - detecting symmetries ...
[main] INFO kodkod.engine.config.Reporter - detected 17 equivalence classes of atoms ...
[main] INFO kodkod.engine.config.Reporter - optimizing bounds and formula (breaking predicate symmetries, inlining, skolemizing) ...
[main] INFO kodkod.engine.config.Reporter - translating to boolean ...
[main] INFO kodkod.engine.config.Reporter - generating lex-leader symmetry breaking predicate ...
[main] INFO kodkod.engine.config.Reporter - translating to cnf ...
[main] INFO kodkod.engine.config.Reporter - solving p cnf 14 16
awwaiid@vorm:~/projects/recurse/org.alloytools.alloy$ head output.txt                                                                                                        [nmacedo/master]
solving command Run run$1
   14 vars. 3 primary vars. 15 clauses.
   SAT!
repeat -2
answers 1
[
  {
    "bitwidth":4,
    "command":"Run run$1",
    "incremental":true,

Note that if you pass in -o outfile.json then the outfile will indeed ONLY have valid JSON. STDOUT still includes the other status output. Maybe that output should go to stderr? Or have it be embedded into the JSON, like:

alloy -t json simple.als
{
  "command": "Run run$1",
  "statistics": "14 vars. 3 primary vars. 15 clauses.",
  "result": "SAT!",
  "output": [ ... ]
}

(usually JSON output from most apps is a single top-level object anyway, in my experience, not wrapped in an array. Sometimes they are a stream of top-level objects, which is what tools like jq excel at processing)

You have to set the -q (but we could automatically set to true if stdout is the output). But I already changed some stuff recently.

I made a small PR that quiets a few more things, but it still doesn't get everything needed for pure-JSON output:

awwaiid@vorm:~/projects/recurse/org.alloytools.alloy$ java -jar org.alloytools.alloy.dist/target/org.alloytools.alloy.dist.jar exec -q -t json simple.als 2>/dev/null | head
   10 vars. 3 primary vars. 7 clauses.
   SAT!
[
  {
    "bitwidth":4,
    "command":"Run run$1",
    "incremental":true,
    "instances":[
      {
        "skolems":{
...

You can see the first two lines come from deeper in the code somewhere.

(I'll refresh this against the main repo once the 6.1 bundle PR is merged)

Fixed