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.

165 lines
4.8KB

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