_dart_fields.py 43 KB

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