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

Draft
wants to merge 12 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 (ln -s)
  • Adds WindowsMklink dir for validating windows symlink (mklink)

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

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
├── WindowsMklink
│   ├── SymlinkedDir -> Test
│   └── Test
│       └── test.txt
└── 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.

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