Пример #1
0
    def _run_flx_pkgconfig(self, src: fbuild.db.SRC) -> fbuild.db.DSTS:
        """
        Run flx_pkgconfig to generate the include files, normally done by flx
        command line harness but we're probably building it here.
        """

        flx_pkgconfig = self.ctx.buildroot / 'host' / 'bin' / 'flx_pkgconfig'
        resh = src.replaceext('.resh')
        includes = src.replaceext('.includes')

        cmd = [
            flx_pkgconfig, '--path+=' + self.ctx.buildroot / 'host' / 'config',
            '--field=includes', '@' + resh
        ]

        stdout, stderr = self.ctx.execute(cmd,
                                          flx_pkgconfig,
                                          '%s -> %s %s' %
                                          (src, resh, includes),
                                          color='yellow',
                                          stdout_quieter=1)

        with open(includes, 'w') as f:
            for include in stdout.decode('utf-8', 'ignore').strip().split(' '):
                print('#include %s' % include, file=f)

        return resh, includes
Пример #2
0
    def __call__(self, src:fbuild.db.SRC, *,
            flags=(),
            buildroot=None) -> fbuild.db.DSTS:
        buildroot = buildroot or self.ctx.buildroot
        # first, copy the src file into the buildroot
        src_buildroot = src.addroot(buildroot)
        dsts = (
            src_buildroot.replaceext('.ml'),
            src_buildroot.replaceext('.mli'),
        )

        if src != src_buildroot:
            src_buildroot.parent.makedirs()
            src.copy(src_buildroot)
            src = src_buildroot

        cmd = [self.exe]
        cmd.extend(self.flags)
        cmd.extend(flags)
        cmd.append(src)

        self.ctx.execute(cmd, str(self), '%s -> %s' % (src, ' '.join(dsts)),
            color='yellow')

        return dsts
Пример #3
0
    def __call__(self, src:fbuild.db.SRC, *,
            flags=(),
            buildroot=None) -> fbuild.db.DSTS:
        buildroot = buildroot or self.ctx.buildroot
        # first, copy the src file into the buildroot
        src_buildroot = src.addroot(buildroot)
        dsts = (
            src_buildroot.replaceext('.ml'),
            src_buildroot.replaceext('.mli'),
        )

        if src != src_buildroot:
            src_buildroot.parent.makedirs()
            src.copy(src_buildroot)
            src = src_buildroot

        cmd = [self.exe]
        cmd.extend(self.flags)
        cmd.extend(flags)
        cmd.append(src)

        self.ctx.execute(cmd, str(self), '%s -> %s' % (src, ' '.join(dsts)),
            color='yellow')

        return dsts
Пример #4
0
    def __call__(self,
                 src: fbuild.db.SRC,
                 *,
                 buildroot=None,
                 flags=[]) -> fbuild.db.DST:
        buildroot = buildroot or self.ctx.buildroot

        # first, copy the src file into the buildroot
        src_buildroot = src.addroot(buildroot)
        dst = src_buildroot.replaceext('.ml')

        if src != src_buildroot:
            src_buildroot.parent.makedirs()
            src.copy(src_buildroot)
            src = src_buildroot

        cmd = [self.exe, '--no-mli']
        cmd.extend(flags)
        cmd.append(src)

        self.ctx.execute(cmd,
                         self.exe.name,
                         '%s -> %s' % (src, dst),
                         color='yellow')

        return dst
Пример #5
0
    def _run_flx_pkgconfig(self, src:fbuild.db.SRC) -> fbuild.db.DSTS:
        """
        Run flx_pkgconfig to generate the include files, normally done by flx
        command line harness but we're probably building it here.
        """

        flx_pkgconfig = self.ctx.buildroot / 'host'/'bin'/'flx_pkgconfig'
        resh = src.replaceext('.resh')
        includes = src.replaceext('.includes')

        cmd = [
            flx_pkgconfig,
            '--path+=' + self.ctx.buildroot / 'host'/'config',
            '--field=includes',
            '@' + resh]

        stdout, stderr = self.ctx.execute(
            cmd,
            flx_pkgconfig,
            '%s -> %s %s' % (src, resh, includes),
            color='yellow',
            stdout_quieter=1)

        with open(includes, 'w') as f:
            for include in stdout.decode('utf-8','ignore').strip().split(' '):
                print('#include %s' % include, file=f)

        return resh, includes
