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.

176 lines
5.3KB

  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. MANIFESTS_DIR = "manifests"
  14. RACK_SYSTEM_DIR = "../Rack2"
  15. RACK_USER_DIR = "$HOME/.Rack2"
  16. SCREENSHOTS_DIR = os.path.join(RACK_USER_DIR, "screenshots")
  17. 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. manifest_versions = {}
  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'^(.*)-(2\..*?)-(.*)$', 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. # Warn if manifest is new
  67. if not os.path.exists(library_manifest_filename):
  68. print(f"Manifest {slug} is new, press enter to approve.")
  69. input()
  70. if os.path.isdir(plugin_path):
  71. # Check if the library manifest is up to date
  72. try:
  73. with open(library_manifest_filename, "r") as f:
  74. library_manifest = json.load(f)
  75. if library_manifest and version == library_manifest['version']:
  76. continue
  77. except IOError:
  78. pass
  79. # Build repo
  80. print()
  81. print(f"Building {slug}")
  82. try:
  83. common.system(f'cd "{TOOLCHAIN_DIR}" && make plugin-build-clean')
  84. common.system(f'cd "{TOOLCHAIN_DIR}" && make -j$(nproc) plugin-build PLUGIN_DIR="{plugin_path}"')
  85. common.system(f'cp -v "{TOOLCHAIN_DIR}"/plugin-build/* "{PACKAGES_DIR}"/')
  86. # Install Linux package for testing
  87. common.system(f'cp -v "{TOOLCHAIN_DIR}"/plugin-build/*-lin-x64.vcvplugin "{PLUGIN_DIR}"/')
  88. except Exception as e:
  89. print(e)
  90. print(f"{slug} build failed")
  91. input()
  92. continue
  93. finally:
  94. common.system(f'cd "{TOOLCHAIN_DIR}" && make plugin-build-clean')
  95. # Open plugin issue thread
  96. os.system(f"xdg-open 'https://github.com/VCVRack/library/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+in%3Atitle+{slug}' &")
  97. elif plugin_ext == ".vcvplugin":
  98. # Review manifest for errors
  99. print(json.dumps(manifest, indent=" "))
  100. print("Press enter to approve manifest")
  101. input()
  102. # Copy package
  103. package_filename = os.path.basename(plugin_path)
  104. common.system(f'cp "{plugin_path}" "{PACKAGES_DIR}/{package_filename}"')
  105. # Update file timestamp
  106. common.system(f'touch "{PACKAGES_DIR}/{package_filename}"')
  107. # Install Linux package for testing
  108. if arch == 'lin' or arch == 'lin-x64':
  109. common.system(f'cp "{plugin_path}" "{PLUGIN_DIR}/{package_filename}"')
  110. # Copy manifest
  111. with open(library_manifest_filename, "w") as f:
  112. json.dump(manifest, f, indent=" ")
  113. # Delete screenshot cache
  114. screenshots_dir = os.path.join(SCREENSHOTS_DIR, slug)
  115. common.system(f'rm -rf "{screenshots_dir}"')
  116. manifest_versions[slug] = version
  117. if not manifest_versions:
  118. print("Nothing to build")
  119. exit(0)
  120. update_cache.update()
  121. update_modulargrid.update()
  122. # Upload data
  123. manifest_versions_str = ", ".join(map(lambda pair: pair[0] + " to " + pair[1], manifest_versions.items()))
  124. print()
  125. print(f"Press enter to launch Rack and test the following packages: {manifest_versions_str}")
  126. input()
  127. try:
  128. common.system(f"cd {RACK_SYSTEM_DIR} && ./Rack")
  129. common.system(f"cd {RACK_USER_DIR} && grep 'warn' log.txt || true")
  130. except:
  131. print(f"Rack failed! Enter to continue if desired")
  132. print(f"Press enter to generate screenshots, upload packages, upload screenshots, and commit/push the library repo.")
  133. input()
  134. # Generate screenshots
  135. common.system(f"cd {RACK_SYSTEM_DIR} && ./Rack -t 4")
  136. # Upload packages
  137. common.system("cd ../packages && make upload")
  138. # Upload screenshots
  139. common.system("cd ../screenshots && make -j$(nproc) upload")
  140. # Commit repository
  141. common.system("git add manifests")
  142. common.system("git add manifests-cache.json ModularGrid-VCVLibrary.json")
  143. common.system(f"git commit -m 'Update manifest {manifest_versions_str}'")
  144. common.system("git push")
  145. print()
  146. print(f"Updated {manifest_versions_str}")