|
154 | 154 | ,v
|
155 | 155 | (,error ,(if err err (string/format "assert failure in %j" x))))))
|
156 | 156 |
|
| 157 | +(defmacro assertf |
| 158 | + "Convenience macro that combines `assert` and `string/format`." |
| 159 | + [x & args] |
| 160 | + ~(as-macro ,assert ,x (,string/format ,;args))) |
| 161 | + |
157 | 162 | (defmacro defdyn
|
158 | 163 | ``Define an alias for a keyword that is used as a dynamic binding. The
|
159 | 164 | alias is a normal, lexically scoped binding that can be used instead of
|
|
3934 | 3939 | (defn make-sig []
|
3935 | 3940 | (ffi/signature :default real-ret-type ;computed-type-args))
|
3936 | 3941 | (defn make-ptr []
|
3937 |
| - (assert (ffi/lookup (if lazy (llib) lib) raw-symbol) (string "failed to find ffi symbol " raw-symbol))) |
| 3942 | + (assertf (ffi/lookup (if lazy (llib) lib) raw-symbol) "failed to find ffi symbol %v" raw-symbol)) |
3938 | 3943 | (if lazy
|
3939 | 3944 | ~(defn ,alias ,;meta [,;formal-args]
|
3940 | 3945 | (,ffi/call (,(delay (make-ptr))) (,(delay (make-sig))) ,;formal-args))
|
|
4111 | 4116 | "Get the manifest for a give installed bundle"
|
4112 | 4117 | [bundle-name]
|
4113 | 4118 | (def name (get-manifest-filename bundle-name))
|
4114 |
| - (assert (fexists name) (string "no bundle " bundle-name " found")) |
| 4119 | + (assertf (fexists name) "no bundle %v found" bundle-name) |
4115 | 4120 | (parse (slurp name)))
|
4116 | 4121 |
|
4117 | 4122 | (defn- get-bundle-module
|
|
4254 | 4259 | (def missing (seq [d :in deps :when (not (bundle/installed? d))] (string d)))
|
4255 | 4260 | (when (next missing) (errorf "missing dependencies %s" (string/join missing ", "))))
|
4256 | 4261 | (def bundle-name (get config :name default-bundle-name))
|
4257 |
| - (assert bundle-name (errorf "unable to infer bundle name for %v, use :name argument" path)) |
4258 |
| - (assert (not (string/check-set "\\/" bundle-name)) |
4259 |
| - (string "bundle name " |
4260 |
| - bundle-name |
4261 |
| - " cannot contain path separators")) |
| 4262 | + (assertf bundle-name "unable to infer bundle name for %v, use :name argument" path) |
| 4263 | + (assertf (not (string/check-set "\\/" bundle-name)) |
| 4264 | + "bundle name %v cannot contain path separators" bundle-name) |
4262 | 4265 | (assert (next bundle-name) "cannot use empty bundle-name")
|
4263 | 4266 | (assert (not (fexists (get-manifest-filename bundle-name)))
|
4264 | 4267 | "bundle is already installed")
|
|
4310 | 4313 | (var i 0)
|
4311 | 4314 | (def man (bundle/manifest bundle-name))
|
4312 | 4315 | (def files (get man :files @[]))
|
4313 |
| - (assert (os/mkdir dest-dir) (string "could not create directory " dest-dir " (or it already exists)")) |
| 4316 | + (assertf (os/mkdir dest-dir) "could not create directory %v (or it already exists)" dest-dir) |
4314 | 4317 | (def s (sep))
|
4315 | 4318 | (os/mkdir (string dest-dir s "bundle"))
|
4316 | 4319 | (def install-hook (string dest-dir s "bundle" s "init.janet"))
|
|
0 commit comments