* `nix-env -qa --description' shows human-readable descriptions of
packages (provided that they have a `meta.description' attribute). E.g., $ ./src/nix-env/nix-env -qa --description gcc gcc-4.0.2 GNU Compiler Collection, 4.0.x (cross-compiler for sparc-linux) gcc-4.0.2 GNU Compiler Collection, 4.0.x (cross-compiler for mips-linux) gcc-4.0.2 GNU Compiler Collection, 4.0.x (cross-compiler for arm-linux) gcc-4.0.2 GNU Compiler Collection, 4.0.x
This commit is contained in:
		
							parent
							
								
									a33fb2d287
								
							
						
					
					
						commit
						37d1b1cafd
					
				
					 7 changed files with 79 additions and 25 deletions
				
			
		|  | @ -56,6 +56,7 @@ Expr evalFile(EvalState & state, const Path & path); | ||||||
| string evalString(EvalState & state, Expr e); | string evalString(EvalState & state, Expr e); | ||||||
| Path evalPath(EvalState & state, Expr e); | Path evalPath(EvalState & state, Expr e); | ||||||
| ATermList evalList(EvalState & state, Expr e); | ATermList evalList(EvalState & state, Expr e); | ||||||
|  | ATerm coerceToString(Expr e); | ||||||
| 
 | 
 | ||||||
