Skip to content

Commit

Permalink
RUMM-1744 Define separate validators for each XCFramework
Browse files Browse the repository at this point in the history
  • Loading branch information
ncreated committed Jan 3, 2022
1 parent c6a9c08 commit f40de15
Showing 1 changed file with 142 additions and 66 deletions.
208 changes: 142 additions & 66 deletions tools/distribution/src/assets/gh_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,134 @@
from tempfile import TemporaryDirectory, NamedTemporaryFile
from src.utils import remember_cwd, shell, read_sdk_version
from src.directory_matcher import DirectoryMatcher
from src.semver import Version


class XCFrameworkValidator:
name: str

def should_be_included(self, in_version: Version) -> bool:
pass

def validate(self, zip_directory: DirectoryMatcher):
pass


class DatadogXCFrameworkValidator(XCFrameworkValidator):
name = 'Datadog.xcframework'

def should_be_included(self, in_version: Version):
return True # always expect `Datadog.xcframework`

def validate(self, zip_directory: DirectoryMatcher):
zip_directory.get('Datadog.xcframework').assert_it_has_files([
'ios-arm64',
'ios-arm64/BCSymbolMaps/*.bcsymbolmap',
'ios-arm64/dSYMs/*.dSYM',
'ios-arm64/**/arm64.swiftinterface',
'ios-arm64/**/arm64-apple-ios.swiftinterface',

'ios-arm64_x86_64-simulator',
'ios-arm64_x86_64-simulator/dSYMs/*.dSYM',
'ios-arm64_x86_64-simulator/**/arm64.swiftinterface',
'ios-arm64_x86_64-simulator/**/arm64-apple-ios-simulator.swiftinterface',
'ios-arm64_x86_64-simulator/**/x86_64.swiftinterface',
'ios-arm64_x86_64-simulator/**/x86_64-apple-ios-simulator.swiftinterface',
])


class DatadogObjcXCFrameworkValidator(XCFrameworkValidator):
name = 'DatadogObjc.xcframework'

def should_be_included(self, in_version: Version):
return True # always expect `DatadogObjc.xcframework`

def validate(self, zip_directory: DirectoryMatcher):
zip_directory.get('DatadogObjc.xcframework').assert_it_has_files([
'ios-arm64',
'ios-arm64/BCSymbolMaps/*.bcsymbolmap',
'ios-arm64/dSYMs/*.dSYM',
'ios-arm64/**/arm64.swiftinterface',
'ios-arm64/**/arm64-apple-ios.swiftinterface',

'ios-arm64_x86_64-simulator',
'ios-arm64_x86_64-simulator/**/arm64.swiftinterface',
'ios-arm64_x86_64-simulator/**/arm64-apple-ios-simulator.swiftinterface',
'ios-arm64_x86_64-simulator/**/x86_64.swiftinterface',
'ios-arm64_x86_64-simulator/**/x86_64-apple-ios-simulator.swiftinterface',
])


class DatadogCrashReportingXCFrameworkValidator(XCFrameworkValidator):
name = 'DatadogCrashReporting.xcframework'

def should_be_included(self, in_version: Version):
min_version = Version.parse('1.7.0') # Datadog Crash Reporting.xcframework was introduced in `1.7.0`
return in_version.is_newer_than_or_equal(min_version)

def validate(self, zip_directory: DirectoryMatcher):
zip_directory.get('DatadogCrashReporting.xcframework').assert_it_has_files([
'ios-arm64',
'ios-arm64/BCSymbolMaps/*.bcsymbolmap',
'ios-arm64/**/arm64.swiftinterface',
'ios-arm64/**/arm64-apple-ios.swiftinterface',

'ios-x86_64-simulator',
'ios-x86_64-simulator/dSYMs/*.dSYM',
'ios-x86_64-simulator/**/x86_64.swiftinterface',
'ios-x86_64-simulator/**/x86_64-apple-ios-simulator.swiftinterface',
])


class CrashReporterXCFrameworkValidator(XCFrameworkValidator):
name = 'CrashReporter.xcframework'

def should_be_included(self, in_version: Version):
min_version = Version.parse('1.7.0') # Datadog Crash Reporting.xcframework was introduced in `1.7.0`
return in_version.is_newer_than_or_equal(min_version)

def validate(self, zip_directory: DirectoryMatcher):
zip_directory.get('CrashReporter.xcframework').assert_it_has_files([
'ios-arm64_arm64e_armv7_armv7s',
'ios-arm64_i386_x86_64-simulator',
])


class KronosXCFrameworkValidator(XCFrameworkValidator):
name = 'Kronos.xcframework'

def should_be_included(self, in_version: Version):
min_version = Version.parse('1.5.0') # First version that depends on Kronos
max_version = Version.parse('1.8.99') # Last version that depends on Kronos
return in_version.is_newer_than_or_equal(min_version) and max_version.is_newer_than_or_equal(in_version)

def validate(self, zip_directory: DirectoryMatcher):
zip_directory.get('Kronos.xcframework').assert_it_has_files([
'ios-arm64_armv7',
'ios-arm64_armv7/BCSymbolMaps/*.bcsymbolmap',
'ios-arm64_armv7/dSYMs/*.dSYM',
'ios-arm64_armv7/**/arm.swiftinterface',
'ios-arm64_armv7/**/arm64-apple-ios.swiftinterface',
'ios-arm64_armv7/**/arm64.swiftinterface',
'ios-arm64_armv7/**/armv7-apple-ios.swiftinterface',
'ios-arm64_armv7/**/armv7.swiftinterface',

'ios-arm64_i386_x86_64-simulator',
'ios-arm64_i386_x86_64-simulator/dSYMs/*.dSYM',
'ios-arm64_i386_x86_64-simulator/**/arm64-apple-ios-simulator.swiftinterface',
'ios-arm64_i386_x86_64-simulator/**/i386-apple-ios-simulator.swiftinterface',
'ios-arm64_i386_x86_64-simulator/**/x86_64-apple-ios-simulator.swiftinterface',
'ios-arm64_i386_x86_64-simulator/**/x86_64.swiftinterface',
])