Пример #6
0
    def _run_flx_pkgconfig(self, src: fbuild.db.SRC) -> fbuild.db.DSTS:
        """
        Run flx_pkgconfig to generate the include files, normally done by flx
        command line harness but we're probably building it here.
        """

        flx_pkgconfig = self.ctx.buildroot / "bin" / "flx_pkgconfig"
        resh = src.replaceext(".resh")
        includes = src.replaceext(".includes")

        cmd = [flx_pkgconfig, "--path+=" + self.ctx.buildroot / "config", "--field=includes", "@" + resh]

        stdout, stderr = self.ctx.execute(
            cmd, flx_pkgconfig, "%s -> %s %s" % (src, resh, includes), color="yellow", stdout_quieter=1
        )

        with open(includes, "w") as f:
            for include in stdout.decode("utf-8", "ignore").strip().split(" "):
                print("#include %s" % include, file=f)

        return resh, includes
Пример #7
0
    def __call__(self,
                 src: fbuild.db.SRC,
                 *,
                 break_on_error=True,
                 flags=[],
                 buildroot=None,
                 **kwargs) -> fbuild.db.DSTS:
        buildroot = buildroot or self.ctx.buildroot
        src = Path(src)

        cmd = [
            sys.executable,
            self.exe.relpath(buildroot),
            '--cache-prefix=lpsrc-cache',
            '--trace=sources',
            '--trace=changes',
            '--nocache',
        ]

        if break_on_error:
            cmd.append('--break-on-error')
        cmd.extend(flags)
        cmd.append(src.relpath(buildroot))

        stdout, stderr = self.ctx.execute(
            cmd,
            'iscr extracting',
            src,
            color='green',
            cwd=buildroot,
            env={'PYTHONPATH': Path('buildsystem').relpath(buildroot)},
            **kwargs)

        srcs = []
        dsts = []
        ipk_regex = re.compile('^CREATING .* NAMED FILE SOURCE (.*) \[.*\]')
        file_regex = re.compile('^File (.*) is (NEW|CHANGED|unchanged)')
        for line in io.StringIO(stdout.decode()):
            m = ipk_regex.match(line)
            if m:
                path = Path(m.group(1))
                if not path.exists():
                    # The path may be relative to the .pak file.
                    path = src.parent / path
                srcs.append(path)
            else:
                m = file_regex.match(line)
                if m:
                    dsts.append(Path(m.group(1)))

        #self.ctx.db.add_external_dependencies_to_call(srcs=srcs)

        return dsts
Пример #8
0
    def __call__(self, src:fbuild.db.SRC, *,
            buildroot=None,
            flags=[]) -> fbuild.db.DST:
        buildroot = buildroot or self.ctx.buildroot

        # first, copy the src file into the buildroot
        src_buildroot = src.addroot(buildroot)
        dst = src_buildroot.replaceext('.ml')

        if src != src_buildroot:
            src_buildroot.parent.makedirs()
            src.copy(src_buildroot)
            src = src_buildroot

        cmd = [self.exe]
        cmd.extend(flags)
        cmd.append(src)

        self.ctx.execute(cmd, self.exe.name, '%s -> %s' % (src, dst),
            color='yellow')

        return dst
