aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorv-homyakov <v-homyakov@yandex-team.ru>2022-06-15 21:16:32 +0300
committerv-homyakov <v-homyakov@yandex-team.ru>2022-06-15 21:16:32 +0300
commit6c64f9cb3a57130c2c3cddc0a42a85fd41698c20 (patch)
treecac1f4416cf6846cbc6c0dd29a70145a3ef1c8af
parent3591e3bbb489851930d8202b55551c1369d423fa (diff)
downloadydb-6c64f9cb3a57130c2c3cddc0a42a85fd41698c20.tar.gz
FEI-24069: ya make + frontend: поддержка eslint
ref:e80bfd2c07b374fcedc5dc4c2bd7c1e9fc65ba93
-rw-r--r--build/conf/ts.conf12
-rw-r--r--build/external_resources/eslint/create-sandbox-resource.sh33
-rw-r--r--build/external_resources/eslint/readme.md13
-rw-r--r--build/plugins/nots.py46
-rw-r--r--build/plugins/ytest.py44
5 files changed, 120 insertions, 28 deletions
diff --git a/build/conf/ts.conf b/build/conf/ts.conf
index 58766b3198a..8076726ba81 100644
--- a/build/conf/ts.conf
+++ b/build/conf/ts.conf
@@ -6,6 +6,8 @@ TSC_ROOT=$TS_COMPILER_RESOURCE_GLOBAL/typescript
TSC_SCRIPT=$TSC_ROOT/lib/tsc.js
WEBPACK_ROOT=$WEBPACK_RESOURCE_GLOBAL/node_modules
WEBPACK_SCRIPT=$WEBPACK_ROOT/.bin/webpack
+ESLINT_ROOT=$ESLINT_RESOURCE_GLOBAL
+ESLINT_SCRIPT=$ESLINT_ROOT/node_modules/.bin/eslint
NOTS_TOOL=${tool:"tools/nots"}
NOTS_TOOL_BASE_ARGS=--build-root $ARCADIA_BUILD_ROOT --bindir $BINDIR --curdir $CURDIR --nodejs-bin $NODEJS_BIN
@@ -100,7 +102,9 @@ module TS_LIBRARY : _TS_BASE_UNIT {
.CMD=TS_COMPILE
.FINAL_TARGET=yes
.PEERDIR_POLICY=as_build_from
+ .EPILOGUE=_TS_LIBRARY_EPILOGUE
+ PEERDIR(build/external_resources/eslint)
SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS ${CURDIR}/${TS_CONFIG_PATH} ${CURDIR}/package.json)
SET(TS_CONFIG_DEDUCE_OUT yes)
@@ -135,3 +139,11 @@ module TS_BUNDLE : _TS_BASE_UNIT {
_TS_CONFIGURE($TS_CONFIG_PATH)
}
+
+_TS_LINT_SRCS_VALUE=
+### _TS_LIBRARY_EPILOGUE() # internal
+###
+### This macro executes macros which should be invoked after all user specified macros in the ya.make file
+macro _TS_LIBRARY_EPILOGUE() {
+ _GLOB(_TS_LINT_SRCS_VALUE ${CURDIR}/**/*.(ts|tsx) EXCLUDE **/node_modules/**/*.(ts|tsx))
+}
diff --git a/build/external_resources/eslint/create-sandbox-resource.sh b/build/external_resources/eslint/create-sandbox-resource.sh
new file mode 100644
index 00000000000..33525c8ca42
--- /dev/null
+++ b/build/external_resources/eslint/create-sandbox-resource.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+set -e
+
+ESLINT_VERSION="7.27.0"
+PACKAGES="eslint@$ESLINT_VERSION @yandex-int/lint@1.15.0"
+
+echo "Creating temporary directory…"
+TMP_DIR=$(mktemp -d)
+cd $TMP_DIR
+echo "Temporary directory ${TMP_DIR} is created"
+
+echo "Installing packages…"
+ESLINT_DIR="eslint-resource"
+mkdir $ESLINT_DIR && cd $ESLINT_DIR
+npm init -y
+npm install --save-dev --save-exact --registry=https://npm.yandex-team.ru ${PACKAGES}
+echo "Packages are installed"
+
+echo "Creating archive…"
+RESOURCE_DIR="node_modules"
+ARCHIVE="eslint-$ESLINT_VERSION.tar.gz"
+tar --create --gzip --file=$ARCHIVE $RESOURCE_DIR
+echo "Archive $(pwd)/$ARCHIVE is created"
+
+echo "Uploading file ${ARCHIVE}…"
+DESCRIPTION="Bundle for https://st.yandex-team.ru/FEI-24069. Content: ${PACKAGES}."
+ya upload $ARCHIVE -d="${DESCRIPTION}" --ttl="inf" --attr="eslint=${ESLINT_VERSION}"
+echo "File $ARCHIVE is uploaded"
+
+echo "Cleaning up…"
+rm -rf $TMP_DIR
+
+echo "Done"
diff --git a/build/external_resources/eslint/readme.md b/build/external_resources/eslint/readme.md
new file mode 100644
index 00000000000..73208679ca9
--- /dev/null
+++ b/build/external_resources/eslint/readme.md
@@ -0,0 +1,13 @@
+# eslint bundle
+
+Ресурс должен быть tar.gz-архивом с пакетами `eslint` и `@yandex-int/lint` и всеми транзитивными зависимостями. Структура:
+
+```
+node_modules/
+ .bin/
+ eslint
+ @yandex-int/
+ lint/
+ eslint/
+ остальные пакеты, нужные для eslint
+```
diff --git a/build/plugins/nots.py b/build/plugins/nots.py
index 5018256ddc9..dbdfd62e11b 100644
--- a/build/plugins/nots.py
+++ b/build/plugins/nots.py
@@ -1,6 +1,7 @@
-import os
+import os.path
-from _common import to_yesno
+import ytest
+from _common import to_yesno, resolve_common_const
from lib.nots.package_manager import manager
from lib.nots.typescript import TsConfig
@@ -44,3 +45,44 @@ def on_ts_configure(unit, tsconfig_path):
unit.set(["TS_CONFIG_DECLARATION", to_yesno(tsconfig.compiler_option("declaration"))])
unit.set(["TS_CONFIG_DECLARATION_MAP", to_yesno(tsconfig.compiler_option("declarationMap"))])
unit.set(["TS_CONFIG_PRESERVE_JSX", to_yesno(tsconfig.compiler_option("jsx") == "preserve")])
+
+ _setup_eslint(unit)
+
+
+def _setup_eslint(unit):
+ # MODDIR == devtools/dummy_arcadia/ts/packages/with_lint
+ # CURDIR == $S/MODDIR
+ mod_dir = unit.get('MODDIR')
+
+ lint_files = ytest.get_values_list(unit, '_TS_LINT_SRCS_VALUE')
+ resolved_files = []
+ for path in lint_files:
+ resolved = unit.resolve(unit.resolve_arc_path(resolve_common_const(path)))
+ resolved_files.append(resolved)
+
+ if resolved_files:
+ # ESLint should start in the MODDIR to properly use relative paths in config files
+ _add_eslint(unit, mod_dir, resolved_files)
+
+
+def _add_eslint(unit, test_cwd, test_files):
+ check_type = "eslint"
+ test_dir = ytest.get_norm_unit_path(unit)
+
+ test_record = {
+ 'TEST-NAME': check_type.lower(),
+ 'TEST-TIMEOUT': '',
+ 'SCRIPT-REL-PATH': check_type,
+ 'TESTED-PROJECT-NAME': os.path.basename(test_dir),
+ 'SOURCE-FOLDER-PATH': test_dir,
+ 'SPLIT-FACTOR': unit.get('TEST_SPLIT_FACTOR') or '',
+ 'FORK-MODE': unit.get('TEST_FORK_MODE') or '',
+ 'SIZE': 'SMALL',
+ 'TEST-FILES': ytest.serialize_list(test_files),
+ 'TEST-CWD': test_cwd,
+ }
+
+ data = ytest.dump_test(unit, test_record)
+ if data:
+ unit.set_property(['DART_DATA', data])
+ ytest.save_in_file(unit.get('TEST_DART_OUT_FILE'), data)
diff --git a/build/plugins/ytest.py b/build/plugins/ytest.py
index acf98701d16..bf68d670456 100644
--- a/build/plugins/ytest.py
+++ b/build/plugins/ytest.py
@@ -551,6 +551,10 @@ def onadd_check(unit, *args):
"REQUIREMENTS": -1, "FORK_MODE": 1, "SPLIT_FACTOR": 1,
"FORK_SUBTESTS": 0, "FORK_TESTS": 0, "SIZE": 1}, args)
check_type = flat_args[0]
+
+ if check_type in ("check.data", "check.resource") and unit.get('VALIDATE_DATA') == "no":
+ return
+
test_dir = get_norm_unit_path(unit)
test_timeout = ''
@@ -558,12 +562,12 @@ def onadd_check(unit, *args):
extra_test_data = ''
extra_test_dart_data = {}
ymake_java_test = unit.get('YMAKE_JAVA_TEST') == 'yes'
+ use_arcadia_python = unit.get('USE_ARCADIA_PYTHON')
+ uid_ext = ''
+ script_rel_path = check_type
+ test_files = flat_args[1:]
- if check_type in ["flake8.py2", "flake8.py3"]:
- script_rel_path = check_type
- fork_mode = unit.get('TEST_FORK_MODE') or ''
- elif check_type == "black":
- script_rel_path = check_type
+ if check_type in ["flake8.py2", "flake8.py3", "black"]:
fork_mode = unit.get('TEST_FORK_MODE') or ''
elif check_type == "JAVA_STYLE":
if ymake_java_test and not unit.get('ALL_SRCDIRS') or '':
@@ -579,9 +583,7 @@ def onadd_check(unit, *args):
}
if check_level not in allowed_levels:
raise Exception('{} is not allowed in LINT(), use one of {}'.format(check_level, allowed_levels.keys()))
- flat_args[1] = allowed_levels[check_level]
- if check_level == 'none':
- return
+ test_files[0] = allowed_levels[check_level] # replace check_level with path to config file
script_rel_path = "java.style"
test_timeout = '120'
fork_mode = unit.get('TEST_FORK_MODE') or ''
@@ -589,19 +591,9 @@ def onadd_check(unit, *args):
extra_test_data = java_srcdirs_to_data(unit, 'ALL_SRCDIRS')
extra_test_dart_data['JDK_RESOURCE'] = 'JDK' + (unit.get('JDK_VERSION') or unit.get('JDK_REAL_VERSION') or '_DEFAULT')
elif check_type == "gofmt":
- script_rel_path = check_type
- go_files = flat_args[1:]
- if go_files:
- test_dir = os.path.dirname(go_files[0]).lstrip("$S/")
- else:
- script_rel_path = check_type
-
- use_arcadia_python = unit.get('USE_ARCADIA_PYTHON')
- uid_ext = ''
- if check_type in ("check.data", "check.resource"):
- if unit.get("VALIDATE_DATA") == "no":
- return
- if check_type == "check.data":
+ if test_files:
+ test_dir = os.path.dirname(test_files[0]).lstrip("$S/")
+ elif check_type == "check.data":
uid_ext = unit.get("SBR_UID_EXT").split(" ", 1)[-1] # strip variable name
data_re = re.compile(r"sbr:/?/?(\d+)=?.*")
data = flat_args[1:]
@@ -611,11 +603,11 @@ def onadd_check(unit, *args):
if matched:
resources.append(matched.group(1))
if resources:
- test_files = serialize_list(resources)
+ test_files = resources
else:
return
- else:
- test_files = serialize_list(flat_args[1:])
+
+ serialized_test_files = serialize_list(test_files)
test_record = {
'TEST-NAME': check_type.lower(),
@@ -638,8 +630,8 @@ def onadd_check(unit, *args):
'OLD_PYTEST': 'no',
'PYTHON-PATHS': '',
# TODO remove FILES, see DEVTOOLS-7052
- 'FILES': test_files,
- 'TEST-FILES': test_files,
+ 'FILES': serialized_test_files,
+ 'TEST-FILES': serialized_test_files,
'NO_JBUILD': 'yes' if ymake_java_test else 'no',
}
test_record.update(extra_test_dart_data)