如何生成和使用生成的文件

时间:2013-12-12 21:47:55

标签: ocaml ocp-build

使用ocp-build是否可以执行以下操作:

  1. 编译生成器。
  2. 调用生成器生成文件。
  3. 使用生成的文件编译项目。
  4. 到目前为止,我试过这个:

    (generator.ocp)

    begin library "error_gen"
        sort = true
        files = [ "error_gen.ml" ]
        requires = [str]
    end
    

    (generated.ocp)

    begin library "error_code"
        sort = true
        files = [
          "error_code.ml" (
            pp = [ "./_obuild/error_gen/error_gen.byte" ]
            pp_requires = [ "error_gen:byte" ]
          )
        ]
        requires = ["error_gen"]
    end
    

    (和main.ocp)

    begin program "main"
        sort = true
        files = []
        requires = ["error_code" "parser"]
    end
    

    它抱怨这条消息:

      

    错误:在项目“error_code”中,源文件名   “src / generated / error_code.ml”不存在

    我看到版本文件生成存在一些支持,例如在项目ocp-indent

    第46行。

    "indentVersion.ml" (ocp2ml) (* auto-generated by ocp-build *)
    

    非常感谢,谢谢。

1 个答案:

答案 0 :(得分:1)

在github.com/OCamlPro/ocp-build的分支“next”中,你会发现一个可能解决你的问题的ocp-build版本:

begin library "error_code"
    sort = true
    files = [ "error_code.ml" ]
    build_rules = [
      "error_code.ml" (
        (* the files that are needed to call the command *)
        sources = [ "%{error_gen_FULL_DST_DIR}%/error_gen.byte" ]
        (* the commands to be executed, in the sub-directory of the library
           each command has the syntax:    { "COMMAND" "ARG1" "ARG2" ... }
        *)
        commands = [ 
           {   "%{error_gen_FULL_DST_DIR}%/error_gen.byte"   } 
        ]
      )
    ]
    requires = ["error_gen"]
end

例如,这在wxOCaml:

中使用

https://github.com/OCamlPro/ocplib-wxOCaml/blob/next-ocpbuild/configure.ocp

命令可以使用选项进行后期修复:

{ "configure" } (chdir = "subdirectory")  (* to execute in a sub-directory *)
{ "cat" "toto" } (stdout = "new_toto")    (* to copy the stdout in "new_toto" *)
相关问题