Exemplo n.º 1
0
        def doCopy():

            sourcePath = getPath(source)
            abspath = self.configuration.abspath
            engine = self.engine

            targetAbsPath = abspath(target)
            sourceAbsPath = abspath(sourcePath)

            if engine.forceBuild:
                reasonToBuild = "rebuild has been forced"
            elif not onlyNewer:
                reasonToBuild = "onlyNewer is False"
            elif not cake.filesys.isFile(targetAbsPath):
                reasonToBuild = "it doesn't exist"
            elif engine.getTimestamp(sourceAbsPath) > engine.getTimestamp(
                    targetAbsPath):
                reasonToBuild = "'%s' has been changed" % sourcePath
            else:
                # up-to-date
                return

            engine.logger.outputDebug(
                "reason",
                "Rebuilding '%s' because %s.\n" % (target, reasonToBuild),
            )
            engine.logger.outputInfo("Copying %s to %s\n" %
                                     (sourcePath, target))

            try:
                cake.filesys.makeDirs(cake.path.dirName(targetAbsPath))
                cake.filesys.copyFile(sourceAbsPath, targetAbsPath)
            except EnvironmentError, e:
                engine.raiseError("%s: %s\n" % (target, str(e)),
                                  targets=[target])
Exemplo n.º 2
0
    def doCopy():
      
      sourcePath = getPath(source)
      abspath = self.configuration.abspath
      engine = self.engine
      
      targetAbsPath = abspath(target)
      sourceAbsPath = abspath(sourcePath) 
      
      if engine.forceBuild:
        reasonToBuild = "rebuild has been forced"
      elif not onlyNewer:
        reasonToBuild = "onlyNewer is False"
      elif not cake.filesys.isFile(targetAbsPath):
        reasonToBuild = "it doesn't exist"
      elif engine.getTimestamp(sourceAbsPath) > engine.getTimestamp(targetAbsPath):
        reasonToBuild = "'%s' has been changed" % sourcePath
      else:
        # up-to-date
        return

      engine.logger.outputDebug(
        "reason",
        "Rebuilding '%s' because %s.\n" % (target, reasonToBuild),
        )
      engine.logger.outputInfo("Copying %s to %s\n" % (sourcePath, target))
      
      try:
        cake.filesys.makeDirs(cake.path.dirName(targetAbsPath))
        cake.filesys.copyFile(sourceAbsPath, targetAbsPath)
      except EnvironmentError, e:
        engine.raiseError("%s: %s\n" % (target, str(e)), targets=[target])
Exemplo n.º 3
0
 def run(sources):
   results = []
   for s in sources:
     sourcePath = getPath(s)
     target = cake.path.join(targetDir, cake.path.baseName(sourcePath))
     results.append(self._copyFile(source=s, target=target))
   return results
Exemplo n.º 4
0
 def run(sources):
     results = []
     for s in sources:
         sourcePath = getPath(s)
         target = cake.path.join(targetDir,
                                 cake.path.baseName(sourcePath))
         results.append(self._copyFile(source=s, target=target))
     return results
Exemplo n.º 5
0
 def _run():
     try:
         _extract()
     except BuildError:
         raise
     except Exception, e:
         msg = "cake: Error extracting %s to %s: %s\n" % (
             getPath(source), targetDir, str(e))
         engine.raiseError(msg, targets=[targetDir])
Exemplo n.º 6
0
 def _run():
   try:
     _extract()
   except BuildError:
     raise
   except Exception, e:
     msg = "cake: Error extracting %s to %s: %s\n" % (
       getPath(source), targetDir, str(e))
     engine.raiseError(msg, targets=[targetDir])
Exemplo n.º 7
0
def _getClangVersion(clangExe):
    """Returns the Clang version number given an executable.
  """
    args = [getPath(clangExe), '--version']
    try:
        p = subprocess.Popen(
            args=args,
            stdout=subprocess.PIPE,
        )
    except EnvironmentError, e:
        raise EnvironmentError("cake: failed to launch %s: %s\n" %
                               (args[0], str(e)))
Exemplo n.º 8
0
def _getClangVersion(clangExe):
  """Returns the Clang version number given an executable.
  """
  args = [getPath(clangExe), '--version']
  try:
    p = subprocess.Popen(
      args=args,
      stdout=subprocess.PIPE,
      )
  except EnvironmentError, e:
    raise EnvironmentError(
      "cake: failed to launch %s: %s\n" % (args[0], str(e))
      )
