Exemplo n.º 1
0
    def enableDeployKey(self, keyID):
        Any.requireIsIntNotZero(keyID)

        logging.debug('adding deployKey=%d to project=%s', keyID,
                      self._project.path_with_namespace)

        self._project.keys.enable(keyID)
Exemplo n.º 2
0
def chmodRecursive(path, dirPermission, filePermission):
    """
        Changes the attributes (permissions) of the file or directory
        <path> recursively so that the given path has permissions as specified in
        <dirPermission> and <filePermission>.

        For example, to make a directory writeable for all HRI-EU members:
        FastScript.setPermissions( '/path', 0o775, 0o664 )

        ATTENTION: <dirPermission> and <filePermission> needs to be passed as octal number,
         with a leading '0o' prefix to support Python 2 and 3.
    """
    Any.requireIsTextNonEmpty(path)
    Any.requireIsIntNotZero(dirPermission)
    Any.requireIsIntNotZero(filePermission)

    for dirpath, dirs, files in os.walk(path):
        for item in dirs:
            path = os.path.join(dirpath, item)
            logging.debug("chmod %o %s", dirPermission, path)
            os.chmod(path, dirPermission)

        for item in files:
            path = os.path.join(dirpath, item)
            logging.debug("chmod %o %s", filePermission, path)
            os.chmod(os.path.join(dirpath, item), filePermission)
Exemplo n.º 3
0
    def setParallelJobs( self, number ):
        Any.requireIsIntNotZero( number )
        self._parallelJobs = number
        self._detectBuildCommand()

        # set env.var. so that child programs (incl. custom compile.sh
        # scripts) know about it
        FastScript.setEnv( 'BST_BUILD_JOBS', str(number) )
Exemplo n.º 4
0
    def getDeployKeys(self):
        """
            Returns all global deploy keys as a dict mapping
            'key title' --> ID.
        """
        result = {}

        for key in self._gl.deploykeys.list():
            Any.requireIsTextNonEmpty(key.title)
            Any.requireIsIntNotZero(key.id)

            result[key.title] = key.id

        return result
Exemplo n.º 5
0
    def __init__(self, repoURL, token):
        """
            Establishes a connection to the specified GitLab server
            using the 'gitlab' Python module.

            'repoURL' should be a complete repository URL in the form
            'http[s]://server/group/project.git'

            Should the URL be a HTTPS resource, SSL certificates will not
            be checked.

            path = '<groupName>/><projectName>'

            'token' needs to be a pre-configured private access token
        """
        Any.requireIsTextNonEmpty(repoURL)
        Any.requireIsMatching(repoURL, '^http.+\.git')
        Any.requireIsTextNonEmpty(token)

        tmp = VersionCompat.urlsplit(repoURL)
        Any.requireIsTextNonEmpty(tmp.scheme)
        Any.requireIsTextNonEmpty(tmp.netloc)
        Any.requireIsTextNonEmpty(tmp.path)

        serverURL = '%s://%s' % (tmp.scheme, tmp.netloc)
        Any.requireIsTextNonEmpty(serverURL)

        match = self._splitProjectExpr.match(tmp.path)
        Any.requireIsNotNone(match)

        path = match.group(1)
        Any.requireIsTextNonEmpty(path)
        Any.requireIsMatching(path, '^[A-Za-z0-9].+/.+[A-Za-z0-9]$')

        self._gls = GitLabServer(serverURL, token)
        Any.requireIsInstance(self._gls, GitLabServer)

        self._project = self._gls.getProject(path)
        Any.requireIsInstance(self._project, gitlab.v4.objects.Project)

        self._projectID = self._project.id
        Any.requireIsIntNotZero(self._projectID)
