Skip to content

Commit

Permalink
nix: Rearrange Hydra release files to match Travis release script
Browse files Browse the repository at this point in the history
  • Loading branch information
rvl committed Apr 29, 2021
1 parent 0d81efd commit a0c5b70
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 209 deletions.
49 changes: 0 additions & 49 deletions nix/linux-release.nix

This file was deleted.

60 changes: 0 additions & 60 deletions nix/macos-release.nix

This file was deleted.

126 changes: 126 additions & 0 deletions nix/release-package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
############################################################################
# Release package
#
# This bundles up the build of the given exes, with their
# dependencies, and sets up the Hydra build artifact.
#
############################################################################

{ pkgs
, platform
, exes
, format
}:

let
inherit (pkgs) lib commonLib;

exe = assert lib.assertMsg (lib.length exes > 0) "empty list of exes";
lib.head exes;
name = "${commonLib.versionTag exe.meta.name}-${platform}";

makeTarball = format == "tar.gz";
makeZip = format == "zip";

isLinux = platform == "linux64";
isMacos = platform == "macos";
isWindows = platform == "win64";

in
assert lib.assertMsg (makeTarball || makeZip)
"format must be tar.gz or zip";
assert lib.assertMsg (isLinux || isMacos || isWindows)
"wrong platform \"${platform}\"";

