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.

160 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"
  12. PACKAGES_DIR = "../packages"
  13. SCREENSHOTS_DIR = "../screenshots"
  14. MANIFESTS_DIR = "manifests"
  15. RACK_SYSTEM_DIR = "../Rack-v1"
  16. RACK_USER_DIR = "$HOME/.Rack"
  17. RACK_USER_PLUGIN_DIR = os.path.join(RACK_USER_DIR, "plugins-v1")
  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. elif plugin_ext == ".zip":
  43. m = re.match(r'^(.*)-(.*?)-(.*?)$', plugin_basename)
  44. slug = m[1]
  45. version = m[2]
  46. arch = m[3]
  47. # Open ZIP
  48. z = zipfile.ZipFile(plugin_path)
  49. # Unzip manifest
  50. manifest_filename = f"{slug}/plugin.json"
  51. with z.open(manifest_filename) as f:
  52. manifest = json.load(f)
  53. if manifest['slug'] != slug:
  54. raise Exception(f"Manifest slug does not match filename slug {slug}")
  55. if manifest['version'] != version:
  56. raise Exception(f"Manifest slug does not match filename slug {slug}")
  57. else:
  58. raise Exception(f"Plugin {plugin_path} is not a valid format")
  59. # Get library manifest
  60. library_manifest_filename = os.path.join(MANIFESTS_DIR, f"{slug}.json")
  61. if os.path.isdir(plugin_path):
  62. # Check if the library manifest is up to date
  63. try:
  64. with open(library_manifest_filename, "r") as f:
  65. library_manifest = json.load(f)
  66. if library_manifest and version == library_manifest['version']:
  67. continue
  68. except IOError:
  69. pass
  70. # Build repo
  71. print()
  72. print(f"Building {slug}")
  73. try:
  74. common.system(f'cd "{TOOLCHAIN_DIR}" && make plugin-build-clean')
  75. common.system(f'cd "{TOOLCHAIN_DIR}" && make -j$(nproc) plugin-build PLUGIN_DIR={plugin_path}')
  76. common.system(f'cp -vi "{TOOLCHAIN_DIR}"/plugin-build/* "{PACKAGES_DIR}"/')
  77. common.system(f'cp -vi "{TOOLCHAIN_DIR}"/plugin-build/*-lin.zip "{RACK_USER_PLUGIN_DIR}"')
  78. except Exception as e:
  79. print(e)
  80. print(f"{slug} build failed")
  81. input()
  82. continue
  83. finally:
  84. common.system(f'cd "{TOOLCHAIN_DIR}" && make plugin-build-clean')
  85. # Open plugin issue thread
  86. os.system(f"xdg-open 'https://github.com/VCVRack/library/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+in%3Atitle+{slug}' &")
  87. elif plugin_ext == ".zip":
  88. # Review manifest for errors
  89. print(json.dumps(manifest, indent=" "))
  90. print("Press enter to approve manifest")
  91. input()
  92. # Copy package
  93. package_dest = os.path.join(PACKAGES_DIR, os.path.basename(plugin_path))
  94. common.system(f'cp "{plugin_path}" "{package_dest}"')
  95. common.system(f'touch "{package_dest}"')
  96. if arch == 'lin':
  97. common.system(f'cp "{plugin_path}" "{RACK_USER_PLUGIN_DIR}"')
  98. # Copy manifest
  99. with open(library_manifest_filename, "w") as f:
  100. json.dump(manifest, f, indent=" ")
  101. # Delete screenshot cache
  102. screenshots_dir = os.path.join(SCREENSHOTS_DIR, slug)
  103. common.system(f'rm -rf "{screenshots_dir}"')
  104. updated_slugs.add(slug)
  105. if not updated_slugs:
  106. print("Nothing to build")
  107. exit(0)
  108. update_cache.update()
  109. update_modulargrid.update()
  110. # Upload data
  111. built_slugs_str = ", ".join(updated_slugs)
  112. print()
  113. print(f"Press enter to launch Rack and test the following packages: {built_slugs_str}")
  114. input()
  115. common.system(f"cd {RACK_SYSTEM_DIR} && ./Rack")
  116. common.system(f"cd {RACK_USER_DIR} && grep 'warn' log.txt || true")
  117. print(f"Press enter to generate screenshots, upload packages, upload screenshots, and commit/push the library repo.")
  118. input()
  119. # Generate screenshots
  120. common.system(f"cd {RACK_SYSTEM_DIR} && ./Rack -t 2")
  121. # Upload packages
  122. common.system("cd ../packages && make upload")
  123. # Upload screenshots
  124. common.system("cd ../screenshots && make -j$(nproc) upload")
  125. # Commit repository
  126. common.system("git add manifests")
  127. common.system("git add manifests-cache.json ModularGrid-VCVLibrary.json")
  128. common.system(f"git commit -m 'Update manifest for {built_slugs_str}'")
  129. common.system("git push")
  130. print()
  131. print(f"Updated {built_slugs_str}")