[haiku-commits] r40877 - in haiku/branches/features/package-management: build/jam headers/os/package src/bin/package src/bin/package_repo src/kits/package

  • From: zooey@xxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 8 Mar 2011 21:36:45 +0100 (CET)

Author: zooey
Date: 2011-03-08 21:36:44 +0100 (Tue, 08 Mar 2011)
New Revision: 40877
Changeset: http://dev.haiku-os.org/changeset/40877

Modified:
   haiku/branches/features/package-management/build/jam/OptionalPackages
   haiku/branches/features/package-management/headers/os/package/PackageFlags.h
   haiku/branches/features/package-management/src/bin/package/command_list.cpp
   
haiku/branches/features/package-management/src/bin/package_repo/command_create.cpp
   
haiku/branches/features/package-management/src/bin/package_repo/command_list.cpp
   haiku/branches/features/package-management/src/kits/package/PackageInfo.cpp
Log:
* revert 40861 (support for 'create_package_link'-flag), as we are 
  going to add those links for every package
* fix printing of package version in 'package list'
* refactor list parsing into a specific method
* made parsing a bit more lenient in order to simplify use of 
  .PackageInfo files:
  + copyright and license can now be added one-by-one
  + lists now silently skip a trailing comma


Modified: haiku/branches/features/package-management/build/jam/OptionalPackages
===================================================================
--- haiku/branches/features/package-management/build/jam/OptionalPackages       
2011-03-08 20:23:03 UTC (rev 40876)
+++ haiku/branches/features/package-management/build/jam/OptionalPackages       
2011-03-08 20:36:44 UTC (rev 40877)
@@ -551,13 +551,12 @@
                && $(TARGET_ARCH) = x86 {
        # gcc and binutils
        if $(HAIKU_GCC_VERSION[1]) = 2 {
-               InstallCommonPackage
-                       gcc-2.95.3_110225-1.hpkg
-                       : $(baseURL)/gcc-2.95.3_110225.hpkg ;
+               InstallCommonPackage gcc-2.95.3_110304-1.hpkg
+                       : $(baseURL)/gcc-2.95.3_110304.hpkg ;
 
                # TODO: remove this when we have a mechanism to switch gcc via 
PATH
                AddSymlinkToHaikuImage common settings develop tools
-                       : /boot/common/develop/tools/gcc-2.95.3-110225
+                       : /boot/common/develop/tools/gcc-2.95.3-110304
                        : current ;
        }
 

Modified: 
haiku/branches/features/package-management/headers/os/package/PackageFlags.h
===================================================================
--- 
haiku/branches/features/package-management/headers/os/package/PackageFlags.h    
    2011-03-08 20:23:03 UTC (rev 40876)
+++ 
haiku/branches/features/package-management/headers/os/package/PackageFlags.h    
    2011-03-08 20:36:44 UTC (rev 40877)
@@ -10,13 +10,10 @@
 
 
 enum {
-       B_PACKAGE_FLAG_APPROVE_LICENSE          = 1ul << 0,
+       B_PACKAGE_FLAG_APPROVE_LICENSE  = 1ul << 0,
                // will trigger display and approval of license before 
installation
-       B_PACKAGE_FLAG_SYSTEM_PACKAGE           = 1ul << 1,
+       B_PACKAGE_FLAG_SYSTEM_PACKAGE   = 1ul << 1,
                // marks package as system package (i.e. belonging into 
/boot/system)
-       B_PACKAGE_FLAG_CREATE_PACKAGE_LINK      = 1ul << 2,
-               // package requires a corresponding link from 
/package-links/... to the
-               // base folder where the package has been activated
 };
 
 

Modified: 
haiku/branches/features/package-management/src/bin/package/command_list.cpp
===================================================================
--- haiku/branches/features/package-management/src/bin/package/command_list.cpp 
2011-03-08 20:23:03 UTC (rev 40876)
+++ haiku/branches/features/package-management/src/bin/package/command_list.cpp 
2011-03-08 20:36:44 UTC (rev 40877)
@@ -141,10 +141,6 @@
                                        printf("\t\tapprove_license\n");
                                if ((value.unsignedInt & 
B_PACKAGE_FLAG_SYSTEM_PACKAGE) != 0)
                                        printf("\t\tsystem_package\n");
