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

How to debug & log NSIS #5119

Closed
gajop opened this issue Jul 3, 2020 · 20 comments · Fixed by #6024
Closed

How to debug & log NSIS #5119

gajop opened this issue Jul 3, 2020 · 20 comments · Fixed by #6024

Comments

@gajop
Copy link

gajop commented Jul 3, 2020

#4712
Fighting the stale bot.

@stale
Copy link

stale bot commented Sep 2, 2020

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the backlog label Sep 2, 2020
@gajop
Copy link
Author

gajop commented Sep 2, 2020

Still relevant, still an annoying bot.

@stale stale bot removed the backlog label Sep 2, 2020
@stale
Copy link

stale bot commented Nov 2, 2020

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the backlog label Nov 2, 2020
@gajop
Copy link
Author

gajop commented Nov 3, 2020

Still relevant, still an annoying bot.

@stale stale bot removed the backlog label Nov 3, 2020
@stale
Copy link

stale bot commented Jan 2, 2021

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the backlog label Jan 2, 2021
@gajop
Copy link
Author

gajop commented Jan 2, 2021

Still relevant, Happy NY

@stale stale bot removed the backlog label Jan 2, 2021
@stale
Copy link

stale bot commented Mar 20, 2021

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the backlog label Mar 20, 2021
@gajop
Copy link
Author

gajop commented Mar 21, 2021

Hey

@ejwilburn
Copy link

I've successfully enabled logging for NSIS with electron builder with these steps:

  1. Download the NSIS build with logging enabled from https://sourceforge.net/projects/nsis/files/NSIS%203/. For elecron-builder 22.10.5 it's this file: https://sourceforge.net/projects/nsis/files/NSIS%203/3.04/nsis-3.04-log.zip/download
  2. Extract that file into %LOCALAPPDATA%\electron-builder\cache\nsis\nsis-3.0.4.1 overwriting what's there.
  3. Add a custom NSIS script per the electron-builder docs and include these two macros:
!macro preInit
  Push $INSTDIR
  StrCpy $INSTDIR "C:\logdir\"
  LogSet On
  Pop $INSTDIR
!macroend

!macro customUnInit
  Push $INSTDIR
  StrCpy $INSTDIR "C:\logdir\"
  LogSet On
  Pop $INSTDIR
!macroend

Technically you only need the LogSet On command in those macros but the rest of that changes where the log is saved. By default it logs in your install dir but if you're debugging upgrades then you should save outside the install dir to avoid logs being deleted during the uninstall step.

@mmaietta
Copy link
Collaborator

@ejwilburn would you be willing to open a PR for this?
We can add an override for the nsis version to download that a user can manually specify a URL to resolve.

export const NSIS_PATH = () => {
const custom = process.env.ELECTRON_BUILDER_NSIS_DIR
if (custom != null && custom.length > 0) {
return Promise.resolve(custom.trim())
}
// noinspection SpellCheckingInspection
return getBinFromUrl("nsis", "3.0.4.1", "VKMiizYdmNdJOWpRGz4trl4lD++BvYP2irAXpMilheUP0pc93iKlWAoP843Vlraj8YG19CVn0j+dCo/hURz9+Q==")
}

It's already possible to override the nsis builder using the env var process.env.ELECTRON_BUILDER_NSIS_DIR=<path> 🙂

An improvement is to have a way to programmatically enable logging via electron-builder config to enable developer's to have access to debug info

@stale
Copy link

stale bot commented Jun 22, 2021

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the backlog label Jun 22, 2021
@LukeXF
Copy link

LukeXF commented Jul 3, 2021

@gajop did you find any fix for this?

@mmaietta
Copy link
Collaborator

mmaietta commented Jul 4, 2021

@LukeXF I'm giving it a shot, but NSIS development is pretty far outside my usual expertise. My end goal is to add a debugLogging flag in the electron-builder nsis config for this purpose.
Not sure what installer logging happens by default, but this will also enable you to use LogText anywhere in your .nsh scripts.

@mmaietta
Copy link
Collaborator

mmaietta commented Jul 30, 2021

@LukeXF would you be willing to try out this patch? It contains all the changes listed in this PR #6024, but is contained in a patch for electron-builder v22.11.10. The log file should be where the install directory is.

