_dart_fields.py 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395
  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. value = '$B/{}/{}.jar ${{DART_CLASSPATH}}'.format(unit.get('MODDIR'), unit.get('REALPRJNAME'))
  268. return {cls.KEY: value}
  269. class ConfigPath:
  270. KEY = 'CONFIG-PATH'
  271. @classmethod
  272. def value(cls, unit, flat_args, spec_args):
  273. test_runner, rel_to = flat_args
  274. return {cls.KEY: _resolve_config_path(unit, test_runner, rel_to=rel_to)}
  275. class CustomDependencies:
  276. KEY = 'CUSTOM-DEPENDENCIES'
  277. @classmethod
  278. def all_standard(cls, unit, flat_args, spec_args):
  279. custom_deps = ' '.join(spec_args.get('DEPENDS', []) + get_values_list(unit, 'TEST_DEPENDS_VALUE'))
  280. return {cls.KEY: custom_deps}
  281. @classmethod
  282. def depends_only(cls, unit, flat_args, spec_args):
  283. return {cls.KEY: " ".join(spec_args.get('DEPENDS', []))}
  284. @classmethod
  285. def test_depends_only(cls, unit, flat_args, spec_args):
  286. custom_deps = get_values_list(unit, 'TEST_DEPENDS_VALUE')
  287. return {cls.KEY: " ".join(custom_deps)}
  288. @classmethod
  289. def depends_with_linter(cls, unit, flat_args, spec_args):
  290. linter = Linter.value(unit, flat_args, spec_args)[Linter.KEY]
  291. deps = spec_args.get('DEPENDS', []) + [os.path.dirname(linter)]
  292. for dep in deps:
  293. unit.ondepends(dep)
  294. return {cls.KEY: " ".join(deps)}
  295. @classmethod
  296. def nots_with_recipies(cls, unit, flat_args, spec_args):
  297. deps = flat_args[0]
  298. recipes_lines = format_recipes(unit.get("TEST_RECIPES_VALUE")).strip().splitlines()
  299. if recipes_lines:
  300. deps = deps or []
  301. deps.extend([os.path.dirname(r.strip().split(" ")[0]) for r in recipes_lines])
  302. return {cls.KEY: " ".join(deps)}
  303. class EslintConfigPath:
  304. KEY = 'ESLINT_CONFIG_PATH'
  305. @classmethod
  306. def value(cls, unit, flat_args, spec_args):
  307. test_runner, rel_to = flat_args
  308. return {cls.KEY: _resolve_config_path(unit, test_runner, rel_to=rel_to)}
  309. class ForkMode:
  310. KEY = 'FORK-MODE'
  311. @classmethod
  312. def from_macro_and_unit(cls, unit, flat_args, spec_args):
  313. fork_mode = []
  314. if 'FORK_SUBTESTS' in spec_args:
  315. fork_mode.append('subtests')
  316. if 'FORK_TESTS' in spec_args:
  317. fork_mode.append('tests')
  318. fork_mode = fork_mode or spec_args.get('FORK_MODE', []) or unit.get('TEST_FORK_MODE').split()
  319. fork_mode = ' '.join(fork_mode) if fork_mode else ''
  320. return {cls.KEY: fork_mode}
  321. @classmethod
  322. def test_fork_mode(cls, unit, flat_args, spec_args):
  323. return {cls.KEY: unit.get('TEST_FORK_MODE')}
  324. class ForkTestFiles:
  325. KEY = 'FORK-TEST-FILES'
  326. @classmethod
  327. def value(cls, unit, flat_args, spec_args):
  328. return {cls.KEY: unit.get('FORK_TEST_FILES_MODE')}
  329. class FuzzDicts:
  330. KEY = 'FUZZ-DICTS'
  331. @classmethod
  332. def value(cls, unit, flat_args, spec_args):
  333. value = serialize_list(spec_args.get('FUZZ_DICTS', []) + get_unit_list_variable(unit, 'FUZZ_DICTS_VALUE'))
  334. return {cls.KEY: value}
  335. class FuzzOpts:
  336. KEY = 'FUZZ-OPTS'
  337. @classmethod
  338. def value(cls, unit, flat_args, spec_args):
  339. value = serialize_list(spec_args.get('FUZZ_OPTS', []) + get_unit_list_variable(unit, 'FUZZ_OPTS_VALUE'))
  340. return {cls.KEY: value}
  341. class Fuzzing:
  342. KEY = 'FUZZING'
  343. @classmethod
  344. def value(cls, unit, flat_args, spec_args):
  345. if unit.get('FUZZING') == 'yes':
  346. return {cls.KEY: '1'}
  347. class GlobalLibraryPath:
  348. KEY = 'GLOBAL-LIBRARY-PATH'
  349. @classmethod
  350. def value(cls, unit, flat_args, spec_args):
  351. return {cls.KEY: unit.global_filename()}
  352. class GoBenchTimeout:
  353. KEY = 'GO_BENCH_TIMEOUT'
  354. @classmethod
  355. def value(cls, unit, flat_args, spec_args):
  356. return {cls.KEY: unit.get('GO_BENCH_TIMEOUT')}
  357. class IgnoreClasspathClash:
  358. KEY = 'IGNORE_CLASSPATH_CLASH'
  359. @classmethod
  360. def value(cls, unit, flat_args, spec_args):
  361. value = ' '.join(get_values_list(unit, 'JAVA_IGNORE_CLASSPATH_CLASH_VALUE'))
  362. return {cls.KEY: value}
  363. class JavaClasspathCmdType:
  364. KEY = 'JAVA_CLASSPATH_CMD_TYPE'
  365. @classmethod
  366. def value(cls, unit, flat_args, spec_args):
  367. java_cp_arg_type = unit.get('JAVA_CLASSPATH_CMD_TYPE_VALUE') or 'MANIFEST'
  368. if java_cp_arg_type not in ('MANIFEST', 'COMMAND_FILE', 'LIST'):
  369. # TODO move error reporting out of field classes
  370. ymake.report_configure_error(
  371. '{}: TEST_JAVA_CLASSPATH_CMD_TYPE({}) are invalid. Choose argument from MANIFEST, COMMAND_FILE or LIST)'.format(
  372. unit.path(), java_cp_arg_type
  373. )
  374. )
  375. raise DartValueError()
  376. return {cls.KEY: java_cp_arg_type}
  377. class JdkForTests:
  378. KEY = 'JDK_FOR_TESTS'
  379. @classmethod
  380. def value(cls, unit, flat_args, spec_args):
  381. value = 'JDK' + (unit.get('JDK_VERSION') or unit.get('JDK_REAL_VERSION') or '_DEFAULT') + '_FOR_TESTS'
  382. return {cls.KEY: value}
  383. class JdkLatestVersion:
  384. KEY = 'JDK_LATEST_VERSION'
  385. @classmethod
  386. def value(cls, unit, flat_args, spec_args):
  387. return {cls.KEY: unit.get('JDK_LATEST_VERSION')}
  388. class JdkResource:
  389. KEY = 'JDK_RESOURCE'
  390. @classmethod
  391. def value(cls, unit, flat_args, spec_args):
  392. value = 'JDK' + (unit.get('JDK_VERSION') or unit.get('JDK_REAL_VERSION') or '_DEFAULT')
  393. return {cls.KEY: value}
  394. class KtlintBaselineFile:
  395. KEY = 'KTLINT_BASELINE_FILE'
  396. @classmethod
  397. def value(cls, unit, flat_args, spec_args):
  398. if unit.get('_USE_KTLINT_OLD') != 'yes':
  399. baseline_path_relative = unit.get('_KTLINT_BASELINE_FILE')
  400. if baseline_path_relative:
  401. return {cls.KEY: baseline_path_relative}
  402. class KtlintBinary:
  403. KEY = 'KTLINT_BINARY'
  404. @classmethod
  405. def value(cls, unit, flat_args, spec_args):
  406. value = '$(KTLINT_OLD)/run.bat' if unit.get('_USE_KTLINT_OLD') == 'yes' else '$(KTLINT)/run.bat'
  407. return {cls.KEY: value}
  408. class Linter:
  409. KEY = 'LINTER'
  410. @classmethod
  411. def value(cls, unit, flat_args, spec_args):
  412. return {cls.KEY: spec_args['LINTER'][0]}
  413. class LintConfigs:
  414. KEY = 'LINT-CONFIGS'
  415. @classmethod
  416. def python_configs(cls, unit, flat_args, spec_args):
  417. resolved_configs = []
  418. project_to_config_map = spec_args.get('PROJECT_TO_CONFIG_MAP', [])
  419. if project_to_config_map:
  420. # ruff, TODO rewrite once custom configs migrated to autoincludes scheme
  421. project_to_config_map = project_to_config_map[0]
  422. assert_file_exists(unit, project_to_config_map)
  423. resolved_configs.append(project_to_config_map)
  424. cfgs = get_linter_configs(unit, project_to_config_map).values()
  425. for c in cfgs:
  426. assert_file_exists(unit, c)
  427. resolved_configs.append(c)
  428. return {cls.KEY: serialize_list(resolved_configs)}
  429. custom_config = spec_args.get('CUSTOM_CONFIG', [])
  430. if custom_config:
  431. # black if custom config is passed
  432. # TODO rewrite once custom configs migrated to autoincludes scheme
  433. custom_config = custom_config[0]
  434. assert_file_exists(unit, custom_config)
  435. resolved_configs.append(custom_config)
  436. return {cls.KEY: serialize_list(resolved_configs)}
  437. config = spec_args['CONFIGS'][0]
  438. # black without custom config or flake8, using default configs file
  439. assert_file_exists(unit, config)
  440. name = spec_args['NAME'][0]
  441. cfg = get_linter_configs(unit, config)[name]
  442. assert_file_exists(unit, cfg)
  443. resolved_configs.append(cfg)
  444. if name in ('flake8', 'py2_flake8'):
  445. resolved_configs.extend(spec_args.get('FLAKE_MIGRATIONS_CONFIG', []))
  446. return {cls.KEY: serialize_list(resolved_configs)}
  447. @classmethod
  448. def cpp_configs(cls, unit, flat_args, spec_args):
  449. custom_config = spec_args.get('CUSTOM_CONFIG')
  450. if custom_config:
  451. config = custom_config[0]
  452. assert_file_exists(unit, config)
  453. else:
  454. # file with default configs
  455. config = spec_args.get('CONFIGS')[0]
  456. assert_file_exists(unit, config)
  457. name = spec_args['NAME'][0]
  458. config = get_linter_configs(unit, config)[name]
  459. assert_file_exists(unit, config)
  460. return {cls.KEY: serialize_list([config])}
  461. class LintExtraParams:
  462. KEY = 'LINT-EXTRA-PARAMS'
  463. @classmethod
  464. def from_macro_args(cls, unit, flat_args, spec_args):
  465. extra_params = spec_args.get('EXTRA_PARAMS', [])
  466. for arg in extra_params:
  467. if '=' not in arg:
  468. message = 'Wrong EXTRA_PARAMS value: "{}". Values must have format "name=value".'.format(arg)
  469. ymake.report_configure_error(message)
  470. raise DartValueError()
  471. return {cls.KEY: serialize_list(extra_params)}
  472. class LintFileProcessingTime:
  473. KEY = 'LINT-FILE-PROCESSING-TIME'
  474. @classmethod
  475. def from_macro_args(cls, unit, flat_args, spec_args):
  476. return {cls.KEY: spec_args.get('FILE_PROCESSING_TIME', [''])[0]}
  477. class LintName:
  478. KEY = 'LINT-NAME'
  479. @classmethod
  480. def value(cls, unit, flat_args, spec_args):
  481. lint_name = spec_args['NAME'][0]
  482. if lint_name in ('flake8', 'py2_flake8') and (unit.get('DISABLE_FLAKE8') or 'no') == 'yes':
  483. unit.message(['INFO', 'Flake8 linting is disabled by `DISABLE_FLAKE8`'])
  484. raise DartValueError()
  485. return {cls.KEY: lint_name}
  486. class ModuleLang:
  487. KEY = 'MODULE_LANG'
  488. @classmethod
  489. def value(cls, unit, flat_args, spec_args):
  490. return {cls.KEY: unit.get("MODULE_LANG").lower() or consts.ModuleLang.UNKNOWN}
  491. class ModuleType:
  492. KEY = 'MODULE_TYPE'
  493. @classmethod
  494. def value(cls, unit, flat_args, spec_args):
  495. return {cls.KEY: unit.get('MODULE_TYPE')}
  496. class NoCheck:
  497. KEY = 'NO-CHECK'
  498. @classmethod
  499. def value(cls, unit, flat_args, spec_args):
  500. if unit.get('NO_CHECK_IMPORTS_FOR_VALUE') != "None":
  501. value = serialize_list(get_values_list(unit, 'NO_CHECK_IMPORTS_FOR_VALUE') or ["*"])
  502. return {cls.KEY: value}
  503. class NodejsRootVarName:
  504. KEY = 'NODEJS-ROOT-VAR-NAME'
  505. @classmethod
  506. def value(cls, unit, flat_args, spec_args):
  507. return {cls.KEY: unit.get("NODEJS-ROOT-VAR-NAME")}
  508. class NodeModulesBundleFilename:
  509. KEY = 'NODE-MODULES-BUNDLE-FILENAME'
  510. @classmethod
  511. def value(cls, unit, flat_args, spec_args):
  512. return {cls.KEY: spec_args.get('nm_bundle')}
  513. class PythonPaths:
  514. KEY = 'PYTHON-PATHS'
  515. @classmethod
  516. def value(cls, unit, flat_args, spec_args):
  517. python_paths = get_values_list(unit, 'TEST_PYTHON_PATH_VALUE')
  518. return {cls.KEY: serialize_list(python_paths)}
  519. class Requirements:
  520. KEY = 'REQUIREMENTS'
  521. @classmethod
  522. def from_macro_args_and_unit(cls, unit, flat_args, spec_args):
  523. test_requirements = spec_args.get('REQUIREMENTS', []) + get_values_list(unit, 'TEST_REQUIREMENTS_VALUE')
  524. return {cls.KEY: serialize_list(test_requirements)}
  525. @classmethod
  526. def with_maybe_fuzzing(cls, unit, flat_args, spec_args):
  527. test_requirements = serialize_list(
  528. spec_args.get('REQUIREMENTS', []) + get_values_list(unit, 'TEST_REQUIREMENTS_VALUE')
  529. )
  530. if unit.get('FUZZING') == 'yes':
  531. value = serialize_list(filter(None, deserialize_list(test_requirements) + ["cpu:all", "ram:all"]))
  532. return {cls.KEY: value}
  533. else:
  534. return {cls.KEY: test_requirements}
  535. @classmethod
  536. def from_macro_args(cls, unit, flat_args, spec_args):
  537. value = " ".join(spec_args.get('REQUIREMENTS', []))
  538. return {cls.KEY: value}
  539. @classmethod
  540. def from_unit(cls, unit, flat_args, spec_args):
  541. requirements = get_values_list(unit, 'TEST_REQUIREMENTS_VALUE')
  542. return {cls.KEY: serialize_list(requirements)}
  543. @classmethod
  544. def from_unit_with_full_network(cls, unit, flat_args, spec_args):
  545. requirements = sorted(set(["network:full"] + get_values_list(unit, "TEST_REQUIREMENTS_VALUE")))
  546. return {cls.KEY: serialize_list(requirements)}
  547. class SbrUidExt:
  548. KEY = 'SBR-UID-EXT'
  549. @classmethod
  550. def value(cls, unit, flat_args, spec_args):
  551. uid_ext = unit.get("SBR_UID_EXT").split(" ", 1)[-1] # strip variable name
  552. return {cls.KEY: uid_ext}
  553. class ScriptRelPath:
  554. KEY = 'SCRIPT-REL-PATH'
  555. @classmethod
  556. def second_flat(cls, unit, flat_args, spec_args):
  557. return {cls.KEY: flat_args[1]}
  558. @classmethod
  559. def first_flat(cls, unit, flat_args, spec_args):
  560. return {cls.KEY: flat_args[0]}
  561. @classmethod
  562. def pytest(cls, unit, flat_args, spec_args):
  563. return {cls.KEY: 'py3test.bin' if (unit.get("PYTHON3") == 'yes') else "pytest.bin"}
  564. @classmethod
  565. def junit(cls, unit, flat_args, spec_args):
  566. return {cls.KEY: 'junit5.test' if unit.get('MODULE_TYPE') == 'JUNIT5' else 'junit.test'}
  567. class Size:
  568. KEY = 'SIZE'
  569. @classmethod
  570. def from_macro_args_and_unit(cls, unit, flat_args, spec_args):
  571. return {cls.KEY: ''.join(spec_args.get('SIZE', [])) or unit.get('TEST_SIZE_NAME')}
  572. @classmethod
  573. def from_unit(cls, unit, flat_args, spec_args):
  574. return {cls.KEY: unit.get('TEST_SIZE_NAME')}
  575. class SkipTest:
  576. KEY = 'SKIP_TEST'
  577. @classmethod
  578. def value(cls, unit, flat_args, spec_args):
  579. return {cls.KEY: unit.get('SKIP_TEST_VALUE')}
  580. class SourceFolderPath:
  581. KEY = 'SOURCE-FOLDER-PATH'
  582. @classmethod
  583. def normalized(cls, unit, flat_args, spec_args):
  584. return {cls.KEY: _common.get_norm_unit_path(unit)}
  585. @classmethod
  586. def test_dir(cls, unit, flat_args, spec_args):
  587. test_dir = _common.get_norm_unit_path(unit)
  588. test_files = flat_args[1:]
  589. if test_files:
  590. test_dir = os.path.dirname(test_files[0]).lstrip("$S/")
  591. return {cls.KEY: test_dir}
  592. class SplitFactor:
  593. KEY = 'SPLIT-FACTOR'
  594. @classmethod
  595. def from_macro_args_and_unit(cls, unit, flat_args, spec_args):
  596. value = ''.join(spec_args.get('SPLIT_FACTOR', [])) or unit.get('TEST_SPLIT_FACTOR')
  597. return {cls.KEY: value}
  598. @classmethod
  599. def from_unit(cls, unit, flat_args, spec_args):
  600. return {cls.KEY: unit.get('TEST_SPLIT_FACTOR')}
  601. class Tag:
  602. KEY = 'TAG'
  603. @classmethod
  604. def from_macro_args_and_unit(cls, unit, flat_args, spec_args):
  605. tags = serialize_list(sorted(_get_test_tags(unit, spec_args)))
  606. return {cls.KEY: tags}
  607. @classmethod
  608. def from_unit(cls, unit, flat_args, spec_args):
  609. tags = serialize_list(get_values_list(unit, "TEST_TAGS_VALUE"))
  610. return {cls.KEY: tags}
  611. @classmethod
  612. def from_unit_fat_external_no_retries(cls, unit, flat_args, spec_args):
  613. tags = sorted(set(["ya:fat", "ya:external", "ya:noretries"] + get_values_list(unit, "TEST_TAGS_VALUE")))
  614. return {cls.KEY: serialize_list(tags)}
  615. class TestClasspath:
  616. KEY = 'TEST_CLASSPATH'
  617. @classmethod
  618. def value(cls, unit, flat_args, spec_args):
  619. value = '${DART_CLASSPATH}'
  620. return {cls.KEY: value}
  621. class TestClasspathDeps:
  622. KEY = 'TEST_CLASSPATH_DEPS'
  623. @classmethod
  624. def value(cls, unit, flat_args, spec_args):
  625. return {cls.KEY: '${DART_CLASSPATH_DEPS}'}
  626. class TestCwd:
  627. KEY = 'TEST-CWD'
  628. @classmethod
  629. def from_unit(cls, unit, flat_args, spec_args):
  630. test_cwd = unit.get('TEST_CWD_VALUE') # TODO: validate test_cwd value
  631. return {cls.KEY: test_cwd}
  632. @classmethod
  633. def keywords_replaced(cls, unit, flat_args, spec_args):
  634. test_cwd = unit.get('TEST_CWD_VALUE') or ''
  635. if test_cwd:
  636. test_cwd = test_cwd.replace("$TEST_CWD_VALUE", "").replace('"MACRO_CALLS_DELIM"', "").strip()
  637. return {cls.KEY: test_cwd}
  638. @classmethod
  639. def moddir(cls, unit, flat_args, spec_args):
  640. return {cls.KEY: unit.get("MODDIR")}
  641. class TestData:
  642. KEY = 'TEST-DATA'
  643. @classmethod
  644. def from_macro_args_and_unit(cls, unit, flat_args, spec_args):
  645. test_data = sorted(
  646. _common.filter_out_by_keyword(
  647. spec_args.get('DATA', []) + get_norm_paths(unit, 'TEST_DATA_VALUE'), 'AUTOUPDATED'
  648. )
  649. )
  650. return {cls.KEY: serialize_list(test_data)}
  651. @classmethod
  652. def from_macro_args_and_unit_with_canonical(cls, unit, flat_args, spec_args):
  653. test_data = sorted(
  654. _common.filter_out_by_keyword(
  655. spec_args.get('DATA', []) + get_norm_paths(unit, 'TEST_DATA_VALUE'), 'AUTOUPDATED'
  656. )
  657. )
  658. data, _ = get_canonical_test_resources(unit)
  659. test_data += data
  660. value = serialize_list(sorted(test_data))
  661. return {cls.KEY: value}
  662. @classmethod
  663. def ktlint(cls, unit, flat_args, spec_args):
  664. if unit.get('_USE_KTLINT_OLD') == 'yes':
  665. extra_test_data = [KTLINT_OLD_EDITOR_CONFIG]
  666. else:
  667. data_list = [KTLINT_CURRENT_EDITOR_CONFIG]
  668. baseline_path_relative = unit.get('_KTLINT_BASELINE_FILE')
  669. if baseline_path_relative:
  670. baseline_path = unit.resolve_arc_path(baseline_path_relative).replace('$S', 'arcadia')
  671. data_list += [baseline_path]
  672. extra_test_data = data_list
  673. # XXX
  674. if unit.get('_WITH_YA_1931') != 'yes':
  675. extra_test_data += java_srcdirs_to_data(unit, 'ALL_SRCDIRS', serialize_result=False)
  676. extra_test_data = serialize_list(extra_test_data)
  677. return {cls.KEY: extra_test_data}
  678. @classmethod
  679. def java_style(cls, unit, flat_args, spec_args):
  680. return {cls.KEY: java_srcdirs_to_data(unit, 'ALL_SRCDIRS')}
  681. @classmethod
  682. def from_unit_with_canonical(cls, unit, flat_args, spec_args):
  683. test_data = get_norm_paths(unit, 'TEST_DATA_VALUE')
  684. data, _ = get_canonical_test_resources(unit)
  685. test_data += data
  686. value = serialize_list(sorted(_common.filter_out_by_keyword(test_data, 'AUTOUPDATED')))
  687. return {cls.KEY: value}
  688. @classmethod
  689. def java_test(cls, unit, flat_args, spec_args):
  690. test_data = get_norm_paths(unit, 'TEST_DATA_VALUE')
  691. test_data.append('arcadia/build/scripts/run_junit.py')
  692. test_data.append('arcadia/build/scripts/unpacking_jtest_runner.py')
  693. data, _ = get_canonical_test_resources(unit)
  694. test_data += data
  695. props, error_mgs = extract_java_system_properties(unit, get_values_list(unit, 'SYSTEM_PROPERTIES_VALUE'))
  696. if error_mgs:
  697. ymake.report_configure_error(error_mgs)
  698. raise DartValueError()
  699. for prop in props:
  700. if prop['type'] == 'file':
  701. test_data.append(prop['path'].replace('${ARCADIA_ROOT}', 'arcadia'))
  702. value = serialize_list(sorted(_common.filter_out_by_keyword(test_data, 'AUTOUPDATED')))
  703. return {cls.KEY: value}
  704. @classmethod
  705. def from_unit(cls, unit, flat_args, spec_args):
  706. return {cls.KEY: serialize_list(get_values_list(unit, "TEST_DATA_VALUE"))}
  707. class DockerImage:
  708. KEY = 'DOCKER-IMAGES'
  709. @staticmethod
  710. def _validate(images):
  711. docker_image_re = consts.DOCKER_LINK_RE
  712. for img in images:
  713. msg = None
  714. if "=" in img:
  715. link, _ = img.rsplit('=', 1)
  716. if docker_image_re.match(link) is None:
  717. msg = 'Invalid docker url format: {}. Link should be provided in format docker://<repo>@sha256:<digest>'.format(
  718. link
  719. )
  720. else:
  721. msg = 'Invalid docker image: {}. Image should be provided in format <link>=<tag>'.format(img)
  722. if msg:
  723. ymake.report_configure_error(msg)
  724. raise DartValueError(msg)
  725. @classmethod
  726. def value(cls, unit, flat_args, spec_args):
  727. raw_value = get_values_list(unit, 'DOCKER_IMAGES_VALUE')
  728. images = sorted(raw_value)
  729. if images:
  730. cls._validate(images)
  731. return {cls.KEY: serialize_list(images)}
  732. class TsConfigPath:
  733. KEY = 'TS_CONFIG_PATH'
  734. class TsStylelintConfig:
  735. KEY = 'TS_STYLELINT_CONFIG'
  736. @classmethod
  737. def value(cls, unit, flat_args, spec_args):
  738. test_config = unit.get('_TS_STYLELINT_CONFIG')
  739. abs_test_config = unit.resolve(unit.resolve_arc_path(test_config))
  740. if not abs_test_config:
  741. ymake.report_configure_error(
  742. f"Config for stylelint not found: {test_config}.\n"
  743. "Set the correct value in `TS_STYLELINT(<config_filename>)` macro in the `ya.make` file."
  744. )
  745. return {cls.KEY: test_config}
  746. class TsTestDataDirs:
  747. KEY = 'TS-TEST-DATA-DIRS'
  748. @classmethod
  749. def value(cls, unit, flat_args, spec_args):
  750. value = serialize_list(_get_ts_test_data_dirs(unit))
  751. return {cls.KEY: value}
  752. class TsTestDataDirsRename:
  753. KEY = 'TS-TEST-DATA-DIRS-RENAME'
  754. @classmethod
  755. def value(cls, unit, flat_args, spec_args):
  756. return {cls.KEY: unit.get("_TS_TEST_DATA_DIRS_RENAME_VALUE")}
  757. class TsTestForPath:
  758. KEY = 'TS-TEST-FOR-PATH'
  759. @classmethod
  760. def value(cls, unit, flat_args, spec_args):
  761. return {cls.KEY: unit.get("TS_TEST_FOR_PATH")}
  762. class TestedProjectFilename:
  763. KEY = 'TESTED-PROJECT-FILENAME'
  764. @classmethod
  765. def value(cls, unit, flat_args, spec_args):
  766. return {cls.KEY: unit.filename()}
  767. class TestedProjectName:
  768. KEY = 'TESTED-PROJECT-NAME'
  769. @classmethod
  770. def unit_name(cls, unit, flat_args, spec_args):
  771. return {cls.KEY: unit.name()}
  772. @classmethod
  773. def normalized_basename(cls, unit, flat_args, spec_args):
  774. test_dir = _common.get_norm_unit_path(unit)
  775. return {cls.KEY: os.path.basename(test_dir)}
  776. @classmethod
  777. def test_dir(cls, unit, flat_args, spec_args):
  778. test_dir = _common.get_norm_unit_path(unit)
  779. test_files = flat_args[1:]
  780. if test_files:
  781. test_dir = os.path.dirname(test_files[0]).lstrip("$S/")
  782. return {cls.KEY: os.path.basename(test_dir)}
  783. @classmethod
  784. def path_filename_basename(cls, unit, flat_args, spec_args):
  785. binary_path = os.path.join(unit.path(), unit.filename())
  786. return {cls.KEY: os.path.basename(binary_path)}
  787. @classmethod
  788. def normalized(cls, unit, flat_args, spec_args):
  789. return {cls.KEY: _common.get_norm_unit_path(unit)}
  790. @classmethod
  791. def path_filename_basename_without_pkg_ext(cls, unit, flat_args, spec_args):
  792. value = os.path.basename(os.path.join(unit.path(), unit.filename()).replace(".pkg", ""))
  793. return {cls.KEY: value}
  794. @classmethod
  795. def filename_without_ext(cls, unit, flat_args, spec_args):
  796. return {cls.KEY: os.path.splitext(unit.filename())[0]}
  797. class TestFiles:
  798. KEY = 'TEST-FILES'
  799. # TODO remove FILES, see DEVTOOLS-7052, currently it's required
  800. # https://a.yandex-team.ru/arcadia/devtools/ya/test/dartfile/__init__.py?rev=r14292146#L10
  801. KEY2 = 'FILES'
  802. @classmethod
  803. def value(cls, unit, flat_args, spec_args):
  804. data_re = re.compile(r"sbr:/?/?(\d+)=?.*")
  805. data = flat_args[1:]
  806. resources = []
  807. for f in data:
  808. matched = re.match(data_re, f)
  809. if matched:
  810. resources.append(matched.group(1))
  811. value = serialize_list(resources)
  812. return {cls.KEY: value, cls.KEY2: value}
  813. @classmethod
  814. def flat_args_wo_first(cls, unit, flat_args, spec_args):
  815. value = serialize_list(flat_args[1:])
  816. return {cls.KEY: value, cls.KEY2: value}
  817. @classmethod
  818. def java_style(cls, unit, flat_args, spec_args):
  819. test_files = flat_args[1:]
  820. check_level = flat_args[1]
  821. allowed_levels = {
  822. 'base': '/yandex_checks.xml',
  823. 'strict': '/yandex_checks_strict.xml',
  824. 'extended': '/yandex_checks_extended.xml',
  825. 'library': '/yandex_checks_library.xml',
  826. }
  827. if check_level not in allowed_levels:
  828. raise Exception("'{}' is not allowed in LINT(), use one of {}".format(check_level, allowed_levels.keys()))
  829. test_files[0] = allowed_levels[check_level]
  830. value = serialize_list(test_files)
  831. return {cls.KEY: value, cls.KEY2: value}
  832. @classmethod
  833. def normalized(cls, unit, flat_args, spec_args):
  834. value = serialize_list([_common.get_norm_unit_path(unit, unit.filename())])
  835. return {cls.KEY: value, cls.KEY2: value}
  836. @classmethod
  837. def test_srcs(cls, unit, flat_args, spec_args):
  838. test_files = get_values_list(unit, 'TEST_SRCS_VALUE')
  839. value = serialize_list(test_files)
  840. return {cls.KEY: value, cls.KEY2: value}
  841. @classmethod
  842. def ts_test_srcs(cls, unit, flat_args, spec_args):
  843. test_files = get_values_list(unit, "_TS_TEST_SRCS_VALUE")
  844. test_files = _resolve_module_files(unit, unit.get("MODDIR"), test_files)
  845. value = serialize_list(test_files)
  846. return {cls.KEY: value, cls.KEY2: value}
  847. @classmethod
  848. def ts_input_files(cls, unit, flat_args, spec_args):
  849. typecheck_files = get_values_list(unit, "TS_INPUT_FILES")
  850. test_files = [_common.resolve_common_const(f) for f in typecheck_files]
  851. value = serialize_list(test_files)
  852. return {cls.KEY: value, cls.KEY2: value}
  853. @classmethod
  854. def ts_lint_srcs(cls, unit, flat_args, spec_args):
  855. test_files = get_values_list(unit, "_TS_LINT_SRCS_VALUE")
  856. test_files = _resolve_module_files(unit, unit.get("MODDIR"), test_files)
  857. value = serialize_list(test_files)
  858. return {cls.KEY: value, cls.KEY2: value}
  859. @classmethod
  860. def stylesheets(cls, unit, flat_args, spec_args):
  861. test_files = get_values_list(unit, "_TS_STYLELINT_FILES")
  862. test_files = _resolve_module_files(unit, unit.get("MODDIR"), test_files)
  863. value = serialize_list(test_files)
  864. return {cls.KEY: value, cls.KEY2: value}
  865. @classmethod
  866. def py_linter_files(cls, unit, flat_args, spec_args):
  867. files = unit.get('PY_LINTER_FILES')
  868. if not files:
  869. raise DartValueError()
  870. files = json.loads(files)
  871. test_files = []
  872. for path in files:
  873. if path.startswith(ARCADIA_ROOT):
  874. test_files.append(path.replace(ARCADIA_ROOT, SOURCE_ROOT_SHORT, 1))
  875. elif path.startswith(SOURCE_ROOT_SHORT):
  876. test_files.append(path)
  877. if not test_files:
  878. lint_name = LintName.value(unit, flat_args, spec_args)[LintName.KEY]
  879. message = 'No files to lint for {}'.format(lint_name)
  880. raise DartValueError(message)
  881. test_files = serialize_list(test_files)
  882. return {cls.KEY: test_files, cls.KEY2: test_files}
  883. @classmethod
  884. def cpp_linter_files(cls, unit, flat_args, spec_args):
  885. files_dart = _reference_group_var("ALL_SRCS", consts.STYLE_CPP_ALL_EXTS)
  886. return {cls.KEY: files_dart, cls.KEY2: files_dart}
  887. class TestEnv:
  888. KEY = 'TEST-ENV'
  889. @classmethod
  890. def value(cls, unit, flat_args, spec_args):
  891. return {cls.KEY: prepare_env(unit.get("TEST_ENV_VALUE"))}
  892. class TestIosDeviceType:
  893. KEY = 'TEST_IOS_DEVICE_TYPE'
  894. @classmethod
  895. def value(cls, unit, flat_args, spec_args):
  896. return {cls.KEY: unit.get('TEST_IOS_DEVICE_TYPE_VALUE')}
  897. class TestIosRuntimeType:
  898. KEY = 'TEST_IOS_RUNTIME_TYPE'
  899. @classmethod
  900. def value(cls, unit, flat_args, spec_args):
  901. return {cls.KEY: unit.get('TEST_IOS_RUNTIME_TYPE_VALUE')}
  902. class TestJar:
  903. KEY = 'TEST_JAR'
  904. @classmethod
  905. def value(cls, unit, flat_args, spec_args):
  906. if unit.get('UNITTEST_DIR'):
  907. value = '${UNITTEST_MOD}'
  908. else:
  909. value = '{}/{}.jar'.format(unit.get('MODDIR'), unit.get('REALPRJNAME'))
  910. return {cls.KEY: value}
  911. class TestName:
  912. KEY = 'TEST-NAME'
  913. @classmethod
  914. def value(cls, unit, flat_args, spec_args):
  915. return {cls.KEY: flat_args[0]}
  916. @classmethod
  917. def first_flat_with_bench(cls, unit, flat_args, spec_args):
  918. return {cls.KEY: flat_args[0] + '_bench'}
  919. @classmethod
  920. def first_flat(cls, unit, flat_args, spec_args):
  921. return {cls.KEY: flat_args[0].lower()}
  922. @classmethod
  923. def filename_without_ext(cls, unit, flat_args, spec_args):
  924. test_name = os.path.basename(os.path.join(unit.path(), unit.filename()))
  925. return {cls.KEY: os.path.splitext(test_name)[0]}
  926. @classmethod
  927. def normalized_joined_dir_basename(cls, unit, flat_args, spec_args):
  928. path = _common.get_norm_unit_path(unit)
  929. value = '-'.join([os.path.basename(os.path.dirname(path)), os.path.basename(path)])
  930. return {cls.KEY: value}
  931. @classmethod
  932. def normalized_joined_dir_basename_deps(cls, unit, flat_args, spec_args):
  933. path = _common.get_norm_unit_path(unit)
  934. value = '-'.join([os.path.basename(os.path.dirname(path)), os.path.basename(path), 'dependencies']).strip('-')
  935. return {cls.KEY: value}
  936. @classmethod
  937. def filename_without_pkg_ext(cls, unit, flat_args, spec_args):
  938. test_name = os.path.basename(os.path.join(unit.path(), unit.filename()).replace(".pkg", ""))
  939. return {cls.KEY: os.path.splitext(test_name)[0]}
  940. @classmethod
  941. def name_from_macro_args(cls, unit, flat_args, spec_args):
  942. return {cls.KEY: spec_args['NAME'][0]}
  943. class TestPartition:
  944. KEY = 'TEST_PARTITION'
  945. @classmethod
  946. def value(cls, unit, flat_args, spec_args):
  947. return {cls.KEY: unit.get("TEST_PARTITION")}
  948. class TestRecipes:
  949. KEY = 'TEST-RECIPES'
  950. @classmethod
  951. def value(cls, unit, flat_args, spec_args):
  952. return {cls.KEY: prepare_recipes(unit.get("TEST_RECIPES_VALUE"))}
  953. class TestRunnerBin:
  954. KEY = 'TEST-RUNNER-BIN'
  955. @classmethod
  956. def value(cls, unit, flat_args, spec_args):
  957. runner_bin = spec_args.get('RUNNER_BIN', [None])[0]
  958. if runner_bin:
  959. return {cls.KEY: runner_bin}
  960. class TestTimeout:
  961. KEY = 'TEST-TIMEOUT'
  962. @classmethod
  963. def from_macro_args_and_unit(cls, unit, flat_args, spec_args):
  964. test_timeout = ''.join(spec_args.get('TIMEOUT', [])) or unit.get('TEST_TIMEOUT') or ''
  965. return {cls.KEY: test_timeout}
  966. @classmethod
  967. def from_unit_with_default(cls, unit, flat_args, spec_args):
  968. timeout = list(filter(None, [unit.get(["TEST_TIMEOUT"])]))
  969. if timeout:
  970. timeout = timeout[0]
  971. else:
  972. timeout = '0'
  973. return {cls.KEY: timeout}
  974. @classmethod
  975. def from_unit(cls, unit, flat_args, spec_args):
  976. return {cls.KEY: unit.get('TEST_TIMEOUT')}
  977. class TsResources:
  978. KEY = "{}-ROOT-VAR-NAME"
  979. @classmethod
  980. def value(cls, unit, flat_args, spec_args):
  981. erm_json = spec_args['erm_json']
  982. ret = {}
  983. for tool in erm_json.list_npm_packages():
  984. tool_resource_label = cls.KEY.format(tool.upper())
  985. tool_resource_value = unit.get(tool_resource_label)
  986. if tool_resource_value:
  987. ret[tool_resource_label] = tool_resource_value
  988. return ret
  989. class JvmArgs:
  990. KEY = 'JVM_ARGS'
  991. @classmethod
  992. def value(cls, unit, flat_args, spec_args):
  993. value = serialize_list(get_values_list(unit, 'JVM_ARGS_VALUE'))
  994. return {cls.KEY: value}
  995. class StrictClasspathClash:
  996. KEY = 'STRICT_CLASSPATH_CLASH'
  997. class SystemProperties:
  998. KEY = 'SYSTEM_PROPERTIES'
  999. @classmethod
  1000. def value(cls, unit, flat_args, spec_args):
  1001. props, error_mgs = extract_java_system_properties(unit, get_values_list(unit, 'SYSTEM_PROPERTIES_VALUE'))
  1002. if error_mgs:
  1003. ymake.report_configure_error(error_mgs)
  1004. raise DartValueError()
  1005. props = base64.b64encode(six.ensure_binary(json.dumps(props)))
  1006. return {cls.KEY: props}
  1007. class UnittestDir:
  1008. KEY = 'UNITTEST_DIR'
  1009. @classmethod
  1010. def value(cls, unit, flat_args, spec_args):
  1011. return {cls.KEY: unit.get('UNITTEST_DIR')}
  1012. class UseArcadiaPython:
  1013. KEY = 'USE_ARCADIA_PYTHON'
  1014. @classmethod
  1015. def value(cls, unit, flat_args, spec_args):
  1016. return {cls.KEY: unit.get('USE_ARCADIA_PYTHON')}
  1017. class UseKtlintOld:
  1018. KEY = 'USE_KTLINT_OLD'
  1019. @classmethod
  1020. def value(cls, unit, flat_args, spec_args):
  1021. if unit.get('_USE_KTLINT_OLD') == 'yes':
  1022. return {cls.KEY: 'yes'}
  1023. class YtSpec:
  1024. KEY = 'YT-SPEC'
  1025. @classmethod
  1026. def from_macro_args_and_unit(cls, unit, flat_args, spec_args):
  1027. value = serialize_list(spec_args.get('YT_SPEC', []) + get_unit_list_variable(unit, 'TEST_YT_SPEC_VALUE'))
  1028. return {cls.KEY: value}
  1029. @classmethod
  1030. def from_unit(cls, unit, flat_args, spec_args):
  1031. yt_spec = get_values_list(unit, 'TEST_YT_SPEC_VALUE')
  1032. if yt_spec:
  1033. return {cls.KEY: serialize_list(yt_spec)}
  1034. @classmethod
  1035. def from_unit_list_var(cls, unit, flat_args, spec_args):
  1036. yt_spec_values = get_unit_list_variable(unit, 'TEST_YT_SPEC_VALUE')
  1037. return {cls.KEY: serialize_list(yt_spec_values)}