large_files.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import os
  2. import ymake
  3. from _common import strip_roots
  4. PLACEHOLDER_EXT = "external"
  5. def onlarge_files(unit, *args):
  6. """
  7. @usage LARGE_FILES([AUTOUPDATED] Files...)
  8. Use large file ether from working copy or from remote storage via placeholder <File>.external
  9. If <File> is present locally (and not a symlink!) it will be copied to build directory.
  10. Otherwise macro will try to locate <File>.external, parse it retrieve ot during build phase.
  11. """
  12. args = list(args)
  13. if args and args[0] == 'AUTOUPDATED':
  14. args = args[1:]
  15. for arg in args:
  16. if arg == 'AUTOUPDATED':
  17. unit.message(["warn", "Please set AUTOUPDATED argument before other file names"])
  18. continue
  19. src = unit.resolve_arc_path(arg)
  20. if src.startswith("$S"):
  21. msg = "Used local large file {}. Don't forget to run 'ya upload --update-external' and commit {}.{}".format(
  22. src, src, PLACEHOLDER_EXT
  23. )
  24. unit.message(["warn", msg])
  25. unit.oncopy_file([arg, arg])
  26. else:
  27. out_file = strip_roots(os.path.join(unit.path(), arg))
  28. external = "{}.{}".format(arg, PLACEHOLDER_EXT)
  29. from_external_cmd = [external, out_file, 'OUT_NOAUTO', arg]
  30. if os.path.dirname(arg):
  31. from_external_cmd.extend(("RENAME", os.path.basename(arg)))
  32. unit.on_from_external(from_external_cmd)
  33. unit.onadd_check(['check.external', external])