Exemplo n.º 6
0
    def retrieveMetaInfoFromSIT(self):
        """
            Helper function which retrieves as much as possible information
            from a package installed into SIT, f.i. all info from pkgInfo.py.
        """
        self._parsePkgInfo()
        self.vcsRevision = self.gitCommitIdLong

        if self.gitOrigin and self.gitCommitIdLong:
            self.vcsBranch = self.gitBranch
            self.vcsRevision = self.gitCommitIdLong
            self.vcsRelPath = self.gitRelPath
            self.vcsURL = self.gitOrigin
            self.vcsRoot = self.gitOrigin

            Any.requireIsTextNonEmpty(self.vcsURL)
            Any.requireIsTextNonEmpty(self.vcsRevision)
            Any.isOptional(self.vcsRelPath)

        elif self.svnRepositoryURL and self.svnRevision:
            self.vcsURL = self.svnRepositoryURL
            self.vcsRevision = self.svnRevision
            self.vcsRelPath = self.svnRelPath
            self.vcsRoot = self.svnRepositoryRoot

            # svnRelPath is not present in pkgInfo.py but solely computed
            # from the svnRepositoryURL and svnRepositoryRoot
            self.svnRelPath = os.path.relpath(self.svnRepositoryURL,
                                              self.svnRepositoryRoot)
            self.vcsRelPath = self.svnRelPath

            Any.requireIsTextNonEmpty(self.vcsURL)
            Any.requireIsTextNonEmpty(self.vcsRoot)
            Any.requireIsIntNotZero(self.vcsRevision)
            Any.isOptional(self.vcsRelPath)

        if not self.vcsURL:
            logging.debug('neither SVN nor Git repository information found')

        self.isDeprecated = ProjectProperties.isDeprecated(self.canonicalPath)
Exemplo n.º 7
0
def makeCategoryWriteable(sitPath, project, groupName='hriall', mode=0o0775):
    """
        Changes the group and permissions of all directories between
        'sitPath' up to the project version (the project's main directory
        will also be group-writeable so that different developers could
        install different versions.

        Mind to provide an octal number as 'mode'!)
    """
    from ToolBOSCore.Packages import ProjectProperties

    Any.requireIsDir(sitPath)
    Any.requireIsTextNonEmpty(project)
    Any.requireIsTextNonEmpty(groupName)
    Any.requireIsIntNotZero(mode)  # <mode> must be an octal number
    ProjectProperties.requireIsCanonicalPath(project)

    # The current HRI-EU install procedure is implemented in a way that it always
    # attempts to change ownership of the category INCLUDING the SIT root
    # directory. Instead of fixing this there (time-consuming, error-prone) we
    # always set it here as a shortcut.
    FastScript.setGroupPermission(sitPath, groupName, mode)

    # cut off the project version
    tmp = ProjectProperties.splitPath(project)
    mainDir = os.path.join(tmp[0], tmp[1])
    tokens = mainDir.split(os.sep)

    # the current path we are operating on with chmod+chgrp, starting from
    # sitPath
    curPath = sitPath

    # for each token in category do a chmod+chgrp
    for token in tokens:
        curPath = os.path.join(curPath, token)
        FastScript.setGroupPermission(curPath, groupName, mode)
Exemplo n.º 8
0
def setGroupPermission(path, groupName, mode):
    """
        Changes the attributes (permissions) of the file or directory
        <path> so that the given group has permissions as specified in
        <mode>.

        For example, to make a directory writeable for all HRI-EU members:
        FastScript.setGroupPermission( '/path', 'users', 0775 )

        ATTENTION: <mode> needs to be passed as octal number with a
                   leading zero!

        If an operation failed e.g. due to insufficient rights it will be
        silently ignored! If you need to catch such cases please use
        the 'os' module directly. We are also not checking if <path>
        exists at all.
            The only known exception will be if the specified group
        does not exist.
    """
    from grp import getgrnam

    Any.requireIsTextNonEmpty(path)  # do not check if exists
    Any.requireIsTextNonEmpty(groupName)
    Any.requireIsIntNotZero(mode)

    groupID = getgrnam(groupName).gr_gid

    try:
        os.chmod(path, mode)
    except OSError:
        pass

    try:
        os.chown(path, -1, groupID)  # -1 == don't change userID
    except OSError:
        pass
