Exemple #1
0
    def test1(self):

        def createTasks(bldr):
            bldr.addTask(
                targets=['out/concat.txt'],
                fileDeps=['src/a.txt', 'src/b.txt'],
                upToDate=targetUpToDate,
                action=concat)
        
        def expectBuild():
            with createBldr(fs) as bldr:
                createTasks(bldr)
                self.assertEquals(
                    self.buildAndCheckOutput(
                        bldr,
                        'out/concat.txt',
                        mustHave=['INFO: Building out/concat.txt.', 'INFO: BUILD PASSED!'],
                        forbidden=['INFO: out/concat.txt is up-to-date.']), 0)
            
        def expectUpToDate():
            with createBldr(fs) as bldr:
                createTasks(bldr)
                self.assertEquals(
                    self.buildAndCheckOutput(
                        bldr,
                        'out/concat.txt',
                        mustHave=['INFO: out/concat.txt is up-to-date.', 'INFO: BUILD PASSED!'],
                        forbidden=['INFO: Building out/concat.txt.']), 0)

        print '>>>--- Test1 ---<<<'
        # setXDebug(True)
        fs = MockFS()
        fs.write('src/a.txt', "aFile\n", mkDirs=True)
        fs.write('src/b.txt', "bFile\n", mkDirs=True)
        expectBuild()
        # print fs.show()
        self.assertEquals("aFile\nbFile\n", fs.read('out/concat.txt'))
        # rebuild
        print '--- rebuild ---'
        expectUpToDate()
        self.assertEquals("aFile\nbFile\n", fs.read('out/concat.txt'))
        print '--- modify a source ---'
        fs.write('src/b.txt', "__bFile\n", mkDirs=True)
        # print fs.show()
        expectBuild()
        self.assertEquals("aFile\n__bFile\n", fs.read('out/concat.txt'))
        print '--- TODO: remove target ----'
        fs.remove('out/concat.txt')
        expectBuild()
        print '--- modify target ----'
        fs.write('out/concat.txt', "Lofasz es estifeny", mkDirs=True)
        expectBuild()
        self.assertEquals("aFile\n__bFile\n", fs.read('out/concat.txt'))
Exemple #2
0
 def testRemove(self):
     fs = MockFS()
     fs.write('src/petymeg/pupak.c', 'Hello', mkDirs=True)
     fs.write('src/petymeg/piroska.c', 'Bello', mkDirs=True)
     self.assertTrue(fs.isfile('src/petymeg/pupak.c'))
     self.assertTrue(fs.isfile('src/petymeg/piroska.c'))
     self.assertTrue(fs.isdir('src/petymeg/'))
     self.assertTrue(fs.isdir('src'))
     fs.remove('src/petymeg/pupak.c')
     self.assertFalse(fs.isfile('src/petymeg/pupak.c'))
     self.assertTrue(fs.isfile('src/petymeg/piroska.c'))
     self.assertTrue(fs.isdir('src/petymeg/'))
     self.assertTrue(fs.isdir('src'))
Exemple #3
0
 def testRace(self):
     '''This doesn't induce race condition.'''
     
     def createTasks(bldr):
         bldr.addTask(
             targets=['out/concat.txt'],
             fileDeps=['src/a.txt', 'src/b.txt'],
             upToDate=targetUpToDate,
             action=concat)
     
     fs = MockFS()
     fs.write('src/a.txt', "aFile\n", mkDirs=True)
     fs.write('src/b.txt', "bFile\n", mkDirs=True)
     with createBldr(fs) as bldr:
         createTasks(bldr)
         bldr.buildOne('out/concat.txt')
     print '--- rebuild ---'
     with createBldr(fs) as bldr:
         createTasks(bldr)
         bldr.buildOne('out/concat.txt')
     print '--- modify a source ---'
     fs.write('src/b.txt', "__bFile\n", mkDirs=True)
     # print fs.show()
     with createBldr(fs) as bldr:
         createTasks(bldr)
         bldr.buildOne('out/concat.txt')
     self.assertEquals("aFile\n__bFile\n", fs.read('out/concat.txt'))
     print '--- TODO: remove target ----'
     fs.remove('out/concat.txt')
     with createBldr(fs) as bldr:
         createTasks(bldr)
         bldr.buildOne('out/concat.txt')
     print '--- modify target ----'
     fs.write('out/concat.txt', "Lofasz es estifeny", mkDirs=True)
     with createBldr(fs) as bldr:
         createTasks(bldr)
         bldr.buildOne('out/concat.txt')
     self.assertEquals("aFile\n__bFile\n", fs.read('out/concat.txt'))
