Skip to content

Commit

Permalink
feat ya-make: add support for DOCS_LIBRARY in PROTO_LIBRARY
Browse files Browse the repository at this point in the history
commit_hash:8f3498b2a434c3f72e0f5789ee69ae2aad71a05a
  • Loading branch information
aserebriyskiy committed Mar 10, 2025
1 parent d707226 commit 65edc48
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 4 deletions.
8 changes: 4 additions & 4 deletions build/conf/docs.conf
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ module DOCS_LIBRARY: _DOCS_BARE_UNIT {

SET(MODULE_TYPE LIBRARY)
SET(MODULE_TAG DOCS_LIBRARY)
SET(PEERDIR_TAGS DOCS_LIBRARY)
SET(PEERDIR_TAGS DOCS_LIBRARY DOCS_PROTO)

SET(MODULE_SUFFIX .docslib)
}
Expand Down Expand Up @@ -160,7 +160,7 @@ multimodule DOCS {
ENABLE(DOCSBOOK)

SET(MODULE_TAG DOCSBOOK)
SET(PEERDIR_TAGS DOCSLIB)
SET(PEERDIR_TAGS DOCSLIB DOCS_PROTO)

_DOCS_YFM_OUTPUT_FORMAT=$_DOCS_YFM_BOOK_OUTPUT_FORMAT

Expand All @@ -177,7 +177,7 @@ multimodule DOCS {
ENABLE(DOCSLIB)

SET(MODULE_TAG DOCSLIB)
SET(PEERDIR_TAGS DOCSLIB_INTERNAL)
SET(PEERDIR_TAGS DOCSLIB_INTERNAL DOCS_PROTO)

REALPRJNAME=preprocessed

Expand All @@ -194,7 +194,7 @@ multimodule DOCS {
DISABLE(START_TARGET)

SET(MODULE_TAG DOCSLIB_INTERNAL)
SET(PEERDIR_TAGS DOCSLIB_EXTERNAL DOCS_LIBRARY)
SET(PEERDIR_TAGS DOCSLIB_EXTERNAL DOCS_LIBRARY DOCS_PROTO)
# additional .fake extension make this output suppressed by ya-bin
SET(MODULE_SUFFIX .docslib.fake)

Expand Down
41 changes: 41 additions & 0 deletions build/conf/proto.conf
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,11 @@ macro _GO_PROTO_CMD(File) {
.CMD=$_GO_PROTO_CMD_IMPL($File $GO_PROTO_OPTS $GO_PROTO_OUTS)
}

# tag:proto tag:docs-specific
macro _DOCS_PROTO_CMD(File) {
.CMD=${cwd;rootdir;input:File} $YMAKE_PYTHON3 ${input:"build/scripts/docs_proto_wrapper.py"} --docs-output ${output;norel;nopath;suf=.md;noext:File} -- $PROTOC -I=./$PROTO_NAMESPACE -I=$ARCADIA_ROOT/$PROTO_NAMESPACE ${pre=-I=:_PROTO__INCLUDE} -I=$ARCADIA_BUILD_ROOT -I=$PROTOBUF_INCLUDE_PATH $_PROTOC_FLAGS --plugin=protoc-gen-doc=${tool:"vendor/github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc"} ${input;rootrel:File} ${hide:PROTO_FAKEID} ${hide;kv:"p PD"} ${hide;kv:"pc yellow"}
}

# tag:proto
### @usage: YT_ORM_PROTO_YSON(Files... OUT_OPTS Opts...)
###
Expand Down Expand Up @@ -765,6 +770,34 @@ module _GO_PROTO: GO_LIBRARY {
}
}

module _DOCS_PROTO: DOCS_LIBRARY {
.ALIASES=SRCS=_SRCS_NO_GLOBAL
.EPILOGUE=_DOCS_LIBRARY_EPILOGUE
.EXTS=.md
.IGNORED=GENERATE_ENUM_SERIALIZATION GENERATE_ENUM_SERIALIZATION_WITH_HEADER YMAPS_SPROTO RESOURCE GO_PROTO_PLUGIN GRPC

ENABLE(DOCS_PROTO)
DISABLE(_NEED_SBOM_INFO)

_EVLOG_CMDLINE=$_DOCS_PROTO_CMDLINE
_PROTO_CMDLINE=$_DOCS_PROTO_CMDLINE

when ($_COMMON_GOOGLE_APIS != "None") {
PEERDIR += contrib/libs/googleapis-common-protos
}

when ($NEED_GOOGLE_PROTO_PEERDIRS == "yes") {
when ($USE_VANILLA_PROTOC == "yes") {
PEERDIR += contrib/libs/protobuf_std/builtin_proto/protos_from_protobuf
}
otherwise {
PEERDIR += contrib/libs/protobuf/builtin_proto/protos_from_protoc
}
}

SET(_YFM_DOCS_DIR_DEFAULT_VALUE __dummy_dir__)
}

module _TS_PROTO: _TS_PROTO_IMPL {
DISABLE(_NEED_SBOM_INFO)
}
Expand Down Expand Up @@ -854,6 +887,13 @@ multimodule PROTO_LIBRARY {
SET_APPEND(PEERDIR_TAGS GO_PROTO)
}

module DOCS_PROTO: _DOCS_PROTO {
.SEM=_SEM_IGNORED
.INCLUDE_TAG=no
.EPILOGUE=_DOCS_LIBRARY_EPILOGUE
SET_APPEND(PEERDIR_TAGS DOCS_PROTO)
}

module TS_PROTO: _TS_PROTO {
.SEM=_SEM_IGNORED
# opt-in. We don't want to have TS_PROTO by default
Expand Down Expand Up @@ -990,5 +1030,6 @@ _CPP_VANILLA_PROTO_CMDLINE=$_CPP_VANILLA_PROTO_CMD($SRC)
_JAVA_EVLOG_CMDLINE=$_JAVA_EVLOG_CMD($SRC)
_JAVA_PROTO_CMDLINE=$_JAVA_PROTO_CMD($SRC)
_PROTO_DESC_CMDLINE=$_PROTO_DESC_RAWPROTO_CMD($SRC)
_DOCS_PROTO_CMDLINE=$_DOCS_PROTO_CMD($SRC)
_PY_EVLOG_CMDLINE=$_PY_EVLOG_CMD($SRC)
_PY_PROTO_CMDLINE=$_PY_PROTO_CMD($SRC)
35 changes: 35 additions & 0 deletions build/scripts/docs_proto_wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import argparse
import subprocess
import sys
import pathlib


def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('--docs-output', required=True)
parser.add_argument('args', nargs='+')

return parser.parse_args()


def main(args):
cmd = list(args.args)
# interface is like this:
# --doc_out=TARGET_DIR
# --doc_opt=markdon,TARGET_FILE_NAME

target_file = pathlib.Path(args.docs_output)
cmd.append(f'--doc_opt=markdown,{target_file.name}')
cmd.append(f'--doc_out={target_file.parent}')

try:
subprocess.check_output(cmd, stdin=None, stderr=subprocess.STDOUT, text=True)
except subprocess.CalledProcessError as e:
sys.stderr.write(f'{e.cmd} returned non-zero exit code {e.returncode}.\n{e.output}\n')
return e.returncode

return 0


if __name__ == '__main__':
sys.exit(main(parse_args()))
1 change: 1 addition & 0 deletions build/scripts/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ ELSEIF (PY3)
copy_to_dir.py
cpp_flatc_wrapper.py
decimal_md5.py
docs_proto_wrapper.py
error.py
extract_asrc.py
extract_docs.py
Expand Down
2 changes: 2 additions & 0 deletions contrib/libs/googleapis-common-protos/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,6 @@ SRCS(

EXCLUDE_TAGS(GO_PROTO)

INCLUDE_TAGS(DOCS_PROTO)

END()

0 comments on commit 65edc48

Please sign in to comment.