Exemplo n.º 9
0
def _switchEnv_linuxToWindows(targetPlatform):
    import logging

    from ToolBOSCore.Settings import ProcessEnv
    from ToolBOSCore.Settings import UserSetup
    from ToolBOSCore.Settings import ToolBOSSettings

    Any.requireIsTextNonEmpty(targetPlatform)

    def _set_msvc_2017_conf():
        UserSetup.ensureMSVCSetup(sdk, postfix='.' + targetPlatform)
        Any.requireMsg(FastScript.getEnv('WINEPREFIX'), '$WINEPREFIX not set')

        msvcBasePath = r'c:\BuildTools\VC'
        msvcToolsBasePath = r'{}\Tools\MSVC\14.13.26128'.format(msvcBasePath)
        msvcAuxiliaryBasePath = r'{}\Auxiliary\VS'.format(msvcBasePath)
        wkitBasePath = r'c:\Program Files\Windows Kits\10'
        wsdkBasePath = r'c:\Program Files\Microsoft SDKs\Windows\v10.0A'
        wkitVersion = '10.0.16299.0'
        cpu = 'x64' if targetArch == 'amd64' else 'x86'

        FastScript.setEnv('TARGETOS', 'windows')
        FastScript.setEnv('TARGETARCH', targetArch)
        FastScript.setEnv('COMPILER', 'vs2017')
        FastScript.setEnv('INCLUDE', r'{}\include'.format(msvcBasePath))
        FastScript.setEnv(
            'LIB',
            r'{0}\lib\{3};{0}\lib\onecore\{3};{1}\Lib\{4}\um\{3};{1}\Lib\{4}\ucrt\{3};{2}\Lib'
            .format(msvcToolsBasePath, wkitBasePath, wsdkBasePath, cpu,
                    wkitVersion))
        FastScript.setEnv(
            'CL',
            r'/I"{0}\UnitTest\include" /I"{0}\include" /I"{1}\atlmfc\include" /I"{1}\include" /I"{2}\Include\{3}\ucrt" /I"{2}\Include\{3}\um" /I"{2}\Include\{3}\shared"'
            .format(msvcAuxiliaryBasePath, msvcToolsBasePath, wkitBasePath,
                    wkitVersion))
        FastScript.setEnv(
            'CL_CMD',
            r'{0}\bin\Host{1}\{1}\cl.exe'.format(msvcToolsBasePath, cpu))
        FastScript.setEnv(
            'LINK_CMD',
            r'{0}\bin\Host{1}\{1}\link.exe'.format(msvcToolsBasePath, cpu))
        FastScript.setEnv('RC_CMD',
                          r'{0}\bin\{1}\rc.Exe'.format(wkitBasePath, cpu))
        FastScript.setEnv('MT_CMD',
                          r'{0}\bin\{1}\mt.Exe'.format(wkitBasePath, cpu))
        FastScript.setEnv(
            'DUMPBIN_CMD',
            r'{0}\bin\Host{1}\{1}\dumpbin.exe'.format(msvcToolsBasePath, cpu))
        FastScript.setEnv(
            'WindowsLibPath',
            r'{0}\UnionMetadata\{1};{0}\References\{1}'.format(
                wkitBasePath, wkitVersion))
        FastScript.setEnv(
            'LIBPATH',
            r'{0}\atlmfc\lib\{2};{0}\lib\{2};{0}\lib\{2}\store\references;{1}\UnionMetadata\{3};{1}\References\{3}'
            .format(msvcToolsBasePath, wkitBasePath, cpu, wkitVersion))

        if cpu == 'x86':
            compilerBasePath = r'{0}\bin\Hostx86\x86'.format(msvcToolsBasePath)
            compilerBasePath += r';{0}\bin\Hostx86\x86;{0}\bin\Hostx86\x64\1033;{0}\bin\Hostx86\x86\1033'.format(
                msvcToolsBasePath)
        elif cpu == 'x64':
            compilerBasePath = r'{0}\bin\Hostx64\x64'.format(msvcToolsBasePath)
            compilerBasePath += r';{0}\bin\Hostx64\x64\1033'.format(
                msvcToolsBasePath)

        FastScript.setEnv('Path', compilerBasePath)

    def _set_msvc_legacy_conf():
        if sdk == 2008:
            compilerSuite = 'msvc'
            pdkVersion = 'v6.1'
        else:
            compilerSuite = 'vs%d' % sdk
            pdkVersion = 'v7.1'

        UserSetup.ensureMSVCSetup(sdk, postfix='.' + targetPlatform)
        Any.requireMsg(FastScript.getEnv('WINEPREFIX'), '$WINEPREFIX not set')

        basePath = '''c:\\msvc-sdk\\''' + compilerSuite + '''\\'''
        compilerBasePath = basePath + '''VC\\'''
        pdkBasePath = '''c:\\msvc-sdk\\Windows\\''' + pdkVersion + '''\\'''
        compilerCrossPath = ''
        x64 = ''
        amd64 = ''

        if targetArch == 'amd64':
            compilerCrossPath = '''\\x86_amd64'''
            x64 = '''\\x64'''
            amd64 = '''\\amd64'''

        FastScript.setEnv('TARGETOS', 'windows')
        FastScript.setEnv('TARGETARCH', targetArch)
        FastScript.setEnv('COMPILER', compilerSuite)
        FastScript.setEnv(
            'Include',
            pdkBasePath + '''Include;''' + compilerBasePath + '''include''')
        FastScript.setEnv(
            'Lib', compilerBasePath + '''lib''' + amd64 + ''';''' +
            pdkBasePath + '''Lib''' + x64)
        FastScript.setEnv(
            'Path', compilerBasePath + '''bin''' + compilerCrossPath +
            ''';''' + compilerBasePath + '''bin''' + compilerCrossPath +
            '''\\1033;''' + compilerBasePath + '''bin;''' + basePath +
            '''Common7\\IDE;''' + pdkBasePath + '''Bin''')
        FastScript.setEnv(
            'CL_CMD',
            compilerBasePath + '''bin''' + compilerCrossPath + '''\\cl.exe''')
        FastScript.setEnv(
            'LINK_CMD', compilerBasePath + '''bin''' + compilerCrossPath +
            '''\\link.exe''')
        FastScript.setEnv('RC_CMD', pdkBasePath + '''Bin\\RC.Exe''')
        FastScript.setEnv('MT_CMD', pdkBasePath + '''Bin\\mt.exe''')
        FastScript.setEnv('DUMPBIN_CMD',
                          compilerBasePath + '''Bin\\dumpbin.exe''')

    tmp = re.match("^(\S+)-(\S+)-vs(\d+)$", targetPlatform)
    targetArch = tmp.group(2)
    sdk = int(tmp.group(3))

    Any.requireIsTextNonEmpty(targetArch)
    Any.requireIsIntNotZero(sdk)

    # source "ToolBOSPluginWindows" if not already done

    bspMap = ToolBOSSettings.getConfigOption('BST_crossCompileBSPs')
    Any.requireIsDictNonEmpty(bspMap)

    neededBSP = bspMap[targetPlatform]
    Any.requireIsTextNonEmpty(neededBSP)
    ProcessEnv.source(neededBSP)

    logging.debug('using wine from: %s', ProcessEnv.which('wine'))

    # setup Wine

    if not FastScript.getEnv('WINEDEBUG'):
        FastScript.setEnv('WINEDEBUG', '-all')

    if sdk == 2017:
        _set_msvc_2017_conf()
    else:
        _set_msvc_legacy_conf()

    # setup arguments which will be passed to CMake

    fileName = os.path.join(FastScript.getEnv('TOOLBOSCORE_ROOT'),
                            'include/CMake/Windows-WineMSVC.cmake')
    Any.requireIsFileNonEmpty(fileName)

    oldOptions = FastScript.getEnv('BST_CMAKE_OPTIONS')

    if oldOptions:
        newOptions = '-DCMAKE_TOOLCHAIN_FILE=%s %s' % (fileName, oldOptions)
    else:
        newOptions = '-DCMAKE_TOOLCHAIN_FILE=%s' % fileName
    FastScript.setEnv('BST_CMAKE_OPTIONS', newOptions)

    FastScript.unsetEnv('GLIBC_ALIAS')
    FastScript.unsetEnv('GLIBC_VERSION')
Exemplo n.º 10
0
 def setInstallUmask(self, umask):
     Any.requireIsIntNotZero(umask)
     self.content += self.writeTable({'installUmask': umask})