Exemple #1
0
 def __init__(self, log: Log, xmlElement: ET.Element) -> None:
     super().__init__(log, xmlElement)
     self.Name = self._ReadAttrib(xmlElement, 'Name')
     self.Version = self._TryReadAttribAsVersion(
         xmlElement, 'Version')  # type: Optional[Version]
     self.TargetName = self._TryReadAttrib(
         xmlElement, 'TargetName')  # type: Optional[str]
     # A optional path that will be specified to cmake
     self.Path = self._TryReadAttrib(xmlElement,
                                     'Path')  # type: Optional[str]
     self.IfCondition = self._TryReadAttrib(
         xmlElement, 'If',
         DependencyCondition.FindPackageAllowed)  # type: Optional[str]
     if self.IfCondition != DependencyCondition.FindPackageAllowed:
         raise XmlFormatException(
             "Unsupported IfCondition '{0}' on FindPackage: '{1}'. Expected {2}"
             .format(self.Version, self.Name,
                     DependencyCondition.FindPackageAllowed))
     if self.Path is not None and IOUtil.IsAbsolutePath(self.Path):
         raise XmlFormatException("Path '{0}' can not be absolute".format(
             self.Path))
Exemple #2
0
 def __init__(self, log: Log, xmlElement: ET.Element) -> None:
     super().__init__(log, xmlElement)
     if self.ValueString == "Disabled":
         self.Value = OptimizationType.Disabled
     elif self.ValueString == "Default":
         self.Value = OptimizationType.Default
     elif self.ValueString == "Full":
         self.Value = OptimizationType.Full
     else:
         raise XmlFormatException(
             "Unknown optimization type '{0}' : '{1}'".format(
                 self.ValueString, self.Name))
Exemple #3
0
 def __init__(self, log: Log, xmlElement: ET.Element) -> None:
     super().__init__(log, xmlElement)
     self.Name = self._ReadAttrib(xmlElement, 'Name')  # type: str
     self.Value =  self._TryReadAttrib(xmlElement, 'Value')  # type: Optional[str]
     self.ConsumedBy = None
     access = self._ReadAttrib(xmlElement, 'Access')  # type: str
     if access == "Public":
         self.Access = AccessType.Public  # type: AccessType
     elif access == "Private":
         self.Access = AccessType.Private
     else:
         raise XmlFormatException("Unknown access type '{0}' on Define: '{1}'".format(access, self.Name))
 def __init__(self, log: Log, xmlElement: ET.Element) -> None:
     super().__init__(log, xmlElement)
     self.Name = self._ReadAttrib(xmlElement, 'Name')  # type: str
     access = self._ReadAttrib(xmlElement, 'Access', 'Public')  # type: str
     if access == "Public":
         self.Access = AccessType.Public  # type: int
     elif access == "Private":
         self.Access = AccessType.Private  # type: int
     elif access == "Link":
         self.Access = AccessType.Link  # type: int
     else:
         raise XmlFormatException(
             "Unknown access type '{0}' on Dependency: '{1}'".format(
                 access, self.Name))
    def __init__(self, log: Log, xmlElement: ET.Element) -> None:
        super().__init__(log, xmlElement)
        self.Name = self._ReadAttrib(xmlElement, 'Name')
        self.DebugName = self._ReadAttrib(xmlElement, 'DebugName', self.Name) # type: str
        defaultTargetName = "{0}::{0}".format(self.Name)
        self.TargetName = self._ReadAttrib(xmlElement, 'TargetName', defaultTargetName) # type: str
        self.Include = self._TryReadAttrib(xmlElement, 'Include')  # type: Optional['str']
        self.Location = self._TryReadAttrib(xmlElement, 'Location')  # type: Optional['str']
        # New assembly keywords primarily used for C# assemblies
        self.HintPath = self._TryReadAttrib(xmlElement, 'HintPath')  # type: Optional['str']
        self.Version =  self._TryReadAttribAsVersion(xmlElement, 'Version')  # type: Optional[Version]
        self.PublicKeyToken = self._TryReadAttrib(xmlElement, 'PublicKeyToken')  # type: Optional['str']
        self.ProcessorArchitecture = self._TryReadAttrib(xmlElement, 'ProcessorArchitecture')  # type: Optional['str']
        self.Culture = self._TryReadAttrib(xmlElement, 'Culture')  # type: Optional['str']
        self.PackageManager = self.__TryGetPackageManager(log, xmlElement)
        self.IfCondition = self._TryReadAttrib(xmlElement, 'If')  # type: Optional[str]
        # Can only be set from code, and it indicates that this dependency is managed by a recipe or similar
        self.IsManaged = False # type: bool
        strAccess = self._TryReadAttrib(xmlElement, 'Access')  # type: Optional['str']

        access = None
        if self.Include != None or strAccess != None:
            strAccess = self._ReadAttrib(xmlElement, 'Access') if access is None else access
            if strAccess == "Public":
                access = AccessType.Public
            elif strAccess == "Private":
                access = AccessType.Private
            else:
                raise XmlFormatException("Unknown access type '{0}' on external dependency: '{1}'".format(access, self.Name))

        strElementType = self._ReadAttrib(xmlElement, 'Type')
        elementType = ExternalDependencyType.TryFromString(strElementType)
        if elementType is None:
            raise XmlException(xmlElement, "Unknown external dependency type: '{0}' expected: {1}".format(strElementType,
                                                                                                          ExternalDependencyType.AllStrings()))
        self.Type = elementType  # type: ExternalDependencyType

        # The access type is only relevant for the include file location
        # the rest should always be included
        self.Access = AccessType.Public if access is None else access   # type: int
        self.ConsumedBy = None

        if self.Type == ExternalDependencyType.DLL:
            if not self.Include is None:
                raise XmlException(xmlElement, "DLL dependency: '{0}' can not contain include paths".format(self.Name))
            if self.Access != AccessType.Public:
                raise XmlException(xmlElement, "DLL dependency: '{0}' can only have a access type of Public".format(self.Name))

        if not isinstance(self.Access, int):
            raise Exception("Internal error")
