示例#1
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'))
示例#2
0
    def test0(self):
        def fileCheck(*fpaths):
            for fpath in fpaths:
                self.assertTrue(fs.exists(fpath))
                self.assertTrue(fs.isfile(fpath))
                self.assertFalse(fs.isdir(fpath))

        def dirCheck(*fpaths):
            for fpath in fpaths:
                self.assertTrue(fs.exists(fpath))
                self.assertFalse(fs.isfile(fpath))
                self.assertTrue(fs.isdir(fpath))

        fs = MockFS()
        self.assertFalse(fs.exists('src/math/vector.c'))
        self.assertFalse(fs.isfile('src/math/vector.c'))
        self.assertFalse(fs.isdir('src/math/vector.c'))
        fs.mkdirs('src/math/utils')
        fs.write('README.txt', 'hello')
        self.assertEquals('hello', fs.read('README.txt'))
        fs.write('README.txt', 'Hello!')
        self.assertEquals('Hello!', fs.read('README.txt'))
        fs.write('src/main.c', '// main')
        self.assertEquals('// main', fs.read('src/main.c'))
        try:
            fs.mkdirs('src/main.c/utils')
            self.fail()
        except:
            pass
        print fs.show()
        fileCheck('README.txt', 'src/main.c')
        dirCheck('', 'src', 'src/math', 'src/math/', 'src/math/utils')
