package awsm-codegen

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file dune.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
open! Core
open! Import

let dashes_to_underscores : string -> string =
  String.map ~f:(function
    | '-' -> '_'
    | c -> c)
;;

let make ~date ~service =
  let extra_deps =
    match service with
    | "s3" -> [ "core_unix"; "core_unix.time_unix" ]
    | _ -> []
  in
  let library =
    let service_unders =
      service
      |> String.map ~f:(function
           | '-' -> '_'
           | c -> c)
    in
    let extra_deps = String.concat ~sep:" " extra_deps in
    [%string
      {|
  (library
    (name awsm_%{service_unders})
    (public_name awsm-%{service})
    (libraries awsm %{extra_deps})
    (flags :standard -open Core -open Printf)
    (ocamlopt_flags (-linscan))
    (preprocess (pps ppx_jane))
    (synopsis "OCaml AWS %{service} API.")
    (inline_tests))
       |}]
  in
  let endpoints_ml =
    sprintf
      {|
  (rule
    (targets endpoints.ml)
    (deps (:service %%{project_root}/vendor/botocore/botocore/data/%s/%s/service-2.json))
    (action (run %%{bin:awsm-codegen} service endpoints
                  --impl endpoints.ml
                  --service %%{service})))
|}
      service
      date
  in
  let num_submodules =
    match service with
    | "ec2" -> 8
    | "ssm" | "iot" | "rds" | "sagemaker" -> 2
    | _ -> 0
  in
  let value_modules =
    num_submodules |> List.init ~f:(sprintf "values_%d.ml") |> String.concat ~sep:" "
  in
  let sub_flags =
    num_submodules
    |> List.init ~f:(sprintf "--sub values_%d.ml")
    |> String.concat ~sep:" "
  in
  let values_ml =
    [%string
      {|
(rule
  (targets values.ml %{value_modules})
  (deps (:service %%{"{"}project_root}/vendor/botocore/botocore/data/%{service}/%{date}/service-2.json))
  (action (run %%{"{"}bin:awsm-codegen} service values
                --service-id %{service}
                --impl values.ml %{sub_flags}
                --service %%{"{"}service})))
      |}]
  in
  [%string
    ";; do not edit! generated by awsm-codegen\n%{library}\n%{endpoints_ml}\n%{values_ml}"]
;;

let make_io (io_kind : [ `Async | `Lwt ]) ~date ~service =
  let io =
    match io_kind with
    | `Async -> "async"
    | `Lwt -> "lwt"
  in
  let service_under =
    service
    |> String.map ~f:(function
         | '-' -> '_'
         | c -> c)
  in
  let io_cap = String.capitalize io in
  let library =
    [%string
      {|
(library
  (name awsm_%{service_under}_%{io})
  (flags (:standard -open Core -open %{io_cap}))
  (public_name awsm-%{service}-%{io})
  (libraries awsm-%{service} awsm-%{io})
  (preprocess (pps ppx_jane))
  (inline_tests))
      |}]
  in
  let num_submodules =
    match service with
    | "ec2" -> 3
    | "iot" | "rds" | "sagemaker" -> 2
    | _ -> 0
  in
  let cli_ml =
    match io_kind with
    | `Lwt -> ""
    | `Async ->
      let value_modules =
        num_submodules |> List.init ~f:(sprintf "cli_%d.ml") |> String.concat ~sep:" "
      in
      let maybe_submodule_flags =
        num_submodules
        |> List.init ~f:(sprintf "--sub cli_%d.ml")
        |> String.concat ~sep:" "
      in
      [%string
        {|
(rule
(targets cli.ml %{value_modules})
(deps (:service %{"%{"}project_root}/vendor/botocore/botocore/data/%{service}/%{date}/service-2.json))
(action (run %{"%{"}bin:awsm-codegen} service-io cli
 --impl cli.ml %{maybe_submodule_flags}
 --service %{"%{"}service})))
    |}]
  in
  let io_ml_mli =
    [%string
      {|
(rule
(targets io.ml io.mli)
(deps (:service %%{"{"}project_root}/vendor/botocore/botocore/data/%{service}/%{date}/service-2.json))
(action (run %%{"{"}bin:awsm-codegen} service-io io
  --service %%{"{"}service}
  --impl io.ml
  --intf io.mli
  --base-module Awsm_%{service_under}
  --io-subsystem %{io})))
    |}]
  in
  let values_ml =
    [%string
      {|
(rule
 (targets values.ml)
 (action (with-stdout-to %%{"{"}targets} (run %%{"{"}bin:awsm-codegen} service-io values
   --service %{service}
 ))))
    |}]
  in
  [%string
    ";; do not edit! generated by awsm-codegen!\n\
     %{library}\n\
     %{cli_ml}\n\
     %{io_ml_mli}\n\
     %{values_ml}"]
;;

let make_cli_async ~service =
  let service_ = dashes_to_underscores service in
  let executable =
    sprintf
      {|
  (executable
    (package awsm-%s-async)
    (name awsm_%s)
    (flags (:standard -open Core -open Async))
    (public_name awsm-%s)
    (libraries awsm-%s-async awsm-async core_unix.command_unix)
    (preprocess (pps ppx_jane)))
  |}
      service
      service_
      service
      service
  in
  let script =
    let target = sprintf "awsm_%s.ml" service_ in
    [%string
      {|
(rule
  (targets %{target})
  (action (with-stdout-to %%{"{"}targets} (run %%{"{"}bin:awsm-codegen} cli script
    --service %{service}
  ))))|}]
  in
  sprintf ";; do not edit! generated by awsm-codegen!\n%s\n%s" executable script
;;