You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
4.6KB

  1. import sys
  2. import os
  3. import glob
  4. import json
  5. import time
  6. import zipfile
  7. import re
  8. import common
  9. import update_modulargrid
  10. import update_cache
  11. TOOLCHAIN_DIR = "../toolchain-v2"
  12. PACKAGES_DIR = "../packages"
  13. SCREENSHOTS_DIR = "../screenshots"
  14. MANIFESTS_DIR = "manifests"
  15. RACK_SYSTEM_DIR = "../Rack-v2"
  16. RACK_USER_DIR = "$HOME/.Rack2"
  17. RACK_USER_PLUGIN_DIR = os.path.join(RACK_USER_DIR, "plugins")
  18. # Update git before continuing
  19. common.system("git pull")
  20. common.system("git submodule sync --quiet")
  21. common.system("git submodule update --init --recursive")
  22. plugin_paths = sys.argv[1:]
  23. # Default to all repos, so all out-of-date repos are built
  24. if not plugin_paths:
  25. plugin_paths = glob.glob("repos/*")
  26. updated_slugs = set()
  27. for plugin_path in plugin_paths:
  28. plugin_path = os.path.abspath(plugin_path)
  29. (plugin_basename, plugin_ext) = os.path.splitext(os.path.basename(plugin_path))
  30. # Extract manifest from plugin dir or package
  31. if os.path.isdir(plugin_path):
  32. manifest_filename = os.path.join(plugin_path, "plugin.json")
  33. try:
  34. # Read manifest
  35. with open(manifest_filename, "r") as f:
  36. manifest = json.load(f)
  37. except IOError:
  38. # Skip plugins without plugin.json
  39. continue
  40. slug = manifest['slug']
  41. version = manifest['version']
  42. # TODO Extract manifest from .vcvplugin
  43. elif plugin_ext == ".zip":
  44. m = re.match(r'^(.*)-(.*?)-(.*?)$', plugin_basename)
  45. slug = m[1]
  46. version = m[2]
  47. arch = m[3]
  48. # Open ZIP
  49. z = zipfile.ZipFile(plugin_path)
  50. # Unzip manifest
  51. manifest_filename = f"{slug}/plugin.json"
  52. with z.open(manifest_filename) as f:
  53. manifest = json.load(f)
  54. if manifest['slug'] != slug:
  55. raise Exception(f"Manifest slug does not match filename slug {slug}")
  56. if manifest['version'] != version:
  57. raise Exception(f"Manifest slug does not match filename slug {slug}")
  58. else:
  59. raise Exception(f"Plugin {plugin_path} is not a valid format")
  60. # Get library manifest
  61. library_manifest_filename = os.path.join(MANIFESTS_DIR, f"{slug}.json")
  62. if os.path.isdir(plugin_path):
  63. # Check if the library manifest is up to date
  64. try:
  65. with open(library_manifest_filename, "r") as f:
  66. library_manifest = json.load(f)
  67. if library_manifest and version == library_manifest['version']:
  68. continue
  69. except IOError:
  70. pass
  71. # Build repo
  72. print()
  73. print(f"Building {slug}")
  74. try:
  75. common.system(f'cd "{TOOLCHAIN_DIR}" && make plugin-build-clean')
  76. common.system(f'cd "{TOOLCHAIN_DIR}" && make -j$(nproc) plugin-build PLUGIN_DIR={plugin_path}')
  77. common.system(f'cp -vi "{TOOLCHAIN_DIR}"/plugin-build/* "{PACKAGES_DIR}"/')
  78. common.system(f'cp -vi "{TOOLCHAIN_DIR}"/plugin-build/*-lin.vcvplugin "{RACK_USER_PLUGIN_DIR}"')
  79. except Exception as e:
  80. print(e)
  81. print(f"{slug} build failed")
  82. input()
  83. continue
  84. finally:
  85. common.system(f'cd "{TOOLCHAIN_DIR}" && make plugin-build-clean')
  86. # Open plugin issue thread
  87. os.system(f"xdg-open 'https://github.com/VCVRack/library/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+in%3Atitle+{slug}' &")
  88. elif plugin_ext == ".zip":
  89. # Review manifest for errors
  90. print(json.dumps(manifest, indent=" "))
  91. print("Press enter to approve manifest")
  92. input()
  93. # Copy package
  94. package_dest = os.path.join(PACKAGES_DIR, os.path.basename(plugin_path))
  95. common.system(f'cp "{plugin_path}" "{package_dest}"')
  96. common.system(f'touch "{package_dest}"')
  97. if arch == 'lin':
  98. common.system(f'cp "{plugin_path}" "{RACK_USER_PLUGIN_DIR}"')
  99. # Copy manifest
  100. with open(library_manifest_filename, "w") as f:
  101. json.dump(manifest, f, indent=" ")
  102. # Delete screenshot cache
  103. screenshots_dir = os.path.join(SCREENSHOTS_DIR, slug)
  104. common.system(f'rm -rf "{screenshots_dir}"')
  105. updated_slugs.add(slug)
  106. if not updated_slugs:
  107. print("Nothing to build")
  108. exit(0)
  109. update_cache.update()
  110. update_modulargrid.update()
  111. # Upload data
  112. built_slugs_str = ", ".join(updated_slugs)
  113. print()
  114. print(f"Press enter to launch Rack and test the following packages: {built_slugs_str}")
  115. input()
  116. common.system(f"cd {RACK_SYSTEM_DIR} && ./Rack")
  117. common.system(f"cd {RACK_USER_DIR} && grep 'warn' log.txt || true")
  118. print(f"Press enter to generate screenshots, upload packages, upload screenshots, and commit/push the library repo.")
  119. input()
  120. # Generate screenshots
  121. common.system(f"cd {RACK_SYSTEM_DIR} && ./Rack -t 2")
  122. # Upload packages
  123. common.system("cd ../packages && make upload")
  124. # Upload screenshots
  125. common.system("cd ../screenshots && make -j$(nproc) upload")
  126. # Commit repository
  127. common.system("git add manifests")
  128. common.system("git add manifests-cache.json ModularGrid-VCVLibrary.json")
  129. common.system(f"git commit -m 'Update manifest for {built_slugs_str}'")
  130. common.system("git push")
  131. print()
  132. print(f"Updated {built_slugs_str}")