Exemplo n.º 9
0
    def _launchTest(self, program, results, cwd, dependencies):

        programPath = getPath(program)

        programArgs = [programPath] + self.extraArgs

        dependencyArgs = programArgs + dependencies

        if self.alwaysRun is None and results:
            try:
                _, reason = self.configuration.checkDependencyInfo(
                    results, dependencyArgs)
                if reason is None:
                    # Up to date
                    return

                self.engine.logger.outputDebug(
                    "reason",
                    "Building '%s' because '%s'\n" % (results, reason),
                )
            except EnvironmentError:
                pass

        self.engine.logger.outputInfo("Testing %s\n" % programPath)

        self.engine.logger.outputDebug("run", " ".join(programArgs))

        if results:
            resultsAbsPath = self.configuration.abspath(results)
            cake.filesys.makeDirs(cake.path.dirName(resultsAbsPath))
            stdout = open(resultsAbsPath, "w+t")
        else:
            stdout = tempfile.TemporaryFile(mode="w+t")

        try:
            p = subprocess.Popen(
                args=programArgs,
                executable=self.configuration.abspath(programPath),
                stdin=subprocess.PIPE,
                stdout=stdout,
                stderr=subprocess.STDOUT,
                cwd=cwd,
                env=self.env)
        except EnvironmentError, e:
            msg = "cake: failed to launch %s: %s\n" % (programPath, str(e))
            self.engine.raiseError(msg, targets=targets)
Exemplo n.º 10
0
        def _extract():
            sourcePath = getPath(source)
            absTargetDir = configuration.abspath(targetDir)
            zipFile = zipfile.ZipFile(configuration.abspath(sourcePath), "r")
            try:
                zipInfos = zipFile.infolist()

                if includeMatch is not None:
                    zipInfos = [
                        z for z in zipInfos if includeMatch(z.filename)
                    ]

                if removeStale:
                    filesInZip = set()
                    for zipInfo in zipInfos:
                        filesInZip.add(
                            os.path.normcase(os.path.normpath(
                                zipInfo.filename)))

                    searchDir = os.path.normpath(absTargetDir)
                    for path in cake.filesys.walkTree(searchDir):
                        normPath = os.path.normcase(path)
                        # Skip files that also exist in the zip.
                        if normPath in filesInZip:
                            continue
                        if engine.dependencyInfoPath is None:
                            # Skip .dep files that match a file in the zip.
                            p, e = os.path.splitext(normPath)
                            if e == ".dep" and p in filesInZip:
                                continue

                        absPath = os.path.join(searchDir, path)
                        engine.logger.outputInfo(
                            "Deleting %s\n" % os.path.join(targetDir, path), )
                        if os.path.isdir(absPath):
                            cake.filesys.removeTree(absPath)
                        else:
                            cake.filesys.remove(absPath)

                for zipinfo in zipInfos:
                    _extractFile(configuration, zipFile, sourcePath, zipinfo,
                                 targetDir, absTargetDir, onlyNewer)
            finally:
                zipFile.close()
Exemplo n.º 11
0
 def _extract():
   sourcePath = getPath(source)
   absTargetDir = configuration.abspath(targetDir)
   zipFile = zipfile.ZipFile(configuration.abspath(sourcePath), "r")
   try:
     zipInfos = zipFile.infolist()
     
     if includeMatch is not None:
       zipInfos = [z for z in zipInfos if includeMatch(z.filename)]
     
     if removeStale:
       filesInZip = set()
       for zipInfo in zipInfos:
         filesInZip.add(os.path.normcase(os.path.normpath(zipInfo.filename)))
       
       searchDir = os.path.normpath(absTargetDir)
       for path in cake.filesys.walkTree(searchDir):
         normPath = os.path.normcase(path)
         # Skip files that also exist in the zip.
         if normPath in filesInZip:
           continue
         if engine.dependencyInfoPath is None:
           # Skip .dep files that match a file in the zip.
           p, e = os.path.splitext(normPath)
           if e == ".dep" and p in filesInZip:
             continue
         
         absPath = os.path.join(searchDir, path)
         engine.logger.outputInfo(
           "Deleting %s\n" % os.path.join(targetDir, path),
           )
         if os.path.isdir(absPath):
           cake.filesys.removeTree(absPath)
         else:
           cake.filesys.remove(absPath)
     
     for zipinfo in zipInfos:
       _extractFile(configuration, zipFile, sourcePath, zipinfo, targetDir, absTargetDir, onlyNewer)   
   finally:
     zipFile.close()
