From 5d8490d2fc7a735f747704792d4fc7d779d6e471 Mon Sep 17 00:00:00 2001 From: sterni Date: Mon, 15 Mar 2021 22:32:16 +0100 Subject: feat(users/Profpatsch): build attrset members on CI Setting meta.targets to include all derivations in the different package sets in Profpatsch's user folder makes them checked by CI until they do the readTree refactor as promised. To reduce code duplication we handle this in a simple function which is exposed from nix.utils which may be a good place for depot specific bits and bops we accumulate over time. To get around the issue of too nested sets we perform the following renames: * users.Profpatsch.tests gets moved into its own directory * users.Profpatsch.arglib.netencode now lives in its own file instead of the default.nix * users.Profpatsch.netstring.tests gets moved into its own directory Change-Id: Icd039c29d7760a711c1c53554504d6b0cd19e120 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2603 Tested-by: BuildkiteCI Reviewed-by: Profpatsch --- users/Profpatsch/arglib/default.nix | 44 ------------ users/Profpatsch/arglib/netencode.nix | 40 +++++++++++ users/Profpatsch/execline/default.nix | 2 +- users/Profpatsch/netencode/default.nix | 2 +- users/Profpatsch/netstring/default.nix | 16 +---- users/Profpatsch/netstring/tests.nix | 61 ----------------- users/Profpatsch/netstring/tests/default.nix | 68 +++++++++++++++++++ users/Profpatsch/nixpkgs-rewriter/default.nix | 2 +- users/Profpatsch/tree-sitter.nix | 2 +- users/Profpatsch/writers/default.nix | 14 ---- users/Profpatsch/writers/tests.nix | 85 ----------------------- users/Profpatsch/writers/tests/default.nix | 98 +++++++++++++++++++++++++++ 12 files changed, 211 insertions(+), 223 deletions(-) delete mode 100644 users/Profpatsch/arglib/default.nix create mode 100644 users/Profpatsch/arglib/netencode.nix delete mode 100644 users/Profpatsch/netstring/tests.nix create mode 100644 users/Profpatsch/netstring/tests/default.nix delete mode 100644 users/Profpatsch/writers/tests.nix create mode 100644 users/Profpatsch/writers/tests/default.nix (limited to 'users/Profpatsch') diff --git a/users/Profpatsch/arglib/default.nix b/users/Profpatsch/arglib/default.nix deleted file mode 100644 index b263654ac3e0..000000000000 --- a/users/Profpatsch/arglib/default.nix +++ /dev/null @@ -1,44 +0,0 @@ -{ depot, pkgs, lib, ... }: - -let - netencode = { - rust = depot.users.Profpatsch.writers.rustSimpleLib { - name = "arglib-netencode"; - dependencies = [ - depot.users.Profpatsch.execline.exec-helpers - depot.users.Profpatsch.netencode.netencode-rs - ]; - } '' - extern crate netencode; - extern crate exec_helpers; - - use netencode::{T}; - use std::os::unix::ffi::OsStrExt; - - pub fn arglib_netencode(prog_name: &str, env: Option<&std::ffi::OsStr>) -> T { - let env = match env { - None => std::ffi::OsStr::from_bytes("ARGLIB_NETENCODE".as_bytes()), - Some(a) => a - }; - let t = match std::env::var_os(env) { - None => exec_helpers::die_user_error(prog_name, format!("could not read args, envvar {} not set", env.to_string_lossy())), - // TODO: good error handling for the different parser errors - Some(soup) => match netencode::parse::t_t(soup.as_bytes()) { - Ok((remainder, t)) => match remainder.is_empty() { - true => t, - false => exec_helpers::die_environment_problem(prog_name, format!("arglib: there was some unparsed bytes remaining: {:?}", remainder)) - }, - Err(err) => exec_helpers::die_environment_problem(prog_name, format!("arglib parsing error: {:?}", err)) - } - }; - std::env::remove_var(env); - t - } - ''; - }; - -in { - inherit - netencode - ; -} diff --git a/users/Profpatsch/arglib/netencode.nix b/users/Profpatsch/arglib/netencode.nix new file mode 100644 index 000000000000..6b568ab80d6e --- /dev/null +++ b/users/Profpatsch/arglib/netencode.nix @@ -0,0 +1,40 @@ +{ depot, pkgs, lib, ... }: + +let + netencode = { + rust = depot.users.Profpatsch.writers.rustSimpleLib { + name = "arglib-netencode"; + dependencies = [ + depot.users.Profpatsch.execline.exec-helpers + depot.users.Profpatsch.netencode.netencode-rs + ]; + } '' + extern crate netencode; + extern crate exec_helpers; + + use netencode::{T}; + use std::os::unix::ffi::OsStrExt; + + pub fn arglib_netencode(prog_name: &str, env: Option<&std::ffi::OsStr>) -> T { + let env = match env { + None => std::ffi::OsStr::from_bytes("ARGLIB_NETENCODE".as_bytes()), + Some(a) => a + }; + let t = match std::env::var_os(env) { + None => exec_helpers::die_user_error(prog_name, format!("could not read args, envvar {} not set", env.to_string_lossy())), + // TODO: good error handling for the different parser errors + Some(soup) => match netencode::parse::t_t(soup.as_bytes()) { + Ok((remainder, t)) => match remainder.is_empty() { + true => t, + false => exec_helpers::die_environment_problem(prog_name, format!("arglib: there was some unparsed bytes remaining: {:?}", remainder)) + }, + Err(err) => exec_helpers::die_environment_problem(prog_name, format!("arglib parsing error: {:?}", err)) + } + }; + std::env::remove_var(env); + t + } + ''; + }; + +in depot.nix.utils.drvTargets netencode diff --git a/users/Profpatsch/execline/default.nix b/users/Profpatsch/execline/default.nix index 852fcfcfa005..c852b82a86d0 100644 --- a/users/Profpatsch/execline/default.nix +++ b/users/Profpatsch/execline/default.nix @@ -5,7 +5,7 @@ let name = "exec-helpers"; } (builtins.readFile ./exec_helpers.rs); -in { +in depot.nix.utils.drvTargets { inherit exec-helpers ; diff --git a/users/Profpatsch/netencode/default.nix b/users/Profpatsch/netencode/default.nix index 294e3b4395da..dabf640d51e9 100644 --- a/users/Profpatsch/netencode/default.nix +++ b/users/Profpatsch/netencode/default.nix @@ -125,7 +125,7 @@ let } ''; -in { +in depot.nix.utils.drvTargets { inherit netencode-rs netencode-mustache diff --git a/users/Profpatsch/netstring/default.nix b/users/Profpatsch/netstring/default.nix index 3cf882d5a279..a1d6a1e77f03 100644 --- a/users/Profpatsch/netstring/default.nix +++ b/users/Profpatsch/netstring/default.nix @@ -52,25 +52,11 @@ let } ''; - tests = import ./tests.nix { - inherit - depot - pkgs - lib - python-netstring - rust-netstring - toNetstring - toNetstringKeyVal - ; - }; - -in { +in depot.nix.utils.drvTargets { inherit toNetstring toNetstringKeyVal python-netstring rust-netstring - tests ; - } diff --git a/users/Profpatsch/netstring/tests.nix b/users/Profpatsch/netstring/tests.nix deleted file mode 100644 index 23141472d6a8..000000000000 --- a/users/Profpatsch/netstring/tests.nix +++ /dev/null @@ -1,61 +0,0 @@ -{ depot, lib, pkgs, python-netstring, rust-netstring, toNetstring, toNetstringKeyVal }: - -let - - python-netstring-test = depot.users.Profpatsch.writers.python3 { - name = "python-netstring-test"; - libraries = p: [ - python-netstring - ]; - } '' - import netstring - - def assEq(left, right): - assert left == right, "{} /= {}".format(str(left), str(right)) - - assEq( - netstring.read_netstring(b"""${toNetstring "hi!"}"""), - (b"hi!", b"") - ) - - assEq( - netstring.read_netstring_key_val( - b"""${toNetstringKeyVal { foo = "42"; }}""" - ), - (b'foo', b'42', b"") - ) - - assEq( - netstring.read_netstring_key_val_list( - b"""${toNetstringKeyVal { foo = "42"; bar = "hi"; }}""" - ), - { b'foo': b'42', b'bar': b'hi' } - ) - ''; - - rust-netstring-test = depot.users.Profpatsch.writers.rustSimple { - name = "rust-netstring-test"; - dependencies = [ - rust-netstring - ]; - } '' - extern crate netstring; - - fn main() { - assert_eq!( - std::str::from_utf8(&netstring::to_netstring(b"hello")).unwrap(), - r##"${toNetstring "hello"}"## - ); - assert_eq!( - std::str::from_utf8(&netstring::to_netstring("こんにちは".as_bytes())).unwrap(), - r##"${toNetstring "こんにちは"}"## - ); - } - ''; - -in { - inherit - python-netstring-test - rust-netstring-test - ; -} diff --git a/users/Profpatsch/netstring/tests/default.nix b/users/Profpatsch/netstring/tests/default.nix new file mode 100644 index 000000000000..a9e6c9c688ec --- /dev/null +++ b/users/Profpatsch/netstring/tests/default.nix @@ -0,0 +1,68 @@ +{ depot, lib, pkgs, ... }: + +let + + inherit (depot.users.Profpatsch.netstring) + toNetstring + toNetstringKeyVal + python-netstring + rust-netstring + ; + + python-netstring-test = depot.users.Profpatsch.writers.python3 { + name = "python-netstring-test"; + libraries = p: [ + python-netstring + ]; + } '' + import netstring + + def assEq(left, right): + assert left == right, "{} /= {}".format(str(left), str(right)) + + assEq( + netstring.read_netstring(b"""${toNetstring "hi!"}"""), + (b"hi!", b"") + ) + + assEq( + netstring.read_netstring_key_val( + b"""${toNetstringKeyVal { foo = "42"; }}""" + ), + (b'foo', b'42', b"") + ) + + assEq( + netstring.read_netstring_key_val_list( + b"""${toNetstringKeyVal { foo = "42"; bar = "hi"; }}""" + ), + { b'foo': b'42', b'bar': b'hi' } + ) + ''; + + rust-netstring-test = depot.users.Profpatsch.writers.rustSimple { + name = "rust-netstring-test"; + dependencies = [ + rust-netstring + ]; + } '' + extern crate netstring; + + fn main() { + assert_eq!( + std::str::from_utf8(&netstring::to_netstring(b"hello")).unwrap(), + r##"${toNetstring "hello"}"## + ); + assert_eq!( + std::str::from_utf8(&netstring::to_netstring("こんにちは".as_bytes())).unwrap(), + r##"${toNetstring "こんにちは"}"## + ); + } + ''; + +in depot.nix.utils.drvTargets { + inherit + python-netstring-test + rust-netstring-test + ; +} diff --git a/users/Profpatsch/nixpkgs-rewriter/default.nix b/users/Profpatsch/nixpkgs-rewriter/default.nix index 286530b03f94..ff414862fa79 100644 --- a/users/Profpatsch/nixpkgs-rewriter/default.nix +++ b/users/Profpatsch/nixpkgs-rewriter/default.nix @@ -102,7 +102,7 @@ let "nix-instantiate" "$1" "-A" "{}" ]; -in { +in depot.nix.utils.drvTargets { inherit instantiate-nixpkgs-randomly # requires hnix, which we don’t want in tvl for now diff --git a/users/Profpatsch/tree-sitter.nix b/users/Profpatsch/tree-sitter.nix index 099fa2d5b7b9..8fc2a847c6bd 100644 --- a/users/Profpatsch/tree-sitter.nix +++ b/users/Profpatsch/tree-sitter.nix @@ -169,7 +169,7 @@ let ''; }; -in { +in depot.nix.utils.drvTargets { inherit print-ast tree-sitter-nix diff --git a/users/Profpatsch/writers/default.nix b/users/Profpatsch/writers/default.nix index 3888579a64d8..a71bed38ed58 100644 --- a/users/Profpatsch/writers/default.nix +++ b/users/Profpatsch/writers/default.nix @@ -138,19 +138,6 @@ let ]; in drvSeqL [ tests ] (crate false); - - tests = import ./tests.nix { - inherit - depot - pkgs - python3 - python3Lib - rustSimpleLib - rustSimple - testRustSimple - ; - }; - in { inherit python3 @@ -159,6 +146,5 @@ in { rustSimpleBin rustSimpleLib testRustSimple - tests ; } diff --git a/users/Profpatsch/writers/tests.nix b/users/Profpatsch/writers/tests.nix deleted file mode 100644 index 680c37a2ec02..000000000000 --- a/users/Profpatsch/writers/tests.nix +++ /dev/null @@ -1,85 +0,0 @@ -{ depot, pkgs, python3, python3Lib, rustSimpleLib, rustSimple, testRustSimple }: - -let - run = drv: depot.nix.runExecline.local "run-${drv.name}" {} [ - "if" [ drv ] - "importas" "out" "out" - "${pkgs.coreutils}/bin/touch" "$out" - ]; - - pythonTransitiveLib = python3Lib { - name = "transitive"; - } '' - def transitive(s): - return s + " 1 2 3" - ''; - - pythonTestLib = python3Lib { - name = "test_lib"; - libraries = _: [ pythonTransitiveLib ]; - } '' - import transitive - def test(): - return transitive.transitive("test") - ''; - - pythonWithLib = run (python3 { - name = "python-with-lib"; - libraries = _: [ pythonTestLib ]; - } '' - import test_lib - - assert(test_lib.test() == "test 1 2 3") - ''); - - - rustTransitiveLib = testRustSimple (rustSimpleLib { - name = "transitive"; - } '' - pub fn transitive(s: &str) -> String { - let mut new = s.to_string(); - new.push_str(" 1 2 3"); - new - } - - #[cfg(test)] - mod tests { - use super::*; - - #[test] - fn test_transitive() { - assert_eq!(transitive("foo").as_str(), "foo 1 2 3") - } - } - ''); - - rustTestLib = rustSimpleLib { - name = "test_lib"; - dependencies = [ rustTransitiveLib ]; - } '' - extern crate transitive; - use transitive::{transitive}; - pub fn test() -> String { - transitive("test") - } - ''; - - rustWithLib = run (rustSimple { - name = "rust-with-lib"; - dependencies = [ rustTestLib ]; - } '' - extern crate test_lib; - - fn main() { - assert_eq!(test_lib::test(), String::from("test 1 2 3")); - } - ''); - - -in { - inherit - pythonWithLib - rustTransitiveLib - rustWithLib - ; -} diff --git a/users/Profpatsch/writers/tests/default.nix b/users/Profpatsch/writers/tests/default.nix new file mode 100644 index 000000000000..a16f5fa1f972 --- /dev/null +++ b/users/Profpatsch/writers/tests/default.nix @@ -0,0 +1,98 @@ +{ depot, ... }: + +let + inherit (depot.users.Profpatsch.writers) + python3Lib + python3 + testRustSimple + rustSimple + rustSimpleLib + rustSimpleBin + ; + + inherit (depot.third_party) + coreutils + ; + + run = drv: depot.nix.runExecline.local "run-${drv.name}" {} [ + "if" [ drv ] + "importas" "out" "out" + "${coreutils}/bin/touch" "$out" + ]; + + pythonTransitiveLib = python3Lib { + name = "transitive"; + } '' + def transitive(s): + return s + " 1 2 3" + ''; + + pythonTestLib = python3Lib { + name = "test_lib"; + libraries = _: [ pythonTransitiveLib ]; + } '' + import transitive + def test(): + return transitive.transitive("test") + ''; + + pythonWithLib = run (python3 { + name = "python-with-lib"; + libraries = _: [ pythonTestLib ]; + } '' + import test_lib + + assert(test_lib.test() == "test 1 2 3") + ''); + + + rustTransitiveLib = testRustSimple (rustSimpleLib { + name = "transitive"; + } '' + pub fn transitive(s: &str) -> String { + let mut new = s.to_string(); + new.push_str(" 1 2 3"); + new + } + + #[cfg(test)] + mod tests { + use super::*; + + #[test] + fn test_transitive() { + assert_eq!(transitive("foo").as_str(), "foo 1 2 3") + } + } + ''); + + rustTestLib = rustSimpleLib { + name = "test_lib"; + dependencies = [ rustTransitiveLib ]; + } '' + extern crate transitive; + use transitive::{transitive}; + pub fn test() -> String { + transitive("test") + } + ''; + + rustWithLib = run (rustSimple { + name = "rust-with-lib"; + dependencies = [ rustTestLib ]; + } '' + extern crate test_lib; + + fn main() { + assert_eq!(test_lib::test(), String::from("test 1 2 3")); + } + ''); + + +in depot.nix.utils.drvTargets { + inherit + pythonWithLib + rustTransitiveLib + rustWithLib + ; +} -- cgit 1.4.1