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: Prevent conflict between parallel makers #3519

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

Conversation

macdja38
Copy link
Contributor

At the moment maker-dmg will simultaneously try to write to out/make/AppName.dmg. This commit changes that to out/make-darwin-arm64/AppName.dmg preventing any conflicts

  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project follows, as appropriate.
  • The changes are appropriately documented (if applicable).
  • The changes have sufficient test coverage (if applicable).
  • The testsuite passes successfully on my local machine (if applicable).

Summarize your changes:
at the moment maker-dmg fails when run in parallel, for an explanation on why / how / the details see here: #3517

This solution:
We pass a different path into the maker from core for each platform & arch combination, which prevents it from trying to use the same file in an intermediary step.

Downsides:
People might rely on the location of the dmg & zip to be in out/make directly, this would obviously ruin that.

Alternatives considered:
Potentially it would be possible to get maker-dmg to generate a DMG with the required name from the start instead of always generating it with name.dmg and then renaming to name-version-arch.dmg.

code for context maker-dmg/src/MakerDMG.ts

    await this.ensureFile(outPath);
    const dmgConfig = {
      overwrite: true,
      name: appName,
      ...this.config,
      appPath: path.resolve(dir, `${appName}.app`),
      out: path.dirname(outPath),
    };
    const opts = await electronDMG(dmgConfig);
    if (!this.config.name) {
      await this.ensureFile(forgeDefaultOutPath);
      await fs.rename(outPath, forgeDefaultOutPath);
      return [forgeDefaultOutPath];
    }

    return [opts.dmgPath];
    ```

At the moment maker-dmg will simultaneously try to write to `out/make/AppName.dmg`. This commit changes that to `out/make-darwin-arm64/AppName.dmg` preventing any conflicts
@macdja38 macdja38 requested a review from a team as a code owner February 29, 2024 20:23
Copy link
Member

@MarshallOfSound MarshallOfSound left a comment

Choose a reason for hiding this comment

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

This is a pretty rough breaking change and IMO not how we want to fix this.

Potentially it would be possible to get maker-dmg to generate a DMG with the required name from the start instead of always generating it with name.dmg and then renaming to name-version-arch.dmg.

This sounds more reasonable

@erickzhao
Copy link
Member

Someone asked me about this on Discord last week and I agree with the above. As you stated in the downsides section in the description, I think this too likely to catch people off-guard.

@macdja38
Copy link
Contributor Author

macdja38 commented Mar 6, 2024

@MarshallOfSound the fallback I mentioned won't work if the user supplies a name via config (though the may have been broken for a long time when building for multiple arches, not sure).

For now I think it's out of scope of this PR to fix that, but I'll leave that up to you.
I'm thinking ideally we'd allow passing a function or string for the name instead of just a string.

current:

{
  name: "@electron-forge/maker-dmg",
  config: {
    name: "AppName",
    overwrite: true,
  },
  platforms: ["darwin"],
},

(this would break because we can't write two AppName.dmg to the same out/make folders. I believe this would have broken before this PR and before 7.0 as well though)

Proposed ability to pass function

{
  name: "@electron-forge/maker-dmg",
  config: {
    name: (version: string, platform: string, arch: string) => `AppName-${arch}-${platform}`,
    overwrite: true,
  },
  platforms: ["darwin"],
}

(idk if we'd want version or not, the user can get that themselves)

@macdja38
Copy link
Contributor Author

macdja38 commented Mar 7, 2024

Updated the PR, also removed the two tests that tested renaming as we don't need to rename anymore.

@macdja38
Copy link
Contributor Author

@MarshallOfSound is there any chance you could take another look?

@macdja38
Copy link
Contributor Author

macdja38 commented May 7, 2024

Updated to resolve merge conflicts

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.

None yet

3 participants