validate_package.py 4.9 KB

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