| /* Print statistics. */ | /* Print statistics. */ | ||||||
| void printEvalStats(EvalState & state); | void printEvalStats(EvalState & state); | ||||||
|  |  | ||||||
|  | @ -2,6 +2,49 @@ | ||||||
| #include "nixexpr-ast.hh" | #include "nixexpr-ast.hh" | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | string DrvInfo::queryDrvPath(EvalState & state) const | ||||||
|  | { | ||||||
|  |     if (drvPath == "") { | ||||||
|  |         Expr a = attrs.get("drvPath"); | ||||||
|  |         (string &) drvPath = a ? evalPath(state, a) : ""; | ||||||
|  |     } | ||||||
|  |     return drvPath; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | string DrvInfo::queryOutPath(EvalState & state) const | ||||||
|  | { | ||||||
|  |     if (outPath == "") { | ||||||
|  |         Expr a = attrs.get("outPath"); | ||||||
|  |         if (!a) throw Error("output path missing"); | ||||||
|  |         (string &) outPath = evalPath(state, a); | ||||||
|  |     } | ||||||
|  |     return outPath; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | MetaInfo DrvInfo::queryMetaInfo(EvalState & state) const | ||||||
|  | { | ||||||
|  |     MetaInfo meta; | ||||||
|  |      | ||||||
|  |     Expr a = attrs.get("meta"); | ||||||
|  |     if (!a) return meta; /* fine, empty meta information */ | ||||||
|  | 
 | ||||||
|  |     ATermMap attrs2; | ||||||
|  |     queryAllAttrs(evalExpr(state, a), attrs2); | ||||||
|  | 
 | ||||||
|  |     for (ATermIterator i(attrs2.keys()); i; ++i) { | ||||||
|  |         ATerm s = coerceToString(evalExpr(state, attrs2.get(*i))); | ||||||
|  |         if (s) | ||||||
|  |             meta[aterm2String(*i)] = aterm2String(s); | ||||||
|  |         /* For future compatibility, ignore attribute values that are
 | ||||||
|  |            not strings. */ | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     return meta; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| typedef set<Expr> Exprs; | typedef set<Expr> Exprs; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -7,6 +7,9 @@ | ||||||
| #include "eval.hh" | #include "eval.hh" | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | typedef map<string, string> MetaInfo; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| struct DrvInfo | struct DrvInfo | ||||||
| { | { | ||||||
| private: | private: | ||||||
|  | @ -19,24 +22,9 @@ public: | ||||||
| 
 | 
 | ||||||
|     ATermMap attrs; |     ATermMap attrs; | ||||||
| 
 | 
 | ||||||
|     string queryDrvPath(EvalState & state) const |     string queryDrvPath(EvalState & state) const; | ||||||
|     { |     string queryOutPath(EvalState & state) const; | ||||||
|         if (drvPath == "") { |     MetaInfo queryMetaInfo(EvalState & state) const; | ||||||
|             Expr a = attrs.get("drvPath"); |  | ||||||
|             (string &) drvPath = a ? evalPath(state, a) : ""; |  | ||||||
|         } |  | ||||||
|         return drvPath; |  | ||||||
|     } |  | ||||||
|      |  | ||||||
|     string queryOutPath(EvalState & state) const |  | ||||||
|     { |  | ||||||
|         if (outPath == "") { |  | ||||||
|             Expr a = attrs.get("outPath"); |  | ||||||
|             if (!a) throw Error("output path missing"); |  | ||||||
|             (string &) outPath = evalPath(state, a); |  | ||||||
|         } |  | ||||||
|         return outPath; |  | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     void setDrvPath(const string & s) |     void setDrvPath(const string & s) | ||||||
|     { |     { | ||||||
|  |  | ||||||
|  | @ -390,14 +390,21 @@ static Expr primDirOf(EvalState & state, const ATermVector & args) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | ATerm coerceToString(Expr e) | ||||||
|  | { | ||||||
|  |     ATerm s; | ||||||
|  |     if (matchStr(e, s) || matchPath(e, s) || matchUri(e, s)) | ||||||
|  |         return s; | ||||||
|  |     return 0; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| /* Convert the argument (which can be a path or a uri) to a string. */ | /* Convert the argument (which can be a path or a uri) to a string. */ | ||||||
| static Expr primToString(EvalState & state, const ATermVector & args) | static Expr primToString(EvalState & state, const ATermVector & args) | ||||||
| { | { | ||||||
|     Expr arg = evalExpr(state, args[0]); |     ATerm s = coerceToString(evalExpr(state, args[0])); | ||||||
|     ATerm s; |     if (!s) throw Error("cannot coerce value to string"); | ||||||
|     if (matchStr(arg, s) || matchPath(arg, s) || matchUri(arg, s)) |  | ||||||
|     return makeStr(s); |     return makeStr(s); | ||||||
|     throw Error("cannot coerce value to string"); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -699,6 +699,7 @@ static void opQuery(Globals & globals, | ||||||
|     bool printSystem = false; |     bool printSystem = false; | ||||||
|     bool printDrvPath = false; |     bool printDrvPath = false; | ||||||
|     bool printOutPath = false; |     bool printOutPath = false; | ||||||
|  |     bool printDescription = false; | ||||||
|     bool compareVersions = false; |     bool compareVersions = false; | ||||||
| 
 | 
 | ||||||
|     enum { sInstalled, sAvailable } source = sInstalled; |     enum { sInstalled, sAvailable } source = sInstalled; | ||||||
|  | @ -710,6 +711,7 @@ static void opQuery(Globals & globals, | ||||||
|         if (*i == "--status" || *i == "-s") printStatus = true; |         if (*i == "--status" || *i == "-s") printStatus = true; | ||||||
|         else if (*i == "--no-name") printName = false; |         else if (*i == "--no-name") printName = false; | ||||||
|         else if (*i == "--system") printSystem = true; |         else if (*i == "--system") printSystem = true; | ||||||
|  |         else if (*i == "--description") printDescription = true; | ||||||
|         else if (*i == "--compare-versions" || *i == "-c") compareVersions = true; |         else if (*i == "--compare-versions" || *i == "-c") compareVersions = true; | ||||||
|         else if (*i == "--drv-path") printDrvPath = true; |         else if (*i == "--drv-path") printDrvPath = true; | ||||||
|         else if (*i == "--out-path") printOutPath = true; |         else if (*i == "--out-path") printOutPath = true; | ||||||
|  | @ -809,6 +811,11 @@ static void opQuery(Globals & globals, | ||||||
|          |          | ||||||
|             if (printOutPath) columns.push_back(i->queryOutPath(globals.state)); |             if (printOutPath) columns.push_back(i->queryOutPath(globals.state)); | ||||||
| 
 | 
 | ||||||
|  |             if (printDescription) { | ||||||
|  |                 MetaInfo meta = i->queryMetaInfo(globals.state); | ||||||
|  |                 columns.push_back(meta["description"]); | ||||||
|  |             } | ||||||
|  |              | ||||||
|             table.push_back(columns); |             table.push_back(columns); | ||||||
|         } |         } | ||||||
|         catch (AssertionError & e) { |         catch (AssertionError & e) { | ||||||
|  |  | ||||||
|  | @ -7,12 +7,16 @@ assert foo == "foo"; | ||||||
| 
 | 
 | ||||||
| let { | let { | ||||||
| 
 | 
 | ||||||
|   makeDrv = name: progName: derivation { |   makeDrv = name: progName: (derivation { | ||||||
|     inherit name progName system; |     inherit name progName system; | ||||||
|     builder = "@shell@"; |     builder = "@shell@"; | ||||||
|     shell = "@shell@"; |     shell = "@shell@"; | ||||||
|     args = ["-e" "-x" ./user-envs.builder.sh]; |     args = ["-e" "-x" ./user-envs.builder.sh]; | ||||||
|  |   } // { | ||||||
|  |     meta = { | ||||||
|  |       description = "A silly test package"; | ||||||
|     }; |     }; | ||||||
|  |   }); | ||||||
| 
 | 
 | ||||||
|   body = [ |   body = [ | ||||||
|     (makeDrv "foo-1.0" "foo") |     (makeDrv "foo-1.0" "foo") | ||||||
|  |  | ||||||
|  | @ -1,6 +1,7 @@ | ||||||
| source common.sh | source common.sh | ||||||
| 
 | 
 | ||||||
| profiles="$NIX_STATE_DIR"/profiles | profiles="$NIX_STATE_DIR"/profiles | ||||||
|  | rm -f $profiles/* | ||||||
| 
 | 
 | ||||||
| # Query installed: should be empty. | # Query installed: should be empty. | ||||||
| test "$($nixenv -p $profiles/test -q '*' | wc -l)" -eq 0 | test "$($nixenv -p $profiles/test -q '*' | wc -l)" -eq 0 | ||||||
|  | @ -8,6 +9,9 @@ test "$($nixenv -p $profiles/test -q '*' | wc -l)" -eq 0 | ||||||
| # Query available: should contain several. | # Query available: should contain several. | ||||||
| test "$($nixenv -p $profiles/test -f ./user-envs.nix -qa '*' | wc -l)" -eq 5 | test "$($nixenv -p $profiles/test -f ./user-envs.nix -qa '*' | wc -l)" -eq 5 | ||||||
| 
 | 
 | ||||||
|  | # Query descriptions. | ||||||
|  | $nixenv -p $profiles/test -f ./user-envs.nix -qa '*' --description | grep silly | ||||||
|  | 
 | ||||||
| # Install "foo-1.0". | # Install "foo-1.0". | ||||||
| $nixenv -p $profiles/test -f ./user-envs.nix -i foo-1.0 | $nixenv -p $profiles/test -f ./user-envs.nix -i foo-1.0 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue