第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

嘗試編寫自定義規(guī)則

嘗試編寫自定義規(guī)則

Go
胡說(shuō)叔叔 2023-07-10 17:43:32
我正在嘗試為gqlgen編寫自定義規(guī)則。這個(gè)想法是運(yùn)行它來(lái)從 GraphQL 模式生成 Go 代碼。我的預(yù)期用途是:gqlgen( ????name?=?"gql-gen-foo", ????schemas?=?["schemas/schema.graphql"], ????visibility?=?["http://visibility:public"], )“name”是規(guī)則的名稱,我希望其他規(guī)則依賴于此;“模式”是輸入文件的集合。到目前為止我有:load(? ? "@io_bazel_rules_go//go:def.bzl",? ? _go_context = "go_context",? ? _go_rule = "go_rule",)def _gqlgen_impl(ctx):? ? go = _go_context(ctx)? ? args = ["run github.com/99designs/gqlgen --config"] + [ctx.attr.config]? ? ctx.actions.run(? ? ? ? inputs = ctx.attr.schemas,? ? ? ? outputs = [ctx.actions.declare_file(ctx.attr.name)],? ? ? ? arguments = args,? ? ? ? progress_message = "Generating GraphQL models and runtime from %s" % ctx.attr.config,? ? ? ? executable = go.go,? ? )_gqlgen = _go_rule(? ? implementation = _gqlgen_impl,? ? attrs = {? ? ? ? "config": attr.string(? ? ? ? ? ? default = "gqlgen.yml",? ? ? ? ? ? doc = "The gqlgen filename",? ? ? ? ),? ? ? ? "schemas": attr.label_list(? ? ? ? ? ? allow_files = [".graphql"],? ? ? ? ? ? doc = "The schema file location",? ? ? ? ),? ? },? ? executable = True,)def gqlgen(**kwargs):? ? tags = kwargs.get("tags", [])? ? if "manual" not in tags:? ? ? ? tags.append("manual")? ? ? ? kwargs["tags"] = tags? ? _gqlgen(**kwargs)我眼前的問(wèn)題是 Bazel 抱怨這些模式不是Files:expected type 'File' for 'inputs' element but got type 'Target' instead指定輸入文件的正確方法是什么?這是生成執(zhí)行命令的規(guī)則的正確方法嗎?最后,是否可以讓輸出文件不存在于文件系統(tǒng)中,而是作為其他規(guī)則可以依賴的標(biāo)簽?
查看完整描述

1 回答

?
智慧大石

TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超3個(gè)贊

代替:

ctx.actions.run(
        inputs = ctx.attr.schemas,

使用:

ctx.actions.run(
        inputs = ctx.files.schemas,

這是生成執(zhí)行命令的規(guī)則的正確方法嗎?

只要gqlgen創(chuàng)建具有正確輸出名稱 ( ) 的文件,這看起來(lái)是正確的outputs = [ctx.actions.declare_file(ctx.attr.name)]。

generated_go_file = ctx.actions.declare_file(ctx.attr.name + ".go")


# ..


ctx.actions.run(

    outputs = [generated_go_file],

    args = ["run", "...", "--output", generated_go_file.short_path],

    # ..

)

最后,是否可以讓輸出文件不存在于文件系統(tǒng)中,而是作為其他規(guī)則可以依賴的標(biāo)簽?


需要?jiǎng)?chuàng)建輸出文件,并且只要它在提供程序中的規(guī)則實(shí)現(xiàn)結(jié)束時(shí)返回DefaultInfo,其他規(guī)則將能夠依賴于文件標(biāo)簽(例如//my/package:foo-gqlgen.go)。


查看完整回答
反對(duì) 回復(fù) 2023-07-10
  • 1 回答
  • 0 關(guān)注
  • 135 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)