large_files.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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(src, src, PLACEHOLDER_EXT)
  22. unit.message(["warn", msg])
  23. unit.oncopy_file([arg, arg])
  24. else:
  25. out_file = strip_roots(os.path.join(unit.path(), arg))
  26. external = "{}.{}".format(arg, PLACEHOLDER_EXT)
  27. from_external_cmd = [external, out_file, 'OUT_NOAUTO', arg]
  28. if os.path.dirname(arg):
  29. from_external_cmd.extend(("RENAME", os.path.basename(arg)))
  30. unit.on_from_external(from_external_cmd)
  31. unit.onadd_check(['check.external', external])