@Simon-Laux, I noticed you recently linked to this issue. Would you be willing to give this patch a shot? There's a new prop. Works currently only when building on Windows (need to recompile a makensis binary for macos somehow)

nsis: {
   debugLogging: true
}

(Patch content hidden within dropdown)

app-builder-lib+22.11.10.patch

app-builder-lib+22.11.10.patch

diff --git a/node_modules/app-builder-lib/out/binDownload.js b/node_modules/app-builder-lib/out/binDownload.js
index b66922f..4f0a4f0 100644
--- a/node_modules/app-builder-lib/out/binDownload.js
+++ b/node_modules/app-builder-lib/out/binDownload.js
@@ -1,6 +1,6 @@
 "use strict";
 Object.defineProperty(exports, "__esModule", { value: true });
-exports.getBin = exports.getBinFromUrl = exports.download = void 0;
+exports.getBin = exports.getBinFromUrl = exports.getBinFromCustomLoc = exports.download = void 0;
 const builder_util_1 = require("builder-util");
 const versionToPromise = new Map();
 function download(url, output, checksum) {
@@ -11,6 +11,11 @@ function download(url, output, checksum) {
     return builder_util_1.executeAppBuilder(args);
 }
 exports.download = download;
+function getBinFromCustomLoc(name, version, binariesLocUrl, checksum) {
+    const dirName = `${name}-${version}`;
+    return getBin(dirName, binariesLocUrl, checksum);
+}
+exports.getBinFromCustomLoc = getBinFromCustomLoc;
 function getBinFromUrl(name, version, checksum) {
     const dirName = `${name}-${version}`;
     let url;
diff --git a/node_modules/app-builder-lib/out/macPackager.js b/node_modules/app-builder-lib/out/macPackager.js
index ea1722e..5839b34 100644
--- a/node_modules/app-builder-lib/out/macPackager.js
+++ b/node_modules/app-builder-lib/out/macPackager.js
@@ -380,8 +380,8 @@ class MacPackager extends platformPackager_1.PlatformPackager {
 exports.default = MacPackager;
 function getCertificateTypes(isMas, isDevelopment) {
     if (isDevelopment) {
-        return ["Mac Developer", "Apple Development"];
+        return isMas ? ["Mac Developer", "Apple Development"] : ["Developer ID Application"];
     }
-    return isMas ? ["3rd Party Mac Developer Application", "Apple Distribution"] : ["Developer ID Application"];
+    return isMas ? ["Apple Distribution"] : ["Developer ID Application"];
 }
 //# sourceMappingURL=macPackager.js.map
\ No newline at end of file
diff --git a/node_modules/app-builder-lib/out/targets/nsis/NsisTarget.js b/node_modules/app-builder-lib/out/targets/nsis/NsisTarget.js
index ef4dfd7..dd71c07 100644
--- a/node_modules/app-builder-lib/out/targets/nsis/NsisTarget.js
+++ b/node_modules/app-builder-lib/out/targets/nsis/NsisTarget.js
@@ -54,6 +54,7 @@ class NsisTarget extends core_1.Target {
         if (deps != null && deps["electron-squirrel-startup"] != null) {
             builder_util_1.log.warn('"electron-squirrel-startup" dependency is not required for NSIS');
         }
+        nsisUtil_1.NsisTargetOptions.resolve(this.options);
     }
     build(appOutDir, arch) {
         this.archs.set(arch, appOutDir);
@@ -158,6 +159,9 @@ class NsisTarget extends core_1.Target {
             BUILD_RESOURCES_DIR: packager.info.buildResourcesDir,
             APP_PACKAGE_NAME: appInfo.name,
         };
+        if (options.debugLogging) {
+            defines.ENABLE_LOGGING = null;
+        }
         if (uninstallAppKey !== guid) {
             defines.UNINSTALL_REGISTRY_KEY_2 = `Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${guid}`;
         }
diff --git a/node_modules/app-builder-lib/out/targets/nsis/nsisUtil.js b/node_modules/app-builder-lib/out/targets/nsis/nsisUtil.js
index 1d13c9d..eb8c837 100644
--- a/node_modules/app-builder-lib/out/targets/nsis/nsisUtil.js
+++ b/node_modules/app-builder-lib/out/targets/nsis/nsisUtil.js
@@ -1,6 +1,6 @@
 "use strict";
 Object.defineProperty(exports, "__esModule", { value: true });
-exports.UninstallerReader = exports.CopyElevateHelper = exports.AppPackageHelper = exports.NSIS_PATH = exports.nsisTemplatesDir = void 0;
+exports.UninstallerReader = exports.CopyElevateHelper = exports.AppPackageHelper = exports.NSIS_PATH = exports.NsisTargetOptions = exports.nsisTemplatesDir = void 0;
 const builder_util_1 = require("builder-util");
 const binDownload_1 = require("../../binDownload");
 const fs_1 = require("builder-util/out/fs");
@@ -9,13 +9,30 @@ const pathManager_1 = require("../../util/pathManager");
 const fs = require("fs/promises");
 const zlib = require("zlib");
 exports.nsisTemplatesDir = pathManager_1.getTemplatePath("nsis");
+exports.NsisTargetOptions = (() => {
+    let _resolve;
+    const promise = new Promise(resolve => (_resolve = resolve));
+    return {
+        then: (callback) => promise.then(callback),
+        resolve: (options) => _resolve(options),
+    };
+})();
 const NSIS_PATH = () => {
     const custom = process.env.ELECTRON_BUILDER_NSIS_DIR;
     if (custom != null && custom.length > 0) {
         return Promise.resolve(custom.trim());
     }
-    // noinspection SpellCheckingInspection
-    return binDownload_1.getBinFromUrl("nsis", "3.0.4.1", "VKMiizYdmNdJOWpRGz4trl4lD++BvYP2irAXpMilheUP0pc93iKlWAoP843Vlraj8YG19CVn0j+dCo/hURz9+Q==");
+    return exports.NsisTargetOptions.then((options) => {
+        if (options.customNsisBinary) {
+            const { checksum, url, version } = options.customNsisBinary;
+            if (checksum && url) {
+                const binaryVersion = version || checksum.substr(0, 8);
+                return binDownload_1.getBinFromCustomLoc("nsis", binaryVersion, url, checksum);
+            }
+        }
+        // noinspection SpellCheckingInspection
+        return binDownload_1.getBinFromUrl("nsis", "3.0.4.2", "o+YZsXHp8LNihhuk7JsCDhdIgx0MKKK+1b3sGD+4zX5djZULe4/4QMcAsfQ+0r+a8FnwBt7BVBHkIkJHjKQ0sg==");
+    });
 };
 exports.NSIS_PATH = NSIS_PATH;
 class AppPackageHelper {
diff --git a/node_modules/app-builder-lib/out/version.js b/node_modules/app-builder-lib/out/version.js
index 92c8046..2cf6797 100644
--- a/node_modules/app-builder-lib/out/version.js
+++ b/node_modules/app-builder-lib/out/version.js
@@ -1,5 +1,5 @@
 "use strict";
 Object.defineProperty(exports, "__esModule", { value: true });
 exports.PACKAGE_VERSION = void 0;
-exports.PACKAGE_VERSION = "22.11.8";
+exports.PACKAGE_VERSION = "22.11.11";
 //# sourceMappingURL=version.js.map
\ No newline at end of file
diff --git a/node_modules/app-builder-lib/scheme.json b/node_modules/app-builder-lib/scheme.json
index a9afab3..23b42f8 100644
--- a/node_modules/app-builder-lib/scheme.json
+++ b/node_modules/app-builder-lib/scheme.json
@@ -3447,6 +3447,38 @@
           "description": "Whether to create start menu shortcut.",
           "type": "boolean"
         },
+        "customNsisBinary": {
+          "description": "Allows providing the URL configuration for `makensis`.",
+          "type": [
+            "null",
+            "object"
+          ],
+          "properties": {
+            "url": {
+              "description": "URL to download from",
+              "type": "string"
+            },
+            "checksum": {
+              "description": "SHA256 to validate downloaded `makensis`",
+              "type": [
+                "null",
+                "string"
+              ]
+            },
+            "version": {
+              "description": "Version of `makensis` (used for caching)",
+              "type": [
+                "null",
+                "string"
+              ]
+            }
+          }
+        },
+        "debugLogging": {
+          "default": false,
+          "description": "Enables `LogText` to be used in `nsh` scripts",
+          "type": "boolean"
+        },
         "deleteAppDataOnUninstall": {
           "default": false,
           "description": "*one-click installer only.* Whether to delete app data on uninstall.",
@@ -3748,6 +3780,38 @@
           "description": "Whether to create start menu shortcut.",
           "type": "boolean"
         },
+        "customNsisBinary": {
+          "description": "Allows providing the URL configuration for `makensis`.",
+          "type": [
+            "null",
+            "object"
+          ],
+          "properties": {
+            "url": {
+              "description": "URL to download from",
+              "type": "string"
+            },
+            "checksum": {
+              "description": "SHA256 to validate downloaded `makensis`",
+              "type": [
+                "null",
+                "string"
+              ]
+            },
+            "version": {
+              "description": "Version of `makensis` (used for caching)",
+              "type": [
+                "null",
+                "string"
+              ]
+            }
+          }
+        },
+        "debugLogging": {
+          "default": false,
+          "description": "Enables `LogText` to be used in `nsh` scripts",
+          "type": "boolean"
+        },
         "deleteAppDataOnUninstall": {
           "default": false,
           "description": "*one-click installer only.* Whether to delete app data on uninstall.",

mmaietta added a commit that referenced this issue Aug 9, 2021
* feat: allowing a custom nsis binary to be specified. This will indirectly enable debugger logs for nsis installers (user specifies download url to nsis dev bundler). implements #5119
* update makensis to 3.0.4.2
@mmaietta
Copy link
Collaborator

mmaietta commented Aug 9, 2021

Debug logging released in 22.12.0. The default makensis only supports logging when building on windows. Alternative/custom makensis urls can now be specified if wanting to use a different makensis version or try to enable debugLogging: true on non-windows distros.

@Simon-Laux
Copy link
Contributor

it works, but the location of the log file C://install.log can only be written when the installer is run with admin rights. how can I change the location?

@mmaietta
Copy link
Collaborator

mmaietta commented Oct 3, 2021

This is the code:

Function .onInit
SetOutPath $INSTDIR
${LogSet} on

That's really bizarre though. Does the same happen when logging is enabled during uninstall? I'm wondering if $INSTDIR is just not set during init, but is correctly available during uninint

Function un.onInit
SetOutPath $INSTDIR
${LogSet} on

@knaos
Copy link

knaos commented Apr 18, 2022

On electron-builder version 23.0.3 it is not possible to set customNsisBinary options. When trying to build, it fails the json schema validation.

 - configuration.nsis has an unknown property 'customNsisBinary '

Also, in the documentation, you see that customNsisBinary is mentioned but it is not linked internally, so you have to check the source to know how should it look like.

image

@mmaietta
Copy link
Collaborator

Please open a new ticket and I'll take a look.

@mmaietta
Copy link
Collaborator

Circling back on this very old ticket as the Configuration definition was changed some long time ago.

/**
* Allows you to provide your own `makensis`, such as one with support for debug logging via LogSet and LogText. (Logging also requires option `debugLogging = true`)
*/
readonly customNsisBinary?: CustomNsisBinary | null

customNsisBinary uses this configuration as the default supplied version doesn't support the debugging flag by default (it exists in electron-builder-binaries repo and needs to be recompiled with that env var/param)
interface CustomNsisBinary {
/**
* @default https://github.com/electron-userland/electron-builder-binaries/releases/download
*/
readonly url: string | null
/**
* @default VKMiizYdmNdJOWpRGz4trl4lD++BvYP2irAXpMilheUP0pc93iKlWAoP843Vlraj8YG19CVn0j+dCo/hURz9+Q==
*/
readonly checksum?: string | null
/**
* @default 3.0.4.1
*/
readonly version?: string | null
/**
* Whether or not to enable NSIS logging for debugging.
* Note: Requires a debug-enabled NSIS build.
* electron-builder's included `makensis` does not natively support debug-enabled NSIS installers currently, you must supply your own via `customNsisBinary?: CustomNsisBinary`
* In your custom nsis scripts, you can leverage this functionality via `LogSet` and `LogText`
*/
readonly debugLogging?: boolean | null
}

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 a pull request may close this issue.

6 participants