Skip to content

Commit a243aa7

Browse files
committed
feat(metadata-generator): Filter according to specified black/white lists
Each text file contains a list of patterns of the form `moduleGlob:symbolGlob`, where `?` and `*` special symbols treated as `any symbol` and `zero or more symbols`. A symbol is whitelisted if it's module name and native name pair matches a pattern in the whitelist, or if a whitelist file is not passed as an argument. All symbols which are not whitelisted or match a pattern in the blacklist are excluded from the global table of metadata symbols. * Update metadata-generator submodule * Add a `blacklist.mdg` file to TestRunner and symlink from the root (because SRCROOT of TestRunner points to the directory of the main CMakeLists.txt) * Add a unit test which checks for the correct filtering of metadata according to the rules in `blacklist.mdg`
1 parent dbfabaf commit a243aa7

5 files changed

Lines changed: 65 additions & 3 deletions

File tree

blacklist.mdg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tests/TestRunner/blacklist.mdg

build/scripts/build-step-metadata-generator.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def map_and_list(func, iterable):
3737
# process environment variables
3838
conf_build_dir = env("CONFIGURATION_BUILD_DIR")
3939
sdk_root = env("SDKROOT")
40+
src_root = env("SRCROOT")
4041
deployment_target_flag_name = env("DEPLOYMENT_TARGET_CLANG_FLAG_NAME")
4142
deployment_target = env(env("DEPLOYMENT_TARGET_CLANG_ENV_NAME"))
4243
std = env("GCC_C_LANGUAGE_STANDARD")
@@ -97,6 +98,14 @@ def generate_metadata(arch):
9798
generator_call.extend(["-output-yaml", current_yaml_output_folder])
9899
print("Generating debug metadata in: \"{}\"".format(current_yaml_output_folder))
99100