Пример #9
0
    def __call__(
        self, src: fbuild.db.SRC, *, break_on_error=True, flags=[], buildroot=None, **kwargs
    ) -> fbuild.db.DSTS:
        buildroot = buildroot or self.ctx.buildroot
        src = Path(src)

        cmd = [
            sys.executable,
            self.exe.relpath(buildroot),
            "--cache-prefix=lpsrc-cache",
            "--trace=sources",
            "--trace=changes",
            "--nocache",
        ]

        if break_on_error:
            cmd.append("--break-on-error")
        cmd.extend(flags)
        cmd.append(src.relpath(buildroot))

        stdout, stderr = self.ctx.execute(
            cmd,
            "iscr extracting",
            src,
            color="green",
            cwd=buildroot,
            env={"PYTHONPATH": Path("buildsystem").relpath(buildroot)},
            **kwargs
        )

        srcs = []
        dsts = []
        ipk_regex = re.compile("^CREATING .* NAMED FILE SOURCE (.*) \[.*\]")
        file_regex = re.compile("^File (.*) is (NEW|CHANGED|unchanged)")
        for line in io.StringIO(stdout.decode()):
            m = ipk_regex.match(line)
            if m:
                path = Path(m.group(1))
                if not path.exists():
                    # The path may be relative to the .pak file.
                    path = src.parent / path
                srcs.append(path)
            else:
                m = file_regex.match(line)
                if m:
                    dsts.append(Path(m.group(1)))

        # self.ctx.db.add_external_dependencies_to_call(srcs=srcs)

        return dsts
Пример #10
0
def build_judytables(ctx, tablegen:fbuild.db.SRC, dst) -> fbuild.db.DST:
    """Create the judytable generator executable."""

    # Make sure the directory exists.
    dst.parent.makedirs()

    # We have to run the tablegen from the working directory to get the files
    # generated in the right place.
    ctx.execute(tablegen.abspath(),
        msg1=tablegen.name,
        msg2=dst,
        cwd=dst.parent,
        color='yellow')

    return dst
Пример #11
0
def build_judytables(ctx, tablegen: fbuild.db.SRC, dst) -> fbuild.db.DST:
    """Create the judytable generator executable."""

    # Make sure the directory exists.
    dst.parent.makedirs()

    # We have to run the tablegen from the working directory to get the files
    # generated in the right place.
    ctx.execute(tablegen.abspath(),
                msg1=tablegen.name,
                msg2=dst,
                cwd=dst.parent,
                color='yellow')

    return dst
Пример #12
0
    def __call__(self, src:fbuild.db.SRC, *,
            flags=(),
            buildroot=None) -> fbuild.db.DST:
        buildroot = buildroot or self.ctx.buildroot
        dst = src.replaceext('.ml').addroot(buildroot)
        dst.parent.makedirs()

        cmd = [self.exe]
        cmd.extend(('-o', dst))
        cmd.extend(self.flags)
        cmd.extend(flags)
        cmd.append(src)

        self.ctx.execute(cmd, str(self),
            '%s -> %s' % (src, dst),
            color='yellow')

        return dst
Пример #13
0
    def __call__(self, src:fbuild.db.SRC, *,
            flags=(),
            buildroot=None) -> fbuild.db.DST:
        buildroot = buildroot or self.ctx.buildroot
        dst = src.replaceext('.ml').addroot(buildroot)
        dst.parent.makedirs()

        cmd = [self.exe]
        cmd.extend(('-o', dst))
        cmd.extend(self.flags)
        cmd.extend(flags)
        cmd.append(src)

        self.ctx.execute(cmd, str(self),
            '%s -> %s' % (src, dst),
            color='yellow')

        return dst
