Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Respect unpack minimatch for symlinks within previously unpacked directories #341

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

mmaietta
Copy link
Contributor

@mmaietta mmaietta commented Nov 12, 2024

Summary:
Fixes issue with unpack configuration when considering symlinks within previously unpacked directories. This directly fixes unpacking static .framework modules on Mac, as otherwise codesigning will fail due to symlink files/directories not being reflected in the app.asar.unpacked directory.

Fix:

  • Tracks all symlinks in a list (similar as files) as to what are supposed to be unpacked.
  • Adds unpacked flag as node.unpacked=true
  • Extracts common logic for detecting if a path is unpacked
  • Added promisified symlink and readlink
  • Adds Hello.framework for mac/linux symlink verification

Added unit test with Hello.framework, generated from HelloWorld tutorial https://jano.dev/apple/mach-o/2024/06/28/Hello-Static-Framework.html

Note: This implementation is isolated to mac/linux. It seems symlinks created on Windows (mklink) do not get properly committed to git, they seem to be committed as an actual file and I couldn't figure out why

Details:
.framework has to have all symlinks reproduced in the unpacked directory for signing. The top is with electron/asar unpacked folder, the bottom is the actual framework contents.
Screenshot 2024-11-11 at 4 28 35 PM

Without this PR, codesigning will fail with QtCore.framework: bundle format unrecognized, invalid, or unsuitable

  • signing         file=dist/mac/SanitizedAppName.app platform=darwin type=distribution identity=<SanitizedIdentity> provisioningProfile=none
  ⨯ Command failed: codesign --sign <SanitizedIdentity> --force --timestamp --options runtime --entitlements ./build/entitlements.mac.plist /Users/<project-folder>/dist/mac/SanitizedAppName.app/Contents/Resources/app.asar.unpacked/node_modules/<sanitized-dep-name>/lib/Release/QtCore.framework
/Users/<project-folder>/dist/mac/SanitizedAppName.app/Contents/Resources/app.asar.unpacked/node_modules/<sanitized-dep-name>/lib/Release/QtCore.framework: bundle format unrecognized, invalid, or unsuitable
~/D/asar> tree test/input/packthis-with-symlink                                   fix/static-framework-symlinks-2!
test/input/packthis-with-symlink
├── A
│   └── real.txt
├── Current -> A
├── Hello.framework
│   ├── Headers -> Versions/Current/Headers
│   ├── Hello -> Versions/Current/Hello
│   ├── Info.plist -> Versions/Current/Info.plist
│   ├── Modules -> Versions/Current/Modules
│   └── Versions
│       ├── A
│       │   ├── Headers
│       │   │   └── HelloFramework.h
│       │   ├── Hello
│       │   ├── Info.plist
│       │   ├── Modules
│       │   │   ├── Hello.abi.json
│       │   │   ├── Hello.swiftdoc
│       │   │   ├── Hello.swiftmodule
│       │   │   │   ├── arm64.private.swiftinterface
│       │   │   │   ├── arm64.swiftinterface
│       │   │   │   ├── arm64.swiftmodule
│       │   │   │   ├── x86_64.private.swiftinterface
│       │   │   │   ├── x86_64.swiftinterface
│       │   │   │   └── x86_64.swiftmodule
│       │   │   ├── Hello.swiftsourceinfo
│       │   │   └── module.modulemap
│       │   └── Resources
│       └── Current -> A
└── real.txt -> Current/real.txt

16 directories, 18 files

Fixes: electron-userland/electron-builder#8655 (comment)

mmaietta and others added 7 commits November 10, 2024 17:47
… previously unpacked directories. This directly fixes unpacking static `.framework` modules on Mac, as otherwise codesigning will fail due to symlink files/directories not being reflected in the app.asar.unpacked directory.

Added unit test with Hello.framework, generated from tutorial https://jano.dev/apple/mach-o/2024/06/28/Hello-Static-Framework.html
Fixes: electron-userland/electron-builder#8655
change readlinkSync to realpathSync for windows OS
@mmaietta mmaietta force-pushed the fix/static-framework-symlinks-2 branch from b98871b to 888ef4f Compare November 13, 2024 21:37
const link = await fs.readlink(file.filename);
await fs.symlink(link, path.join(`${dest}.unpacked`, filename)).catch(async (error) => {
if (error.code === 'EPERM' && error.syscall === 'symlink') {
throw new Error(

Choose a reason for hiding this comment

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

On Windows, using junction to create symlinks should avoid permission issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great callout. I read somewhere (can't find the link atm) that junctions are absolute links, as opposed to a "pointer" relative path. If so, we don't want absolute links between folders in the unpacked folder, otherwise I don't think the asar will work on other computers.

test/cli-spec.js Outdated
.endsWith('tmp/packthis-with-symlink.asar.unpacked/Hello.framework/Versions/A/Headers'),
);
} else {
assert.ok(

Choose a reason for hiding this comment

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

After git cloning on Windows, SymlinkedDir is not a symlink but rather a regular file. I suggest only testing this on macOS/Linux. No need to test on Windows since you're not handling symlink in window.

https://github.com/mmaietta/asar/blob/1676a0ea070967f818167164be5bf7d0e378fb41/src/disk.ts#L65-L68

@mmaietta mmaietta marked this pull request as ready for review December 13, 2024 19:08
@mmaietta mmaietta requested a review from a team as a code owner December 13, 2024 19:08
@mmaietta mmaietta changed the title Fix: Respect unpack minimatch for symlinks within previously unpacked directories fix: Respect unpack minimatch for symlinks within previously unpacked directories Dec 14, 2024
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.

electron builder v26.0.0-alpha.2 fails to copy native deps with sym links
2 participants