-                               if ((value.unsignedInt & 
B_PACKAGE_FLAG_CREATE_PACKAGE_LINK)
-                                       != 0) {
-                                       printf("\t\tcreate_package_link\n");
-                               }
                                break;
 
                        case B_PACKAGE_INFO_ARCHITECTURE:
@@ -153,9 +149,7 @@
                                break;
 
                        case B_PACKAGE_INFO_VERSION:
-                               printf("\tversion: %s.%s.%s-%d\n", 
value.version.major,
-                                       value.version.minor, 
value.version.micro,
-                                       value.version.release);
+                               _PrintPackageVersion(value.version);
                                break;
 
                        case B_PACKAGE_INFO_COPYRIGHTS:

Modified: 
haiku/branches/features/package-management/src/bin/package_repo/command_create.cpp
===================================================================
--- 
haiku/branches/features/package-management/src/bin/package_repo/command_create.cpp
  2011-03-08 20:23:03 UTC (rev 40876)
+++ 
haiku/branches/features/package-management/src/bin/package_repo/command_create.cpp
  2011-03-08 20:36:44 UTC (rev 40877)
@@ -58,8 +58,6 @@
                                        printf("\t\tapprove_license\n");
                                if ((flags & B_PACKAGE_FLAG_SYSTEM_PACKAGE) != 
0)
                                        printf("\t\tsystem_package\n");
-                               if ((flags & 
B_PACKAGE_FLAG_CREATE_PACKAGE_LINK) != 0)
-                                       printf("\t\tcreate_package_link\n");
                        }
                } else
                        printf("\tchecksum: %s\n", 
packageInfo.Checksum().String());

Modified: 
haiku/branches/features/package-management/src/bin/package_repo/command_list.cpp
===================================================================
--- 
haiku/branches/features/package-management/src/bin/package_repo/command_list.cpp
    2011-03-08 20:23:03 UTC (rev 40876)
+++ 
haiku/branches/features/package-management/src/bin/package_repo/command_list.cpp
    2011-03-08 20:36:44 UTC (rev 40877)
@@ -88,10 +88,6 @@
                                        printf("\t\tapprove_license\n");
                                if ((value.unsignedInt & 
B_PACKAGE_FLAG_SYSTEM_PACKAGE) != 0)
                                        printf("\t\tsystem_package\n");
-                               if ((value.unsignedInt & 
B_PACKAGE_FLAG_CREATE_PACKAGE_LINK)
-                                       != 0) {
-                                       printf("\t\tcreate_package_link\n");
-                               }
                                break;
 
                        case B_PACKAGE_INFO_ARCHITECTURE:

Modified: 
haiku/branches/features/package-management/src/kits/package/PackageInfo.cpp
===================================================================
--- haiku/branches/features/package-management/src/kits/package/PackageInfo.cpp 
2011-03-08 20:23:03 UTC (rev 40876)
+++ haiku/branches/features/package-management/src/kits/package/PackageInfo.cpp 
2011-03-08 20:36:44 UTC (rev 40877)
@@ -67,6 +67,8 @@
 
 private:
                        struct Token;
+                       struct ListElementParser;
+       friend  struct ListElementParser;
 
                        Token                           _NextToken();
                        void                            _RewindTo(const Token& 
token);
@@ -77,6 +79,7 @@
                                                                        
BPackageArchitecture* value);
                        void                            
_ParseVersionValue(BPackageVersion* value,
                                                                        bool 
releaseIsOptional);
+                       void                            
_ParseList(ListElementParser& elementParser);
                        void                            
_ParseStringList(BObjectList<BString>* value,
                                                                        bool 
allowQuotedStrings = true);
                        void                            _ParseResolvableList(
@@ -139,6 +142,11 @@
 };
 
 