Пример #14
0
    def source_dependencies(self, src:fbuild.db.SRC, *,
            includes=(),
            **kwargs) -> fbuild.db.DSTS:
        """Compute the source files this ocaml file depends on."""
        deps = []

        def f(module, include):
            # On case-insensitive but case-preserving filesystems, we need to
            # be careful on how we deal with finding OCaml dependencies. Since
            # OCaml can store a module named List in either list.ml or List.ml,
            # we can't just test if the filename exists since fbuild needs to
            # deal with the exact filenames.  To do that, we'll grab the list
            # of filenames in the directory, then search for the right
            # spelling in that list.

            # Grab the filenames in the directory.
            if include is None:
                dirs = Path.getcwd().listdir()
            else:
                include = Path(include)

                if not include.exists():
                    # We can't search for dependencies in a directory that
                    # doesn't exist, so exit early.
                    return False

                dirs = include.listdir()

            found = False
            for suffix in '.mli', '.ml':
                # Look for the traditional lowercase form.
                path = module[0].lower() + module[1:] + suffix
                if path not in dirs:
                    # That didn't work, so lets try the uppercase form.
                    path = module[0].upper() + module[1:] + suffix
                    if path not in dirs:
                        # Couldn't find it, so just skip this module.
                        continue

                # We found it! Add that file to the dependencies.
                if include is None:
                    deps.append(Path(path))
                else:
                    deps.append(include / path)
                found = True

            return found

        modules = self.modules(src, **kwargs)
        for module in modules:
            if not f(module, None):
                for include in includes:
                    f(module, include)

        if src.endswith('.ml'):
            # The .mli file might not live right next to the .ml file, so
            # search the include path for it.
            mli = Path(src).replaceext('.mli')
            if mli.exists():
                deps.append(mli)
            else:
                # If we generated the .ml file, then perhaps there's a
                # pre-defined .mli file not in the buildroot.
                buildroot = kwargs.get('buildroot') or self.ctx.buildroot
                mli = mli.removeroot(buildroot + os.sep)

                if mli.exists():
                    deps.append(mli)
                else:
                    for include in includes:
                        path = mli.name
                        if include is not None: path = include / path
                        if path.exists():
                            deps.append(path)
                        break

        return deps
Пример #15
0
    def source_dependencies(self, src:fbuild.db.SRC, *,
            includes=(),
            **kwargs) -> fbuild.db.DSTS:
        """Compute the source files this ocaml file depends on."""
        deps = []

        def f(module, include):
            # On case-insensitive but case-preserving filesystems, we need to
            # be careful on how we deal with finding OCaml dependencies. Since
            # OCaml can store a module named List in either list.ml or List.ml,
            # we can't just test if the filename exists since fbuild needs to
            # deal with the exact filenames.  To do that, we'll grab the list
            # of filenames in the directory, then search for the right
            # spelling in that list.

            # Grab the filenames in the directory.
            if include is None:
                dirs = Path.getcwd().listdir()
            else:
                include = Path(include)

                if not include.exists():
                    # We can't search for dependencies in a directory that
                    # doesn't exist, so exit early.
                    return False

                dirs = include.listdir()

            found = False
            for suffix in '.mli', '.ml':
                # Look for the traditional lowercase form.
                path = module[0].lower() + module[1:] + suffix
                if path not in dirs:
                    # That didn't work, so lets try the uppercase form.
                    path = module[0].upper() + module[1:] + suffix
                    if path not in dirs:
                        # Couldn't find it, so just skip this module.
                        continue

                # We found it! Add that file to the dependencies.
                if include is None:
                    deps.append(Path(path))
                else:
                    deps.append(include / path)
                found = True

            return found

        modules = self.modules(src, **kwargs)
        for module in modules:
            if not f(module, None):
                for include in includes:
                    f(module, include)

        if src.endswith('.ml'):
            # The .mli file might not live right next to the .ml file, so
            # search the include path for it.
            mli = Path(src).replaceext('.mli')
            if mli.exists():
                deps.append(mli)
            else:
                # If we generated the .ml file, then perhaps there's a
                # pre-defined .mli file not in the buildroot.
                buildroot = kwargs.get('buildroot') or self.ctx.buildroot
                mli = mli.removeroot(buildroot + os.sep)

                if mli.exists():
                    deps.append(mli)
                else:
                    for include in includes:
                        path = mli.name
                        if include is not None: path = include / path
                        if path.exists():
                            deps.append(path)
                        break

        return deps