Exemple #4
0
    def test2(self):
        
        def countAction(bldr, task, **kwargs):
            
            def countChars(trg, fileDeps):
                res = ''
                for fileDep in fileDeps:
                    content = bldr.fs.read(fileDep)
                    res += 'fileName: {}, chars: {}\n'.format(fileDep, len(content))
                bldr.fs.write(trg, res, mkDirs=True)
            
            def calcHash(trg, fileDeps):
                res = ''
                for fileDep in fileDeps:
                    hashCode = HashEnt.calcHash(bldr.fs.read(fileDep))
                    res += 'fileName: {}, hash: {}\n'.format(fileDep, hashCode)
                bldr.fs.write(trg, res, mkDirs=True)
            
            fileDeps = task.getFileDeps()
            for trg in task.targets:
                if 'charCnt.txt' == bldr.fs.basename(trg):
                    countChars(trg, fileDeps)
                elif 'hash.txt' == bldr.fs.basename(trg):
                    calcHash(trg, fileDeps)
            return 0
            

        def createTasks(bldr):
            bldr.addTask(
                name='all',
                targets=['out/charCnt.txt', 'out/hash.txt'],
                fileDeps=['out/concat.txt', 'src/a.txt', 'src/b.txt'],
                upToDate=targetUpToDate,
                action=countAction)
            bldr.addTask(
                targets=['out/concat.txt'],
                fileDeps=['src/a.txt', 'src/b.txt'],
                upToDate=targetUpToDate,
                action=concat)
            return bldr
        
        print '>>>--- Test2 ---<<<'
        fs = MockFS()
        fs.write('src/a.txt', 'aFile\n', mkDirs=True)
        fs.write('src/b.txt', 'bFile\n', mkDirs=True)
        with createBldr(fs) as bldr:
            createTasks(bldr)
            self.assertEquals(
                self.buildAndCheckOutput(
                    bldr,
                    'out/hash.txt',
                    mustHave=['INFO: Building out/concat.txt.', 'INFO: Building all.', 'INFO: BUILD PASSED!'],
                    forbidden=[]),
                0)
        # print fs.show()
        self.assertEquals('aFile\nbFile\n', fs.read('out/concat.txt'))
        self.assertTrue(fs.isfile('out/hash.txt'))
        print "--- rebuild ---"
        with createBldr(fs) as bldr:
            createTasks(bldr)
            self.assertEquals(
                self.buildAndCheckOutput(
                    bldr,
                    'out/hash.txt',
                    mustHave=['INFO: out/concat.txt is up-to-date.', 'INFO: all is up-to-date.', 'INFO: BUILD PASSED!'],
                    forbidden=[]),
                0)
        print "--- modify a source ---"
        fs.write('src/b.txt', 'brrrr\n', mkDirs=True)
        with createBldr(fs) as bldr:
            createTasks(bldr)
            self.assertEquals(
                self.buildAndCheckOutput(
                    bldr,
                    'out/hash.txt',
                    mustHave=['INFO: Building out/concat.txt.', 'INFO: Building all.', 'INFO: BUILD PASSED!'],
                    forbidden=[]),
                0)
        # print fs.show()
        self.assertEquals('aFile\nbrrrr\n', fs.read('out/concat.txt'))
        self.assertTrue(fs.isfile('out/hash.txt'))
        print "--- remove a top level target ---"
        fs.remove('out/hash.txt')
        with createBldr(fs) as bldr:
            createTasks(bldr)
            self.assertEquals(
                self.buildAndCheckOutput(
                    bldr,
                    'out/hash.txt',
                    mustHave=['INFO: out/concat.txt is up-to-date.', 'INFO: Building all.', 'INFO: BUILD PASSED!'],
                    forbidden=[]),
                0)