示例#3
0
    def test0(self):
        def createTasks(bldr, cont):
            return self.createTasks(bldr, cont)

        cont = ContentHelper(
            cEnts=['main', 'helper', 'mgr'],
            vEnts=['core', 'CzokCodec', 'SPI'],
            libPath='out/sw/liba.so',
            binPath='out/hw/a.bin',
            cfgPath='cfg/pupak.desc',
            cfg=('c: mp3\nc: ogg\nc: avi\nc:mp4\n'
                 'v:add8_8_C\nv:mul16_16\nv: CzokEngiene: 10'))
        print '--- clean all ---'
        fs = MockFS()
        cont.create(fs)
        # print 'FS content before build:\n' + fs.show()
        with Builder(fs=fs) as bldr:
            createTasks(bldr, cont)
            self.assertEquals(0, bldr.buildOne('all'))
            allTasks = bldr.db.taskIdSavedTaskDict.keys()
        self.assertEquals(A_BIN_REF, fs.read('out/hw/a.bin'))
        self.assertEquals(LIBA_SO_REF, fs.read('out/sw/liba.so'))
        # print 'FS content after build:\n' + fs.show()
        with Builder(fs=fs) as bldr:
            createTasks(bldr, cont)
            # logger.setLevel(logging.DEBUG)
            self.cleanAndMatchOutput(
                bldr, 'all',
                ['INFO: Removed folder: gen', 'INFO: Removed folder: out'])
        print 'FS content after clean All:\n' + fs.show()
        # print str(fs.getFileList())
        for d in ('gen', 'out'):
            self.assertFalse(fs.isdir(d))
        files = [
            'cfg/pupak.desc', 'src/helper.c', 'src/main.c', 'src/mgr.c',
            'vhdl/CzokCodec.vhdl', 'vhdl/SPI.vhdl', 'vhdl/core.vhdl',
            'default.xbuild'
        ]
        for f in files:
            self.assertTrue(fs.isfile(f), '{} does not exist'.format(f))
        # check DB
        # print fs.read('default.xbuild')
        self.checkDB(fs, allTasks, allTasks)

        print '--- clean hwTask ---'
        fs = MockFS()
        cont.create(fs)
        # print 'FS content before build:\n' + fs.show()
        with Builder(fs=fs) as bldr:
            createTasks(bldr, cont)
            bldr.buildOne('all')
            allTasks = bldr.db.taskIdSavedTaskDict.keys()
        # print 'FS content after build:\n' + fs.show()
        with Builder(fs=fs) as bldr:
            createTasks(bldr, cont)
            # logger.setLevel(logging.DEBUG)
            self.cleanAndMatchOutput(bldr, 'hwTask',
                                     ['INFO: Removed folder: out/hw'])
        print 'FS content after clean All:\n' + fs.show()
        # print str(fs.getFileList())
        for d in ['out/hw']:
            self.assertFalse(fs.isdir(d))
        files = [
            'cfg/pupak.desc', 'gen/pupak/src/avi.c', 'gen/pupak/src/mp3.c',
            'gen/pupak/src/mp4.c', 'gen/pupak/src/ogg.c', 'out/sw/avi.o',
            'out/sw/helper.o', 'out/sw/liba.so', 'out/sw/main.o',
            'out/sw/mgr.o', 'out/sw/mp3.o', 'out/sw/mp4.o', 'out/sw/ogg.o',
            'src/helper.c', 'src/main.c', 'src/mgr.c', 'vhdl/CzokCodec.vhdl',
            'vhdl/SPI.vhdl', 'vhdl/core.vhdl', 'default.xbuild'
        ]
        for f in files:
            self.assertTrue(fs.isfile(f), '{} does not exist'.format(f))
        # print str(sorted(allTasks))
        removedTasks = [
            'hwTask', 'out/hw/CzokCodec.o', 'out/hw/CzokEngiene.o',
            'out/hw/SPI.o', 'out/hw/add8_8_C.o', 'out/hw/core.o',
            'out/hw/mul16_16.o'
        ]
        # check DB
        # print fs.read('default.xbuild')
        self.checkDB(fs, removedTasks, allTasks)
        print '--- clean out/hw/CzokEngiene.o ---'
        fs = MockFS()
        cont.create(fs)
        # print 'FS content before build:\n' + fs.show()
        with Builder(fs=fs) as bldr:
            createTasks(bldr, cont)
            bldr.buildOne('all')
            allTasks = bldr.db.taskIdSavedTaskDict.keys()
        # print 'FS content after build:\n' + fs.show()
        with Builder(fs=fs) as bldr:
            createTasks(bldr, cont)
            # logger.setLevel(logging.DEBUG)
            self.cleanAndMatchOutput(
                bldr, 'out/hw/CzokEngiene.o',
                ['INFO: Removed file: out/hw/CzokEngiene.o'])
        print 'FS content after clean out/hw/CzokEngiene.o:\n' + fs.show()
        # print str(fs.getFileList())
        # for d in ['out/hw']: self.assertFalse(fs.isdir(d))
        files = [
            'cfg/pupak.desc', 'gen/pupak/src/avi.c', 'gen/pupak/src/mp3.c',
            'gen/pupak/src/mp4.c', 'gen/pupak/src/ogg.c',
            'gen/pupak/vhdl/CzokEngiene.vhdl', 'gen/pupak/vhdl/add8_8_C.vhdl',
            'gen/pupak/vhdl/mul16_16.vhdl', 'out/hw/CzokCodec.o',
            'out/hw/SPI.o', 'out/hw/a.bin', 'out/hw/add8_8_C.o',
            'out/hw/core.o', 'out/hw/mul16_16.o', 'out/sw/avi.o',
            'out/sw/helper.o', 'out/sw/liba.so', 'out/sw/main.o',
            'out/sw/mgr.o', 'out/sw/mp3.o', 'out/sw/mp4.o', 'out/sw/ogg.o',
            'src/helper.c', 'src/main.c', 'src/mgr.c', 'vhdl/CzokCodec.vhdl',
            'vhdl/SPI.vhdl', 'vhdl/core.vhdl', 'default.xbuild'
        ]
        for f in files:
            self.assertTrue(fs.isfile(f), '{} does not exist'.format(f))
        # print str(sorted(allTasks))
        removedTasks = ['out/hw/CzokEngiene.o']
        # check DB
        # print fs.read('default.xbuild')
        self.checkDB(fs, removedTasks, allTasks)
        print '--- cleanAll() ---'
        fs = MockFS()
        cont.create(fs)
        # print 'FS content before build:\n' + fs.show()
        with Builder(fs=fs) as bldr:
            createTasks(bldr, cont)
            bldr.buildOne('all')
            allTasks = bldr.db.taskIdSavedTaskDict.keys()
        with Builder(fs=fs) as bldr:
            createTasks(bldr, cont)
            # logger.setLevel(logging.DEBUG)
            bldr.db.cleanAll()
        # TODO: asserts
        print 'FS content after cleanAll():\n' + fs.show()
        # print str(fs.getFileList())
        for d in ('gen', 'out'):
            self.assertFalse(fs.isdir(d))
        files = [
            'cfg/pupak.desc', 'src/helper.c', 'src/main.c', 'src/mgr.c',
            'vhdl/CzokCodec.vhdl', 'vhdl/SPI.vhdl', 'vhdl/core.vhdl',
            'default.xbuild'
        ]
        for f in files:
            self.assertTrue(fs.isfile(f), '{} does not exist'.format(f))
        # check DB
        # print fs.read('default.xbuild')
        self.checkDB(fs, allTasks, allTasks)
示例#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)