Пример #16
0
    def _run_flxg(
        self,
        src: fbuild.db.SRC,
        *,
        includes=[],
        syntaxes=[],
        imports=[],
        flags=[],
        include_std=True,
        preparse=False,
        buildroot=None,
        **kwargs
    ) -> fbuild.db.DST:
        buildroot = buildroot or self.ctx.buildroot

        src = Path(src)
        # src_buildroot = src.addroot(buildroot)

        print("Buildroot        = " + buildroot)
        print("Src to flxg      = " + src)
        if preparse:
            dst = buildroot / "cache" / "binary" + _getcwd() / src
            dst = dst.replaceext(".par")
        else:
            dst = buildroot / "cache" / "text" + _getcwd() / src
            dst = dst.replaceext(".cpp")

        print("Expected flg dst = " + dst)
        # if src != src_buildroot:
        #    src_buildroot.parent.makedirs()
        #    src.copy(src_buildroot)
        #    src = src_buildroot

        # dst.parent.makedirs()

        cmd = [self.flxg]

        if preparse:
            cmd.append("-c")

        includes = set(includes)
        includes.add(src.parent)
        includes.add(dst.parent)

        imports = list(imports)
        syntaxes = list(syntaxes)
        if include_std:
            imports.insert(0, "plat/flx.flxh")  # Unix filename correct here
            syntaxes.insert(0, "@grammar/grammar.files")  # Unix filename correct here

        cmd.extend("-I" + i for i in sorted(includes) if Path.exists(i))
        cmd.extend("--syntax=" + i for i in syntaxes)
        cmd.extend("--import=" + i for i in imports)
        cmd.append("--output_dir=" + Path(buildroot) / "cache" / "text")
        cmd.append("--cache_dir=" + Path(buildroot) / "cache" / "binary")
        cmd.extend(flags)

        if include_std:
            cmd.append("std")

        if src.ext == ".flx":
            cmd.append(src.replaceext(""))
        else:
            cmd.append(src)

        self.ctx.execute(cmd, self.flxg.name, "%s -> %s" % (src, dst), color="yellow", **kwargs)

        return dst
Пример #17
0
def copy_dll2(ctx, fluid: fbuild.db.SRC) -> fbuild.db.DST:
    dst = ctx.buildroot / fluid.basename()
    copy(ctx, fluid, dst)
    return dst
Пример #18
0
    def _run_flxg(self, src:fbuild.db.SRC, *,
            includes=[],
            syntaxes=[],
            imports=[],
            flags=[],
            include_std=True,
            preparse=False,
            buildroot=None,
            **kwargs) -> fbuild.db.DST:
        buildroot = buildroot or self.ctx.buildroot

        src = Path(src)
        #src_buildroot = src.addroot(buildroot)

        print("Buildroot        = " + buildroot)
        print("Src to flxg      = " + src)
        if preparse:
            dst = buildroot /"cache"/"binary"+_getcwd()/src
            dst = dst.replaceext('.par')
        else:
            dst =buildroot /"cache"/"text"+_getcwd()/src
            dst = dst.replaceext('.cpp')

        print("Expected flg dst = " + dst)
        #if src != src_buildroot:
        #    src_buildroot.parent.makedirs()
        #    src.copy(src_buildroot)
        #    src = src_buildroot

        #dst.parent.makedirs()

        cmd = [self.flxg]

        if preparse:
            cmd.append('-c')

        includes = set(includes)
        includes.add(src.parent)
        includes.add(dst.parent)

        imports = list(imports)
        syntaxes = list(syntaxes)
        if include_std:
            imports.insert(0, 'plat/flx.flxh')               # Unix filename correct here
            syntaxes.insert(0, '@grammar/grammar.files')     # Unix filename correct here

        cmd.extend('-I' + i for i in sorted(includes) if Path.exists(i))
        cmd.extend('--syntax=' + i for i in syntaxes)
        cmd.extend('--import=' + i for i in imports)
        cmd.append('--output_dir=' + Path(buildroot)/"cache"/"text")
        cmd.append('--cache_dir=' + Path(buildroot)/"cache"/"binary")
        cmd.append('--with-comments') # add lots of comments to generated C++ to help debugging
        cmd.extend(flags)

        if include_std:
            cmd.append('std')

        if src.ext == '.flx':
            cmd.append(src.replaceext(''))
        else:
            cmd.append(src)

        self.ctx.execute(cmd, self.flxg.name, '%s -> %s' % (src, dst),
                color='yellow', **kwargs)

        return dst
Пример #19
0
    def _run_flxg(self,
                  src: fbuild.db.SRC,
                  *,
                  includes=[],
                  syntaxes=[],
                  imports=[],
                  flags=[],
                  include_std=True,
                  preparse=False,
                  buildroot=None,
                  **kwargs) -> fbuild.db.DST:
        buildroot = buildroot or self.ctx.buildroot

        src = Path(src)
        #src_buildroot = src.addroot(buildroot)

        print("Buildroot        = " + buildroot)
        print("Src to flxg      = " + src)
        if preparse:
            dst = buildroot / "cache" / "binary" + _getcwd() / src
            dst = dst.replaceext('.par')
        else:
            dst = buildroot / "cache" / "text" + _getcwd() / src
            dst = dst.replaceext('.cpp')

        print("Expected flg dst = " + dst)
        #if src != src_buildroot:
        #    src_buildroot.parent.makedirs()
        #    src.copy(src_buildroot)
        #    src = src_buildroot

        #dst.parent.makedirs()

        cmd = [self.flxg]

        if preparse:
            cmd.append('-c')

        includes = set(includes)
        includes.add(src.parent)
        includes.add(dst.parent)

        imports = list(imports)
        syntaxes = list(syntaxes)
        if include_std:
            imports.insert(0, 'plat/flx.flxh')  # Unix filename correct here
            imports.insert(
                0,
                'concordance/concordance.flxh')  # Unix filename correct here
            syntaxes.insert(
                0, '@grammar/grammar.files')  # Unix filename correct here

        cmd.extend('-I' + i for i in sorted(includes) if Path.exists(i))
        cmd.extend('--syntax=' + i for i in syntaxes)
        cmd.extend('--import=' + i for i in imports)
        cmd.append('--output_dir=' + Path(buildroot) / "cache" / "text")
        cmd.append('--cache_dir=' + Path(buildroot) / "cache" / "binary")
        #cmd.append('--with-comments') # add lots of comments to generated C++ to help debugging
        cmd.extend(flags)

        if include_std:
            cmd.append('std')

        if src.ext == '.flx':
            cmd.append(src.replaceext(''))
        else:
            cmd.append(src)

        self.ctx.execute(cmd,
                         self.flxg.name,
                         '%s -> %s' % (src, dst),
                         color='yellow',
                         **kwargs)

        return dst
Пример #20
0
    def _run_flxg(self, src:fbuild.db.SRC, *,
            includes=[],
            syntaxes=[],
            imports=[],
            flags=[],
            include_std=True,
            preparse=False,
            buildroot=None,
            **kwargs) -> fbuild.db.DST:
        buildroot = buildroot or self.ctx.buildroot

        src = Path(src)
        src_buildroot = src.addroot(buildroot)

        dst = src.addroot(buildroot)

        if preparse:
            dst = dst.replaceext('.par')
        else:
            dst = dst.replaceext('.cpp')

        if src != src_buildroot:
            src_buildroot.parent.makedirs()
            src.copy(src_buildroot)
            src = src_buildroot

        dst.parent.makedirs()

        cmd = [self.flxg]

        if preparse:
            cmd.append('-c')

        includes = set(includes)
        includes.add(src.parent)
        includes.add(dst.parent)

        imports = list(imports)
        syntaxes = list(syntaxes)
        if include_std:
            imports.insert(0, 'plat/flx.flxh')
            syntaxes.insert(0, '@grammar/grammar.files')

        cmd.extend('-I' + i for i in sorted(includes) if Path.exists(i))
        cmd.extend('--syntax=' + i for i in syntaxes)
        cmd.extend('--import=' + i for i in imports)
        cmd.append('--output_dir=' + dst.parent)
        cmd.extend(flags)

        if include_std:
            cmd.append('std')

        if src.ext == '.flx':
            cmd.append(src.replaceext(''))
        else:
            cmd.append(src)

        self.ctx.execute(cmd, self.flxg.name, '%s -> %s' % (src, dst),
                color='yellow', **kwargs)

        return dst