Beispiel #1
0
    def clean(self, context):
        """
			Calls the wrapped clean method
		"""
        try:
            deleteFile(self._implicitInputsFile)
        except Exception:
            time.sleep(10.0)
            deleteFile(self._implicitInputsFile)
        self.target.clean(context)
Beispiel #2
0
    def internal_clean(self, context):
        """
			Calls the BaseTarget clean, not the target-specific clean
		"""
        try:
            deleteFile(self._implicitInputsFile)
        except Exception:
            time.sleep(10.0)
            deleteFile(self._implicitInputsFile)
        BaseTarget.clean(self.target, context)
Beispiel #3
0
	def internal_clean(self, context):
		"""
			Calls the BaseTarget clean, not the target-specific clean
		"""
		try:
			deleteFile(self._implicitInputsFile)
		except Exception:
			time.sleep(10.0)
			deleteFile(self._implicitInputsFile)
		BaseTarget.clean(self.target, context)
Beispiel #4
0
	def clean(self, context):
		"""
			Calls the wrapped clean method
		"""
		try:
			deleteFile(self._implicitInputsFile)
		except Exception:
			time.sleep(10.0)
			deleteFile(self._implicitInputsFile)
		self.target.clean(context)
Beispiel #5
0
    def clean(self, context):
        """ Clean this target. 
		
		Default implementation will simply delete the target, and any target 
		workdir, but can be overridden to delete additional temporary files if 
		needed (shouldn't be).
		"""
        try:
            if self.workDir:
                fileutils.deleteDir(self.workDir)
        finally:
            if os.path.isdir(self.path):
                self.log.info('Target clean is deleting directory: %s',
                              self.path)
                fileutils.deleteDir(self.path)
            else:
                fileutils.deleteFile(self.path)
Beispiel #6
0
    def run(self, context):
        """
			Calls the wrapped run method
		"""
        implicitInputs = self.__getImplicitInputs(context)
        if implicitInputs or isDirPath(self.target.name):
            deleteFile(self._implicitInputsFile)

        self.target.run(context)

        # if target built successfully, record what the implicit inputs were to help with the next up to date
        # check and ensure incremental build is correct
        if implicitInputs or isDirPath(self.target.name):
            log.debug('writing implicitInputsFile: %s',
                      self._implicitInputsFile)
            mkdir(os.path.dirname(self._implicitInputsFile))
            with openForWrite(toLongPathSafe(self._implicitInputsFile),
                              'wb') as f:
                f.write(os.linesep.join(implicitInputs))
Beispiel #7
0
	def run(self, context):
		"""
			Calls the wrapped run method
		"""
		implicitInputs = self.__getImplicitInputs(context)
		if implicitInputs or isDirPath(self.target.name):
			deleteFile(self._implicitInputsFile)
		
		self.target.run(context)
		
		# if target built successfully, record what the implicit inputs were to help with the next up to date 
		# check and ensure incremental build is correct
		if implicitInputs or isDirPath(self.target.name):
			log.debug('writing implicitInputsFile: %s', self._implicitInputsFile)
			mkdir(os.path.dirname(self._implicitInputsFile))
			iminpath = os.path.normpath(self._implicitInputsFile)
			if isWindows(): iminpath = u'\\\\?\\'+iminpath
			with openForWrite(iminpath, 'wb') as f:
				f.write(os.linesep.join(implicitInputs))