Exemple #5
0
    def test0(self):

        def createTasks(bldr, cont):
            return self.createTasks(bldr, cont)

        print '--- 1st build ---'
        cont = self.createContent()
        fs = MockFS()
        cont.create(fs)
        # print 'FS content before build:\n' + fs.show()
        with createBldr(fs) as bldr:
            createTasks(bldr, cont)
            bldr.buildOne('all')
        # hwTask = bldr._getTaskByName('hwTask')
        # print 'FS content after build:\n' + fs.show()
        # print 'a.bin:\n' + fs.read('out/hw/a.bin')
        self.assertEquals(A_BIN_REF, fs.read('out/hw/a.bin'))
        self.assertEquals(LIBA_SO_REF, fs.read('out/sw/liba.so'))
        if True:
            print '--- rebuild ---'
            with createBldr(fs) as bldr:
                createTasks(bldr, cont)
                self.buildAndCheckOutput(
                    bldr, 'all',
                    mustHave=[
                        'INFO: generator is up-to-date.',
                        'INFO: out/hw/core.o is up-to-date.',
                        'INFO: out/hw/SPI.o is up-to-date.',
                        'INFO: out/hw/CzokCodec.o is up-to-date.',
                        'INFO: hwTask is up-to-date.',
                        'INFO: out/sw/main.o is up-to-date.',
                        'INFO: out/sw/helper.o is up-to-date.',
                        'INFO: out/sw/mgr.o is up-to-date.',
                        'INFO: swTask is up-to-date.',
                        'INFO: all is up-to-date.',
                        'INFO: BUILD PASSED!'],
                    forbidden=[])
            self.assertEquals(A_BIN_REF, fs.read('out/hw/a.bin'))
            self.assertEquals(LIBA_SO_REF, fs.read('out/sw/liba.so'))
        if True:
            print '--- modify static dependency ---'
            fs.write('vhdl/SPI.vhdl', 'lofasz es estifeny\n')
            with createBldr(fs) as bldr:
                createTasks(bldr, cont)
                self.buildAndCheckOutput(
                    bldr, 'all',
                    mustHave=[
                        'INFO: generator is up-to-date.',
                        'INFO: out/hw/core.o is up-to-date.',
                        'INFO: Building out/hw/SPI.o.',
                        'INFO: out/hw/CzokCodec.o is up-to-date.',
                        'INFO: Building hwTask.',
                        'INFO: out/sw/main.o is up-to-date.',
                        'INFO: out/sw/helper.o is up-to-date.',
                        'INFO: out/sw/mgr.o is up-to-date.',
                        'INFO: swTask is up-to-date.',
                        'INFO: all is up-to-date.',
                        'INFO: BUILD PASSED!'],
                    forbidden=[])
            # print fs.read('out/hw/a.bin')
            self.assertEquals(LIBA_SO_REF, fs.read('out/sw/liba.so'))
            self.assertEquals(A_BIN_SPI_HACK, fs.read('out/hw/a.bin'))

        if True:
            print '--- modify config ---'
            fs.write(
                'cfg/pupak.desc',
                ('c: mp3\nc: ogg\nc: avi\nc:mp4\n'
                'v:add8_8_C\nv:mul16_16\nv: ALU: 10'))
            with createBldr(fs) as bldr:
                createTasks(bldr, cont)
                self.buildAndCheckOutput(
                    bldr, 'all',
                    mustHave=[
                        'INFO: Building generator.',
                        'INFO: out/hw/core.o is up-to-date.',
                        'INFO: out/hw/SPI.o is up-to-date.',
                        'INFO: out/hw/CzokCodec.o is up-to-date.',
                        'INFO: Building out/hw/ALU.o.',
                        'INFO: out/hw/add8_8_C.o is up-to-date.',
                        'INFO: out/hw/mul16_16.o is up-to-date.',
                        'INFO: Building hwTask.',
                        'INFO: out/sw/main.o is up-to-date.',
                        'INFO: out/sw/helper.o is up-to-date.',
                        'INFO: out/sw/mgr.o is up-to-date.',
                        'INFO: out/sw/mp3.o is up-to-date.',
                        'INFO: out/sw/ogg.o is up-to-date.',
                        'INFO: out/sw/avi.o is up-to-date.',
                        'INFO: out/sw/mp4.o is up-to-date.',
                        'INFO: swTask is up-to-date.',
                        'INFO: all is up-to-date.',
                        'INFO: BUILD PASSED!'],
                    forbidden=[])
            self.assertEquals(LIBA_SO_REF, fs.read('out/sw/liba.so'))
            self.assertEquals(A_BIN_SPI_HACK2, fs.read('out/hw/a.bin'))

        if True:
            print '--- modify source of dynamic dependency ---'
            fs.write('gen/pupak/vhdl/ALU.vhdl', 'Macsonya bacsi')
            with createBldr(fs) as bldr:
                createTasks(bldr, cont)
                # bldr.showDepGraph()
                self.buildAndCheckOutput(
                    bldr, 'all',
                    mustHave=[
                        'INFO: Building generator.',
                        'INFO: out/hw/core.o is up-to-date.',
                        'INFO: out/hw/SPI.o is up-to-date.',
                        'INFO: out/hw/CzokCodec.o is up-to-date.',
                        'INFO: out/hw/ALU.o is up-to-date.',
                        'INFO: out/hw/add8_8_C.o is up-to-date.',
                        'INFO: out/hw/mul16_16.o is up-to-date.',
                        'INFO: hwTask is up-to-date.',
                        'INFO: out/sw/main.o is up-to-date.',
                        'INFO: out/sw/helper.o is up-to-date.',
                        'INFO: out/sw/mgr.o is up-to-date.',
                        'INFO: out/sw/mp3.o is up-to-date.',
                        'INFO: out/sw/ogg.o is up-to-date.',
                        'INFO: out/sw/avi.o is up-to-date.',
                        'INFO: out/sw/mp4.o is up-to-date.',
                        'INFO: swTask is up-to-date.',
                        'INFO: all is up-to-date.',
                        'INFO: BUILD PASSED!'],
                    forbidden=[])
            # bldr.db.showDepGraph()
            self.assertEquals(LIBA_SO_REF, fs.read('out/sw/liba.so'))
            self.assertEquals(A_BIN_SPI_HACK2, fs.read('out/hw/a.bin'))

        if True:
            print '--- modify object of dynamic dependency ---'
            fs.write('out/hw/ALU.o', 'Macsonya bacsi')
            with createBldr(fs) as bldr:
                createTasks(bldr, cont)
                self.buildAndCheckOutput(
                    bldr, 'all',
                    mustHave=[
                        'INFO: generator is up-to-date.',
                        'INFO: out/hw/core.o is up-to-date.',
                        'INFO: out/hw/SPI.o is up-to-date.',
                        'INFO: out/hw/CzokCodec.o is up-to-date.',
                        'INFO: Building out/hw/ALU.o.',
                        'INFO: out/hw/add8_8_C.o is up-to-date.',
                        'INFO: out/hw/mul16_16.o is up-to-date.',
                        'INFO: hwTask is up-to-date.',
                        'INFO: out/sw/main.o is up-to-date.',
                        'INFO: out/sw/helper.o is up-to-date.',
                        'INFO: out/sw/mgr.o is up-to-date.',
                        'INFO: out/sw/mp3.o is up-to-date.',
                        'INFO: out/sw/ogg.o is up-to-date.',
                        'INFO: out/sw/avi.o is up-to-date.',
                        'INFO: out/sw/mp4.o is up-to-date.',
                        'INFO: swTask is up-to-date.',
                        'INFO: all is up-to-date.',
                        'INFO: BUILD PASSED!'],
                    forbidden=[])
            self.assertEquals(LIBA_SO_REF, fs.read('out/sw/liba.so'))
            self.assertEquals(A_BIN_SPI_HACK2, fs.read('out/hw/a.bin'))

        if True:
            print '--- remove object of dynamic dependency ---'
            fs.remove('out/hw/ALU.o')
            with createBldr(fs) as bldr:
                createTasks(bldr, cont)
                # print bldr.show()
                self.buildAndCheckOutput(
                    bldr, 'all',
                    mustHave=[
                        'INFO: generator is up-to-date.',
                        'INFO: out/hw/core.o is up-to-date.',
                        'INFO: out/hw/SPI.o is up-to-date.',
                        'INFO: out/hw/CzokCodec.o is up-to-date.',
                        'INFO: Building out/hw/ALU.o.',
                        'INFO: out/hw/add8_8_C.o is up-to-date.',
                        'INFO: out/hw/mul16_16.o is up-to-date.',
                        'INFO: hwTask is up-to-date.',
                        'INFO: out/sw/main.o is up-to-date.',
                        'INFO: out/sw/helper.o is up-to-date.',
                        'INFO: out/sw/mgr.o is up-to-date.',
                        'INFO: out/sw/mp3.o is up-to-date.',
                        'INFO: out/sw/ogg.o is up-to-date.',
                        'INFO: out/sw/avi.o is up-to-date.',
                        'INFO: out/sw/mp4.o is up-to-date.',
                        'INFO: swTask is up-to-date.',
                        'INFO: all is up-to-date.',
                        'INFO: BUILD PASSED!'],
                    forbidden=[])
            self.assertEquals(LIBA_SO_REF, fs.read('out/sw/liba.so'))
            self.assertEquals(A_BIN_SPI_HACK2, fs.read('out/hw/a.bin'))