Beispiel #1
0
def shell(ctx):
    """Run an interactive shell inside the container."""

    if on_windows():
        pake.FileHelper().makedirs('artifacts')

    run_docker(enter_to_shell=True)
Beispiel #2
0
def build(ctx):
    """Build Firestorm Viewer inside the container."""

    if on_windows():
        pake.FileHelper().makedirs('artifacts')

    run_docker(enter_to_shell=False)
Beispiel #3
0
    def __call__(self, ctx):
        ctx.print('Toucher {}'.format(self._tag))

        fp = pake.FileHelper(ctx)

        for i in ctx.outputs:
            fp.touch(i)
Beispiel #4
0
def glob_and_pattern_test(ctx):
    file_helper = pake.FileHelper(ctx)
    for i, o in ctx.outdated_pairs:
        file_helper.touch(o)

    file_helper.makedirs('test_data/glob_and_pattern/delete_me_dir1')
    file_helper.makedirs('test_data/glob_and_pattern/delete_me_dir2')
    file_helper.makedirs('test_data/glob_and_pattern/delete_me_dir3')
Beispiel #5
0
def clean(ctx):
    """Clean the library"""

    file_helper = pake.FileHelper(ctx)
    file_helper.remove(os.path.join(inc_dir, 'libasm_io_defines.inc'))
    file_helper.remove(os.path.join(inc_dir, 'libasm_io_libc_call.inc'))
    file_helper.remove(os.path.join(inc_dir, 'libasm_io_cdecl.inc'))
    file_helper.rmtree('bin')
    file_helper.rmtree('obj')
Beispiel #6
0
def do_all(ctx):
    file_helper = pake.FileHelper(ctx)

    ctx.print(ctx.inputs[0])

    file_helper.touch(ctx.outputs[0])

    # Run a test pakefile.py script in a subdirectory, build 'build' task
    ctx.subpake('test_data/subpake/pakefile.py', 'build')
Beispiel #7
0
def do_multiple_2(ctx):
    file_helper = pake.FileHelper(ctx)

    # All inputs and outputs will be considered out of date

    for i in ctx.inputs:
        ctx.print(i)

    for o in ctx.outputs:
        file_helper.touch(o)
Beispiel #8
0
def do_multiple_3(ctx):
    file_helper = pake.FileHelper(ctx)
    # Only out of date inputs/outputs will be in these collections

    # The elements correspond to each other when the number of inputs is the same
    # as the number of outputs.  ctx.outdated_input[i] is the input related to
    # the output: ctx.outdated_output[i]
    with ctx.multitask() as mt:
        for i, o in zip(ctx.outdated_inputs, ctx.outdated_outputs):
            mt.submit(file_helper.copy, i, o, silent=True)
Beispiel #9
0
def compile_c(ctx):
    file_helper = pake.FileHelper(ctx)
    file_helper.makedirs(obj_dir)

    compiler_args = ([compiler, cc_flags, i, '-o', o]
                     for i, o in ctx.outdated_pairs)
    sync_call = partial(ctx.call, collect_output=pk.max_jobs > 1)

    with ctx.multitask() as mt:
        list(mt.map(sync_call, compiler_args))
Beispiel #10
0
def run_docker(enter_to_shell):
    interactive_message = 'true' if enter_to_shell else 'false'

    have_winpty = shutil.which('winpty') != None

    pwd = os.getcwd()

    path_escape = ''

    if have_winpty:
        pwd = '/' + pwd
        path_escape = '/'

    if on_windows():
        args = []

        if have_winpty:
            args += ['winpty']

        args += [
            'docker', 'run', '--privileged',
            get_windows_interactive_switch(have_winpty), '-e',
            'ON_WINDOWS=true', '-e',
            'INTERACTIVE_MESSAGE=' + interactive_message, '-v',
            '{volume}:{path_escape}/home/build'.format(
                volume=WIN_VOLUME, path_escape=path_escape), '-v',
            '{pwd}\\src:{path_escape}/home/build/src'.format(
                pwd=pwd, path_escape=path_escape), '-v',
            '{pwd}\\artifacts:{path_escape}/home/build/artifacts'.format(
                pwd=pwd, path_escape=path_escape), '-v',
            '{pwd}\\config:{path_escape}/home/build/config'.format(
                pwd=pwd, path_escape=path_escape), IMAGE, ENTRY_SCRIPT
        ]
    else:
        pake.FileHelper().makedirs('install.cache')

        username = getpass.getuser()
        args = [
            'docker', 'run', '--privileged', '-ti', '-e', 'ON_WINDOWS=false',
            '-e', 'INTERACTIVE_MESSAGE=' + interactive_message, '-e',
            'LOCAL_USER_ID=' + str(os.getuid()), '-e',
            'LOCAL_USER='******'-v',
            '{pwd}/install.cache:/var/tmp/{username}/install.cache'.format(
                pwd=pwd, username=username), '-v',
            '{pwd}:/home/build'.format(pwd=pwd), IMAGE, ENTRY_SCRIPT
        ]

    if not enter_to_shell:
        args += [
            '{path_escape}/home/build/src/build_in_docker.sh'.format(
                path_escape=path_escape)
        ]

    process.call(args)
Beispiel #11
0
def build(ctx):
    file_helper = pake.FileHelper(ctx)
    file_helper.touch(ctx.outputs[0])

    # Move to and back, just to test out move
    file_helper.move(ctx.outputs[0], script_dir)
    file_helper.move(os.path.join(script_dir, 'main'), 'test_data')

    file_helper.move('test_data/subpake', '.')
    file_helper.move('subpake', 'test_data/')

    file_helper.copytree('test_data', 'test_data/subpake_copy')
Beispiel #12
0
    def test_filehelper(self):

        fh = pake.FileHelper()

        self.assertEqual(fh.printer, None)

        class SilentTestCtx:
            def print(*args):
                nonlocal self
                self.fail('SilentTestCtx printed from file helper function set to be silent.')

        class TestCtx:
            def print(*args):
                pass

        class ErrCtx:
            # I don't implement print
            pass

        with self.assertRaises(ValueError):
            # Error because no print function is defined.
            _ = pake.FileHelper(ErrCtx())

        past_cwd = os.getcwd()
        os.chdir(script_dir)

        pake.FileHelper().rmtree('test_data/filehelper')

        self.file_helper_test_stub(SilentTestCtx(), silent=True)

        self.file_helper_test_stub(TestCtx(), silent=False)

        self.file_helper_test_stub(None, silent=True)

        self.file_helper_test_stub(None, silent=False)

        os.chdir(past_cwd)
Beispiel #13
0
    def test_integrated(self):
        print('===== STARTING INTEGRATION TEST =====')

        fh = pake.FileHelper()
        fh.glob_remove(os.path.join(script_dir, '**', '*.o'))
        fh.remove(os.path.join(script_dir, 'test_data', 'main'))

        self.assertEqual(
            pake.run(pk, tasks=[print_define, build], call_exit=False), 0)

        self._check_outputs()

        self.assertEqual(pake.run(pk, tasks=[clean], call_exit=False), 0)

        self._check_outputs(exist=False)

        print('===== FINISHED INTEGRATION TEST =====')
Beispiel #14
0
def clean(ctx):
    file_helper = pake.FileHelper(ctx)

    file_helper.glob_remove('test_data/glob_and_pattern/*.o')
    file_helper.glob_remove('test_data/glob_and_pattern/src_a/*.o')
    file_helper.glob_remove('test_data/glob_and_pattern/src_b/*.o')

    file_helper.glob_remove('test_data/*.o')

    file_helper.remove('test_data/main')

    file_helper.rmtree('test_data/test')
    file_helper.remove('test_data/test2')

    ctx.subpake('test_data/subpake/pakefile.py', 'clean')

    file_helper.rmtree('test_data/subpake_copy')

    file_helper.glob_remove_dirs('test_data/glob_and_pattern/delete_me_dir*')

    file_helper.rmtree('test_data/directory_create_test')
Beispiel #15
0
def libasm_io_libc_call(ctx):
    file_helper = pake.FileHelper(ctx)
    file_helper.copy(ctx.inputs[0], ctx.outputs[0])
Beispiel #16
0
    def _existing_files_test(self, jobs):
        # Test file comparisons when outputs already exist

        in1 = os.path.join(script_dir, 'test_data', 'in1')
        in2 = os.path.join(script_dir, 'test_data', 'in2')
        out1 = os.path.join(script_dir, 'test_data', 'out1')
        out2 = os.path.join(script_dir, 'test_data', 'out2')

        # ================

        pake.de_init(clear_conf=False)
        pk = pake.init()

        ran = False

        # Make all the modification times ancient

        os.utime(in1, (0, 0))
        os.utime(in2, (0, 0))
        os.utime(out1, (0, 0))
        os.utime(out2, (0, 0))

        # Make an input recent

        pake.FileHelper().touch(in1)

        # This should run
        @pk.task(i=[in1, in2], o=out1)
        def task_a(ctx):
            nonlocal ran
            ran = True

        pk.run(tasks=task_a, jobs=jobs)

        self.assertTrue(ran)

        # ================

        # Same test as above, except with multiple outputs

        pake.de_init(clear_conf=False)
        pk = pake.init()

        ran = False

        # Make all the modification times ancient

        os.utime(in1, (0, 0))
        os.utime(in2, (0, 0))
        os.utime(out1, (0, 0))
        os.utime(out2, (0, 0))

        # Make an input recent

        pake.FileHelper().touch(in2)

        # This should run
        @pk.task(i=[in1, in2], o=[out1, out2])
        def task_a(ctx):
            nonlocal ran
            ran = True

        pk.run(tasks=task_a, jobs=jobs)

        self.assertTrue(ran)
Beispiel #17
0
def build_example(ctx):
    file_helper = pake.FileHelper(ctx)
    file_helper.makedirs(bin_dir)
    ctx.call(compiler, link_flags, ctx.dependency_outputs, asm_lib_path, '-o',
             exe_target)
Beispiel #18
0
def build(ctx):
    file_helper = pake.FileHelper(ctx)
    file_helper.touch(ctx.outputs[0])
    ctx.print(ctx.inputs[0])
Beispiel #19
0
def do_single_2(ctx):
    file_helper = pake.FileHelper(ctx)

    ctx.print(ctx.inputs[0])
    file_helper.copy(ctx.inputs[0], ctx.outputs[0], copy_metadata=True)
Beispiel #20
0
def clean(ctx):
    file_helper = pake.FileHelper(ctx)
    file_helper.rmtree('bin')
    file_helper.rmtree('obj')
Beispiel #21
0
def do_single(ctx):
    file_helper = pake.FileHelper(ctx)

    ctx.print(ctx.inputs[0])
    file_helper.copy(ctx.inputs[0], ctx.outputs[0])
Beispiel #22
0
def glob_and_pattern_test2(ctx):
    file_helper = pake.FileHelper(ctx)
    with ctx.multitask() as mt:
        list(mt.map(file_helper.touch, ctx.outdated_outputs))
