diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2009-06-30T15·53+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2009-06-30T15·53+0000 |
commit | 749dd97a54f50467d266dde2b833f272cb556145 (patch) | |
tree | e70922e3611144f69bf0613742fa92619d8f776f /src/libexpr/get-drvs.cc | |
parent | f2c3fc519190b021f0bb3b66f58d0fe7fc40b0e7 (diff) |
* Support integers and lists of strings in meta fields. This is
useful for fields like meta.maintainers, meta.priority (which can be a proper integer now) and even meta.license (if there are multiple licenses).
Diffstat (limited to 'src/libexpr/get-drvs.cc')
-rw-r--r-- | src/libexpr/get-drvs.cc | 46 |
1 files changed, 35 insertions, 11 deletions
diff --git a/src/libexpr/get-drvs.cc b/src/libexpr/get-drvs.cc index 84f8ddf9bfb1..1442d7988b8b 100644 --- a/src/libexpr/get-drvs.cc +++ b/src/libexpr/get-drvs.cc @@ -50,31 +50,55 @@ MetaInfo DrvInfo::queryMetaInfo(EvalState & state) const Expr e = evalExpr(state, i->value); string s; PathSet context; - if (matchStr(e, s, context)) - meta[aterm2String(i->key)] = s; - /* For future compatibility, ignore attribute values that are - not strings. */ + MetaValue value; + int n; + ATermList es; + if (matchStr(e, s, context)) { + value.type = MetaValue::tpString; + value.stringValue = s; + meta[aterm2String(i->key)] = value; + } else if (matchInt(e, n)) { + value.type = MetaValue::tpInt; + value.intValue = n; + meta[aterm2String(i->key)] = value; + } else if (matchList(e, es)) { + value.type = MetaValue::tpStrings; + for (ATermIterator j(es); j; ++j) + value.stringValues.push_back(evalStringNoCtx(state, *j)); + meta[aterm2String(i->key)] = value; + } } return meta; } -string DrvInfo::queryMetaInfo(EvalState & state, const string & name) const +MetaValue DrvInfo::queryMetaInfo(EvalState & state, const string & name) const { /* !!! evaluates all meta attributes => inefficient */ - MetaInfo meta = queryMetaInfo(state); - MetaInfo::iterator i = meta.find(name); - return i == meta.end() ? "" : i->second; + return queryMetaInfo(state)[name]; } void DrvInfo::setMetaInfo(const MetaInfo & meta) { ATermMap metaAttrs; - for (MetaInfo::const_iterator i = meta.begin(); i != meta.end(); ++i) - metaAttrs.set(toATerm(i->first), - makeAttrRHS(makeStr(i->second), makeNoPos())); + foreach (MetaInfo::const_iterator, i, meta) { + Expr e; + switch (i->second.type) { + case MetaValue::tpInt: e = makeInt(i->second.intValue); break; + case MetaValue::tpString: e = makeStr(i->second.stringValue); break; + case MetaValue::tpStrings: { + ATermList es = ATempty; + foreach (Strings::const_iterator, j, i->second.stringValues) + es = ATinsert(es, makeStr(*j)); + e = makeList(ATreverse(es)); + break; + } + default: abort(); + } + metaAttrs.set(toATerm(i->first), makeAttrRHS(e, makeNoPos())); + } attrs->set(toATerm("meta"), makeAttrs(metaAttrs)); } |