Skip to content
This repository has been archived by the owner on Apr 1, 2022. It is now read-only.

Commit

Permalink
Aport copySource.nix with descriptive error message
Browse files Browse the repository at this point in the history
  • Loading branch information
zainab-ali committed Jul 1, 2021
1 parent f4f69a7 commit 2f4ef77
Showing 1 changed file with 37 additions and 32 deletions.
69 changes: 37 additions & 32 deletions nix/copySource.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# A helper for copying (actually linking) source files.
#
# This generates a shell script for the task.
{ pkgs ? import <nixpkgs> {}
{ pkgs ? import <nixpkgs> { }
, src
, recipeFile
}:
Expand All @@ -23,35 +23,40 @@ let
mainFileRegex = "(.*/)?" + recipeAttrs.pname + "\.el";
isMainFile = file: match mainFileRegex file != null;
in
rec {
inherit (recipeAttrs) pname;
packageFiles =
filter (file: match "(.*/)?flycheck_.+\.el" file == null)
(expandPackageFiles srcRoot recipeAttrs.files);
sourceFiles = filter isElisp packageFiles;
mainFile =
if length sourceFiles == 1
then head sourceFiles
else head (filter isMainFile sourceFiles);
};
rec {
inherit (recipeAttrs) pname;
packageFiles =
filter (file: match "(.*/)?flycheck_.+\.el" file == null)
(expandPackageFiles srcRoot recipeAttrs.files);
sourceFiles = filter isElisp packageFiles;
mainFile =
if length sourceFiles == 1
then head sourceFiles
else
let mainFiles = (filter isMainFile sourceFiles);
in
if mainFiles == [ ]
then abort "Main elisp file not found for recipe ${recipeFile}."
else head mainFiles;
};
in
with package;
let
packageFilePaths = map (file: src + "/" + file) packageFiles;
baseNames = xs: concatStringsSep " " (map baseNameOf xs);
in
writeText "emacs-${package.pname}-link-source"
''
cat > .elinter-env <<HERE
export PACKAGE_NAME=${pname}
export PACKAGE_FILES="${baseNames packageFiles}"
export PACKAGE_ELISP_FILES="${baseNames sourceFiles}"
export PACKAGE_MAIN_FILE=${baseNameOf mainFile}
HERE
for f in ${lib.escapeShellArgs packageFilePaths}; do
if ! ln -s $f; then
echo "This is possibly due to duplicate file specs in the recipe." >&2
exit 1
fi
done
''
with package;
let
packageFilePaths = map (file: src + "/" + file) packageFiles;
baseNames = xs: concatStringsSep " " (map baseNameOf xs);
in
writeText "emacs-${package.pname}-link-source"
''
cat > .elinter-env <<HERE
export PACKAGE_NAME=${pname}
export PACKAGE_FILES="${baseNames packageFiles}"
export PACKAGE_ELISP_FILES="${baseNames sourceFiles}"
export PACKAGE_MAIN_FILE=${baseNameOf mainFile}
HERE
for f in ${lib.escapeShellArgs packageFilePaths}; do
if ! ln -s $f; then
echo "This is possibly due to duplicate file specs in the recipe." >&2
exit 1
fi
done
''

0 comments on commit 2f4ef77

Please sign in to comment.