Exemple #6
0
    def __TryParseFlavor(self, flavor: Optional[str]) -> Dict[str, str]:
        if flavor is None or len(flavor) <= 0:
            return {}
        uniqueIds = {}  # type: Dict[str, str]
        resDict = {}  # type: Dict[str, str]
        entries = flavor.split(',')
        for entry in entries:
            parts = entry.split('=')
            if len(parts) != 2:
                raise XmlFormatException(
                    "Dependency flavor constraint '{0}' not in the expected format 'flavor1=option, flavor2=option'"
                    .format(flavor))
            key = parts[0].strip()
            value = parts[1].strip()
            if key in resDict:
                raise XmlFormatException(
                    "Dependency flavor constraint key '{0}' already defined to '{1}'"
                    .format(key, resDict[key]))
            keyId = key.upper()
            if keyId in uniqueIds:
                raise XmlFormatException(
                    "Dependency flavor constraint key '{0}' already collides with '{1}'"
                    .format(key, uniqueIds[keyId]))

            if not Util.IsValidFlavorName(key):
                raise XmlFormatException(
                    "Dependency flavor name '{0}' is invalid".format(key))

            if not Util.IsValidFlavorOptionName(value):
                raise XmlFormatException(
                    "Dependency flavor option '{1}' is invalid in {0}={1}".
                    format(key, value))

            uniqueIds[keyId] = key
            resDict[key] = value
        return resDict
 def _TryReadAttribAsVersion(
         self,
         xmlElement: ET.Element,
         attribName: str,
         defaultValue: Optional[Version] = None) -> Optional[Version]:
     """ Read the attrib if its available, else return defaultValue """
     strValue = self._TryReadAttrib(xmlElement, attribName, None)
     if strValue is not None:
         res = Version.TryFromString(strValue)
         if res is None:
             raise XmlFormatException(
                 "{0} expects a value in the format 'major[.minor[.patch[.tweak]]]' not '{1}'"
                 .format(attribName, strValue))
         return res
     return defaultValue
 def _ReadBoolAttrib(self,
                     xmlElement: ET.Element,
                     attribName: str,
                     defaultValue: Optional[bool] = None) -> bool:
     """ If the attrib is there we return it
         if its not there and defaultValue is not None we return the default value.
         if its not there and defaultValue is None we throw a exception.
     """
     strValue = self._TryReadAttrib(xmlElement, attribName, None)
     if strValue is not None:
         return BoolStringHelper.FromString(strValue)
     elif defaultValue is not None:
         return defaultValue
     raise XmlFormatException(
         "{0} expects a value of either 'true' or 'false' not '{1}'".format(
             attribName, strValue))
