Просмотр исходного кода

feat(TS_PROTO): basic TS_PROTO implementation
398e9820bbfd2c0ed45e74bf152431910ead2c4c

zaverden 1 год назад
Родитель
Сommit
c2dc3cacac

+ 7 - 0
build/conf/proto.conf

@@ -754,6 +754,13 @@ multimodule PROTO_LIBRARY {
         }
     }
 
+    module TS_PROTO: _TS_PROTO_IMPL {
+        # opt-in. We don't want to have TS_PROTO by default
+        # To include TS_PROTO user have to set INCLUDE_TAGS(TS_PROTO) in ya.make
+        .INCLUDE_TAG=no
+        .EPILOGUE=_TS_CONFIG_EPILOGUE
+    }
+
     module DESC_PROTO: _BARE_UNIT {
         .CMD=_PROTO_DESC_MERGE_CMD
         .SEM=IGNORED

+ 1 - 1
build/conf/ts/node_modules.conf

@@ -40,7 +40,7 @@ module _NODE_MODULES_BASE: _BARE_UNIT {
     # define own tag
     SET(MODULE_TAG NODE_MODULES)
     # what modules it can PEERDIR to
-    SET(PEERDIR_TAGS TS NPM_CONTRIBS)
+    SET(PEERDIR_TAGS TS TS_PROTO NPM_CONTRIBS)
     # do not include it into "results" of graph
     DISABLE(START_TARGET)
 

+ 2 - 1
build/conf/ts/ts.conf

@@ -54,7 +54,7 @@ module _TS_BASE_UNIT: _BARE_UNIT {
     # Include processor works only for TS tag
     SET(MODULE_TAG TS)
     # TS should peer to TS
-    SET(PEERDIR_TAGS TS)
+    SET(PEERDIR_TAGS TS TS_PROTO)
     # .fake tells builder to not materialize it in results
     SET(MODULE_SUFFIX .ts.fake)
 
@@ -120,6 +120,7 @@ macro TS_FILES(Files...) {
 @import "${CONF_ROOT}/conf/ts/node_modules.conf"
 @import "${CONF_ROOT}/conf/ts/ts_next.conf"
 @import "${CONF_ROOT}/conf/ts/ts_package.conf"
+@import "${CONF_ROOT}/conf/ts/ts_proto.conf"
 @import "${CONF_ROOT}/conf/ts/ts_test.conf"
 @import "${CONF_ROOT}/conf/ts/ts_tsc.conf"
 @import "${CONF_ROOT}/conf/ts/ts_vite.conf"

+ 44 - 0
build/conf/ts/ts_proto.conf

@@ -0,0 +1,44 @@
+_TS_PROTO_SRCS_FILES=
+_TS_PROTO_IMPL_CMD=$TOUCH_UNIT \
+    && $_TS_FILES_COPY_CMD \
+    && $NOTS_TOOL $NOTS_TOOL_BASE_ARGS build-ts-proto $NOTS_TOOL_COMMON_BUILDER_ARGS \
+        --protoc-bin $PROTOC \
+        --proto-srcs $_TS_PROTO_SRCS_FILES \
+        --proto-paths ./$PROTO_NAMESPACE $ARCADIA_ROOT/$PROTO_NAMESPACE $_PROTO__INCLUDE $ARCADIA_BUILD_ROOT $PROTOBUF_PATH \
+        $_NODE_MODULES_INOUTS \
+        ${input;hide:"package.json"} ${TS_CONFIG_FILES} $_AS_HIDDEN_INPUTS(IN $TS_INPUT_FILES) \
+        ${output;hide:"package.json"} \
+        ${hide:PROTO_FAKEID} \
+        ${kv;hide:"pc magenta"} ${kv;hide:"p TS_PRO"}
+
+
+
+module _TS_PROTO_IMPL: _TS_BASE_UNIT {
+	.CMD=_TS_PROTO_IMPL_CMD
+	.IGNORED=GENERATE_ENUM_SERIALIZATION GENERATE_ENUM_SERIALIZATION_WITH_HEADER USE_SKIFF CPP_PROTO_PLUGIN2 PY_PROTO_PLUGIN YMAPS_SPROTO RESOURCE
+    # We need to collect SRCS paths into list to pass to command
+    .ALIASES=SRCS=_TS_PROTO_SRCS
+
+    # PEERDIR should be resolved to DESC_PROTO submodule
+	SET(PEERDIR_TAGS DESC_PROTO)
+    # For users to add some conditional config for TS_PROTO, like
+    #   IF (TS_PROTO)
+    #       MESSAGE(Building TS_PROTO!!!)
+	ENABLE(TS_PROTO)
+    # Disable linting
+    NO_LINT()
+
+    _PEERDIR_TS_RESOURCE(typescript)
+
+    DISABLE(TS_CONFIG_DEDUCE_OUT)
+    ENABLE(TS_CONFIG_USE_OUTDIR)
+
+    _TS_CONFIGURE($TS_CONFIG_PATH)
+
+    SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS ${CURDIR}/package.json ${CURDIR}/pnpm-lock.yaml ${CURDIR}/${TS_CONFIG_PATH})
+    _TS_ADD_NODE_MODULES_FOR_BUILDER()
+}
+
+macro _TS_PROTO_SRCS(FILES...) {
+    _SET_APPEND_WITH_DIRECTIVE(_TS_PROTO_SRCS_FILES input $FILES)
+}

+ 8 - 2
build/plugins/nots.py

@@ -78,8 +78,8 @@ def _build_directives(name, flags, paths):
     # type: (str, list[str]|tuple[str], list[str]) -> str
 
     parts = [p for p in [name] + (flags or []) if p]
-
-    expressions = ["${{{parts}:\"{path}\"}}".format(parts=";".join(parts), path=path) for path in paths]
+    parts_str = ";".join(parts)
+    expressions = ['${{{parts}:"{path}"}}'.format(parts=parts_str, path=path) for path in paths]
 
     return " ".join(expressions)
 
@@ -121,6 +121,12 @@ def _create_erm_json(unit):
     return ErmJsonLite.load(path)
 
 
+@_with_report_configure_error
+def on_set_append_with_directive(unit, var_name, dir, *values):
+    wrapped = ['${{{dir}:"{v}"}}'.format(dir=dir, v=v) for v in values]
+    __set_append(unit, var_name, " ".join(wrapped))
+
+
 @_with_report_configure_error
 def on_from_npm_lockfiles(unit, *args):
     from lib.nots.package_manager.base import PackageManagerError