xcframeworks_validators: [XCFrameworkValidator] = [
DatadogXCFrameworkValidator(),
DatadogObjcXCFrameworkValidator(),
DatadogCrashReportingXCFrameworkValidator(),
CrashReporterXCFrameworkValidator(),
KronosXCFrameworkValidator(),
]


class GHAsset:
Expand Down Expand Up @@ -48,7 +176,7 @@ def __init__(self):
def __repr__(self):
return f'[GHAsset: path = {self.__path}]'

def validate(self, git_tag: str):
def validate(self, git_tag: str): # 1.5.0
"""
Checks the `.zip` archive integrity with given `git_tag`.
"""
Expand All @@ -69,71 +197,19 @@ def validate(self, git_tag: str):
print(f' - {file_path.removeprefix(unzip_dir)}')

dm = DirectoryMatcher(path=unzip_dir)
dm.assert_number_of_files(expected_count=5)

dm.get(file='Datadog.xcframework').assert_it_has_files([
'ios-arm64',
'ios-arm64/BCSymbolMaps/*.bcsymbolmap',
'ios-arm64/dSYMs/*.dSYM',
'ios-arm64/**/arm64.swiftinterface',
'ios-arm64/**/arm64-apple-ios.swiftinterface',

'ios-arm64_x86_64-simulator',
'ios-arm64_x86_64-simulator/dSYMs/*.dSYM',
'ios-arm64_x86_64-simulator/**/arm64.swiftinterface',
'ios-arm64_x86_64-simulator/**/arm64-apple-ios-simulator.swiftinterface',
'ios-arm64_x86_64-simulator/**/x86_64.swiftinterface',
'ios-arm64_x86_64-simulator/**/x86_64-apple-ios-simulator.swiftinterface',
])

dm.get('DatadogObjc.xcframework').assert_it_has_files([
'ios-arm64',
'ios-arm64/BCSymbolMaps/*.bcsymbolmap',
'ios-arm64/dSYMs/*.dSYM',
'ios-arm64/**/arm64.swiftinterface',
'ios-arm64/**/arm64-apple-ios.swiftinterface',

'ios-arm64_x86_64-simulator',
'ios-arm64_x86_64-simulator/**/arm64.swiftinterface',
'ios-arm64_x86_64-simulator/**/arm64-apple-ios-simulator.swiftinterface',
'ios-arm64_x86_64-simulator/**/x86_64.swiftinterface',
'ios-arm64_x86_64-simulator/**/x86_64-apple-ios-simulator.swiftinterface',
])

dm.get('DatadogCrashReporting.xcframework').assert_it_has_files([
'ios-arm64',
'ios-arm64/BCSymbolMaps/*.bcsymbolmap',
'ios-arm64/**/arm64.swiftinterface',
'ios-arm64/**/arm64-apple-ios.swiftinterface',

'ios-x86_64-simulator',
'ios-x86_64-simulator/dSYMs/*.dSYM',
'ios-x86_64-simulator/**/x86_64.swiftinterface',
'ios-x86_64-simulator/**/x86_64-apple-ios-simulator.swiftinterface',
])

dm.get('CrashReporter.xcframework').assert_it_has_files([
'ios-arm64_arm64e_armv7_armv7s',
'ios-arm64_i386_x86_64-simulator',
])

dm.get('Kronos.xcframework').assert_it_has_files([
'ios-arm64_armv7',
'ios-arm64_armv7/BCSymbolMaps/*.bcsymbolmap',
'ios-arm64_armv7/dSYMs/*.dSYM',
'ios-arm64_armv7/**/arm.swiftinterface',
'ios-arm64_armv7/**/arm64-apple-ios.swiftinterface',
'ios-arm64_armv7/**/arm64.swiftinterface',
'ios-arm64_armv7/**/armv7-apple-ios.swiftinterface',
'ios-arm64_armv7/**/armv7.swiftinterface',

'ios-arm64_i386_x86_64-simulator',
'ios-arm64_i386_x86_64-simulator/dSYMs/*.dSYM',
'ios-arm64_i386_x86_64-simulator/**/arm64-apple-ios-simulator.swiftinterface',
'ios-arm64_i386_x86_64-simulator/**/i386-apple-ios-simulator.swiftinterface',
'ios-arm64_i386_x86_64-simulator/**/x86_64-apple-ios-simulator.swiftinterface',
'ios-arm64_i386_x86_64-simulator/**/x86_64.swiftinterface',
])
this_version = Version.parse(git_tag)

print(f' → Validating each `XCFramework`:')
validated_count = 0
for validator in xcframeworks_validators:
if validator.should_be_included(in_version=this_version):
validator.validate(zip_directory=dm)
print(f' → {validator.name} - OK')
validated_count += 1
else:
print(f' → {validator.name} - SKIPPING for {this_version}')

dm.assert_number_of_files(expected_count=validated_count) # assert there are no other files

print(f' → the content of `.zip` archive is correct')

Expand Down

0 comments on commit f40de15

Please sign in to comment.