+struct BPackageInfo::Parser::ListElementParser {
+       virtual void operator()(const Token& token) = 0;
+};
+
+
 BPackageInfo::ParseErrorListener::~ParseErrorListener()
 {
 }
@@ -384,8 +392,7 @@
 
 
 void
-BPackageInfo::Parser::_ParseStringList(BObjectList<BString>* value, bool
-       allowQuotedStrings)
+BPackageInfo::Parser::_ParseList(ListElementParser& elementParser)
 {
        Token openBracket = _NextToken();
        if (openBracket.type != TOKEN_OPEN_BRACKET)
@@ -401,60 +408,86 @@
                        if (token.type != TOKEN_COMMA)
                                throw ParseError("expected comma", token.pos);
                        token = _NextToken();
+                       if (token.type == TOKEN_CLOSE_BRACKET) {
+                               // silently skip trailing comma at end of list
+                               return;
+                       }
                } else
                        needComma = true;
 
-               if (allowQuotedStrings) {
-                       if (token.type != TOKEN_QUOTED_STRING && token.type != 
TOKEN_WORD)
-                               throw ParseError("expected quoted-string or 
word", token.pos);
-               } else {
-                       if (token.type != TOKEN_WORD)
-                               throw ParseError("expected word", token.pos);
+               elementParser(token);
+       }
+}
+
+
+void
+BPackageInfo::Parser::_ParseStringList(BObjectList<BString>* value,
+       bool allowQuotedStrings)
+{
+       struct StringParser : public ListElementParser {
+               BObjectList<BString>* value;
+               bool allowQuotedStrings;
+
+               StringParser(BObjectList<BString>* value_, bool 
allowQuotedStrings_)
+                       :
+                       value(value_),
+                       allowQuotedStrings(allowQuotedStrings_)
+               {
                }
 
-               value->AddItem(new BString(token.text));
-       }
+               virtual void operator()(const Token& token)
+               {
+                       if (allowQuotedStrings) {
+                               if (token.type != TOKEN_QUOTED_STRING
+                                       && token.type != TOKEN_WORD) {
+                                       throw ParseError("expected 
quoted-string or word",
+                                               token.pos);
+                               }
+                       } else {
+                               if (token.type != TOKEN_WORD)
+                                       throw ParseError("expected word", 
token.pos);
+                       }
+
+                       value->AddItem(new BString(token.text));
+               }
+       } stringParser(value, allowQuotedStrings);
+
+       _ParseList(stringParser);
 }
 
 
 uint32
 BPackageInfo::Parser::_ParseFlags()
 {
-       uint32 flags = 0;
+       struct FlagParser : public ListElementParser {
+               uint32 flags;
 
-       Token openBracket = _NextToken();
-       if (openBracket.type != TOKEN_OPEN_BRACKET)
-               throw ParseError("expected start of list ('[')", 
openBracket.pos);
+               FlagParser()
+                       :
+                       flags(0)
+               {
+               }
 
-       bool needComma = false;
-       while (true) {
-               Token token = _NextToken();
-               if (token.type == TOKEN_CLOSE_BRACKET)
-                       break;
+               virtual void operator()(const Token& token)
+               {
+                       if (token.type != TOKEN_WORD)
+                               throw ParseError("expected word (a flag)", 
token.pos);
 
-               if (needComma) {
-                       if (token.type != TOKEN_COMMA)
-                               throw ParseError("expected comma", token.pos);
-                       token = _NextToken();
-               } else
-                       needComma = true;
+                       if (token.text.ICompare("approve_license") == 0)
+                               flags |= B_PACKAGE_FLAG_APPROVE_LICENSE;
+                       else if (token.text.ICompare("system_package") == 0)
+                               flags |= B_PACKAGE_FLAG_SYSTEM_PACKAGE;
+                       else {
+                               throw ParseError(
+                                       "expected 'approve_license' or 
'system_package'",
+                                       token.pos);
+                       }
+               }
+       } flagParser;
 
-               if (token.type != TOKEN_WORD)
-                       throw ParseError("expected word (a flag)", token.pos);
+       _ParseList(flagParser);
 
-               if (token.text.ICompare("approve_license") == 0)
-                       flags |= B_PACKAGE_FLAG_APPROVE_LICENSE;
-               else if (token.text.ICompare("system_package") == 0)
-                       flags |= B_PACKAGE_FLAG_SYSTEM_PACKAGE;
-               else if (token.text.ICompare("create_package_link") == 0)
-                       flags |= B_PACKAGE_FLAG_CREATE_PACKAGE_LINK;
-               else {
-                       throw ParseError("expected 'approve_license' or 
'system_package'",
-                               token.pos);
-               }
-       }
-
-       return flags;
+       return flagParser.flags;
 }
 
 