Beispiel #8
0
    def _run_target(self, target):
        """
			Run a single target, calling clean or run appropriately and counting the time taken
			target - the target object to build
			number - how far through the build are we
			total - the total number of targets to (potentially) build
			Returns a list of error(s) encountered during the build
		"""

        errors = []

        log.info("%s: executing", target.name)
        duration = time.time()
        try:
            if self.options["clean"]:
                try:
                    target.clean(self.context)
                except Exception as e:
                    errors.extend(
                        self._handle_error(target.target,
                                           prefix='Target clean FAILED'))
            else:
                # must always clean before running, in case there's some incorrect junk around
                # in output dir or work dir from a previous execution;
                # doing this means we don't require a full clean when a target incremental build
                # fails
                try:
                    log.debug('%s: Performing pre-execution clean',
                              target.name)
                    target.internal_clean(
                        self.context
                    )  # removes the target and work dir, but doesn't call target-specific clean
                except Exception as e:
                    errors.extend(
                        self._handle_error(
                            target.target,
                            prefix='Target pre-execution clean FAILED'))

                # run the target
                try:
                    if not errors:
                        # if it's enabled, this is the point we want log statements
                        # to get buffered for writing to the output at the end of
                        # this target's execution
                        outputBufferingManager.startBufferingForCurrentThread()

                        log.debug('%s: executing run method for target',
                                  target.name)
                        target.run(self.context)
                except Exception as e:
                    errors.extend(self._handle_error(target.target))

                    # if it failed we MUST delete the stamp file so it rebuilds next time, but
                    # probably useful to not delete the target as it might help tracking
                    # down the error; and definitely don't want to nuke the work dir which often
                    # contains invaluable log files - so don't actually call clean here
                    try:
                        deleteFile(target.stampfile)
                    except Exception:
                        # hopefully won't happen ever
                        errors.extend(
                            self._handle_error(
                                target.target,
                                prefix=
                                'ERROR deleting target stampfile after target failure'
                            ))

            duration = time.time() - duration

            if not self.options["clean"]:
                self.targetTimes[target.name] = (target.path, duration)
            log.critical("    %s: done in %.1f seconds", target.name, duration)
            return errors
        finally:
            outputBufferingManager.endBufferingForCurrentThread()
Beispiel #9
0
    def run(self, context):
        if self.cwd: self.cwd = context.getFullPath(self.cwd, self.baseDir)
        if isDirPath(self.path):
            mkdir(self.path)
            cwd = self.cwd or self.path
        else:
            mkdir(os.path.dirname(self.path))
            cwd = self.cwd or self.workDir
        mkdir(self.workDir)

        cmd = self._resolveCommand(context)

        # this location is a lot easier to find than the target's workdir
        logbasename = os.path.normpath(
            context.getPropertyValue('BUILD_WORK_DIR') +
            '/CustomCommandOutput/' + os.path.basename(cmd[0]) + "." +
            targetNameToUniqueId(self.name))

        stdoutPath = context.getFullPath(
            self.path if self.redirectStdOutToTarget else
            (self.stdout or logbasename + '.out'),
            defaultDir='${BUILD_WORK_DIR}/CustomCommandOutput/')
        stderrPath = context.getFullPath(
            self.stderr or logbasename + '.err',
            defaultDir='${BUILD_WORK_DIR}/CustomCommandOutput/')

        self.log.info('Building %s by executing command line: %s', self.name,
                      ''.join(['\n\t"%s"' % x for x in cmd]))
        if self.cwd:
            self.log.info('Building %s from working directory: %s', self.name,
                          self.cwd)  # only print if overridden
        env = self.env or {}
        if env:
            if callable(env):
                env = env(context)
            else:
                env = {
                    k: None if None == env[k] else self._resolveItem(
                        env[k], context)
                    for k in env
                }
            self.log.info('Environment overrides for %s are: %s', self.name,
                          ''.join(['\n\t"%s=%s"' % (k, env[k]) for k in env]))
        for k in os.environ:
            if k not in env: env[k] = os.getenv(k)

        for k in env.keys():
            if None == env[k]:
                del env[k]
        self.log.info('Output from %s will be written to "%s" and "%s"',
                      self.name, stdoutPath, stderrPath)

        if not os.path.exists(cmd[0]) and not (
                isWindows() and os.path.exists(cmd[0] + '.exe')):
            raise BuildException(
                'Cannot run command because the executable does not exist: "%s"'
                % (cmd[0]),
                location=self.location)

        try:
            success = False
            rc = None
            try:
                # maybe send output to a file instead
                mkdir(os.path.dirname(logbasename))
                with open(stderrPath, 'w') as fe:
                    with open(stdoutPath, 'w') as fo:
                        process = subprocess.Popen(cmd,
                                                   stderr=fe,
                                                   stdout=fo,
                                                   cwd=cwd,
                                                   env=env)

                        rc = _wait_with_timeout(
                            process,
                            '%s(%s)' % (self.name, os.path.basename(cmd[0])),
                            self.options['process.timeout'], False)
                        success = rc == 0

            finally:
                try:
                    if os.path.getsize(stderrPath) == 0 and not self.stderr:
                        deleteFile(stderrPath, allowRetry=True)
                    if not self.redirectStdOutToTarget and os.path.getsize(
                            stdoutPath) == 0 and not self.stdout:
                        deleteFile(stdoutPath, allowRetry=True)
                except Exception, e:
                    # stupid windows, it passes understanding
                    self.log.info(
                        'Failed to delete empty .out/.err files (ignoring error as its not critical): %s',
                        e)

                #if not os.listdir(self.workDir): deleteDir(self.workDir) # don't leave empty work dirs around

                mainlog = '<command generated no output>'

                logMethod = self.log.info if success else self.log.error

                if not self.redirectStdOutToTarget and os.path.isfile(
                        stdoutPath) and os.path.getsize(stdoutPath) > 0:
                    if os.path.getsize(stdoutPath) < 15 * 1024:
                        logMethod(
                            'Output from %s stdout is: \n%s', self.name,
                            open(stdoutPath, 'r').read().replace('\n', '\n\t'))
                    mainlog = stdoutPath
                    if not success:
                        context.publishArtifact('%s stdout' % self, stdoutPath)
                if os.path.isfile(
                        stderrPath) and os.path.getsize(stderrPath) > 0:
                    if os.path.getsize(stderrPath) < 15 * 1024:
                        logMethod(
                            'Output from %s stderr is: \n%s', self.name,
                            open(stderrPath, 'r').read().replace('\n', '\n\t'))
                    mainlog = stderrPath  # take precedence over stdout
                    if not success:
                        context.publishArtifact('%s stderr' % self, stderrPath)

            if rc != None and rc != 0:
                raise BuildException(
                    '%s command failed with error code %s; see output at "%s"'
                    % (os.path.basename(cmd[0]), rc, mainlog),
                    location=self.location)
