Starting to add tool builder. Extracting bundler file computation.

This commit is contained in:
Judson 2017-05-31 09:44:46 -07:00
parent e4bb4d4788
commit c4fc70f53c
No known key found for this signature in database
GPG Key ID: 1817B08954BF0B7D
7 changed files with 90 additions and 11 deletions

View File

@ -7,10 +7,10 @@
{
name
, pname ? name
, gemdir
, gemfile
, lockfile
, gemset
, gemdir
, ruby ? defs.ruby
, gemConfig ? defaultGemConfig
, postBuild ? null

View File

@ -1,5 +1,25 @@
{ lib, gemConfig, ... }:
rec {
bundlerFiles = {
gemfile ? null
, lockfile ? null
, gemset ? null
, gemdir ? null
, ...
}: {
gemfile =
if gemfile == null then assert gemdir != null; gemdir + "/Gemfile"
else gemfile;
lockfile =
if lockfile == null then assert gemdir != null; gemdir + "/Gemfile.lock"
else lockfile;
gemset =
if gemset == null then assert gemdir != null; gemdir + "/gemset.nix"
else gemset;
};
filterGemset = {ruby, groups,...}@env: gemset: lib.filterAttrs (name: attrs: platformMatches ruby attrs && groupMatches groups attrs) gemset;
platformMatches = {rubyEngine, version, ...}@ruby: attrs: (

View File

@ -7,7 +7,34 @@ let
functions = (import ./functions.nix testConfigs);
in
builtins.concatLists [
(test.run "Filter empty gemset" {} (set: functions.filterGemset {inherit ruby; groups = ["default"]; } set == {}))
( test.run "All set, no gemdir" (functions.bundlerFiles {
gemfile = test/Gemfile;
lockfile = test/Gemfile.lock;
gemset = test/gemset.nix;
}) {
gemfile = should.equal test/Gemfile;
lockfile = should.equal test/Gemfile.lock;
gemset = should.equal test/gemset.nix;
})
( test.run "Just gemdir" (functions.bundlerFiles {
gemdir = test/.;
}) {
gemfile = should.equal test/Gemfile;
lockfile = should.equal test/Gemfile.lock;
gemset = should.equal test/gemset.nix;
})
( test.run "Gemset and dir" (functions.bundlerFiles {
gemdir = test/.;
gemset = test/extraGemset.nix;
}) {
gemfile = should.equal test/Gemfile;
lockfile = should.equal test/Gemfile.lock;
gemset = should.equal test/extraGemset.nix;
})
( test.run "Filter empty gemset" {} (set: functions.filterGemset {inherit ruby; groups = ["default"]; } set == {}))
( let gemSet = { test = { groups = ["x" "y"]; }; };
in
test.run "Filter matches a group" gemSet (set: functions.filterGemset {inherit ruby; groups = ["y" "z"];} set == gemSet))

View File

@ -1,10 +1,6 @@
{ stdenv, runCommand, writeText, writeScript, writeScriptBin, ruby, lib
, callPackage, defaultGemConfig, fetchurl, fetchgit, buildRubyGem, buildEnv
, linkFarm
, git
, makeWrapper
, bundler
, tree
, linkFarm, git, makeWrapper, bundler, tree
}@defs:
{ name ? null
@ -13,12 +9,12 @@
, gemfile ? null
, lockfile ? null
, gemset ? null
, groups ? ["default"]
, ruby ? defs.ruby
, gemConfig ? defaultGemConfig
, postBuild ? null
, document ? []
, meta ? {}
, groups ? ["default"]
, ignoreCollisions ? false
, ...
}@args:

View File

@ -3,7 +3,11 @@
equal = expected: actual:
if actual == expected then
(test.passed "= ${toString expected}") else
(test.failed "'${toString actual}'(${builtins.typeOf actual}) != '${toString expected}'(${builtins.typeOf expected})");
(test.failed (
"expected '${toString expected}'(${builtins.typeOf expected})"
+ " != "+
"actual '${toString actual}'(${builtins.typeOf actual})"
));
beASet = actual:
if builtins.isAttrs actual then
@ -15,7 +19,7 @@
(ex: builtins.any (ac: ex == ac) (builtins.attrNames actual))
expected then
(test.passed "has expected keys") else
(test.failed "keys differ: expected [${lib.concatStringsSep ";" expected}] have [${lib.concatStringsSep ";" (builtins.attrNames actual)}]");
(test.failed "keys differ: expected: [${lib.concatStringsSep ";" expected}] actual: [${lib.concatStringsSep ";" (builtins.attrNames actual)}]");
havePrefix = expected: actual:
if lib.hasPrefix expected actual then

View File

@ -2,7 +2,7 @@ with builtins;
let
withIndexes = list: genList (idx: (elemAt list idx) // {index = idx;}) (length list);
testLine = report: "${okStr report} ${toString report.index} ${report.description}" + testDirective report + testYaml report;
testLine = report: "${okStr report} ${toString (report.index + 1)} ${report.description}" + testDirective report + testYaml report;
testDirective = report: "";

View File

@ -0,0 +1,32 @@
{ stdenv }@defs:
{
name
, gemdir
, exes ? []
, scripts ? []
, postBuild
}@args:
let
basicEnv = (callPackage ../bundled-common {}) (args // { inherit name gemdir;
gemfile = gemfile';
lockfile = lockfile';
gemset = gemset';
});
args = removeAttrs args_ [ "name" "postBuild" ]
// { inherit preferLocalBuild allowSubstitutes; }; # pass the defaults
in
runCommand name args ''
mkdir -p $out; cd $out;
${(lib.concatMapStrings (x: "ln -s '${basicEnv}/bin/${x}' '${x}';\n") exes)}
${(lib.concatMapStrings (s: "makeWrapper ${out}/bin/$(basename ${s}) $srcdir/${s} " +
"--set BUNDLE_GEMFILE ${basicEnv.confFiles}/Gemfile "+
"--set BUNDLE_PATH ${basicEnv}/${ruby.gemPath} "+
"--set BUNDLE_FROZEN 1 "+
"--set GEM_HOME ${basicEnv}/${ruby.gemPath} "+
"--set GEM_PATH ${basicEnv}/${ruby.gemPath} "+
"--run \"cd $srcdir\";\n") scripts)}
${postBuild}
''