files.anubis 2.6 KB
/*
 * Created by PyramIDE.
 * User: フランスのトトロ aka (David RENÉ) 
 * Date: 15/01/2017
 * Time: 23:40
 * © David RENÉ 
 */

read system/parameter/inifile.anubis
read densaku_lib/types/densaku.anubis
read densaku_lib/ds_generator.anubis
read tools/basis.anubis
read types_checking.anubis
read generation/types.anubis    //generate all types and the message for these types
read generation/messages.anubis //generate all messages collection
read generation/graphviz/graphviz_main.anubis

public define Maybe(One)
  generate_message_files
  (
    List(DS_Type)     types,             //Types description
    List(DS_Message)  messages,
    String            destination_dir
  )=
  //before processing the generation we check if we need to do it, by checking the SHA1 generated with the 
  //previous generation. If SHA1 is same, this means the database is exactly same and we have nothing to do.
  //This behaviour prevent to generate same database during automatic generation on compilation time.
  
  //process. We serialize the types and messages model and make SHA1 of the result. This result is stored in file densaku.ini
  //in root of destination_dir
  with current_types_SHA1    = to_ascii(sha1(serialize(types))),
  with current_messages_SHA1 = to_ascii(sha1(serialize(messages))),
  
  println("\nDensaku Generator");
  println("Destination dir: "+destination_dir);
  with ini = loadIniFile(destination_dir+"/densaku.ini"),
  
  with types_SHA1    = readString(ini, "TYPES",    "SHA1", "N/A"),
  with messages_SHA1 = readString(ini, "MESSAGES", "SHA1", "N/A"),  
  
  println("Saved Types SHA1   = "+types_SHA1);
  println("Current Types SHA1 = "+current_types_SHA1);
  
  println("Saved Messages SHA1   = "+messages_SHA1);  
  println("Current Messages SHA1 = "+messages_SHA1);  

  
  if types_SHA1 = current_types_SHA1 & messages_SHA1 = current_messages_SHA1 then
    success(println("Types and messages already generated, nothing to do"))
  else 
  if check_types(types) is 
  {
    failure           then failure,
    success(_) then  

      println("Generating types and message files");
      make_all_types(types, destination_dir);

      println("Generating messages collection");
      make_all_messages(messages, destination_dir);
      
      println("Generating graphviz");
      forget(make_graphviz_types(types, destination_dir));
      
        writeString(ini, "TYPES",    "SHA1", current_types_SHA1);
        writeString(ini, "MESSAGES", "SHA1", current_messages_SHA1);        
        writeIniInfo(ini);      
      success(unique)
  }.

global define DS_Generator_API
  ds_gen =
  ds_api(generate_message_files).