pkgs.stdenv.mkDerivation {
inherit name;
buildInputs = with pkgs.buildPackages; [
binutils
haskellBuildUtils
nix
]
++ lib.optionals makeTarball [ gnutar gzip ]
++ lib.optionals makeZip [ zip ];
checkInputs = with pkgs.buildPackages; [
ruby
gnugrep
gnused
]
++ lib.optionals isMacos [ darwin.cctools ]
++ lib.optionals isWindows [ unzip wineMinimal ]
++ lib.optional (stdenv.buildPlatform.libc == "glibc") glibcLocales;

doCheck = true;
phases = [ "buildPhase" "checkPhase" ];
pkgname = "${name}.${format}";
exeName = lib.getName exe.name;
buildPhase = ''
mkdir -p $out/nix-support $name
cp -nR ${lib.concatMapStringsSep " " (exe: "${exe}/bin/*") exes} $name
chmod -R 755 $name
'' + lib.optionalString isMacos ''
# Rewrite library paths to standard non-nix locations
( cd $name; rewrite-libs . `ls -1 | grep -Fv .dylib` )
'' + lib.optionalString (isLinux || isMacos) ''
mkdir -p $name/auto-completion/{bash,zsh,fish}
cp ${exe}/share/bash-completion/completions/* $name/auto-completion/bash/$exeName.sh
cp ${exe}/share/zsh/vendor-completions/* $name/auto-completion/zsh/_$exeName
cp ${exe}/share/fish/vendor_completions.d/* $name/auto-completion/fish/$exeName.fish
'' + lib.optionalString makeTarball ''
tar -czf $out/$pkgname $name
'' + lib.optionalString makeZip ''
( cd $name; zip -r $out/$pkgname . )
'' + ''
echo "file binary-dist $out/$pkgname" > $out/nix-support/hydra-build-products
'' + lib.optionalString isWindows ''
# make a separate configuration package if needed
if [ -d ${exe}/configuration ]; then
cp -R ${exe}/configuration ..
cd ../configuration
chmod -R +w .
zip -r $out/${exe.name}-configuration.zip .
echo "file binary-dist $out/${exe.name}-configuration.zip" >> $out/nix-support/hydra-build-products
fi
# make a separate deployments configuration package if needed
if [ -d ${exe}/deployments ]; then
cp -R ${exe}/deployments ..
cd ../deployments
chmod -R +w .
zip -r $out/${exe.name}-deployments.zip .
echo "file binary-dist $out/${exe.name}-deployments.zip" >> $out/nix-support/hydra-build-products
fi
'';

# test that executables work
exeRunner = lib.optionalString isWindows "wine64";
checkPhase = ''
cd `mktemp -d`
echo " - extracting $pkgname"
${lib.optionalString makeTarball "tar -xzvf $out/$pkgname"}
${lib.optionalString makeZip "unzip $out/$pkgname"}
'' + lib.optionalString isWindows ''
# setup wine
export WINEPREFIX=$TMP
export HOME=$TMP
export WINEDLLOVERRIDES="winemac.drv=d"
export WINEDEBUG=warn-all,fixme-all,-menubuilder,-mscoree,-ole,-secur32,-winediag
'' + ''
export PATH=`pwd`/$name:$PATH
echo " - running checks"
ruby ${../scripts/check-bundle.rb} $exeName $exeRunner
'';
} // lib.optionalAttrs (pkgs.stdenv.buildPlatform.libc == "glibc") {
LOCALE_ARCHIVE = "${pkgs.buildPackages.glibcLocales}/lib/locale/locale-archive";
LANG = "en_US.UTF-8";
LC_ALL = "en_US.UTF-8";
}
13 changes: 9 additions & 4 deletions nix/util.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@

# Convert version strings from Cabal format (YYYY.M.D)
# to git tag format (vYYYY-MM-DD).
versionTag = cabal: let
parts = builtins.match "([[:digit:]]{4})\.([[:digit:]]{1,2})\.([[:digit:]]{1,2})" cabal;
versionTag = cabalName: let
versionRegExp = "(^.*)([[:digit:]]{4})\.([[:digit:]]{1,2})\.([[:digit:]]{1,2})(.*$)";
parts = builtins.match versionRegExp cabalName;
name = lib.head parts;
cabalVer = lib.take 3 (lib.drop 1 parts);
rest = lib.drop 4 parts;
leading0 = str: if lib.stringLength str == 1 then "0" + str else str;
tag = "v" + lib.concatMapStringsSep "-" leading0 cabalVer;
in
assert lib.assertMsg (parts != null)
"versionTag: ${cabal} is not in YYYY.M.D format";
"v" + lib.concatMapStringsSep "-" leading0 parts;
"versionTag: \"${cabalName}\" does not have a version in YYYY.M.D format";
(name + tag + lib.concatStrings rest);

}
81 changes: 0 additions & 81 deletions nix/windows-release.nix

This file was deleted.

34 changes: 19 additions & 15 deletions release.nix
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,26 @@ let
# function to take a list of jobs by name from a jobset.
selectExes = subjobs: system: map (exe: subjobs.${exe}.${system});

releaseDistJobs = optionalAttrs buildWindows {

# Windows release ZIP archive - shelley
cardano-wallet-win64 = import ./nix/windows-release.nix {
releaseDistJobs = optionalAttrs buildMusl {
cardano-wallet-linux64 = import ./nix/release-package.nix {
inherit pkgs;
exes = selectExes jobs.musl64 "x86_64-linux" releaseContents;
platform = "linux64";
format = "tar.gz";
};
} // optionalAttrs buildMacOS {
cardano-wallet-macos64 = hydraJob' (import ./nix/release-package.nix {
inherit (pkgsFor "x86_64-darwin") pkgs;
exes = selectExes jobs.native "x86_64-darwin" releaseContents;
platform = "macos64";
format = "tar.gz";
});
} // optionalAttrs buildWindows {
cardano-wallet-win64 = import ./nix/release-package.nix {
inherit pkgs;
exes = selectExes jobs.x86_64-w64-mingw32 "x86_64-linux" releaseContents;
exes = selectExes jobs.x86_64-w64-mingw32 builtins.currentSystem releaseContents;
platform = "win64";
format = "zip";
};

# This is used for testing the build on windows.
Expand All @@ -236,16 +250,6 @@ let
tests = collectTests winJobs.tests;
benchmarks = collectTests winJobs.benchmarks;
};
} // optionalAttrs buildMusl {
cardano-wallet-linux64 = import ./nix/linux-release.nix {
inherit pkgs;
exes = selectExes jobs.musl64 "x86_64-linux" releaseContents;
};
} // optionalAttrs buildMacOS {
cardano-wallet-macos64 = hydraJob' (import ./nix/macos-release.nix {
inherit (pkgsFor "x86_64-darwin") pkgs;
exes = selectExes jobs.native "x86_64-darwin" releaseContents;
});
};

############################################################################
Expand Down

0 comments on commit a0c5b70

Please sign in to comment.