_dart_fields.py 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405
  1. import base64
  2. import functools
  3. import json
  4. import operator
  5. import os
  6. import re
  7. import shlex
  8. import sys
  9. from functools import reduce
  10. import six
  11. import ymake
  12. import _common
  13. import lib.test_const as consts
  14. CANON_RESULT_FILE_NAME = 'result.json'
  15. CANON_DATA_DIR_NAME = 'canondata'
  16. CANON_OUTPUT_STORAGE = 'canondata_storage'
  17. KTLINT_CURRENT_EDITOR_CONFIG = "arcadia/build/platform/java/ktlint/.editorconfig"
  18. KTLINT_OLD_EDITOR_CONFIG = "arcadia/build/platform/java/ktlint_old/.editorconfig"
  19. ARCADIA_ROOT = '${ARCADIA_ROOT}/'
  20. SOURCE_ROOT_SHORT = '$S/'
  21. class DartValueError(ValueError):
  22. pass
  23. def create_dart_record(fields, *args):
  24. try:
  25. return reduce(operator.or_, (value for field in fields if (value := field(*args))), {})
  26. except Exception as e:
  27. if str(e) != "":
  28. ymake.report_configure_error("Exception: {}".format(e))
  29. else:
  30. raise (e)
  31. return None
  32. def with_fields(fields):
  33. def inner(func):
  34. @functools.wraps(func)
  35. def innermost(*args, **kwargs):
  36. func(fields, *args, **kwargs)
  37. return innermost
  38. return inner
  39. def serialize_list(lst):
  40. lst = list(filter(None, lst))
  41. return '\"' + ';'.join(lst) + '\"' if lst else ''
  42. def deserialize_list(val):
  43. return list(filter(None, val.replace('"', "").split(";")))
  44. def get_unit_list_variable(unit, name):
  45. items = unit.get(name)
  46. if items:
  47. items = items.split(' ')
  48. assert items[0] == "${}".format(name), (items, name)
  49. return items[1:]
  50. return []
  51. def get_values_list(unit, key):
  52. res = map(str.strip, (unit.get(key) or '').replace('$' + key, '').strip().split())
  53. return [r for r in res if r and r not in ['""', "''"]]
  54. def _get_test_tags(unit, spec_args=None):
  55. if spec_args is None:
  56. spec_args = {}
  57. tags = spec_args.get('TAG', []) + get_values_list(unit, 'TEST_TAGS_VALUE')
  58. tags = set(tags)
  59. if unit.get('EXPORT_SEM') == 'yes':
  60. filter_only_tags = sorted(t for t in tags if ':' not in t)
  61. unit.set(['FILTER_ONLY_TEST_TAGS', ' '.join(filter_only_tags)])
  62. # DEVTOOLS-7571
  63. if unit.get('SKIP_TEST_VALUE') and consts.YaTestTags.Fat in tags:
  64. tags.add(consts.YaTestTags.NotAutocheck)
  65. return tags
  66. def format_recipes(data: str | None) -> str:
  67. if not data:
  68. return ""
  69. data = data.replace('"USE_RECIPE_DELIM"', "\n")
  70. data = data.replace("$TEST_RECIPES_VALUE", "")
  71. return data
  72. def prepare_recipes(data: str | None) -> bytes:
  73. formatted = format_recipes(data)
  74. return base64.b64encode(six.ensure_binary(formatted))
  75. def prepare_env(data):
  76. data = data.replace("$TEST_ENV_VALUE", "")
  77. return serialize_list(shlex.split(data))
  78. def get_norm_paths(unit, key):
  79. # return paths without trailing (back)slash
  80. return [x.rstrip('\\/').replace('${ARCADIA_ROOT}/', '') for x in get_values_list(unit, key)]
  81. def _load_canonical_file(filename, unit_path):
  82. try:
  83. with open(filename, 'rb') as results_file:
  84. return json.load(results_file)
  85. except Exception as e:
  86. print("malformed canonical data in {}: {} ({})".format(unit_path, e, filename), file=sys.stderr)
  87. return {}
  88. def _get_resource_from_uri(uri):
  89. m = consts.CANON_MDS_RESOURCE_REGEX.match(uri)
  90. if m:
  91. key = m.group(1)
  92. return "{}:{}".format(consts.MDS_SCHEME, key)
  93. m = consts.CANON_BACKEND_RESOURCE_REGEX.match(uri)
  94. if m:
  95. key = m.group(1)
  96. return "{}:{}".format(consts.MDS_SCHEME, key)
  97. m = consts.CANON_SBR_RESOURCE_REGEX.match(uri)
  98. if m:
  99. # There might be conflict between resources, because all resources in sandbox have 'resource.tar.gz' name
  100. # That's why we use notation with '=' to specify specific path for resource
  101. uri = m.group(1)
  102. res_id = m.group(2)
  103. return "{}={}".format(uri, '/'.join([CANON_OUTPUT_STORAGE, res_id]))
  104. def _get_external_resources_from_canon_data(data):
  105. # Method should work with both canonization versions:
  106. # result.json: {'uri':X 'checksum':Y}
  107. # result.json: {'testname': {'uri':X 'checksum':Y}}
  108. # result.json: {'testname': [{'uri':X 'checksum':Y}]}
  109. # Also there is a bug - if user returns {'uri': 1} from test - machinery will fail
  110. # That's why we check 'uri' and 'checksum' fields presence
  111. # (it's still a bug - user can return {'uri':X, 'checksum': Y}, we need to unify canonization format)
  112. res = set()
  113. if isinstance(data, dict):
  114. if 'uri' in data and 'checksum' in data:
  115. resource = _get_resource_from_uri(data['uri'])
  116. if resource:
  117. res.add(resource)
  118. else:
  119. for k, v in six.iteritems(data):
  120. res.update(_get_external_resources_from_canon_data(v))
  121. elif isinstance(data, list):
  122. for e in data:
  123. res.update(_get_external_resources_from_canon_data(e))
  124. return res
  125. def _get_canonical_data_resources_v2(filename, unit_path):
  126. return (_get_external_resources_from_canon_data(_load_canonical_file(filename, unit_path)), [filename])
  127. def get_canonical_test_resources(unit):
  128. unit_path = unit.path()
  129. if unit.get("CUSTOM_CANONDATA_PATH"):
  130. path_to_canondata = unit_path.replace("$S", unit.get("CUSTOM_CANONDATA_PATH"))
  131. else:
  132. path_to_canondata = unit.resolve(unit_path)
  133. canon_data_dir = os.path.join(path_to_canondata, CANON_DATA_DIR_NAME, unit.get('CANONIZE_SUB_PATH') or '')
  134. try:
  135. _, dirs, files = next(os.walk(canon_data_dir))
  136. except StopIteration:
  137. # path doesn't exist
  138. return [], []
  139. if CANON_RESULT_FILE_NAME in files:
  140. return _get_canonical_data_resources_v2(os.path.join(canon_data_dir, CANON_RESULT_FILE_NAME), unit_path)
  141. return [], []
  142. def java_srcdirs_to_data(unit, var, serialize_result=True):
  143. extra_data = []
  144. for srcdir in (unit.get(var) or '').replace('$' + var, '').split():
  145. if srcdir == '.':
  146. srcdir = unit.get('MODDIR')
  147. if srcdir.startswith('${ARCADIA_ROOT}/') or srcdir.startswith('$ARCADIA_ROOT/'):
  148. srcdir = srcdir.replace('${ARCADIA_ROOT}/', '$S/')
  149. srcdir = srcdir.replace('$ARCADIA_ROOT/', '$S/')
  150. if srcdir.startswith('${CURDIR}') or srcdir.startswith('$CURDIR'):
  151. srcdir = srcdir.replace('${CURDIR}', os.path.join('$S', unit.get('MODDIR')))
  152. srcdir = srcdir.replace('$CURDIR', os.path.join('$S', unit.get('MODDIR')))
  153. srcdir = unit.resolve_arc_path(srcdir)
  154. if not srcdir.startswith('$'):
  155. srcdir = os.path.join('$S', unit.get('MODDIR'), srcdir)
  156. if srcdir.startswith('$S'):
  157. extra_data.append(srcdir.replace('$S', 'arcadia'))
  158. return serialize_list(extra_data) if serialize_result else extra_data
  159. def extract_java_system_properties(unit, args):
  160. if len(args) % 2:
  161. return [], 'Wrong use of SYSTEM_PROPERTIES in {}: odd number of arguments'.format(unit.path())
  162. props = []
  163. for x, y in zip(args[::2], args[1::2]):
  164. if x == 'FILE':
  165. if y.startswith('${BINDIR}') or y.startswith('${ARCADIA_BUILD_ROOT}') or y.startswith('/'):
  166. return [], 'Wrong use of SYSTEM_PROPERTIES in {}: absolute/build file path {}'.format(unit.path(), y)
  167. y = _common.rootrel_arc_src(y, unit)
  168. if not os.path.exists(unit.resolve('$S/' + y)):
  169. return [], 'Wrong use of SYSTEM_PROPERTIES in {}: can\'t resolve {}'.format(unit.path(), y)
  170. y = '${ARCADIA_ROOT}/' + y
  171. props.append({'type': 'file', 'path': y})
  172. else:
  173. props.append({'type': 'inline', 'key': x, 'value': y})
  174. return props, None
  175. def _resolve_module_files(unit, mod_dir, file_paths):
  176. mod_dir_with_sep_len = len(mod_dir) + 1
  177. resolved_files = []
  178. for path in file_paths:
  179. resolved = _common.rootrel_arc_src(path, unit)
  180. if resolved.startswith(mod_dir):
  181. resolved = resolved[mod_dir_with_sep_len:]
  182. resolved_files.append(resolved)
  183. return resolved_files
  184. def _resolve_config_path(unit, test_runner, rel_to):
  185. config_path = unit.get("ESLINT_CONFIG_PATH") if test_runner == "eslint" else unit.get("TS_TEST_CONFIG_PATH")
  186. arc_config_path = unit.resolve_arc_path(config_path)
  187. abs_config_path = unit.resolve(arc_config_path)
  188. if not abs_config_path:
  189. raise Exception("{} config not found: {}".format(test_runner, config_path))
  190. unit.onsrcs([arc_config_path])
  191. abs_rel_to = unit.resolve(unit.resolve_arc_path(unit.get(rel_to)))
  192. return os.path.relpath(abs_config_path, start=abs_rel_to)
  193. def _get_ts_test_data_dirs(unit):
  194. return sorted(
  195. set(
  196. [
  197. os.path.dirname(_common.rootrel_arc_src(p, unit))
  198. for p in (get_values_list(unit, "_TS_TEST_DATA_VALUE") or [])
  199. ]
  200. )
  201. )
  202. @_common.cache_by_second_arg
  203. def get_linter_configs(unit, config_paths):
  204. rel_config_path = _common.rootrel_arc_src(config_paths, unit)
  205. arc_config_path = unit.resolve_arc_path(rel_config_path)
  206. abs_config_path = unit.resolve(arc_config_path)
  207. with open(abs_config_path, 'r') as fd:
  208. return json.load(fd)
  209. def _reference_group_var(varname: str, extensions: list[str] | None = None) -> str:
  210. if extensions is None:
  211. return f'"${{join=\\;:{varname}}}"'
  212. return serialize_list(f'${{ext={ext};join=\\;:{varname}}}' for ext in extensions)
  213. def assert_file_exists(unit, path):
  214. path = unit.resolve(SOURCE_ROOT_SHORT + path)
  215. if not os.path.exists(path):
  216. message = 'File {} is not found'.format(path)
  217. ymake.report_configure_error(message)
  218. raise DartValueError()
  219. class AndroidApkTestActivity:
  220. KEY = 'ANDROID_APK_TEST_ACTIVITY'
  221. @classmethod
  222. def value(cls, unit, flat_args, spec_args):
  223. return {cls.KEY: unit.get('ANDROID_APK_TEST_ACTIVITY_VALUE')}
  224. class BenchmarkOpts:
  225. KEY = 'BENCHMARK-OPTS'
  226. @classmethod
  227. def value(cls, unit, flat_args, spec_args):
  228. return {cls.KEY: serialize_list(get_unit_list_variable(unit, 'BENCHMARK_OPTS_VALUE'))}
  229. class BinaryPath:
  230. KEY = 'BINARY-PATH'
  231. @classmethod
  232. def normalized(cls, unit, flat_args, spec_args):
  233. unit_path = _common.get_norm_unit_path(unit)
  234. return {cls.KEY: os.path.join(unit_path, unit.filename())}
  235. @classmethod
  236. def stripped(cls, unit, flat_args, spec_args):
  237. unit_path = unit.path()
  238. binary_path = os.path.join(unit_path, unit.filename())
  239. if binary_path:
  240. return {cls.KEY: _common.strip_roots(binary_path)}
  241. @classmethod
  242. def stripped_without_pkg_ext(cls, unit, flat_args, spec_args):
  243. value = _common.strip_roots(os.path.join(unit.path(), unit.filename()).replace(".pkg", ""))
  244. return {cls.KEY: value}
  245. class Blob:
  246. KEY = 'BLOB'
  247. @classmethod
  248. def value(cls, unit, flat_args, spec_args):
  249. return {cls.KEY: unit.get('TEST_BLOB_DATA')}
  250. class BuildFolderPath:
  251. KEY = 'BUILD-FOLDER-PATH'
  252. @classmethod
  253. def normalized(cls, unit, flat_args, spec_args):
  254. return {cls.KEY: _common.get_norm_unit_path(unit)}
  255. @classmethod
  256. def stripped(cls, unit, flat_args, spec_args):
  257. return {cls.KEY: _common.strip_roots(unit.path())}
  258. class CanonizeSubPath:
  259. KEY = 'CANONIZE_SUB_PATH'
  260. @classmethod
  261. def value(cls, unit, flat_args, spec_args):
  262. return {cls.KEY: unit.get('CANONIZE_SUB_PATH')}
  263. class Classpath:
  264. KEY = 'CLASSPATH'
  265. @classmethod
  266. def value(cls, unit, flat_args, spec_args):
  267. ymake_java_test = unit.get('YMAKE_JAVA_TEST') == 'yes'
  268. if ymake_java_test:
  269. value = '$B/{}/{}.jar ${{DART_CLASSPATH}}'.format(unit.get('MODDIR'), unit.get('REALPRJNAME'))
  270. return {cls.KEY: value}
  271. class ConfigPath:
  272. KEY = 'CONFIG-PATH'
  273. @classmethod
  274. def value(cls, unit, flat_args, spec_args):
  275. test_runner, rel_to = flat_args
  276. return {cls.KEY: _resolve_config_path(unit, test_runner, rel_to=rel_to)}
  277. class CustomDependencies:
  278. KEY = 'CUSTOM-DEPENDENCIES'
  279. @classmethod
  280. def all_standard(cls, unit, flat_args, spec_args):
  281. custom_deps = ' '.join(spec_args.get('DEPENDS', []) + get_values_list(unit, 'TEST_DEPENDS_VALUE'))
  282. return {cls.KEY: custom_deps}
  283. @classmethod
  284. def depends_only(cls, unit, flat_args, spec_args):
  285. return {cls.KEY: " ".join(spec_args.get('DEPENDS', []))}
  286. @classmethod
  287. def test_depends_only(cls, unit, flat_args, spec_args):
  288. custom_deps = get_values_list(unit, 'TEST_DEPENDS_VALUE')
  289. return {cls.KEY: " ".join(custom_deps)}
  290. @classmethod
  291. def depends_with_linter(cls, unit, flat_args, spec_args):
  292. linter = Linter.value(unit, flat_args, spec_args)[Linter.KEY]
  293. deps = spec_args.get('DEPENDS', []) + [os.path.dirname(linter)]
  294. for dep in deps:
  295. unit.ondepends(dep)
  296. return {cls.KEY: " ".join(deps)}
  297. @classmethod
  298. def nots_with_recipies(cls, unit, flat_args, spec_args):
  299. deps = flat_args[0]
  300. recipes_lines = format_recipes(unit.get("TEST_RECIPES_VALUE")).strip().splitlines()
  301. if recipes_lines:
  302. deps = deps or []
  303. deps.extend([os.path.dirname(r.strip().split(" ")[0]) for r in recipes_lines])
  304. return {cls.KEY: " ".join(deps)}
  305. class EslintConfigPath:
  306. KEY = 'ESLINT_CONFIG_PATH'
  307. @classmethod
  308. def value(cls, unit, flat_args, spec_args):
  309. test_runner, rel_to = flat_args
  310. return {cls.KEY: _resolve_config_path(unit, test_runner, rel_to=rel_to)}
  311. class ForkMode:
  312. KEY = 'FORK-MODE'
  313. @classmethod
  314. def from_macro_and_unit(cls, unit, flat_args, spec_args):
  315. fork_mode = []
  316. if 'FORK_SUBTESTS' in spec_args:
  317. fork_mode.append('subtests')
  318. if 'FORK_TESTS' in spec_args:
  319. fork_mode.append('tests')
  320. fork_mode = fork_mode or spec_args.get('FORK_MODE', []) or unit.get('TEST_FORK_MODE').split()
  321. fork_mode = ' '.join(fork_mode) if fork_mode else ''
  322. return {cls.KEY: fork_mode}
  323. @classmethod
  324. def test_fork_mode(cls, unit, flat_args, spec_args):
  325. return {cls.KEY: unit.get('TEST_FORK_MODE')}
  326. class ForkTestFiles:
  327. KEY = 'FORK-TEST-FILES'
  328. @classmethod
  329. def value(cls, unit, flat_args, spec_args):
  330. return {cls.KEY: unit.get('FORK_TEST_FILES_MODE')}
  331. class FuzzDicts:
  332. KEY = 'FUZZ-DICTS'
  333. @classmethod
  334. def value(cls, unit, flat_args, spec_args):
  335. value = serialize_list(spec_args.get('FUZZ_DICTS', []) + get_unit_list_variable(unit, 'FUZZ_DICTS_VALUE'))
  336. return {cls.KEY: value}
  337. class FuzzOpts:
  338. KEY = 'FUZZ-OPTS'
  339. @classmethod
  340. def value(cls, unit, flat_args, spec_args):
  341. value = serialize_list(spec_args.get('FUZZ_OPTS', []) + get_unit_list_variable(unit, 'FUZZ_OPTS_VALUE'))
  342. return {cls.KEY: value}
  343. class Fuzzing:
  344. KEY = 'FUZZING'
  345. @classmethod
  346. def value(cls, unit, flat_args, spec_args):
  347. if unit.get('FUZZING') == 'yes':
  348. return {cls.KEY: '1'}
  349. class GlobalLibraryPath:
  350. KEY = 'GLOBAL-LIBRARY-PATH'
  351. @classmethod
  352. def value(cls, unit, flat_args, spec_args):
  353. return {cls.KEY: unit.global_filename()}
  354. class GoBenchTimeout:
  355. KEY = 'GO_BENCH_TIMEOUT'
  356. @classmethod
  357. def value(cls, unit, flat_args, spec_args):
  358. return {cls.KEY: unit.get('GO_BENCH_TIMEOUT')}
  359. class IgnoreClasspathClash:
  360. KEY = 'IGNORE_CLASSPATH_CLASH'
  361. @classmethod
  362. def value(cls, unit, flat_args, spec_args):
  363. value = ' '.join(get_values_list(unit, 'JAVA_IGNORE_CLASSPATH_CLASH_VALUE'))
  364. return {cls.KEY: value}
  365. class JavaClasspathCmdType:
  366. KEY = 'JAVA_CLASSPATH_CMD_TYPE'
  367. @classmethod
  368. def value(cls, unit, flat_args, spec_args):
  369. java_cp_arg_type = unit.get('JAVA_CLASSPATH_CMD_TYPE_VALUE') or 'MANIFEST'
  370. if java_cp_arg_type not in ('MANIFEST', 'COMMAND_FILE', 'LIST'):
  371. # TODO move error reporting out of field classes
  372. ymake.report_configure_error(
  373. '{}: TEST_JAVA_CLASSPATH_CMD_TYPE({}) are invalid. Choose argument from MANIFEST, COMMAND_FILE or LIST)'.format(
  374. unit.path(), java_cp_arg_type
  375. )
  376. )
  377. raise DartValueError()
  378. return {cls.KEY: java_cp_arg_type}
  379. class JdkForTests:
  380. KEY = 'JDK_FOR_TESTS'
  381. @classmethod
  382. def value(cls, unit, flat_args, spec_args):
  383. value = 'JDK' + (unit.get('JDK_VERSION') or unit.get('JDK_REAL_VERSION') or '_DEFAULT') + '_FOR_TESTS'
  384. return {cls.KEY: value}
  385. class JdkLatestVersion:
  386. KEY = 'JDK_LATEST_VERSION'
  387. @classmethod
  388. def value(cls, unit, flat_args, spec_args):
  389. return {cls.KEY: unit.get('JDK_LATEST_VERSION')}
  390. class JdkResource:
  391. KEY = 'JDK_RESOURCE'
  392. @classmethod
  393. def value(cls, unit, flat_args, spec_args):
  394. value = 'JDK' + (unit.get('JDK_VERSION') or unit.get('JDK_REAL_VERSION') or '_DEFAULT')
  395. return {cls.KEY: value}
  396. class KtlintBaselineFile:
  397. KEY = 'KTLINT_BASELINE_FILE'
  398. @classmethod
  399. def value(cls, unit, flat_args, spec_args):
  400. if unit.get('_USE_KTLINT_OLD') != 'yes':
  401. baseline_path_relative = unit.get('_KTLINT_BASELINE_FILE')
  402. if baseline_path_relative:
  403. return {cls.KEY: baseline_path_relative}
  404. class KtlintBinary:
  405. KEY = 'KTLINT_BINARY'
  406. @classmethod
  407. def value(cls, unit, flat_args, spec_args):
  408. value = '$(KTLINT_OLD)/run.bat' if unit.get('_USE_KTLINT_OLD') == 'yes' else '$(KTLINT)/run.bat'
  409. return {cls.KEY: value}
  410. class Linter:
  411. KEY = 'LINTER'
  412. @classmethod
  413. def value(cls, unit, flat_args, spec_args):
  414. return {cls.KEY: spec_args['LINTER'][0]}
  415. class LintConfigs:
  416. KEY = 'LINT-CONFIGS'
  417. @classmethod
  418. def python_configs(cls, unit, flat_args, spec_args):
  419. resolved_configs = []
  420. project_to_config_map = spec_args.get('PROJECT_TO_CONFIG_MAP', [])
  421. if project_to_config_map:
  422. # ruff, TODO rewrite once custom configs migrated to autoincludes scheme
  423. project_to_config_map = project_to_config_map[0]
  424. assert_file_exists(unit, project_to_config_map)
  425. resolved_configs.append(project_to_config_map)
  426. cfgs = get_linter_configs(unit, project_to_config_map).values()
  427. for c in cfgs:
  428. assert_file_exists(unit, c)
  429. resolved_configs.append(c)
  430. return {cls.KEY: serialize_list(resolved_configs)}
  431. custom_config = spec_args.get('CUSTOM_CONFIG', [])
  432. if custom_config:
  433. # black if custom config is passed
  434. # TODO rewrite once custom configs migrated to autoincludes scheme
  435. custom_config = custom_config[0]
  436. assert_file_exists(unit, custom_config)
  437. resolved_configs.append(custom_config)
  438. return {cls.KEY: serialize_list(resolved_configs)}
  439. config = spec_args['CONFIGS'][0]
  440. # black without custom config or flake8, using default configs file
  441. assert_file_exists(unit, config)
  442. name = spec_args['NAME'][0]
  443. cfg = get_linter_configs(unit, config)[name]
  444. assert_file_exists(unit, cfg)
  445. resolved_configs.append(cfg)
  446. if name in ('flake8', 'py2_flake8'):
  447. resolved_configs.extend(spec_args.get('FLAKE_MIGRATIONS_CONFIG', []))
  448. return {cls.KEY: serialize_list(resolved_configs)}
  449. @classmethod
  450. def cpp_configs(cls, unit, flat_args, spec_args):
  451. custom_config = spec_args.get('CUSTOM_CONFIG')
  452. if custom_config:
  453. config = custom_config[0]
  454. assert_file_exists(unit, config)
  455. else:
  456. # file with default configs
  457. config = spec_args.get('CONFIGS')[0]
  458. assert_file_exists(unit, config)
  459. name = spec_args['NAME'][0]
  460. config = get_linter_configs(unit, config)[name]
  461. assert_file_exists(unit, config)
  462. return {cls.KEY: serialize_list([config])}
  463. class LintExtraParams:
  464. KEY = 'LINT-EXTRA-PARAMS'
  465. @classmethod
  466. def from_macro_args(cls, unit, flat_args, spec_args):
  467. extra_params = spec_args.get('EXTRA_PARAMS', [])
  468. for arg in extra_params:
  469. if '=' not in arg:
  470. message = 'Wrong EXTRA_PARAMS value: "{}". Values must have format "name=value".'.format(arg)
  471. ymake.report_configure_error(message)
  472. raise DartValueError()
  473. return {cls.KEY: serialize_list(extra_params)}
  474. class LintFileProcessingTime:
  475. KEY = 'LINT-FILE-PROCESSING-TIME'
  476. @classmethod
  477. def from_macro_args(cls, unit, flat_args, spec_args):
  478. return {cls.KEY: spec_args.get('FILE_PROCESSING_TIME', [''])[0]}
  479. class LintName:
  480. KEY = 'LINT-NAME'
  481. @classmethod
  482. def value(cls, unit, flat_args, spec_args):
  483. lint_name = spec_args['NAME'][0]
  484. if lint_name in ('flake8', 'py2_flake8') and (unit.get('DISABLE_FLAKE8') or 'no') == 'yes':
  485. unit.message(['INFO', 'Flake8 linting is disabled by `DISABLE_FLAKE8`'])
  486. raise DartValueError()
  487. return {cls.KEY: lint_name}
  488. class ModuleLang:
  489. KEY = 'MODULE_LANG'
  490. @classmethod
  491. def value(cls, unit, flat_args, spec_args):
  492. return {cls.KEY: unit.get("MODULE_LANG").lower() or consts.ModuleLang.UNKNOWN}
  493. class ModuleType:
  494. KEY = 'MODULE_TYPE'
  495. @classmethod
  496. def value(cls, unit, flat_args, spec_args):
  497. return {cls.KEY: unit.get('MODULE_TYPE')}
  498. class NoCheck:
  499. KEY = 'NO-CHECK'
  500. @classmethod
  501. def value(cls, unit, flat_args, spec_args):
  502. if unit.get('NO_CHECK_IMPORTS_FOR_VALUE') != "None":
  503. value = serialize_list(get_values_list(unit, 'NO_CHECK_IMPORTS_FOR_VALUE') or ["*"])
  504. return {cls.KEY: value}
  505. class NodejsRootVarName:
  506. KEY = 'NODEJS-ROOT-VAR-NAME'
  507. @classmethod
  508. def value(cls, unit, flat_args, spec_args):
  509. return {cls.KEY: unit.get("NODEJS-ROOT-VAR-NAME")}
  510. class NodeModulesBundleFilename:
  511. KEY = 'NODE-MODULES-BUNDLE-FILENAME'
  512. @classmethod
  513. def value(cls, unit, flat_args, spec_args):
  514. return {cls.KEY: spec_args.get('nm_bundle')}
  515. class PythonPaths:
  516. KEY = 'PYTHON-PATHS'
  517. @classmethod
  518. def value(cls, unit, flat_args, spec_args):
  519. python_paths = get_values_list(unit, 'TEST_PYTHON_PATH_VALUE')
  520. return {cls.KEY: serialize_list(python_paths)}
  521. class Requirements:
  522. KEY = 'REQUIREMENTS'
  523. @classmethod
  524. def from_macro_args_and_unit(cls, unit, flat_args, spec_args):
  525. test_requirements = spec_args.get('REQUIREMENTS', []) + get_values_list(unit, 'TEST_REQUIREMENTS_VALUE')
  526. return {cls.KEY: serialize_list(test_requirements)}
  527. @classmethod
  528. def with_maybe_fuzzing(cls, unit, flat_args, spec_args):
  529. test_requirements = serialize_list(
  530. spec_args.get('REQUIREMENTS', []) + get_values_list(unit, 'TEST_REQUIREMENTS_VALUE')
  531. )
  532. if unit.get('FUZZING') == 'yes':
  533. value = serialize_list(filter(None, deserialize_list(test_requirements) + ["cpu:all", "ram:all"]))
  534. return {cls.KEY: value}
  535. else:
  536. return {cls.KEY: test_requirements}
  537. @classmethod
  538. def from_macro_args(cls, unit, flat_args, spec_args):
  539. value = " ".join(spec_args.get('REQUIREMENTS', []))
  540. return {cls.KEY: value}
  541. @classmethod
  542. def from_unit(cls, unit, flat_args, spec_args):
  543. requirements = get_values_list(unit, 'TEST_REQUIREMENTS_VALUE')
  544. return {cls.KEY: serialize_list(requirements)}
  545. @classmethod
  546. def from_unit_with_full_network(cls, unit, flat_args, spec_args):
  547. requirements = sorted(set(["network:full"] + get_values_list(unit, "TEST_REQUIREMENTS_VALUE")))
  548. return {cls.KEY: serialize_list(requirements)}
  549. class SbrUidExt:
  550. KEY = 'SBR-UID-EXT'
  551. @classmethod
  552. def value(cls, unit, flat_args, spec_args):
  553. uid_ext = unit.get("SBR_UID_EXT").split(" ", 1)[-1] # strip variable name
  554. return {cls.KEY: uid_ext}
  555. class ScriptRelPath:
  556. KEY = 'SCRIPT-REL-PATH'
  557. @classmethod
  558. def second_flat(cls, unit, flat_args, spec_args):
  559. return {cls.KEY: flat_args[1]}
  560. @classmethod
  561. def first_flat(cls, unit, flat_args, spec_args):
  562. return {cls.KEY: flat_args[0]}
  563. @classmethod
  564. def pytest(cls, unit, flat_args, spec_args):
  565. return {cls.KEY: 'py3test.bin' if (unit.get("PYTHON3") == 'yes') else "pytest.bin"}
  566. @classmethod
  567. def junit(cls, unit, flat_args, spec_args):
  568. return {cls.KEY: 'junit5.test' if unit.get('MODULE_TYPE') == 'JUNIT5' else 'junit.test'}
  569. class Size:
  570. KEY = 'SIZE'
  571. @classmethod
  572. def from_macro_args_and_unit(cls, unit, flat_args, spec_args):
  573. return {cls.KEY: ''.join(spec_args.get('SIZE', [])) or unit.get('TEST_SIZE_NAME')}
  574. @classmethod
  575. def from_unit(cls, unit, flat_args, spec_args):
  576. return {cls.KEY: unit.get('TEST_SIZE_NAME')}
  577. class SkipTest:
  578. KEY = 'SKIP_TEST'
  579. @classmethod
  580. def value(cls, unit, flat_args, spec_args):
  581. return {cls.KEY: unit.get('SKIP_TEST_VALUE')}
  582. class SourceFolderPath:
  583. KEY = 'SOURCE-FOLDER-PATH'
  584. @classmethod
  585. def normalized(cls, unit, flat_args, spec_args):
  586. return {cls.KEY: _common.get_norm_unit_path(unit)}
  587. @classmethod
  588. def test_dir(cls, unit, flat_args, spec_args):
  589. test_dir = _common.get_norm_unit_path(unit)
  590. test_files = flat_args[1:]
  591. if test_files:
  592. test_dir = os.path.dirname(test_files[0]).lstrip("$S/")
  593. return {cls.KEY: test_dir}
  594. class SplitFactor:
  595. KEY = 'SPLIT-FACTOR'
  596. @classmethod
  597. def from_macro_args_and_unit(cls, unit, flat_args, spec_args):
  598. value = ''.join(spec_args.get('SPLIT_FACTOR', [])) or unit.get('TEST_SPLIT_FACTOR')
  599. return {cls.KEY: value}
  600. @classmethod
  601. def from_unit(cls, unit, flat_args, spec_args):
  602. return {cls.KEY: unit.get('TEST_SPLIT_FACTOR')}
  603. class Tag:
  604. KEY = 'TAG'
  605. @classmethod
  606. def from_macro_args_and_unit(cls, unit, flat_args, spec_args):
  607. tags = serialize_list(sorted(_get_test_tags(unit, spec_args)))
  608. return {cls.KEY: tags}
  609. @classmethod
  610. def from_unit(cls, unit, flat_args, spec_args):
  611. tags = serialize_list(get_values_list(unit, "TEST_TAGS_VALUE"))
  612. return {cls.KEY: tags}
  613. @classmethod
  614. def from_unit_fat_external_no_retries(cls, unit, flat_args, spec_args):
  615. tags = sorted(set(["ya:fat", "ya:external", "ya:noretries"] + get_values_list(unit, "TEST_TAGS_VALUE")))
  616. return {cls.KEY: serialize_list(tags)}
  617. class TestClasspath:
  618. KEY = 'TEST_CLASSPATH'
  619. @classmethod
  620. def value(cls, unit, flat_args, spec_args):
  621. ymake_java_test = unit.get('YMAKE_JAVA_TEST') == 'yes'
  622. if ymake_java_test:
  623. value = '${DART_CLASSPATH}'
  624. return {cls.KEY: value}
  625. class TestClasspathDeps:
  626. KEY = 'TEST_CLASSPATH_DEPS'
  627. @classmethod
  628. def value(cls, unit, flat_args, spec_args):
  629. ymake_java_test = unit.get('YMAKE_JAVA_TEST') == 'yes'
  630. if ymake_java_test:
  631. return {cls.KEY: '${DART_CLASSPATH_DEPS}'}
  632. class TestCwd:
  633. KEY = 'TEST-CWD'
  634. @classmethod
  635. def from_unit(cls, unit, flat_args, spec_args):
  636. test_cwd = unit.get('TEST_CWD_VALUE') # TODO: validate test_cwd value
  637. return {cls.KEY: test_cwd}
  638. @classmethod
  639. def keywords_replaced(cls, unit, flat_args, spec_args):
  640. test_cwd = unit.get('TEST_CWD_VALUE') or ''
  641. if test_cwd:
  642. test_cwd = test_cwd.replace("$TEST_CWD_VALUE", "").replace('"MACRO_CALLS_DELIM"', "").strip()
  643. return {cls.KEY: test_cwd}
  644. @classmethod
  645. def moddir(cls, unit, flat_args, spec_args):
  646. return {cls.KEY: unit.get("MODDIR")}
  647. class TestData:
  648. KEY = 'TEST-DATA'
  649. @classmethod
  650. def from_macro_args_and_unit(cls, unit, flat_args, spec_args):
  651. test_data = sorted(
  652. _common.filter_out_by_keyword(
  653. spec_args.get('DATA', []) + get_norm_paths(unit, 'TEST_DATA_VALUE'), 'AUTOUPDATED'
  654. )
  655. )
  656. return {cls.KEY: serialize_list(test_data)}
  657. @classmethod
  658. def from_macro_args_and_unit_with_canonical(cls, unit, flat_args, spec_args):
  659. test_data = sorted(
  660. _common.filter_out_by_keyword(
  661. spec_args.get('DATA', []) + get_norm_paths(unit, 'TEST_DATA_VALUE'), 'AUTOUPDATED'
  662. )
  663. )
  664. data, _ = get_canonical_test_resources(unit)
  665. test_data += data
  666. value = serialize_list(sorted(test_data))
  667. return {cls.KEY: value}
  668. @classmethod
  669. def ktlint(cls, unit, flat_args, spec_args):
  670. if unit.get('_USE_KTLINT_OLD') == 'yes':
  671. extra_test_data = [KTLINT_OLD_EDITOR_CONFIG]
  672. else:
  673. data_list = [KTLINT_CURRENT_EDITOR_CONFIG]
  674. baseline_path_relative = unit.get('_KTLINT_BASELINE_FILE')
  675. if baseline_path_relative:
  676. baseline_path = unit.resolve_arc_path(baseline_path_relative).replace('$S', 'arcadia')
  677. data_list += [baseline_path]
  678. extra_test_data = data_list
  679. # XXX
  680. if unit.get('_WITH_YA_1931') != 'yes':
  681. extra_test_data += java_srcdirs_to_data(unit, 'ALL_SRCDIRS', serialize_result=False)
  682. extra_test_data = serialize_list(extra_test_data)
  683. return {cls.KEY: extra_test_data}
  684. @classmethod
  685. def java_style(cls, unit, flat_args, spec_args):
  686. ymake_java_test = unit.get('YMAKE_JAVA_TEST') == 'yes'
  687. if ymake_java_test:
  688. return {cls.KEY: java_srcdirs_to_data(unit, 'ALL_SRCDIRS')}
  689. @classmethod
  690. def from_unit_with_canonical(cls, unit, flat_args, spec_args):
  691. test_data = get_norm_paths(unit, 'TEST_DATA_VALUE')
  692. data, _ = get_canonical_test_resources(unit)
  693. test_data += data
  694. value = serialize_list(sorted(_common.filter_out_by_keyword(test_data, 'AUTOUPDATED')))
  695. return {cls.KEY: value}
  696. @classmethod
  697. def java_test(cls, unit, flat_args, spec_args):
  698. test_data = get_norm_paths(unit, 'TEST_DATA_VALUE')
  699. test_data.append('arcadia/build/scripts/run_junit.py')
  700. test_data.append('arcadia/build/scripts/unpacking_jtest_runner.py')
  701. data, _ = get_canonical_test_resources(unit)
  702. test_data += data
  703. props, error_mgs = extract_java_system_properties(unit, get_values_list(unit, 'SYSTEM_PROPERTIES_VALUE'))
  704. if error_mgs:
  705. ymake.report_configure_error(error_mgs)
  706. raise DartValueError()
  707. for prop in props:
  708. if prop['type'] == 'file':
  709. test_data.append(prop['path'].replace('${ARCADIA_ROOT}', 'arcadia'))
  710. value = serialize_list(sorted(_common.filter_out_by_keyword(test_data, 'AUTOUPDATED')))
  711. return {cls.KEY: value}
  712. @classmethod
  713. def from_unit(cls, unit, flat_args, spec_args):
  714. return {cls.KEY: serialize_list(get_values_list(unit, "TEST_DATA_VALUE"))}
  715. class DockerImage:
  716. KEY = 'DOCKER-IMAGES'
  717. @staticmethod
  718. def _validate(images):
  719. docker_image_re = consts.DOCKER_LINK_RE
  720. for img in images:
  721. msg = None
  722. if "=" in img:
  723. link, _ = img.rsplit('=', 1)
  724. if docker_image_re.match(link) is None:
  725. msg = 'Invalid docker url format: {}. Link should be provided in format docker://<repo>@sha256:<digest>'.format(
  726. link
  727. )
  728. else:
  729. msg = 'Invalid docker image: {}. Image should be provided in format <link>=<tag>'.format(img)
  730. if msg:
  731. ymake.report_configure_error(msg)
  732. raise DartValueError(msg)
  733. @classmethod
  734. def value(cls, unit, flat_args, spec_args):
  735. raw_value = get_values_list(unit, 'DOCKER_IMAGES_VALUE')
  736. images = sorted(raw_value)
  737. if images:
  738. cls._validate(images)
  739. return {cls.KEY: serialize_list(images)}
  740. class TsConfigPath:
  741. KEY = 'TS_CONFIG_PATH'
  742. class TsStylelintConfig:
  743. KEY = 'TS_STYLELINT_CONFIG'
  744. @classmethod
  745. def value(cls, unit, flat_args, spec_args):
  746. test_config = unit.get('_TS_STYLELINT_CONFIG')
  747. abs_test_config = unit.resolve(unit.resolve_arc_path(test_config))
  748. if not abs_test_config:
  749. ymake.report_configure_error(
  750. f"Config for stylelint not found: {test_config}.\n"
  751. "Set the correct value in `TS_STYLELINT(<config_filename>)` macro in the `ya.make` file."
  752. )
  753. return {cls.KEY: test_config}
  754. class TsTestDataDirs:
  755. KEY = 'TS-TEST-DATA-DIRS'
  756. @classmethod
  757. def value(cls, unit, flat_args, spec_args):
  758. value = serialize_list(_get_ts_test_data_dirs(unit))
  759. return {cls.KEY: value}
  760. class TsTestDataDirsRename:
  761. KEY = 'TS-TEST-DATA-DIRS-RENAME'
  762. @classmethod
  763. def value(cls, unit, flat_args, spec_args):
  764. return {cls.KEY: unit.get("_TS_TEST_DATA_DIRS_RENAME_VALUE")}
  765. class TsTestForPath:
  766. KEY = 'TS-TEST-FOR-PATH'
  767. @classmethod
  768. def value(cls, unit, flat_args, spec_args):
  769. return {cls.KEY: unit.get("TS_TEST_FOR_PATH")}
  770. class TestedProjectFilename:
  771. KEY = 'TESTED-PROJECT-FILENAME'
  772. @classmethod
  773. def value(cls, unit, flat_args, spec_args):
  774. return {cls.KEY: unit.filename()}
  775. class TestedProjectName:
  776. KEY = 'TESTED-PROJECT-NAME'
  777. @classmethod
  778. def unit_name(cls, unit, flat_args, spec_args):
  779. return {cls.KEY: unit.name()}
  780. @classmethod
  781. def normalized_basename(cls, unit, flat_args, spec_args):
  782. test_dir = _common.get_norm_unit_path(unit)
  783. return {cls.KEY: os.path.basename(test_dir)}
  784. @classmethod
  785. def test_dir(cls, unit, flat_args, spec_args):
  786. test_dir = _common.get_norm_unit_path(unit)
  787. test_files = flat_args[1:]
  788. if test_files:
  789. test_dir = os.path.dirname(test_files[0]).lstrip("$S/")
  790. return {cls.KEY: os.path.basename(test_dir)}
  791. @classmethod
  792. def path_filename_basename(cls, unit, flat_args, spec_args):
  793. binary_path = os.path.join(unit.path(), unit.filename())
  794. return {cls.KEY: os.path.basename(binary_path)}
  795. @classmethod
  796. def normalized(cls, unit, flat_args, spec_args):
  797. return {cls.KEY: _common.get_norm_unit_path(unit)}
  798. @classmethod
  799. def path_filename_basename_without_pkg_ext(cls, unit, flat_args, spec_args):
  800. value = os.path.basename(os.path.join(unit.path(), unit.filename()).replace(".pkg", ""))
  801. return {cls.KEY: value}
  802. @classmethod
  803. def filename_without_ext(cls, unit, flat_args, spec_args):
  804. return {cls.KEY: os.path.splitext(unit.filename())[0]}
  805. class TestFiles:
  806. KEY = 'TEST-FILES'
  807. # TODO remove FILES, see DEVTOOLS-7052, currently it's required
  808. # https://a.yandex-team.ru/arcadia/devtools/ya/test/dartfile/__init__.py?rev=r14292146#L10
  809. KEY2 = 'FILES'
  810. @classmethod
  811. def value(cls, unit, flat_args, spec_args):
  812. data_re = re.compile(r"sbr:/?/?(\d+)=?.*")
  813. data = flat_args[1:]
  814. resources = []
  815. for f in data:
  816. matched = re.match(data_re, f)
  817. if matched:
  818. resources.append(matched.group(1))
  819. value = serialize_list(resources)
  820. return {cls.KEY: value, cls.KEY2: value}
  821. @classmethod
  822. def flat_args_wo_first(cls, unit, flat_args, spec_args):
  823. value = serialize_list(flat_args[1:])
  824. return {cls.KEY: value, cls.KEY2: value}
  825. @classmethod
  826. def java_style(cls, unit, flat_args, spec_args):
  827. test_files = flat_args[1:]
  828. check_level = flat_args[1]
  829. allowed_levels = {
  830. 'base': '/yandex_checks.xml',
  831. 'strict': '/yandex_checks_strict.xml',
  832. 'extended': '/yandex_checks_extended.xml',
  833. 'library': '/yandex_checks_library.xml',
  834. }
  835. if check_level not in allowed_levels:
  836. raise Exception("'{}' is not allowed in LINT(), use one of {}".format(check_level, allowed_levels.keys()))
  837. test_files[0] = allowed_levels[check_level]
  838. value = serialize_list(test_files)
  839. return {cls.KEY: value, cls.KEY2: value}
  840. @classmethod
  841. def normalized(cls, unit, flat_args, spec_args):
  842. value = serialize_list([_common.get_norm_unit_path(unit, unit.filename())])
  843. return {cls.KEY: value, cls.KEY2: value}
  844. @classmethod
  845. def test_srcs(cls, unit, flat_args, spec_args):
  846. test_files = get_values_list(unit, 'TEST_SRCS_VALUE')
  847. value = serialize_list(test_files)
  848. return {cls.KEY: value, cls.KEY2: value}
  849. @classmethod
  850. def ts_test_srcs(cls, unit, flat_args, spec_args):
  851. test_files = get_values_list(unit, "_TS_TEST_SRCS_VALUE")
  852. test_files = _resolve_module_files(unit, unit.get("MODDIR"), test_files)
  853. value = serialize_list(test_files)
  854. return {cls.KEY: value, cls.KEY2: value}
  855. @classmethod
  856. def ts_input_files(cls, unit, flat_args, spec_args):
  857. typecheck_files = get_values_list(unit, "TS_INPUT_FILES")
  858. test_files = [_common.resolve_common_const(f) for f in typecheck_files]
  859. value = serialize_list(test_files)
  860. return {cls.KEY: value, cls.KEY2: value}
  861. @classmethod
  862. def ts_lint_srcs(cls, unit, flat_args, spec_args):
  863. test_files = get_values_list(unit, "_TS_LINT_SRCS_VALUE")
  864. test_files = _resolve_module_files(unit, unit.get("MODDIR"), test_files)
  865. value = serialize_list(test_files)
  866. return {cls.KEY: value, cls.KEY2: value}
  867. @classmethod
  868. def stylesheets(cls, unit, flat_args, spec_args):
  869. test_files = get_values_list(unit, "_TS_STYLELINT_FILES")
  870. test_files = _resolve_module_files(unit, unit.get("MODDIR"), test_files)
  871. value = serialize_list(test_files)
  872. return {cls.KEY: value, cls.KEY2: value}
  873. @classmethod
  874. def py_linter_files(cls, unit, flat_args, spec_args):
  875. files = unit.get('PY_LINTER_FILES')
  876. if not files:
  877. raise DartValueError()
  878. files = json.loads(files)
  879. test_files = []
  880. for path in files:
  881. if path.startswith(ARCADIA_ROOT):
  882. test_files.append(path.replace(ARCADIA_ROOT, SOURCE_ROOT_SHORT, 1))
  883. elif path.startswith(SOURCE_ROOT_SHORT):
  884. test_files.append(path)
  885. if not test_files:
  886. lint_name = LintName.value(unit, flat_args, spec_args)[LintName.KEY]
  887. message = 'No files to lint for {}'.format(lint_name)
  888. raise DartValueError(message)
  889. test_files = serialize_list(test_files)
  890. return {cls.KEY: test_files, cls.KEY2: test_files}
  891. @classmethod
  892. def cpp_linter_files(cls, unit, flat_args, spec_args):
  893. files_dart = _reference_group_var("ALL_SRCS", consts.STYLE_CPP_ALL_EXTS)
  894. return {cls.KEY: files_dart, cls.KEY2: files_dart}
  895. class TestEnv:
  896. KEY = 'TEST-ENV'
  897. @classmethod
  898. def value(cls, unit, flat_args, spec_args):
  899. return {cls.KEY: prepare_env(unit.get("TEST_ENV_VALUE"))}
  900. class TestIosDeviceType:
  901. KEY = 'TEST_IOS_DEVICE_TYPE'
  902. @classmethod
  903. def value(cls, unit, flat_args, spec_args):
  904. return {cls.KEY: unit.get('TEST_IOS_DEVICE_TYPE_VALUE')}
  905. class TestIosRuntimeType:
  906. KEY = 'TEST_IOS_RUNTIME_TYPE'
  907. @classmethod
  908. def value(cls, unit, flat_args, spec_args):
  909. return {cls.KEY: unit.get('TEST_IOS_RUNTIME_TYPE_VALUE')}
  910. class TestJar:
  911. KEY = 'TEST_JAR'
  912. @classmethod
  913. def value(cls, unit, flat_args, spec_args):
  914. ymake_java_test = unit.get('YMAKE_JAVA_TEST') == 'yes'
  915. if ymake_java_test:
  916. if unit.get('UNITTEST_DIR'):
  917. value = '${UNITTEST_MOD}'
  918. else:
  919. value = '{}/{}.jar'.format(unit.get('MODDIR'), unit.get('REALPRJNAME'))
  920. return {cls.KEY: value}
  921. class TestName:
  922. KEY = 'TEST-NAME'
  923. @classmethod
  924. def value(cls, unit, flat_args, spec_args):
  925. return {cls.KEY: flat_args[0]}
  926. @classmethod
  927. def first_flat_with_bench(cls, unit, flat_args, spec_args):
  928. return {cls.KEY: flat_args[0] + '_bench'}
  929. @classmethod
  930. def first_flat(cls, unit, flat_args, spec_args):
  931. return {cls.KEY: flat_args[0].lower()}
  932. @classmethod
  933. def filename_without_ext(cls, unit, flat_args, spec_args):
  934. test_name = os.path.basename(os.path.join(unit.path(), unit.filename()))
  935. return {cls.KEY: os.path.splitext(test_name)[0]}
  936. @classmethod
  937. def normalized_joined_dir_basename(cls, unit, flat_args, spec_args):
  938. path = _common.get_norm_unit_path(unit)
  939. value = '-'.join([os.path.basename(os.path.dirname(path)), os.path.basename(path)])
  940. return {cls.KEY: value}
  941. @classmethod
  942. def normalized_joined_dir_basename_deps(cls, unit, flat_args, spec_args):
  943. path = _common.get_norm_unit_path(unit)
  944. value = '-'.join([os.path.basename(os.path.dirname(path)), os.path.basename(path), 'dependencies']).strip('-')
  945. return {cls.KEY: value}
  946. @classmethod
  947. def filename_without_pkg_ext(cls, unit, flat_args, spec_args):
  948. test_name = os.path.basename(os.path.join(unit.path(), unit.filename()).replace(".pkg", ""))
  949. return {cls.KEY: os.path.splitext(test_name)[0]}
  950. @classmethod
  951. def name_from_macro_args(cls, unit, flat_args, spec_args):
  952. return {cls.KEY: spec_args['NAME'][0]}
  953. class TestPartition:
  954. KEY = 'TEST_PARTITION'
  955. @classmethod
  956. def value(cls, unit, flat_args, spec_args):
  957. return {cls.KEY: unit.get("TEST_PARTITION")}
  958. class TestRecipes:
  959. KEY = 'TEST-RECIPES'
  960. @classmethod
  961. def value(cls, unit, flat_args, spec_args):
  962. return {cls.KEY: prepare_recipes(unit.get("TEST_RECIPES_VALUE"))}
  963. class TestRunnerBin:
  964. KEY = 'TEST-RUNNER-BIN'
  965. @classmethod
  966. def value(cls, unit, flat_args, spec_args):
  967. runner_bin = spec_args.get('RUNNER_BIN', [None])[0]
  968. if runner_bin:
  969. return {cls.KEY: runner_bin}
  970. class TestTimeout:
  971. KEY = 'TEST-TIMEOUT'
  972. @classmethod
  973. def from_macro_args_and_unit(cls, unit, flat_args, spec_args):
  974. test_timeout = ''.join(spec_args.get('TIMEOUT', [])) or unit.get('TEST_TIMEOUT') or ''
  975. return {cls.KEY: test_timeout}
  976. @classmethod
  977. def from_unit_with_default(cls, unit, flat_args, spec_args):
  978. timeout = list(filter(None, [unit.get(["TEST_TIMEOUT"])]))
  979. if timeout:
  980. timeout = timeout[0]
  981. else:
  982. timeout = '0'
  983. return {cls.KEY: timeout}
  984. @classmethod
  985. def from_unit(cls, unit, flat_args, spec_args):
  986. return {cls.KEY: unit.get('TEST_TIMEOUT')}
  987. class TsResources:
  988. KEY = "{}-ROOT-VAR-NAME"
  989. @classmethod
  990. def value(cls, unit, flat_args, spec_args):
  991. erm_json = spec_args['erm_json']
  992. ret = {}
  993. for tool in erm_json.list_npm_packages():
  994. tool_resource_label = cls.KEY.format(tool.upper())
  995. tool_resource_value = unit.get(tool_resource_label)
  996. if tool_resource_value:
  997. ret[tool_resource_label] = tool_resource_value
  998. return ret
  999. class JvmArgs:
  1000. KEY = 'JVM_ARGS'
  1001. @classmethod
  1002. def value(cls, unit, flat_args, spec_args):
  1003. value = serialize_list(get_values_list(unit, 'JVM_ARGS_VALUE'))
  1004. return {cls.KEY: value}
  1005. class StrictClasspathClash:
  1006. KEY = 'STRICT_CLASSPATH_CLASH'
  1007. class SystemProperties:
  1008. KEY = 'SYSTEM_PROPERTIES'
  1009. @classmethod
  1010. def value(cls, unit, flat_args, spec_args):
  1011. props, error_mgs = extract_java_system_properties(unit, get_values_list(unit, 'SYSTEM_PROPERTIES_VALUE'))
  1012. if error_mgs:
  1013. ymake.report_configure_error(error_mgs)
  1014. raise DartValueError()
  1015. props = base64.b64encode(six.ensure_binary(json.dumps(props)))
  1016. return {cls.KEY: props}
  1017. class UnittestDir:
  1018. KEY = 'UNITTEST_DIR'
  1019. @classmethod
  1020. def value(cls, unit, flat_args, spec_args):
  1021. return {cls.KEY: unit.get('UNITTEST_DIR')}
  1022. class UseArcadiaPython:
  1023. KEY = 'USE_ARCADIA_PYTHON'
  1024. @classmethod
  1025. def value(cls, unit, flat_args, spec_args):
  1026. return {cls.KEY: unit.get('USE_ARCADIA_PYTHON')}
  1027. class UseKtlintOld:
  1028. KEY = 'USE_KTLINT_OLD'
  1029. @classmethod
  1030. def value(cls, unit, flat_args, spec_args):
  1031. if unit.get('_USE_KTLINT_OLD') == 'yes':
  1032. return {cls.KEY: 'yes'}
  1033. class YtSpec:
  1034. KEY = 'YT-SPEC'
  1035. @classmethod
  1036. def from_macro_args_and_unit(cls, unit, flat_args, spec_args):
  1037. value = serialize_list(spec_args.get('YT_SPEC', []) + get_unit_list_variable(unit, 'TEST_YT_SPEC_VALUE'))
  1038. return {cls.KEY: value}
  1039. @classmethod
  1040. def from_unit(cls, unit, flat_args, spec_args):
  1041. yt_spec = get_values_list(unit, 'TEST_YT_SPEC_VALUE')
  1042. if yt_spec:
  1043. return {cls.KEY: serialize_list(yt_spec)}
  1044. @classmethod
  1045. def from_unit_list_var(cls, unit, flat_args, spec_args):
  1046. yt_spec_values = get_unit_list_variable(unit, 'TEST_YT_SPEC_VALUE')
  1047. return {cls.KEY: serialize_list(yt_spec_values)}