macros_with_error.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import sys
  2. import _common
  3. import ymake
  4. def onmacros_with_error(unit, *args):
  5. sys.stderr.write('This macros will fail\n')
  6. raise Exception('Expected fail in MACROS_WITH_ERROR')
  7. def onrestrict_path(unit, *args):
  8. if args:
  9. if 'MSG' in args:
  10. pos = args.index('MSG')
  11. paths, msg = args[:pos], args[pos + 1 :]
  12. msg = ' '.join(msg)
  13. else:
  14. paths, msg = args, 'forbidden'
  15. if not _common.strip_roots(unit.path()).startswith(paths):
  16. error_msg = "Path '[[imp]]{}[[rst]]' is restricted - [[bad]]{}[[rst]]. Valid path prefixes are: [[unimp]]{}[[rst]]".format(
  17. unit.path(), msg, ', '.join(paths)
  18. )
  19. ymake.report_configure_error(error_msg)
  20. def onassert(unit, *args):
  21. val = unit.get(args[0])
  22. if val and val.lower() == "no":
  23. msg = ' '.join(args[1:])
  24. ymake.report_configure_error(msg)
  25. def onvalidate_in_dirs(unit, *args):
  26. files_var = args[0]
  27. pattern = args[1]
  28. no_srcdir = args[2] == '--'
  29. srcdir = '' if no_srcdir else args[2]
  30. dirs = args[3:] if no_srcdir else args[4:]
  31. pfx = '[[imp]]DECLARE_IN_DIRS[[rst]]: '
  32. if '**' in pattern:
  33. ymake.report_configure_error(f"{pfx}'**' in files mask is prohibited. Seen [[unimp]]{pattern}[[rst]]")
  34. unit.set([files_var, ""])
  35. for pat in ('*', '?'):
  36. if pat in srcdir:
  37. ymake.report_configure_error(
  38. f"{pfx}'{pat}' in [[imp]]SRCDIR[[rst]] argument is prohibited. Seen [[unimp]]{srcdir}[[rst]]"
  39. )
  40. unit.set([files_var, ""])
  41. for dir in dirs:
  42. for pat in ('*', '?', '$', '..'):
  43. if pat in dir:
  44. ymake.report_configure_error(
  45. f"{pfx}'{pat}' in [[imp]]DIRS[[rst]] argument is prohibited. Seen [[unimp]]{dir}[[rst]]"
  46. )
  47. unit.set([files_var, ""])