Beispiel #10
0
	def clean(self):
		dfile = self.target.workDir+'.makedepend'
		deleteFile(dfile)
Beispiel #11
0
	def run(self, context):
		if self.cwd: self.cwd = context.getFullPath(self.cwd, self.baseDir)
		if isDirPath(self.path):
			mkdir(self.path)
			cwd = self.cwd or self.path
		else:
			mkdir(os.path.dirname(self.path))
			cwd = self.cwd or self.workDir
		mkdir(self.workDir)
		
		cmd = self._resolveCommand(context)
		
		# this location is a lot easier to find than the target's workdir
		logbasename = os.path.normpath(context.getPropertyValue('BUILD_WORK_DIR')+'/CustomCommandOutput/'+os.path.basename(cmd[0])+"."+targetNameToUniqueId(self.name))
		
		
		stdoutPath = context.getFullPath(self.path if self.redirectStdOutToTarget else (self.stdout or logbasename+'.out'), defaultDir='${BUILD_WORK_DIR}/CustomCommandOutput/')
		stderrPath = context.getFullPath(self.stderr or logbasename+'.err', defaultDir='${BUILD_WORK_DIR}/CustomCommandOutput/')

		self.log.info('Building %s by executing command line: %s', self.name, ''.join(['\n\t"%s"'%x for x in cmd]))
		if self.cwd: self.log.info('Building %s from working directory: %s', self.name, self.cwd) # only print if overridden
		env = self.env
		if env:
			if callable(env):
				env = env(context)
			else:
				env = {k: self._resolveItem(env[k], context) for k in env}
			self.log.info('Environment overrides for %s are: %s', self.name, ''.join(['\n\t"%s=%s"'%(k, env[k]) for k in env]))
			for k in os.environ:
				if k not in env: env[k] = os.getenv(k)
		
		self.log.info('Output from %s will be written to "%s" and "%s"', self.name, 
			stdoutPath, 
			stderrPath)
		
				
		if not os.path.exists(cmd[0]) and not (isWindows() and os.path.exists(cmd[0]+'.exe')):
			raise BuildException('Cannot run command because the executable does not exist: "%s"'%(cmd[0]), location=self.location)
		
		try:
			success=False
			rc = None
			try:
				# maybe send output to a file instead
				mkdir(os.path.dirname(logbasename))
				with open(stderrPath, 'w') as fe:
					with open(stdoutPath, 'w') as fo:
						process = subprocess.Popen(cmd, 
							stderr=fe, 
							stdout=fo,
							cwd=cwd, 
							env=env)

						options = context.mergeOptions(self) # get the merged options
						rc = _wait_with_timeout(process, '%s(%s)'%(self.name, os.path.basename(cmd[0])), options['process.timeout'], False)
						success = rc == 0
				
			finally:
				try:
					if os.path.getsize(stderrPath) == 0 and not self.stderr: deleteFile(stderrPath, allowRetry=True)
					if not self.redirectStdOutToTarget and os.path.getsize(stdoutPath) == 0 and not self.stdout: deleteFile(stdoutPath, allowRetry=True)
				except Exception, e:
					# stupid windows, it passes understanding
					self.log.info('Failed to delete empty .out/.err files (ignoring error as its not critical): %s', e)
					
				#if not os.listdir(self.workDir): deleteDir(self.workDir) # don't leave empty work dirs around
	
				mainlog = '<command generated no output>'
				
				logMethod = self.log.info if success else self.log.error
				
				if not self.redirectStdOutToTarget and os.path.isfile(stdoutPath) and os.path.getsize(stdoutPath) > 0:
					if os.path.getsize(stdoutPath) < 15*1024:
						logMethod('Output from %s stdout is: \n%s', self.name, open(stdoutPath, 'r').read().replace('\n', '\n\t'))
					mainlog = stdoutPath
					if not success: context.publishArtifact('%s stdout'%self, stdoutPath)
				if os.path.isfile(stderrPath) and os.path.getsize(stderrPath) > 0:
					if os.path.getsize(stderrPath) < 15*1024:
						logMethod('Output from %s stderr is: \n%s', self.name, open(stderrPath, 'r').read().replace('\n', '\n\t'))
					mainlog = stderrPath # take precedence over stdout
					if not success: context.publishArtifact('%s stderr'%self, stderrPath)
			
			if rc != None and rc != 0:
				raise BuildException('%s command failed with error code %s; see output at "%s"'%(os.path.basename(cmd[0]), rc, mainlog), location=self.location)
