validate_package.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. """Validate the package layout and migration constraints without opening Unity."""
  2. import json
  3. from pathlib import Path
  4. import re
  5. import sys
  6. import xml.etree.ElementTree as ET
  7. PACKAGE = Path(__file__).resolve().parents[1]
  8. errors = []
  9. def check(condition, message):
  10. if not condition:
  11. errors.append(message)
  12. def visible(path):
  13. return not any(p.startswith('.') or p.endswith('~') for p in path.relative_to(PACKAGE).parts)
  14. manifest = json.loads((PACKAGE / 'package.json').read_text(encoding='utf-8-sig'))
  15. check(manifest['name'] == 'come.app.runtimes', 'Unexpected technical name')
  16. check(manifest['displayName'] == 'AppRuntimes', 'Unexpected display name')
  17. for name, version in manifest['dependencies'].items():
  18. check(re.fullmatch(r'\d+\.\d+\.\d+(?:-[\w.-]+)?', version), f'Non-registry dependency: {name}')
  19. check('com.unity.inputsystem' not in manifest['dependencies'], 'Input System must remain optional')
  20. check('com.unity.modules.androidjni' in manifest['dependencies'], 'Android JNI support missing')
  21. for sample in manifest.get('samples', []):
  22. check((PACKAGE / sample['path']).is_dir(), f'Missing sample: {sample["path"]}')
  23. guids = {}
  24. for meta in PACKAGE.rglob('*.meta'):
  25. if not visible(meta):
  26. continue
  27. match = re.search(r'^guid: ([0-9a-f]{32})$', meta.read_text(encoding='utf-8-sig'), re.M)
  28. check(match is not None, f'Invalid meta: {meta.relative_to(PACKAGE)}')
  29. if match:
  30. check(match[1] not in guids, f'Duplicate GUID: {meta} / {guids.get(match[1])}')
  31. guids[match[1]] = meta
  32. check(meta.with_suffix('').exists(), f'Orphan meta: {meta.relative_to(PACKAGE)}')
  33. definitions = {}
  34. names = set()
  35. for path in PACKAGE.rglob('*.asmdef'):
  36. if not visible(path):
  37. continue
  38. definition = json.loads(path.read_text(encoding='utf-8-sig'))
  39. name = definition['name']
  40. check(name not in names, f'Duplicate assembly: {name}')
  41. names.add(name)
  42. definitions[path.parent] = definition
  43. check(path.with_name(path.name + '.meta').exists(), f'Missing assembly meta: {path}')
  44. check('dotween' not in json.dumps(definition).lower(), f'DOTween reference: {path}')
  45. if name == 'AppRuntimes':
  46. check(not definition.get('includePlatforms') and not definition.get('excludePlatforms'), 'Runtime platforms restricted')
  47. scripts = [p for p in PACKAGE.rglob('*.cs') if visible(p)]
  48. for script in scripts:
  49. parent = script.parent
  50. while parent != PACKAGE and parent not in definitions:
  51. parent = parent.parent
  52. check(parent in definitions, f'Script outside an assembly: {script.relative_to(PACKAGE)}')
  53. if parent in definitions and 'Editor' in script.relative_to(PACKAGE).parts:
  54. check(definitions[parent].get('includePlatforms') == ['Editor'], f'Editor code in runtime assembly: {script}')
  55. check(script.with_name(script.name + '.meta').exists(), f'Missing script metadata: {script}')
  56. for forbidden in ('DOTweenSettings.asset', 'DOTween.dll', 'AndroidManifest.xml'):
  57. check(not any(visible(p) for p in PACKAGE.rglob(forbidden)), f'Project-specific or removed content shipped: {forbidden}')
  58. for filename in ('AppSettings.asset', 'FacebookSettings.asset', 'settings.asset'):
  59. expected = PACKAGE / 'Editor' / 'DefaultSettings' / filename
  60. check(expected.is_file(), f'Missing default settings template: {filename}')
  61. check(expected.with_name(filename + '.meta').is_file(), f'Missing default settings metadata: {filename}')
  62. check(all(p == expected for p in PACKAGE.rglob(filename) if visible(p)),
  63. f'Settings must only ship as Editor templates: {filename}')
  64. check(len(list(PACKAGE.rglob('package.json'))) == 1, 'Nested package manifest found')
  65. for relative in (
  66. 'ThirdParty/FacebookSDK/Plugins/Android/Facebook.Unity.Android.dll',
  67. 'ThirdParty/FacebookSDK/Plugins/Editor/Dependencies.xml',
  68. 'ThirdParty/ExternalDependencyManager/Editor/1.2.187/Google.JarResolver.dll',
  69. 'ThirdParty/ExternalDependencyManager/Editor/1.2.187/Google.IOSResolver.dll',
  70. 'ThirdParty/UniWebView/Plugins/Android/UniWebView.aar',
  71. 'ThirdParty/UniWebView/Plugins/iOS/UniWebView.xcframework/Info.plist',
  72. 'ThirdParty/UniWebView/Plugins/macOS/UniWebView.bundle/Contents/Info.plist',
  73. 'ThirdParty/UniTask/LICENSE.md', 'Runtime/Resources/Loading.prefab',
  74. 'Runtime/IAP/IAPWrapper.cs', 'Runtime/IAP/IAPAndroidImpl.cs',
  75. 'ThirdParty/IAPiOS/IAP/Editor/iOS/IAPUnityInterface.mm',
  76. 'ThirdParty/IAPiOS/IAP/Editor/iOS/IAPSK1.mm',
  77. 'ThirdParty/IAPiOS/IAP/Editor/iOS/Swift/IAPSK2.swift',
  78. 'ThirdParty/IAPiOS/IAP/Editor/iOS/FBSDKUnityStoreKit.storekit',
  79. 'StreamingAssets~/meta.mp4', 'StreamingAssets~/meta-logo.png'
  80. ):
  81. check((PACKAGE / relative).is_file(), f'Missing dependency/resource: {relative}')
  82. for relative in ('ThirdParty/FacebookSDK/link.xml', 'ThirdParty/UniWebView/link.xml'):
  83. check(ET.parse(PACKAGE / relative).getroot().tag == 'linker', f'Invalid linker file: {relative}')
  84. if errors:
  85. print('\n'.join('ERROR: ' + error for error in errors))
  86. sys.exit(1)
  87. print(f'PASS: {manifest["name"]}; {len(names)} assemblies, {len(scripts)} scripts, {len(guids)} GUIDs')