以某种方式一直到 buildHook 的自定义字段?
Custom fields that somehow get all the way to buildHook?
我想从我的 .cabal
传递一些自定义的 per-executable/library 配置(最好是一整袋键值对,但至少有一个 String
)一直归档到 Setup.hs
的 buildHook
.
作为参考,buildHook
的参数是:
buildHook
:: PackageDescription
-> LocalBuildInfo
-> UserHooks
-> BuildFlags -> IO ()
所以我希望 PackageDescription
的 library
/ executables
字段中有一些东西可以让我访问自定义字段,而不会中断所有其他 Cabal 阶段,即我可以放入 .cabal
文件。这是一个虚构的例子,基本上已经很好了:
...
executable my-exe
main-is: my-main.hs
...
plugin-args:
myplugin:
foo: bar
baz: quux
所以我可以检索所有 myplugin
key/value 对以在某种关联数据结构中获得 "foo" |-> "bar", "baz" |-> "quux"
,例如 HashMap
.
请注意,我已经在我的 Setup.hs
中进行了激烈的暴力,因此欢迎任何形式的骇人听闻的建议。如果需要,我可以覆盖所有 Setup.hs
挂钩以忽略所有内容中的某些设置 - 但 -buildHook
,如果某些解决方案需要的话。
虽然在用户文档里没找到,但是有this nugget in the BuildInfo
type:
customFieldsBI :: [(String, String)]
Custom fields starting with x-
, stored in a simple assoc-list.
原来你可以这样写
...
executable my-exe
main-is: my-main.hs
...
plugin-args:
x-myplugin: foo
然后使用 lookup "x-myplugin" . view customFieldsBI :: (HasBuildInfo bi) => bi -> Maybe String
访问它。
特别是,Executable
和 Library
有 HasBuildInfo
个实例,因此您可以遍历 buildHook
中的 PackageDescription
并处理它们的 String
那里的价值。
我想从我的 .cabal
传递一些自定义的 per-executable/library 配置(最好是一整袋键值对,但至少有一个 String
)一直归档到 Setup.hs
的 buildHook
.
作为参考,buildHook
的参数是:
buildHook
:: PackageDescription
-> LocalBuildInfo
-> UserHooks
-> BuildFlags -> IO ()
所以我希望 PackageDescription
的 library
/ executables
字段中有一些东西可以让我访问自定义字段,而不会中断所有其他 Cabal 阶段,即我可以放入 .cabal
文件。这是一个虚构的例子,基本上已经很好了:
...
executable my-exe
main-is: my-main.hs
...
plugin-args:
myplugin:
foo: bar
baz: quux
所以我可以检索所有 myplugin
key/value 对以在某种关联数据结构中获得 "foo" |-> "bar", "baz" |-> "quux"
,例如 HashMap
.
请注意,我已经在我的 Setup.hs
中进行了激烈的暴力,因此欢迎任何形式的骇人听闻的建议。如果需要,我可以覆盖所有 Setup.hs
挂钩以忽略所有内容中的某些设置 - 但 -buildHook
,如果某些解决方案需要的话。
虽然在用户文档里没找到,但是有this nugget in the BuildInfo
type:
customFieldsBI :: [(String, String)]
Custom fields starting with
x-
, stored in a simple assoc-list.
原来你可以这样写
...
executable my-exe
main-is: my-main.hs
...
plugin-args:
x-myplugin: foo
然后使用 lookup "x-myplugin" . view customFieldsBI :: (HasBuildInfo bi) => bi -> Maybe String
访问它。
特别是,Executable
和 Library
有 HasBuildInfo
个实例,因此您可以遍历 buildHook
中的 PackageDescription
并处理它们的 String
那里的价值。