Exemple #9
0
    def __init__(self, log: Log, xmlElement: ET.Element) -> None:
        super().__init__(log, xmlElement)
        self.Name = self._ReadAttrib(xmlElement, 'Name')  # type: str
        flavor = self._TryReadAttrib(xmlElement,
                                     'Flavor')  # type: Optional[str]
        self.Flavor = self.__TryParseFlavor(flavor)
        access = self._ReadAttrib(xmlElement, 'Access', 'Public')  # type: str
        self.IfCondition = self._TryReadAttrib(xmlElement,
                                               'If')  # type: Optional[str]

        if access == "Public":
            self.Access = AccessType.Public  # type: AccessType
        elif access == "Private":
            self.Access = AccessType.Private
        elif access == "Link":
            self.Access = AccessType.Link
        else:
            raise XmlFormatException(
                "Unknown access type '{0}' on Dependency: '{1}'".format(
                    access, self.Name))
    def __init__(self, log: Log, xmlElement: ET.Element) -> None:
        super(XmlGenFileExternalDependency, self).__init__(log, xmlElement)
        self.Name = self._ReadAttrib(xmlElement, 'Name')
        self.DebugName = self._ReadAttrib(xmlElement, 'DebugName',
                                          self.Name)  # type: str
        self.Include = self._TryReadAttrib(xmlElement,
                                           'Include')  # type: Optional['str']
        self.Location = self._TryReadAttrib(
            xmlElement, 'Location')  # type: Optional['str']
        # New assembly keywords primarily used for C# assemblies
        self.HintPath = self._TryReadAttrib(
            xmlElement, 'HintPath')  # type: Optional['str']
        self.Version = self._TryReadAttrib(xmlElement,
                                           'Version')  # type: Optional['str']
        self.PublicKeyToken = self._TryReadAttrib(
            xmlElement, 'PublicKeyToken')  # type: Optional['str']
        self.ProcessorArchitecture = self._TryReadAttrib(
            xmlElement, 'ProcessorArchitecture')  # type: Optional['str']
        self.Culture = self._TryReadAttrib(xmlElement,
                                           'Culture')  # type: Optional['str']
        self.PackageManager = self.__TryGetPackageManager(log, xmlElement)
        strAccess = self._TryReadAttrib(xmlElement,
                                        'Access')  # type: Optional['str']

        access = None
        if self.Include != None or strAccess != None:
            strAccess = self._ReadAttrib(
                xmlElement, 'Access') if access is None else access
            if strAccess == "Public":
                access = AccessType.Public
            elif strAccess == "Private":
                access = AccessType.Private
            else:
                raise XmlFormatException(
                    "Unknown access type '{0}' on external dependency: '{1}'".
                    format(access, self.Name))

        strElementType = self._ReadAttrib(xmlElement, 'Type')
        elementType = ExternalDependencyType.TryFromString(strElementType)
        if elementType is None:
            raise XmlException(
                xmlElement,
                "Unknown external dependency type: '{0}' expected: StaticLib, DLL, Headers, Assembly, Find"
                .format(type))
        self.Type = elementType  # type: int

        # The access type is only relevant for the include file location
        # the rest should always be included
        self.Access = AccessType.Public if access is None else access  # type: int
        self.ConsumedBy = None

        if self.Type == ExternalDependencyType.DLL:
            if not self.Include is None:
                raise XmlException(
                    xmlElement,
                    "DLL dependency: '{0}' can not contain include paths".
                    format(self.Name))
            if self.Access != AccessType.Public:
                raise XmlException(
                    xmlElement,
                    "DLL dependency: '{0}' can only have a access type of Public"
                    .format(self.Name))

        if not isinstance(self.Access, int):
            raise Exception("Internal error")