Beispiel #1
0
 def _do_subproc(self):
     # careful: REDO_PWD was the PWD relative to the STARTPATH at the time
     # we *started* building the current target; but that target ran
     # redo-ifchange, and it might have done it from a different directory
     # than we started it in.  So os.getcwd() might be != REDO_PWD right
     # now.
     dn = self.dodir
     newp = os.path.realpath(dn)
     os.environ['REDO_PWD'] = state.relpath(newp, vars.STARTDIR)
     os.environ['REDO_TARGET'] = self.basename + self.ext
     os.environ['REDO_DEPTH'] = vars.DEPTH + '  '
     if dn:
         os.chdir(dn)
     os.dup2(self.f.fileno(), 1)
     os.close(self.f.fileno())
     close_on_exec(1, False)
     if vars.VERBOSE or vars.XTRACE: log_('* %s\n' % ' '.join(self.argv))
     os.execvp(self.argv[0], self.argv)
     assert (0)
Beispiel #2
0
 def _do_subproc(self):
     # careful: REDO_PWD was the PWD relative to the STARTPATH at the time
     # we *started* building the current target; but that target ran
     # redo-ifchange, and it might have done it from a different directory
     # than we started it in.  So os.getcwd() might be != REDO_PWD right
     # now.
     dn = self.dodir
     newp = os.path.realpath(dn)
     os.environ['REDO_PWD'] = state.relpath(newp, vars.STARTDIR)
     os.environ['REDO_TARGET'] = self.basename + self.ext
     os.environ['REDO_DEPTH'] = vars.DEPTH + '  '
     if dn:
         os.chdir(dn)
     os.dup2(self.f.fileno(), 1)
     os.close(self.f.fileno())
     close_on_exec(1, False)
     if vars.VERBOSE or vars.XTRACE: log_('* %s\n' % ' '.join(self.argv))
     os.execvp(self.argv[0], self.argv)
     assert(0)
Beispiel #3
0
def _nice(t):
    return state.relpath(t, vars.STARTDIR)
Beispiel #4
0
 def _start_do(self, reason):
     assert(self.lock.owned)
     t = self.t
     sf = self.sf
     newstamp = sf.read_stamp()
     if (sf.is_generated and
         newstamp != state.STAMP_MISSING and 
         (sf.stamp != newstamp or sf.is_override)):
             state.warn_override(_nice(t))
             sf.set_override()
             sf.set_checked()
             sf.save()
             return self._after2(0)
     if (os.path.exists(t) and not os.path.isdir(t + '/.')
          and not sf.is_generated):
         # an existing source file that was not generated by us.
         # This step is mentioned by djb in his notes.
         # For example, a rule called default.c.do could be used to try
         # to produce hello.c, but we don't want that to happen if
         # hello.c was created by the end user.
         # FIXME: always refuse to redo any file that was modified outside
         # of redo?  That would make it easy for someone to override a
         # file temporarily, and could be undone by deleting the file.
         debug2("-- static (%r)\n" % t)
         sf.set_static()
         sf.save()
         return self._after2(0)
     sf.zap_deps1()
     (dodir, dofile, basedir, basename, ext) = _find_do_file(sf)
     if not dofile:
         if os.path.exists(t):
             sf.set_static()
             sf.save()
             return self._after2(0)
         else:
             err('no rule to make %r\n' % t)
             return self._after2(1)
     unlink(self.tmpname1)
     unlink(self.tmpname2)
     ffd = os.open(self.tmpname1, os.O_CREAT|os.O_RDWR|os.O_EXCL, 0666)
     close_on_exec(ffd, True)
     self.f = os.fdopen(ffd, 'w+')
     # this will run in the dofile's directory, so use only basenames here
     if vars.OLD_ARGS:
         arg1 = basename  # target name (no extension)
         arg2 = ext       # extension (if any), including leading dot
     else:
         arg1 = basename + ext  # target name (including extension)
         arg2 = basename        # target name (without extension)
     argv = ['/bin/bash', '-e',
             dofile,
             arg1,
             arg2,
             # temp output file name
             state.relpath(os.path.abspath(self.tmpname2), dodir),
             ]
     if vars.VERBOSE: argv[1] += 'v'
     if vars.XTRACE: argv[1] += 'x'
     if vars.VERBOSE or vars.XTRACE: log_('\n')
     firstline = open(os.path.join(dodir, dofile)).readline().strip()
     if firstline.startswith('#!/'):
         argv[0:2] = firstline[2:].split(' ')
     log('%s => %s\n' % (_nice(t), reason))
     self.dodir = dodir
     self.basename = basename
     self.ext = ext
     self.argv = argv
     sf.is_generated = True
     sf.save()
     dof = state.File(name=os.path.join(dodir, dofile))
     dof.set_static()
     dof.save()
     state.commit()
     jwack.start_job(t, self._do_subproc, self._after)
