Skip to content

Conversation

@tux-mind
Copy link

When stripping XCTests, some .framework folders will left empty. Such folders are expected to have a valid framework inside and installing the resultting .ipa will result in errors.

Make sure that any directory that was empties as a result of our stripping process is also deleted.

I've done this in a rush, feel free to improve the code.

When stripping XCTests, some `.framework` folders will left empty.
Such folders are expected to have a valid framework inside and
installing the resultting `.ipa` will result in errors.

Make sure that any directory that was empties as a result of our
stripping process is also deleted.
@tux-mind tux-mind requested review from dki and trufae as code owners November 28, 2025 16:58
removedDirs = new Set<string>();
for (const d of dirsToCheck) {
if (fs.readdirSync(d).length === 0) {
this.emit('message', 'Deleting ' + d);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use “ instead of ‘ (see ci complains)

walk.walkSync(dir, (basedir: string, filename: string, stat: any) => {
const target = path.join(basedir, filename);
// if (target.toLowerCase().indexOf('/xct') !== -1)
if (target.toLowerCase().indexOf("xctest") !== -1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (target.toLowerCase().indexOf("xctest") !== -1) {
if (target.toLowerCase().indexOf(".xctest") !== -1) {

This check is probably safer

dirsToCheck.add(basedir);
}
});
let removedDirs: Set<string> = new Set<string>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s unclear to me the need to define a set of paths, an array should be fine and simpler because you cant have two different paths with the same path

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplify the loop iteration, the filter to remove the element from the set is adding an extra complication that is not necessary.

if (fs.readdirSync(d).length === 0) {
this.emit('message', 'Deleting ' + d);
fs.rmdirSync(d);
removedDirs.add(d);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what i understand this code is deleting empty directories. But if an empty directory is contained within a directory that only had this one it wont be removed, so the removal must happen recursively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants