コード例 #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 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'))
コード例 #4
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'))
コード例 #5
0
ファイル: example_gen2.py プロジェクト: ebak/xbuild
        elif trg.endswith('.lines'):
            assert src.endswith('.json')
            prefix, countFn = 'number of lines in', countLines
        tasks.append(
            Task(
                 targets=[trg],
                 fileDeps=[src],
                 action=(countAction, {'prefix': prefix, 'countFn': countFn})))
    return tasks


# This example runs on a virtual (mock) filesystem.
fs = MockFS()
# Creating a generator configuration file.
# Here content 2 means the number of files, the generator creates.
fs.write('cfg/cfg.txt', '2', mkDirs=True)
# Create a Builder.
with Builder(fs=fs) as bldr:
    # Create the generator task.
    bldr.addTask(
        name='generator',
        fileDeps=['cfg/cfg.txt'],
        action=generatorAction,
        taskFactory=taskFactory)
    # Create a task for concatenating the .size files
    bldr.addTask(
        name='concatSizeFiles',
        targets=['out/txtInfo.txt'],
        taskDeps=['generator'],
        dynFileDepFetcher=FetchDynFileDeps(EndFilter('.size'), fetchProv=True),
        action=concatAction)
コード例 #6
0
 def test3(self):
     '''Testing when more targets depends on the same file.'''
     def createTasks(bldr):
         bldr.addTask(
             targets=['out/c1.txt'],
             fileDeps=['src/a.txt', 'src/b.txt'],
             upToDate=targetUpToDate,
             action=concat)
         bldr.addTask(
             targets=['out/c2.txt'],
             fileDeps=['src/b.txt', 'src/c.txt'],
             upToDate=targetUpToDate,
             action=concat)
         bldr.addTask(
             targets=['out/c3.txt'],
             fileDeps=['src/d.txt', 'src/e.txt'],
             upToDate=targetUpToDate,
             action=concat)
         bldr.addTask(
             name='all',
             fileDeps=['out/c1.txt', 'out/c2.txt', 'out/c3.txt'],
             upToDate=targetUpToDate)
 
     print '>>>--- Test3 ---<<<'
     fs = MockFS()
     fs.write('src/a.txt', 'aFile\n', mkDirs=True)
     fs.write('src/b.txt', 'bFile\n', mkDirs=True)
     fs.write('src/c.txt', 'cFile\n', mkDirs=True)
     fs.write('src/d.txt', 'dFile\n', mkDirs=True)
     fs.write('src/e.txt', 'eFile\n', mkDirs=True)
     with createBldr(fs) as bldr:
         createTasks(bldr)
         self.assertEquals(
             self.buildAndCheckOutput(
                 bldr,
                 'all',
                 mustHave=[
                     'INFO: Building out/c1.txt.',
                     'INFO: Building out/c2.txt.',
                     'INFO: Building out/c3.txt.',
                     'INFO: Building all.',
                     'INFO: BUILD PASSED!'],
                 forbidden=[]),
             0)
     self.assertEquals('aFile\nbFile\n', fs.read('out/c1.txt'))
     self.assertEquals('bFile\ncFile\n', fs.read('out/c2.txt'))
     self.assertEquals('dFile\neFile\n', fs.read('out/c3.txt'))
     print '--- rebuild ---'
     with createBldr(fs) as bldr:
         createTasks(bldr)
         self.assertEquals(
             self.buildAndCheckOutput(
                 bldr,
                 'all',
                 mustHave=[
                     'INFO: out/c1.txt is up-to-date.',
                     'INFO: out/c2.txt is up-to-date.',
                     'INFO: out/c3.txt is up-to-date.',
                     'INFO: all is up-to-date.',
                     'INFO: BUILD PASSED!'],
                 forbidden=[]),
             0)
     self.assertEquals('aFile\nbFile\n', fs.read('out/c1.txt'))
     self.assertEquals('bFile\ncFile\n', fs.read('out/c2.txt'))
     self.assertEquals('dFile\neFile\n', fs.read('out/c3.txt'))
     print '--- modify common depend file ---'
     fs.write('src/b.txt', 'brrrFile\n', mkDirs=True)
     with createBldr(fs) as bldr:
         createTasks(bldr)
         self.assertEquals(
             self.buildAndCheckOutput(
                 bldr,
                 'all',
                 mustHave=[
                     'INFO: out/c3.txt is up-to-date.',
                     'INFO: Building out/c1.txt.',
                     'INFO: Building out/c2.txt.',
                     'INFO: BUILD PASSED!'],
                 forbidden=[]),
             0)
     self.assertEquals('aFile\nbrrrFile\n', fs.read('out/c1.txt'))
     self.assertEquals('brrrFile\ncFile\n', fs.read('out/c2.txt'))
     self.assertEquals('dFile\neFile\n', fs.read('out/c3.txt'))
コード例 #7
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)
コード例 #8
0
ファイル: example_gen0.py プロジェクト: ebak/xbuild
    cfgPath = task.fileDeps[0]
    cfgValue = int(bldr.fs.read(cfgPath).strip())
    for i in range(cfgValue):
        fpath = 'gen/gen{}.txt'.format(i)
        bldr.fs.write(fpath, 'Generated file {}\n'.format(i), mkDirs=True)
        # Important! All the generated files have to be appended for Task.generatedFiles.
        # In real case, when the generator is an external binary, you can use
        # Task.addGeneratedFiles(fs, dpath) for scanning up the generators output directory.
        task.generatedFiles.append(fpath)
    return 0  # success


# This example runs on a virtual (mock) filesystem.
fs = MockFS()
# Let's create some static files for input.
fs.write('src/a.txt', "aFile\n", mkDirs=True)
fs.write('src/b.txt', "bFile\n", mkDirs=True)
# Creating a generator configuration file.
# Here content 3 means the number of files, the generator creates.
fs.write('cfg/cfg.txt', '3', mkDirs=True)
# Create a Builder.
with Builder(fs=fs) as bldr:
    # Create the generator task.
    bldr.addTask(name='generator',
                 fileDeps=['cfg/cfg.txt'],
                 action=generatorAction)
    # Create a task for concatenating files.
    bldr.addTask(
        name='all',  # It is just a short alias name for the task.
        targets=['out/concat.txt'],
        fileDeps=['src/a.txt', 'src/b.txt'],
コード例 #9
0
ファイル: test_gen0.py プロジェクト: ebak/xbuild
    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'))
コード例 #10
0
# It's an action function.
def concat(bldr, task):
    res = ''
    # Read and append all file dependencies.
    for src in task.getFileDeps():
        res += bldr.fs.read(src)
    # Write targets.
    for trg in task.targets:
        bldr.fs.write(trg, res, mkDirs=True)
    return 0


# This example runs on a virtual (mock) filesystem.
fs = MockFS()
# Let's create some files for input.
fs.write('src/a.txt', "aFile\n", mkDirs=True)
fs.write('src/b.txt', "bFile\n", mkDirs=True)
# Create a Builder.
with Builder(fs=fs) as bldr:
    # Create a task for concatenating the two files.
    bldr.addTask(
        targets=['out/concat.txt'],
        fileDeps=['src/a.txt', 'src/b.txt'],
        upToDate=
        targetUpToDate,  # It is the default up-to-date function, can be skipped.
        action=concat)
    # Build the target.
    bldr.buildOne('out/concat.txt')
    # Print the target.
    print "Content of target:\n{}".format(fs.read('out/concat.txt'))
コード例 #11
0
 def createFS(self):
     fs = MockFS()
     for n in ('a', 'b', 'c', 'd'):
         fs.write('src/{}.txt'.format(n), '{}File'.format(n), mkDirs=True)
     return fs