Beispiel #5
0
#!/usr/bin/env python2
import sys, os

import vars_init
vars_init.init([])

import state, vars
from logs import err

if len(sys.argv[1:]) != 0:
    err('%s: no arguments expected.\n' % sys.argv[0])
    sys.exit(1)

cwd = os.getcwd()
for f in state.files():
    if f.is_generated and f.read_stamp() != state.STAMP_MISSING:
        print state.relpath(os.path.join(vars.BASE, f.name), cwd)
Beispiel #6
0
 def _start_do(self):
     assert (self.lock.owned)
     t = self.t
     sf = self.sf
     newstamp = sf.read_stamp()
     if (sf.is_generated and newstamp != state.STAMP_MISSING
             and (sf.stamp != newstamp or sf.is_override)):
         state.warn_override(_nice(t))
         if not sf.is_override:
             warn('%s - old: %r\n' % (_nice(t), sf.stamp))
             warn('%s - new: %r\n' % (_nice(t), newstamp))
             sf.set_override()
         sf.set_checked()
         sf.save()
         return self._after2(0)
     if (os.path.exists(t) and not os.path.isdir(t + '/.')
             and not sf.is_generated):
         # an existing source file that was not generated by us.
         # This step is mentioned by djb in his notes.
         # For example, a rule called default.c.do could be used to try
         # to produce hello.c, but we don't want that to happen if
         # hello.c was created by the end user.
         debug2("-- static (%r)\n" % t)
         sf.set_static()
         sf.save()
         return self._after2(0)
     sf.zap_deps1()
     (dodir, dofile, basedir, basename, ext) = paths.find_do_file(sf)
     if not dofile:
         if os.path.exists(t):
             sf.set_static()
             sf.save()
             return self._after2(0)
         else:
             err('no rule to make %r\n' % t)
             return self._after2(1)
     unlink(self.tmpname1)
     unlink(self.tmpname2)
     ffd = os.open(self.tmpname1, os.O_CREAT | os.O_RDWR | os.O_EXCL, 0666)
     close_on_exec(ffd, True)
     self.f = os.fdopen(ffd, 'w+')
     # this will run in the dofile's directory, so use only basenames here
     arg1 = basename + ext  # target name (including extension)
     arg2 = basename  # target name (without extension)
     argv = [
         'sh',
         '-e',
         dofile,
         arg1,
         arg2,
         # temp output file name
         state.relpath(os.path.abspath(self.tmpname2), dodir),
     ]
     if vars.VERBOSE: argv[1] += 'v'
     if vars.XTRACE: argv[1] += 'x'
     if vars.VERBOSE or vars.XTRACE: log_('\n')
     firstline = open(os.path.join(dodir, dofile)).readline().strip()
     if firstline.startswith('#!/'):
         argv[0:2] = firstline[2:].split(' ')
     log('%s\n' % _nice(t))
     self.dodir = dodir
     self.basename = basename
     self.ext = ext
     self.argv = argv
     sf.is_generated = True
     sf.save()
     dof = state.File(name=os.path.join(dodir, dofile))
     dof.set_static()
     dof.save()
     state.commit()
     jwack.start_job(t, self._do_subproc, self._after)
Beispiel #7
0
def _nice(t):
    return state.relpath(t, vars.STARTDIR)
Beispiel #8
0
import sys
sys.path.insert(0, '..')
import state

assert(state.relpath('/a/b/c', '/a/b') == 'c')
assert(state.relpath('/a/b/c/', '/a/b') == 'c')
assert(state.relpath('/a/b/c', '/a/b/') == 'c')
assert(state.relpath('/a/b/c//', '/a/b/') == 'c')
assert(state.relpath('/a/b/c/../d', '/a/b/') == 'd')