From 2bc61ad2ba34c003db66e7716849066449a87ab7 Mon Sep 17 00:00:00 2001 From: Lin Jian Date: Sat, 20 Jul 2024 22:28:33 +0800 Subject: [PATCH 1/3] emacs: format genericBuild in preparation for adding more flags --- pkgs/applications/editors/emacs/build-support/generic.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkgs/applications/editors/emacs/build-support/generic.nix b/pkgs/applications/editors/emacs/build-support/generic.nix index bdf1cd4e50f3..e455e4cf824b 100644 --- a/pkgs/applications/editors/emacs/build-support/generic.nix +++ b/pkgs/applications/editors/emacs/build-support/generic.nix @@ -83,7 +83,11 @@ stdenv.mkDerivation (finalAttrs: ({ find $out/share/emacs -type f -name '*.el' -print0 \ | xargs -0 -I {} -n 1 -P $NIX_BUILD_CORES sh -c \ - "emacs --batch --eval '(setq large-file-warning-threshold nil)' -f batch-native-compile {} || true" + "emacs \ + --batch \ + --eval '(setq large-file-warning-threshold nil)' \ + -f batch-native-compile {} \ + || true" ''; } From eabd7cf0fc1e760c5069f43c5dbe325eb48decfd Mon Sep 17 00:00:00 2001 From: Lin Jian Date: Sat, 20 Jul 2024 22:34:45 +0800 Subject: [PATCH 2/3] emacs: log native compilation commands in genericBuild --- pkgs/applications/editors/emacs/build-support/generic.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/applications/editors/emacs/build-support/generic.nix b/pkgs/applications/editors/emacs/build-support/generic.nix index e455e4cf824b..ec0ffa3ae9f8 100644 --- a/pkgs/applications/editors/emacs/build-support/generic.nix +++ b/pkgs/applications/editors/emacs/build-support/generic.nix @@ -82,7 +82,7 @@ stdenv.mkDerivation (finalAttrs: ({ addEmacsVars "$out" find $out/share/emacs -type f -name '*.el' -print0 \ - | xargs -0 -I {} -n 1 -P $NIX_BUILD_CORES sh -c \ + | xargs --verbose -0 -I {} -n 1 -P $NIX_BUILD_CORES sh -c \ "emacs \ --batch \ --eval '(setq large-file-warning-threshold nil)' \ From 45f2e58881c82d757de609e0dee50e7bcfe2aeff Mon Sep 17 00:00:00 2001 From: Lin Jian Date: Sat, 20 Jul 2024 10:02:15 +0800 Subject: [PATCH 3/3] emacs: add two parameters to genericBuild to control errors This patch introduces two parameters, turnCompilationWarningToError and ignoreCompilationError, to control errors in genericBuild, which makes "nix build" be able to fail at elisp native compilation errors or warnings. This feature can be used in CI to improve code quality. Note that this patch keeps the old behavior by default. Hopefully one day we can flip the default value of ignoreCompilationError to false when enough packages are fixed. Also note that these two parameters can be changed per package using the overrideAttrs interface. --- pkgs/applications/editors/emacs/build-support/generic.nix | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkgs/applications/editors/emacs/build-support/generic.nix b/pkgs/applications/editors/emacs/build-support/generic.nix index ec0ffa3ae9f8..b013dee9e017 100644 --- a/pkgs/applications/editors/emacs/build-support/generic.nix +++ b/pkgs/applications/editors/emacs/build-support/generic.nix @@ -27,6 +27,8 @@ in , buildInputs ? [] , packageRequires ? [] , meta ? {} +, turnCompilationWarningToError ? false +, ignoreCompilationError ? true , ... }@args: @@ -73,6 +75,8 @@ stdenv.mkDerivation (finalAttrs: ({ addEmacsNativeLoadPath = true; + inherit turnCompilationWarningToError ignoreCompilationError; + postInstall = '' # Besides adding the output directory to the native load path, make sure # the current package's elisp files are in the load path, otherwise @@ -86,8 +90,9 @@ stdenv.mkDerivation (finalAttrs: ({ "emacs \ --batch \ --eval '(setq large-file-warning-threshold nil)' \ + --eval '(setq byte-compile-error-on-warn ${if finalAttrs.turnCompilationWarningToError then "t" else "nil"})' \ -f batch-native-compile {} \ - || true" + || exit ${if finalAttrs.ignoreCompilationError then "0" else "\\$?"}" ''; }