Beispiel #12
0
	def clean(self):
		dfile = self.target.workDir+'.makedepend'
		log = logging.getLogger('MakeDepend')
		deleteFile(dfile)
Beispiel #13
0
 def clean(self):
     dfile = self.target.workDir + '.makedepend'
     log = logging.getLogger('MakeDepend')
     deleteFile(dfile)
Beispiel #14
0
	def _run_target(self, target):
		"""
			Run a single target, calling clean or run appropriately and counting the time taken
			target - the target object to build
			number - how far through the build are we
			total - the total number of targets to (potentially) build
			Returns a list of error(s) encountered during the build
		"""
		
		errors = []
		
		log.info("%s: executing", target.name)
		duration = time.time()
		try:
			if self.options["clean"]:
				try:
					target.clean(self.context)
				except Exception as e:
					errors.extend(self._handle_error(target.target, prefix='Target clean FAILED'))
			else:
				# must always clean before running, in case there's some incorrect junk around 
				# in output dir or work dir from a previous execution; 
				# doing this means we don't require a full clean when a target incremental build 
				# fails
				try:
					log.debug('%s: Performing pre-execution clean', target.name)
					target.internal_clean(self.context) # removes the target and work dir, but doesn't call target-specific clean
				except Exception as e:
					errors.extend(self._handle_error(target.target, prefix='Target pre-execution clean FAILED'))
				
				# run the target
				try:
					if not errors:
						# if it's enabled, this is the point we want log statements 
						# to get buffered for writing to the output at the end of 
						# this target's execution
						outputBufferingManager.startBufferingForCurrentThread()
	
						log.debug('%s: executing run method for target', target.name)
						target.run(self.context)
				except Exception as e:
					errors.extend(self._handle_error(target.target))
					
					# if it failed we MUST delete the stamp file so it rebuilds next time, but 
					# probably useful to not delete the target as it might help tracking 
					# down the error; and definitely don't want to nuke the work dir which often 
					# contains invaluable log files - so don't actually call clean here
					try:
						deleteFile(target.stampfile)
					except Exception:
						# hopefully won't happen ever
						errors.extend(self._handle_error(target.target, prefix='ERROR deleting target stampfile after target failure'))
					
			duration = time.time() - duration
			
			if not self.options["clean"]:
				self.targetTimes[target.name] = (target.path, duration)
			log.critical("    %s: done in %.1f seconds", target.name, duration)
			return errors
		finally:
			outputBufferingManager.endBufferingForCurrentThread()