Beispiel #23
0
    def file_helper_test_stub(self, ctx, silent):

        fp = pake.FileHelper(ctx)

        self.assertEqual(fp.printer, ctx)

        # FileHelper.makedirs
        # =============================

        fp.makedirs('test_data/filehelper/sub', silent=silent)

        try:
            fp.makedirs('test_data/filehelper/sub', silent=silent)
        except Exception:
            self.fail('pake.FileHelper.makedirs threw creating an existing directory tree.  '
                      'It should not do this when exist_ok=True, which is default.')

        with self.assertRaises(OSError):
            fp.makedirs('test_data/filehelper/sub', exist_ok=False, silent=silent)

        with self.assertRaises(OSError):
            fp.makedirs('test_data/filehelper', exist_ok=False, silent=silent)

        with self.assertRaises(OSError):
            fp.makedirs('test_data', exist_ok=False, silent=silent)

        self.assertTrue(os.path.isdir('test_data/filehelper'))

        self.assertTrue(os.path.isdir('test_data/filehelper/sub'))

        for i in range(0, 3):
            fp.makedirs('test_data/filehelper/delete_me_{}/sub'.format(i), silent=silent)
            self.assertTrue(os.path.isdir('test_data/filehelper/delete_me_{}/sub'.format(i)))

            touch_file = 'test_data/filehelper/delete_me_{idx}/sub/file{idx}.txt'.format(idx=i)

            fp.touch(touch_file, silent=silent)

            self.assertTrue(os.path.isfile(touch_file))

        # FileHelper.copytree
        # =============================

        fp.copytree('test_data/filehelper', 'test_data/filehelper/copy_test', silent=silent)

        self.assertTrue(os.path.isdir('test_data/filehelper/copy_test'))

        for i in range(0, 3):
            touch_file = 'test_data/filehelper/copy_test/delete_me_{idx}/sub/file{idx}.txt'.format(idx=i)
            self.assertTrue(os.path.isfile(touch_file))

        with self.assertRaises(FileExistsError):
            fp.copytree('test_data/filehelper', 'test_data/filehelper/copy_test', silent=silent)

        # FileHelper.move
        # =============================

        fp.makedirs('test_data/filehelper/movedir', silent=silent)
        fp.touch('test_data/filehelper/move.txt', silent=silent)

        fp.move('test_data/filehelper/move.txt', 'test_data/filehelper/movedir', silent=silent)

        self.assertTrue(os.path.isfile('test_data/filehelper/movedir/move.txt'))

        fp.move('test_data/filehelper/movedir', 'test_data/filehelper/copy_test', silent=silent)

        self.assertTrue(os.path.isfile('test_data/filehelper/copy_test/movedir/move.txt'))

        # FileHelper.remove
        #  =============================

        fp.remove('test_data/filehelper/copy_test/movedir/move.txt', silent=silent)

        self.assertFalse(os.path.isfile('test_data/filehelper/copy_test/movedir/move.txt'))

        try:
            fp.remove('test_data/filehelper/copy_test/movedir/move.txt', silent=silent)
        except Exception:
            self.fail(
                'pake.FileHelper.remove threw removing a non existing file.  It should not do this when must_exist=True, which is default.')

        with self.assertRaises(FileNotFoundError):
            fp.remove('test_data/filehelper/copy_test/movedir/move.txt', must_exist=True, silent=silent)

        # Cannot use remove to remove directories, must use rmtree
        with self.assertRaises(OSError):
            fp.remove('test_data/filehelper/copy_test/movedir', must_exist=True, silent=silent)

        # FileHelper.touch
        # =============================

        try:
            fp.touch('test_data/filehelper/delete_me_0/sub/file0.txt', silent=silent)
        except Exception:
            self.fail(
                'pake.FileHelper.touch threw touching an existing file.  It should not do this when exist_ok=True, which is default.')

        with self.assertRaises(FileExistsError):
            fp.touch('test_data/filehelper/delete_me_0/sub/file0.txt', silent=silent, exist_ok=False)

        # FileHelper.glob_remove
        # =============================

        fp.glob_remove('test_data/filehelper/delete_me_**/sub/file*.txt', silent=silent)

        for i in range(0, 3):
            self.assertFalse(os.path.isfile('test_data/filehelper/delete_me_{idx}/sub/file{idx}.txt'.format(idx=i)))

        # FileHelper.copy
        # =============================

        fp.copy('test_data/in1', 'test_data/filehelper', silent=silent)

        self.assertTrue(os.path.isfile('test_data/filehelper/in1'))

        try:
            fp.copy('test_data/in1', 'test_data/filehelper', silent=silent)
        except Exception:
            self.fail(
                'pake.FileHelper.copy threw overwriting an existing file.  It should not do this.')

        # Just to hit the second path, there is not really a way to portably test copying the metadata,
        # it is up to the shutil module to do it anyway.

        fp.copy('test_data/in2', 'test_data/filehelper', silent=silent, copy_metadata=True)

        self.assertTrue(os.path.isfile('test_data/filehelper/in2'))

        try:
            fp.copy('test_data/in2', 'test_data/filehelper', silent=silent, copy_metadata=True)
        except Exception:
            self.fail(
                'pake.FileHelper.copy with metadata threw overwriting an existing file.  It should not do this.')

        # FileHelper.glob_remove_dirs
        # =============================

        # remove the sub folders under the folders starting with delete_me_*

        fp.glob_remove_dirs('test_data/filehelper/delete_me_**/su*', silent=silent)

        for i in range(0, 3):
            # delete_me_* should remain intact, the sub folders should not
            self.assertTrue(os.path.isdir('test_data/filehelper/delete_me_{}'.format(i)))
            self.assertFalse(os.path.isdir('test_data/filehelper/delete_me_{}/sub'.format(i)))

        fp.glob_remove_dirs('test_data/filehelper/delete_me_*', silent=silent)

        for i in range(0, 3):
            # now they should be gone
            self.assertFalse(os.path.isdir('test_data/filehelper/delete_me_{}'.format(i)))

        # FileHelper.rmtree
        # =============================

        fp.rmtree('test_data/filehelper', silent=silent)

        try:
            fp.rmtree('test_data/filehelper', silent=silent)
        except Exception:
            self.fail(
                'pake.FileHelper.rmtree threw removing a non existent directory.  It should not do this when must_exist=False, which is default.')

        with self.assertRaises(FileNotFoundError):
            fp.rmtree('test_data/filehelper', silent=silent, must_exist=True)
Beispiel #24
0
def build_library(ctx):
    """Build the library."""

    file_helper = pake.FileHelper(ctx)
    file_helper.makedirs(bin_dir)
    ctx.call('ar', 'rcs', library_target, ctx.dependency_outputs)
Beispiel #25
0
def directory_create_test(ctx):
    # Create the above directory if it does not exist (directory compare test)
    file_helper = pake.FileHelper(ctx)
    file_helper.makedirs(ctx.outputs[0])
Beispiel #26
0
def directory_compare_test(ctx):
    # glob_and_pattern_test modifies the input folder, so this should run
    file_helper = pake.FileHelper(ctx)
    file_helper.touch(ctx.outputs[0])
Beispiel #27
0
def toucher_task_func(ctx):
    fp = pake.FileHelper(ctx)

    for i in ctx.outputs:
        fp.touch(i)