Exemplo n.º 12
0
        def _compress():
            sourceDir = getPath(source)
            absSourceDir = configuration.abspath(sourceDir)

            # Build a list of files/dirs to zip
            toZip = cake.zipping.findFilesToCompress(absSourceDir,
                                                     includeMatch)

            # Check for an existing dependency info file
            buildArgs = []
            toAppend = None
            _, reasonToBuild = configuration.checkDependencyInfo(
                target, buildArgs)
            if reasonToBuild is None:
                # Figure out if we need to rebuild/append
                toAppend, reasonToBuild = _shouldCompress(
                    configuration,
                    sourceDir,
                    target,
                    toZip,
                    onlyNewer,
                    removeStale,
                )
                if reasonToBuild is None:
                    return  # Target is up to date

            engine.logger.outputDebug(
                "reason",
                "Rebuilding '" + target + "' because " + reasonToBuild + ".\n",
            )

            absTargetPath = configuration.abspath(target)
            if toAppend is None:
                # Recreate zip
                cake.filesys.makeDirs(os.path.dirname(absTargetPath))
                f = open(absTargetPath, "wb")
                try:
                    zipFile = zipfile.ZipFile(f, "w")
                    for originalPath in toZip.itervalues():
                        sourcePath = os.path.join(sourceDir, originalPath)
                        absSourcePath = configuration.abspath(sourcePath)
                        configuration.engine.logger.outputInfo(
                            "Adding %s to %s\n" % (sourcePath, target))
                        cake.zipping.writeFileToZip(zipFile, absSourcePath,
                                                    originalPath)
                    zipFile.close()
                finally:
                    f.close()
            else:
                # Append to existing zip
                f = open(absTargetPath, "r+b")
                try:
                    zipFile = zipfile.ZipFile(f, "a")
                    for originalPath in toAppend:
                        sourcePath = os.path.join(sourceDir, originalPath)
                        absSourcePath = configuration.abspath(sourcePath)
                        configuration.engine.logger.outputInfo(
                            "Adding %s to %s\n" % (sourcePath, target))
                        cake.zipping.writeFileToZip(zipFile, absSourcePath,
                                                    originalPath)
                    zipFile.close()
                finally:
                    f.close()

            # Now that the zip has been written successfully, save the new dependency file
            newDependencyInfo = configuration.createDependencyInfo(
                targets=[target],
                args=buildArgs,
                dependencies=[],
            )
            configuration.storeDependencyInfo(newDependencyInfo)
Exemplo n.º 13
0
    def _compress():
      sourceDir = getPath(source)
      absSourceDir = configuration.abspath(sourceDir)

      # Build a list of files/dirs to zip
      toZip = cake.zipping.findFilesToCompress(absSourceDir, includeMatch)

      # Check for an existing dependency info file
      buildArgs = []
      toAppend = None
      _, reasonToBuild = configuration.checkDependencyInfo(target, buildArgs)
      if reasonToBuild is None:
        # Figure out if we need to rebuild/append
        toAppend, reasonToBuild = _shouldCompress(
          configuration,
          sourceDir,
          target,
          toZip,
          onlyNewer,
          removeStale,
          )
        if reasonToBuild is None:
          return # Target is up to date

      engine.logger.outputDebug(
        "reason",
        "Rebuilding '" + target + "' because " + reasonToBuild + ".\n",
        )
      
      absTargetPath = configuration.abspath(target)
      if toAppend is None:
        # Recreate zip
        cake.filesys.makeDirs(os.path.dirname(absTargetPath))
        f = open(absTargetPath, "wb")
        try:
          zipFile = zipfile.ZipFile(f, "w")
          for originalPath in toZip.itervalues():
            sourcePath = os.path.join(sourceDir, originalPath)
            absSourcePath = configuration.abspath(sourcePath)
            configuration.engine.logger.outputInfo("Adding %s to %s\n" % (sourcePath, target))
            cake.zipping.writeFileToZip(zipFile, absSourcePath, originalPath)
          zipFile.close()
        finally:
          f.close()
      else:
        # Append to existing zip
        f = open(absTargetPath, "r+b")
        try:
          zipFile = zipfile.ZipFile(f, "a")
          for originalPath in toAppend:
            sourcePath = os.path.join(sourceDir, originalPath)
            absSourcePath = configuration.abspath(sourcePath)
            configuration.engine.logger.outputInfo("Adding %s to %s\n" % (sourcePath, target))
            cake.zipping.writeFileToZip(zipFile, absSourcePath, originalPath)
          zipFile.close()
        finally:
          f.close()

      # Now that the zip has been written successfully, save the new dependency file 
      newDependencyInfo = configuration.createDependencyInfo(
        targets=[target],
        args=buildArgs,
        dependencies=[],
        )
      configuration.storeDependencyInfo(newDependencyInfo)