@@ -462,60 +495,63 @@
 BPackageInfo::Parser::_ParseResolvableList(
        BObjectList<BPackageResolvable>* value)
 {
-       Token openBracket = _NextToken();
-       if (openBracket.type != TOKEN_OPEN_BRACKET)
-               throw ParseError("expected start of list ('[')", 
openBracket.pos);
+       struct ResolvableParser : public ListElementParser {
+               Parser& parser;
+               BObjectList<BPackageResolvable>* value;
 
-       bool needComma = false;
-       while (true) {
-               BPackageResolvableType type = B_PACKAGE_RESOLVABLE_TYPE_DEFAULT;
+               ResolvableParser(Parser& parser_,
+                       BObjectList<BPackageResolvable>* value_)
+                       :
+                       parser(parser_),
+                       value(value_)
+               {
+               }
 
-               Token word = _NextToken();
-               if (word.type == TOKEN_CLOSE_BRACKET)
-                       return;
+               virtual void operator()(const Token& token)
+               {
+                       if (token.type != TOKEN_WORD) {
+                               throw ParseError("expected word (a resolvable 
name)",
+                                       token.pos);
+                       }
 
-               if (needComma) {
-                       if (word.type != TOKEN_COMMA)
-                               throw ParseError("expected comma", word.pos);
-                       word = _NextToken();
-               } else
-                       needComma = true;
-
-               if (word.type != TOKEN_WORD)
-                       throw ParseError("expected word (a resolvable name)", 
word.pos);
-
-               int32 colonPos = word.text.FindFirst(':');
-               if (colonPos >= 0) {
-                       BString typeName(word.text, colonPos);
-                       for (int i = 0; i < 
B_PACKAGE_RESOLVABLE_TYPE_ENUM_COUNT; ++i) {
-                               if 
(typeName.ICompare(BPackageResolvable::kTypeNames[i]) == 0) {
-                                       type = (BPackageResolvableType)i;
-                                       break;
+                       BPackageResolvableType type = 
B_PACKAGE_RESOLVABLE_TYPE_DEFAULT;
+                       int32 colonPos = token.text.FindFirst(':');
+                       if (colonPos >= 0) {
+                               BString typeName(token.text, colonPos);
+                               for (int i = 0; i < 
B_PACKAGE_RESOLVABLE_TYPE_ENUM_COUNT; ++i) {
+                                       if 
(typeName.ICompare(BPackageResolvable::kTypeNames[i])
+                                                       == 0) {
+                                               type = 
(BPackageResolvableType)i;
+                                               break;
+                                       }
                                }
-                       }
-                       if (type == B_PACKAGE_RESOLVABLE_TYPE_DEFAULT) {
-                               BString error("resolvable type (<type>:) must 
be one of [");
-                               for (int i = 1; i < 
B_PACKAGE_RESOLVABLE_TYPE_ENUM_COUNT; ++i) {
-                                       if (i > 1)
-                                               error << ",";
-                                       error << 
BPackageResolvable::kTypeNames[i];
+                               if (type == B_PACKAGE_RESOLVABLE_TYPE_DEFAULT) {
+                                       BString error("resolvable type 
(<type>:) must be one of [");
+                                       for (int i = 1; i < 
B_PACKAGE_RESOLVABLE_TYPE_ENUM_COUNT;
+                                               ++i) {
+                                               if (i > 1)
+                                                       error << ",";
+                                               error << 
BPackageResolvable::kTypeNames[i];
+                                       }
+                                       error << "]";
+                                       throw ParseError(error, token.pos);
                                }
-                               error << "]";
-                               throw ParseError(error, word.pos);
                        }
+
+                       BPackageVersion version;
+                       Token op = parser._NextToken();
+                       if (op.type == TOKEN_OPERATOR_ASSIGN)
+                               parser._ParseVersionValue(&version, true);
+                       else if (op.type == TOKEN_COMMA || op.type == 
TOKEN_CLOSE_BRACKET)
+                               parser._RewindTo(op);
+                       else
+                               throw ParseError("expected '=', comma or ']'", 
op.pos);
+
+                       value->AddItem(new BPackageResolvable(token.text, type, 
version));
                }
+       } resolvableParser(*this, value);
 
-               BPackageVersion version;
-               Token op = _NextToken();
-               if (op.type == TOKEN_OPERATOR_ASSIGN)
-                       _ParseVersionValue(&version, true);
-               else if (op.type == TOKEN_COMMA || op.type == 
TOKEN_CLOSE_BRACKET)
-                       _RewindTo(op);
-               else
-                       throw ParseError("expected '=', comma or ']'", op.pos);
-
-               value->AddItem(new BPackageResolvable(word.text, type, 
version));
-       }
+       _ParseList(resolvableParser);
 }
 
 
@@ -523,49 +559,51 @@
 BPackageInfo::Parser::_ParseResolvableExprList(
        BObjectList<BPackageResolvableExpression>* value)
 {
-       Token openBracket = _NextToken();
-       if (openBracket.type != TOKEN_OPEN_BRACKET)
-               throw ParseError("expected start of list ('[')", 
openBracket.pos);
+       struct ResolvableExpressionParser : public ListElementParser {
+               Parser& parser;
+               BObjectList<BPackageResolvableExpression>* value;
 
-       bool needComma = false;
-       while (true) {
-               Token name = _NextToken();
-               if (name.type == TOKEN_CLOSE_BRACKET)
-                       return;
+               ResolvableExpressionParser(Parser& parser_,
+                       BObjectList<BPackageResolvableExpression>* value_)
+                       :
+                       parser(parser_),
+                       value(value_)
+               {
+               }
 
-               if (needComma) {
-                       if (name.type != TOKEN_COMMA)
-                               throw ParseError("expected comma", name.pos);
-                       name = _NextToken();
-               } else
-                       needComma = true;
+               virtual void operator()(const Token& token)
+               {
+                       if (token.type != TOKEN_WORD) {
+                               throw ParseError("expected word (a resolvable 
name)",
+                                       token.pos);
+                       }
 
-               if (name.type != TOKEN_WORD)
-                       throw ParseError("expected word (a resolvable name)", 
name.pos);
+                       BPackageVersion version;
+                       Token op = parser._NextToken();
+                       if (op.type == TOKEN_OPERATOR_LESS
+                               || op.type == TOKEN_OPERATOR_LESS_EQUAL
+                               || op.type == TOKEN_OPERATOR_EQUAL
+                               || op.type == TOKEN_OPERATOR_NOT_EQUAL
+                               || op.type == TOKEN_OPERATOR_GREATER_EQUAL
+                               || op.type == TOKEN_OPERATOR_GREATER)
+                               parser._ParseVersionValue(&version, true);
+                       else if (op.type == TOKEN_COMMA || op.type == 
TOKEN_CLOSE_BRACKET)
+                               parser._RewindTo(op);
+                       else {
+                               throw ParseError(
+                                       "expected '<', '<=', '==', '!=', '>=', 
'>', comma or ']'",
+                                       op.pos);
+                       }
 
-               BPackageVersion version;
-               Token op = _NextToken();
-               if (op.type == TOKEN_OPERATOR_LESS
-                       || op.type == TOKEN_OPERATOR_LESS_EQUAL
-                       || op.type == TOKEN_OPERATOR_EQUAL
-                       || op.type == TOKEN_OPERATOR_NOT_EQUAL
-                       || op.type == TOKEN_OPERATOR_GREATER_EQUAL
-                       || op.type == TOKEN_OPERATOR_GREATER)
-                       _ParseVersionValue(&version, true);
-               else if (op.type == TOKEN_COMMA || op.type == 
TOKEN_CLOSE_BRACKET)
-                       _RewindTo(op);
-               else {
-                       throw ParseError(
-                               "expected '<', '<=', '==', '!=', '>=', '>', 
comma or ']'",
-                               op.pos);
+                       BPackageResolvableOperator resolvableOperator
+                               = (BPackageResolvableOperator)(op.type - 
TOKEN_OPERATOR_LESS);
+
+                       value->AddItem(new 
BPackageResolvableExpression(token.text,
+                               resolvableOperator, version));
                }
+       } resolvableExpressionParser(*this, value);
 
-               BPackageResolvableOperator resolvableOperator
-                       = (BPackageResolvableOperator)(op.type - 
TOKEN_OPERATOR_LESS);
-
-               value->AddItem(new BPackageResolvableExpression(name.text,
-                       resolvableOperator, version));
-       }
+       _ParseList(resolvableExpressionParser);
 }
 
 
@@ -667,6 +705,11 @@
                        _ParseVersionValue(&version, false);
                        packageInfo->SetVersion(version);
                        seen[B_PACKAGE_INFO_VERSION] = true;
+               } else if (t.text.ICompare("copyright") == 0) {
+                       BString copyright;
+                       _ParseStringValue(&copyright);
+                       packageInfo->AddCopyright(copyright);
+                       seen[B_PACKAGE_INFO_COPYRIGHTS] = true;
                } else if (t.text.ICompare(names[B_PACKAGE_INFO_COPYRIGHTS]) == 
0) {
                        if (seen[B_PACKAGE_INFO_COPYRIGHTS]) {
                                BString error = 
BString(names[B_PACKAGE_INFO_COPYRIGHTS])
@@ -680,6 +723,11 @@
                        for (int i = 0; i < count; ++i)
                                
packageInfo->AddCopyright(*(copyrightList.ItemAt(i)));
                        seen[B_PACKAGE_INFO_COPYRIGHTS] = true;
+               } else if (t.text.ICompare("license") == 0) {
+                       BString license;
+                       _ParseStringValue(&license);
+                       packageInfo->AddLicense(license);
+                       seen[B_PACKAGE_INFO_LICENSES] = true;
                } else if (t.text.ICompare(names[B_PACKAGE_INFO_LICENSES]) == 
0) {
                        if (seen[B_PACKAGE_INFO_LICENSES]) {
                                BString error = 
BString(names[B_PACKAGE_INFO_LICENSES])
@@ -771,8 +819,7 @@
                        for (int i = 0; i < count; ++i)
                                
packageInfo->AddReplaces(*(replacesList.ItemAt(i)));
                        seen[B_PACKAGE_INFO_REPLACES] = true;
-               } else if (t.text.ICompare(names[B_PACKAGE_INFO_FLAGS])
-                               == 0) {
+               } else if (t.text.ICompare(names[B_PACKAGE_INFO_FLAGS]) == 0) {
                        if (seen[B_PACKAGE_INFO_FLAGS]) {
                                BString error = 
BString(names[B_PACKAGE_INFO_FLAGS])
                                        << " already seen!";


Other related posts:

  • » [haiku-commits] r40877 - in haiku/branches/features/package-management: build/jam headers/os/package src/bin/package src/bin/package_repo src/kits/package - zooey