diff options
author | Jan Tojnar <jtojnar@gmail.com> | 2020-03-31 21:32:15 +0200 |
---|---|---|
committer | Jan Tojnar <jtojnar@gmail.com> | 2020-03-31 21:32:15 +0200 |
commit | 3e0f4e202f4221d5a05a9664fd46e492de711fa2 (patch) | |
tree | 5f62c67bff9ccc643621e80b04cf43e3959d723d /pkgs/build-support | |
parent | a803f716bdf756edaedbdd99d66cf04f27496682 (diff) | |
parent | a8811cb82bab25aa835a09dc48a2d9450448d6d5 (diff) | |
download | nixpkgs-3e0f4e202f4221d5a05a9664fd46e492de711fa2.tar nixpkgs-3e0f4e202f4221d5a05a9664fd46e492de711fa2.tar.gz nixpkgs-3e0f4e202f4221d5a05a9664fd46e492de711fa2.tar.bz2 nixpkgs-3e0f4e202f4221d5a05a9664fd46e492de711fa2.tar.lz nixpkgs-3e0f4e202f4221d5a05a9664fd46e492de711fa2.tar.xz nixpkgs-3e0f4e202f4221d5a05a9664fd46e492de711fa2.tar.zst nixpkgs-3e0f4e202f4221d5a05a9664fd46e492de711fa2.zip |
Merge branch 'master' into staging-next
Diffstat (limited to 'pkgs/build-support')
5 files changed, 179 insertions, 30 deletions
diff --git a/pkgs/build-support/make-desktopitem/default.nix b/pkgs/build-support/make-desktopitem/default.nix index 67b82fd66db..8355a5ad29b 100644 --- a/pkgs/build-support/make-desktopitem/default.nix +++ b/pkgs/build-support/make-desktopitem/default.nix @@ -1,4 +1,5 @@ -{ lib, runCommandLocal }: +{ lib, runCommandLocal, desktop-file-utils }: + { name , type ? "Application" , exec @@ -8,9 +9,10 @@ , desktopName , genericName ? null , mimeType ? null -, categories ? "Application;Other;" +, categories ? null , startupNotify ? null , extraEntries ? null +, fileValidation ? true # whether to validate resulting desktop file. }: let @@ -18,6 +20,7 @@ let {k="Comment"; v=comment;} {k="GenericName"; v=genericName;} {k="MimeType"; v=mimeType;} + {k="Categories"; v=categories;} {k="StartupNotify"; v=startupNotify;}]; valueNotNull = {k, v}: v != null; @@ -28,16 +31,20 @@ let in runCommandLocal "${name}.desktop" {} '' - mkdir -p $out/share/applications - cat > $out/share/applications/${name}.desktop <<EOF + mkdir -p "$out/share/applications" + cat > "$out/share/applications/${name}.desktop" <<EOF [Desktop Entry] Type=${type} Exec=${exec} Terminal=${terminal} Name=${desktopName} - Categories=${categories} ${optionalEntriesString} ${if extraEntries == null then ''EOF'' else '' ${extraEntries} EOF''} + + ${lib.optionalString fileValidation '' + echo "Running desktop-file validation" + ${desktop-file-utils}/bin/desktop-file-validate "$out/share/applications/${name}.desktop" + ''} '' diff --git a/pkgs/build-support/rust/build-rust-crate/install-crate.nix b/pkgs/build-support/rust/build-rust-crate/install-crate.nix index 5ba7b69bedc..f4a4dcdb0d9 100644 --- a/pkgs/build-support/rust/build-rust-crate/install-crate.nix +++ b/pkgs/build-support/rust/build-rust-crate/install-crate.nix @@ -14,7 +14,7 @@ if !buildTests then '' fi if [[ "$(ls -A target/lib)" ]]; then mkdir -p $lib/lib - cp target/lib/* $lib/lib #*/ + cp -r target/lib/* $lib/lib #*/ for library in $lib/lib/*.so $lib/lib/*.dylib; do #*/ ln -s $library $(echo $library | sed -e "s/-${metadata}//") done @@ -26,7 +26,7 @@ if !buildTests then '' if [[ -d target/bin ]]; then if [[ "$(ls -A target/bin)" ]]; then mkdir -p $out/bin - cp -P target/bin/* $out/bin # */ + cp -rP target/bin/* $out/bin # */ fi fi runHook postInstall diff --git a/pkgs/build-support/rust/build-rust-crate/lib.sh b/pkgs/build-support/rust/build-rust-crate/lib.sh index 6cf3481754b..3bf1992cecd 100644 --- a/pkgs/build-support/rust/build-rust-crate/lib.sh +++ b/pkgs/build-support/rust/build-rust-crate/lib.sh @@ -14,7 +14,6 @@ build_lib() { --crate-name $CRATE_NAME \ $lib_src \ --out-dir target/lib \ - --emit=dep-info,link \ -L dependency=target/deps \ --cap-lints allow \ $LIB_RUSTC_OPTS \ @@ -45,7 +44,6 @@ build_bin() { --crate-type bin \ $BIN_RUSTC_OPTS \ --out-dir target/bin \ - --emit=dep-info,link \ -L dependency=target/deps \ $LINK \ $EXTRA_LIB \ diff --git a/pkgs/build-support/rust/build-rust-crate/test/default.nix b/pkgs/build-support/rust/build-rust-crate/test/default.nix index 2251a1b40f2..fba938f6237 100644 --- a/pkgs/build-support/rust/build-rust-crate/test/default.nix +++ b/pkgs/build-support/rust/build-rust-crate/test/default.nix @@ -1,4 +1,14 @@ -{ lib, buildRustCrate, runCommand, runCommandCC, writeTextFile, symlinkJoin, callPackage, releaseTools }: +{ lib +, buildRustCrate +, callPackage +, releaseTools +, runCommand +, runCommandCC +, stdenv +, symlinkJoin +, writeTextFile +}: + let mkCrate = args: let p = { @@ -94,6 +104,58 @@ let '' ); + /* Returns a derivation that asserts that the crate specified by `crateArgs` + has the specified files as output. + + `name` is used as part of the derivation name that performs the checking. + + `crateArgs` is passed to `mkCrate` to build the crate with `buildRustCrate`. + + `expectedFiles` contains a list of expected file paths in the output. E.g. + `[ "./bin/my_binary" ]`. + + `output` specifies the name of the output to use. By default, the default + output is used but e.g. `output = "lib";` will cause the lib output + to be checked instead. You do not need to specify any directories. + */ + assertOutputs = { name, crateArgs, expectedFiles, output? null }: + assert (builtins.isString name); + assert (builtins.isAttrs crateArgs); + assert (builtins.isList expectedFiles); + + let + crate = mkCrate (builtins.removeAttrs crateArgs ["expectedTestOutput"]); + crateOutput = if output == null then crate else crate."${output}"; + expectedFilesFile = writeTextFile { + name = "expected-files-${name}"; + text = + let sorted = builtins.sort (a: b: a<b) expectedFiles; + concatenated = builtins.concatStringsSep "\n" sorted; + in "${concatenated}\n"; + }; + in + runCommand "assert-outputs-${name}" { + } '' + local actualFiles=$(mktemp) + + cd "${crateOutput}" + find . -type f | sort >$actualFiles + diff -q ${expectedFilesFile} $actualFiles >/dev/null || { + echo -e "\033[0;1;31mERROR: Difference in expected output files in ${crateOutput} \033[0m" >&2 + echo === Got: + sed -e 's/^/ /' $actualFiles + echo === Expected: + sed -e 's/^/ /' ${expectedFilesFile} + echo === Diff: + diff -u ${expectedFilesFile} $actualFiles |\ + tail -n +3 |\ + sed -e 's/^/ /' + exit 1 + } + touch $out + '' + ; + in rec { tests = let @@ -284,12 +346,18 @@ let ]; }; buildInputs = let - compile = name: text: runCommandCC name {} '' - mkdir -p $out/lib - $CC -shared -o $out/lib/${name}.so ${writeTextFile { + compile = name: text: let + src = writeTextFile { name = "${name}-src.c"; inherit text; - }} + }; + in runCommandCC name {} '' + mkdir -p $out/lib + # Note: On darwin (which defaults to clang) we have to add + # `-undefined dynamic_lookup` as otherwise the compilation fails. + cc -shared \ + ${lib.optionalString stdenv.isDarwin "-undefined dynamic_lookup"} \ + -o $out/lib/${name}${stdenv.hostPlatform.extensions.sharedLibrary} ${src} ''; b = compile "libb" '' #include <stdio.h> @@ -346,7 +414,80 @@ let }; }; brotliCrates = (callPackage ./brotli-crates.nix {}); - in lib.mapAttrs (key: value: mkTest (value // lib.optionalAttrs (!value?crateName) { crateName = key; })) cases // { + tests = lib.mapAttrs (key: value: mkTest (value // lib.optionalAttrs (!value?crateName) { crateName = key; })) cases; + in tests // rec { + + crateBinWithPathOutputs = assertOutputs { + name="crateBinWithPath"; + crateArgs = { + crateBin = [{ name = "test_binary1"; path = "src/foobar.rs"; }]; + src = mkBin "src/foobar.rs"; + }; + expectedFiles = [ + "./bin/test_binary1" + ]; + }; + + crateBinWithPathOutputsDebug = assertOutputs { + name="crateBinWithPath"; + crateArgs = { + release = false; + crateBin = [{ name = "test_binary1"; path = "src/foobar.rs"; }]; + src = mkBin "src/foobar.rs"; + }; + expectedFiles = [ + "./bin/test_binary1" + ] ++ lib.optionals stdenv.isDarwin [ + # On Darwin, the debug symbols are in a seperate directory. + "./bin/test_binary1.dSYM/Contents/Info.plist" + "./bin/test_binary1.dSYM/Contents/Resources/DWARF/test_binary1" + ]; + }; + + crateBinNoPath1Outputs = assertOutputs { + name="crateBinNoPath1"; + crateArgs = { + crateBin = [{ name = "my-binary2"; }]; + src = mkBin "src/my_binary2.rs"; + }; + expectedFiles = [ + "./bin/my-binary2" + ]; + }; + + crateLibOutputs = assertOutputs { + name="crateLib"; + output="lib"; + crateArgs = { + libName = "test_lib"; + type = [ "rlib" ]; + libPath = "src/lib.rs"; + src = mkLib "src/lib.rs"; + }; + expectedFiles = [ + "./nix-support/propagated-build-inputs" + "./lib/libtest_lib-042a1fdbef.rlib" + "./lib/link" + ]; + }; + + crateLibOutputsDebug = assertOutputs { + name="crateLib"; + output="lib"; + crateArgs = { + release = false; + libName = "test_lib"; + type = [ "rlib" ]; + libPath = "src/lib.rs"; + src = mkLib "src/lib.rs"; + }; + expectedFiles = [ + "./nix-support/propagated-build-inputs" + "./lib/libtest_lib-042a1fdbef.rlib" + "./lib/link" + ]; + }; + brotliTest = let pkg = brotliCrates.brotli_2_5_0 {}; in runCommand "run-brotli-test-cmd" { diff --git a/pkgs/build-support/skaware/build-skaware-package.nix b/pkgs/build-support/skaware/build-skaware-package.nix index 9e4456a3a15..e6e2e35789b 100644 --- a/pkgs/build-support/skaware/build-skaware-package.nix +++ b/pkgs/build-support/skaware/build-skaware-package.nix @@ -18,15 +18,12 @@ in { , configureFlags # mostly for moving and deleting files from the build directory # : lines -, postInstall ? "" - # : lines -, postFixup ? "" +, postInstall # : list Maintainer , maintainers ? [] - # : attrs -, meta ? {} -, ... -} @ args: + + +}: let @@ -53,17 +50,24 @@ let "README.*" ]; -in stdenv.mkDerivation ({ +in stdenv.mkDerivation { + inherit pname version; + src = fetchurl { url = "https://skarnet.org/software/${pname}/${pname}-${version}.tar.gz"; inherit sha256; }; + inherit outputs; + dontDisableStatic = true; enableParallelBuilding = true; configureFlags = configureFlags ++ [ "--enable-absolute-paths" + # We assume every nix-based cross target has urandom. + # This might not hold for e.g. BSD. + "--with-sysdep-devurandom=yes" (if stdenv.isDarwin then "--disable-shared" else "--enable-shared") @@ -83,11 +87,13 @@ in stdenv.mkDerivation ({ noiseFiles = commonNoiseFiles; docFiles = commonMetaFiles; }} $doc/share/doc/${pname} - '' + postInstall; + + ${postInstall} + ''; postFixup = '' ${cleanPackaging.checkForRemainingFiles} - '' + postFixup; + ''; meta = { homepage = "https://skarnet.org/software/${pname}/"; @@ -95,9 +101,6 @@ in stdenv.mkDerivation ({ license = stdenv.lib.licenses.isc; maintainers = with lib.maintainers; [ pmahoney Profpatsch ] ++ maintainers; - } // meta; + }; -} // builtins.removeAttrs args [ - "sha256" "configureFlags" "postInstall" "postFixup" - "meta" "description" "platforms" "maintainers" -]) +} |