101+
whitelist_file_name = os.path.join(src_root, "whitelist.mdg")
102+
if os.path.exists(whitelist_file_name):
103+
generator_call.extend(["--whitelist-modules-file", whitelist_file_name])
104+
105+
blacklist_file_name = os.path.join(src_root, "blacklist.mdg")
106+
if os.path.exists(blacklist_file_name):
107+
generator_call.extend(["--blacklist-modules-file", blacklist_file_name])
108+
100109
# clang arguments
101110
generator_call.extend(["Xclang",
102111
"-isysroot", sdk_root,

tests/TestRunner/app/ApiTests.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,12 +522,12 @@ describe(module.id, function () {
522522
// structures have all members initialized to zero.
523523
expect(arr.count).toBe(0);
524524
});
525-
525+
526526
it("exceptions", function () {
527527
expect(() => __releaseNativeCounterpart(1, 2, 3)).toThrowError(/Actual arguments count: "3". Expected: "1". \(evaluating '__releaseNativeCounterpart\(1, 2, 3\)'\)/);
528528
const getNotANativeWrapperRegex2 = (obj, objParam) => new RegExp(`${obj} is an object which is not a native wrapper. \\(evaluating '__releaseNativeCounterpart\\(${objParam}\\)'\\)`);
529529
const getNotANativeWrapperRegex = obj => getNotANativeWrapperRegex2(obj, JSON.stringify(obj));
530-
530+
531531
expect(() => __releaseNativeCounterpart(0)).toThrowError(getNotANativeWrapperRegex(0));
532532
expect(() => __releaseNativeCounterpart("")).toThrowError(getNotANativeWrapperRegex(""));
533533
expect(() => __releaseNativeCounterpart([])).toThrowError(getNotANativeWrapperRegex2("Array", "\\[\\]"));
@@ -732,6 +732,32 @@ describe(module.id, function () {
732732
}
733733
});
734734

735+
it("Metadata blacklist APIs", function() {
736+
const symbolsRemovedByBlacklisting = {
737+
"HealthKit.HKClinicalType": ["HKClinicalTypeIdentifierAllergyRecord", "HKClinicalTypeIdentifierConditionRecord", "HKClinicalTypeIdentifierImmunizationRecord", "HKClinicalTypeIdentifierLabResultRecord", "HKClinicalTypeIdentifierMedicationRecord", "HKClinicalTypeIdentifierProcedureRecord", "HKClinicalTypeIdentifierVitalSignRecord", "ClinicalType", "HKClinicalType"],
738+
"HealthKit.HKSampleQuery:": ["HKObjectQueryNoLimit", "HKSampleQuery"],
739+
"CloudKit.CKReference:*": ["CKReferenceAction", "CKReferenceActionNone", "CKReferenceActionDeleteSelf", "CKReference"],
740+
"Darwin.POSIX.*:*_info_v*": ["rusage_info_v0", "rusage_info_v1", "rusage_info_v2", "rusage_info_v3", "rusage_info_v4"],
741+
"CoreFoundation.CFCh*:k*SetNe?line": ["kCFCharacterSetNewline"],
742+
};
743+
const symbolsRemainingAfterBlacklisting = {
744+
"Darwin.POSIX.*:*_info_v*": ["task_power_info_v2"],
745+
"CoreFoundation:kCFCharacterSetWhitespaceAndNewline": ["kCFCharacterSetWhitespaceAndNewline"],
746+
};
747+
748+
for (let rule in symbolsRemovedByBlacklisting) {
749+
for (let symbol of symbolsRemovedByBlacklisting[rule]) {
750+
expect(global[symbol]).toBeUndefined(`Rule ${rule} should have removed symbol ${symbol}`);
751+
}
752+
}
753+
754+
for (let rule in symbolsRemainingAfterBlacklisting) {
755+
for (let symbol of symbolsRemainingAfterBlacklisting[rule]) {
756+
expect(global[symbol]).toBeDefined(`Rule ${rule} should have removed symbol ${symbol}`);
757+
}
758+
}
759+
});
760+
735761
// Metal is unavailable on iOS Simulator and devices with processors before A7 (arm64 on iPhone 5s)
736762
if (!isSimulator && interop.sizeof(interop.types.id) == 8) {
737763
it("MetalKit private interface members can be accessed", function() {

tests/TestRunner/blacklist.mdg

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Metadata Generator filtering tests. Strip well-known symbols to perform checks at runtime with TestRunner.
2+
3+
# should exclude everything from HealthKit.HKClinicalType:
4+
# HKClinicalTypeIdentifierAllergyRecord HKClinicalTypeIdentifierConditionRecord
5+
# HKClinicalTypeIdentifierImmunizationRecord HKClinicalTypeIdentifierLabResultRecord
6+
# HKClinicalTypeIdentifierMedicationRecord HKClinicalTypeIdentifierProcedureRecord
7+
# HKClinicalTypeIdentifierVitalSignRecord ClinicalType HKClinicalType
8+
HealthKit.HKClinicalType
9+
10+
# should exclude everything from HealthKit.HKSampleQuery:
11+
# HKObjectQueryNoLimit HKSampleQuery
12+
HealthKit.HKSampleQuery:
13+
14+
# should exclude everything from CloudKit.CKReference
15+
# CKReferenceAction CKReferenceActionNone CKReferenceActionDeleteSelf CKReference
16+
CloudKit.CKReference:*
17+
18+
# should exclude rusage_info_v0 to _v4 from Darwin.POSIX.sys.resource
19+
# but should leave task_power_info_v2 from Darwin.Mach.task_info
20+
Darwin.POSIX.*:*_info_v*
21+
22+
# should exclude kCFCharacterSetNewline from CoreFoundation.CFCharacterSet
23+
CoreFoundation.CFCh*:k*SetNe?line
24+
25+
# shouldn't exclude kCFCharacterSetWhitespaceAndNewline because it resides in the CoreFoundation.CFCharacterSet submodule
26+
CoreFoundation:kCFCharacterSetWhitespaceAndNewline

0 commit comments

Comments
 (0)