logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

submodule.py (1827B)


  1. import shutil
  2. from pathlib import Path
  3. from milc import cli
  4. from qmk import submodules
  5. REMOVE_DIRS = [
  6. 'lib/ugfx',
  7. 'lib/chibios-contrib/ext/mcux-sdk',
  8. ]
  9. IGNORE_DIRS = [
  10. 'lib/arm_atsam',
  11. 'lib/fnv',
  12. 'lib/lib8tion',
  13. 'lib/python',
  14. 'lib/usbhost',
  15. ]
  16. @cli.argument('--check', arg_only=True, action='store_true', help='Check if the submodules are dirty, and display a warning if they are.')
  17. @cli.argument('--sync', arg_only=True, action='store_true', help='Shallow clone any missing submodules.')
  18. @cli.argument('-f', '--force', action='store_true', help='Flag to remove unexpected directories')
  19. @cli.subcommand('Git Submodule actions.')
  20. def git_submodule(cli):
  21. """Git Submodule actions
  22. """
  23. if cli.args.check:
  24. return all(item['status'] for item in submodules.status().values())
  25. if cli.args.sync:
  26. cli.run(['git', 'submodule', 'sync', '--recursive'])
  27. for name, item in submodules.status().items():
  28. if item['status'] is None:
  29. cli.run(['git', 'submodule', 'update', '--depth=50', '--init', name], capture_output=False)
  30. return True
  31. # can be the default behavior with: qmk config git_submodule.force=True
  32. remove_dirs = REMOVE_DIRS
  33. if cli.config.git_submodule.force:
  34. # Also trash everything that isnt marked as "safe"
  35. for path in Path('lib').iterdir():
  36. if not any(ignore in path.as_posix() for ignore in IGNORE_DIRS):
  37. remove_dirs.append(path)
  38. for folder in map(Path, remove_dirs):
  39. if folder.is_dir():
  40. print(f"Removing '{folder}'")
  41. shutil.rmtree(folder)
  42. cli.run(['git', 'submodule', 'sync', '--recursive'], capture_output=False)
  43. cli.run(['git', 'submodule', 'update', '--init', '--recursive', '--progress'], capture_output=False)