コード例 #1
0
ファイル: base.py プロジェクト: edgedb/metapkg
    def get_build_install_script(self, build: targets.Build) -> str:
        service_scripts = self.get_service_scripts(build)
        if service_scripts:
            install = build.sh_get_command("cp", relative_to="pkgbuild")
            extras_dir = build.get_extras_root(relative_to="pkgbuild")
            install_dir = build.get_install_dir(self, relative_to="pkgbuild")
            ensuredir = build.target.get_action("ensuredir", build)
            if TYPE_CHECKING:
                assert isinstance(ensuredir, targets.EnsureDirAction)

            commands = []

            for path, _content in service_scripts.items():
                path = path.relative_to("/")
                commands.append(
                    ensuredir.get_script(path=str((install_dir / path).parent))
                )
                args: dict[str, str | None] = {
                    str(extras_dir / path): None,
                    str(install_dir / path): None,
                }
                cmd = build.sh_format_command(install, args)
                commands.append(cmd)

            return "\n".join(commands)
        else:
            return ""
コード例 #2
0
ファイル: rust.py プロジェクト: edgedb/metapkg
    def get_build_install_script(self, build: targets.Build) -> str:
        script = super().get_build_install_script(build)
        cargo = build.sh_get_command("cargo")
        sed = build.sh_get_command("sed")
        installdest = build.get_temp_dir(self, relative_to="pkgbuild")
        src = build.get_source_dir(self, relative_to="pkgbuild")
        bindir = build.get_install_path("systembin").relative_to("/")
        install_bindir = (build.get_install_dir(self, relative_to="pkgbuild") /
                          bindir)
        if isinstance(build.target, targets.linux.LinuxMuslTarget):
            target = "--target x86_64-unknown-linux-musl"
        else:
            target = ""

        env = build.sh_append_global_flags({})
        env["RUST_BACKTRACE"] = "1"
        env_str = build.sh_format_command("env", env, force_args_eq=True)
        script += textwrap.dedent(f"""\
            {sed} -i -e '/\\[package\\]/,/\\[.*\\]/{{
                    s/^version\\s*=.*/version = "{self.version.text}"/;
                }}' \\
                "{src}/Cargo.toml"
            {env_str} \\
                {cargo} install {target} \\
                    --verbose --verbose \\
                    --root "{installdest}" \\
                    --path "{src}" \\
                    --locked
            mkdir -p "{install_bindir}"
            cp -a "{installdest}/bin/"* "{install_bindir}/"
            """)
        return script
コード例 #3
0
    def get_configure_script(self, build: targets.Build) -> str:
        sdir = build.get_source_dir(self, relative_to="pkgbuild")
        configure = sdir / "configure"

        configure_flags = {
            "--prefix": str(build.get_full_install_prefix()),
        }

        return build.sh_format_command(configure, configure_flags)
コード例 #4
0
ファイル: python.py プロジェクト: edgedb/metapkg
    def get_build_install_script(self, build: targets.Build) -> str:
        common_script = super().get_build_install_script(build)

        python = build.sh_get_command("python", package=self)
        root = build.get_install_dir(self, relative_to="pkgbuild")
        wheeldir_script = 'import pathlib; print(pathlib.Path(".").resolve())'

        pkgname = getattr(self, "dist_name", None)
        if pkgname is None:
            pkgname = self.name
            if pkgname.startswith("pypkg-"):
                pkgname = pkgname[len("pypkg-"):]

        if pkgname == "wheel":
            binary = False
        else:
            binary = True

        env = {
            "PIP_DISABLE_PIP_VERSION_CHECK": "1",
        }

        env_str = build.sh_format_command("env", env, force_args_eq=True)

        wheel_install = textwrap.dedent(f"""\
            _wheeldir=$("{python}" -c '{wheeldir_script}')
            {env_str} \\
            "{python}" -m pip install \\
                --no-build-isolation \\
                --ignore-installed \\
                --no-index \\
                --no-deps \\
                --upgrade \\
                --force-reinstall \\
                --no-warn-script-location -f "file://${{_wheeldir}}" \\
                {'--only-binary' if binary else '--no-binary'} :all: \\
                --root "{root}" \\
                "{pkgname}"
        """)

        if common_script:
            return f"{common_script}\n{wheel_install}"
        else:
            return wheel_install
コード例 #5
0
ファイル: base.py プロジェクト: edgedb/metapkg
    def sh_configure(
        self,
        build: targets.Build,
        path: str | pathlib.Path,
        args: Mapping[str, str | pathlib.Path | None],
    ) -> str:
        conf_args = dict(args)
        shlib_paths = self.get_shlib_paths(build)
        ldflags = []
        for shlib_path in shlib_paths:
            ldflags.extend(
                build.target.get_shlib_path_run_time_ldflags(
                    build, shlex.quote(str(shlib_path))
                )
            )
        if ldflags:
            build.sh_append_flags(conf_args, "LDFLAGS", ldflags)

        if "--prefix" not in args:
            conf_args["--prefix"] = str(build.get_full_install_prefix())

        conf_args = build.sh_append_global_flags(conf_args)
        return build.sh_format_command(path, conf_args, force_args_eq=True)
コード例 #6
0
ファイル: python.py プロジェクト: edgedb/metapkg
    def get_build_script(self, build: targets.Build) -> str:
        sdir = build.get_source_dir(self, relative_to="pkgbuild")
        src_python = build.sh_get_command("python",
                                          package=self,
                                          relative_to="pkgsource")
        build_python = build.sh_get_command("python")
        dest = build.get_temp_root(
            relative_to="pkgbuild") / build.get_full_install_prefix(
            ).relative_to("/")

        sitescript = (f"import site; "
                      f'print(site.getsitepackages(["{dest}"])[0])')

        src_dest = build.get_temp_root(
            relative_to="pkgsource") / build.get_full_install_prefix(
            ).relative_to("/")

        src_sitescript = (f"import site; "
                          f'print(site.getsitepackages(["{src_dest}"])[0])')

        wheeldir_script = 'import pathlib; print(pathlib.Path(".").resolve())'

        abspath = (
            "import pathlib, sys; print(pathlib.Path(sys.argv[1]).resolve())")

        pkgname = getattr(self, "dist_name", None)
        if pkgname is None:
            pkgname = self.name
            if pkgname.startswith("pypkg-"):
                pkgname = pkgname[len("pypkg-"):]

        env = build.sh_append_global_flags({
            "SETUPTOOLS_SCM_PRETEND_VERSION":
            self.pretty_version,
            "PIP_DISABLE_PIP_VERSION_CHECK":
            "1",
        })

        dep_names = [dep.name for dep in self.build_requires]
        build_deps = build.get_packages(dep_names)

        if pkgname == "wheel":
            build_command = f'"{src_python}" setup.py sdist -d ${{_wheeldir}}'
            binary = False
        else:
            args = [
                src_python,
                "-m",
                "pip",
                "wheel",
                "--verbose",
                "--wheel-dir",
                "${_wheeldir}",
                "--no-binary=:all:",
                "--no-build-isolation",
                "--use-feature=in-tree-build",
                "--no-deps",
                ".",
            ]
            build_command = " ".join(
                shlex.quote(c) if c[0] != "$" else c for c in args)
            env.update(
                self.sh_get_build_wheel_env(
                    build, site_packages_var="${_sitepkg_from_src}"))

            cflags = build.sh_get_bundled_shlibs_cflags(
                build_deps,
                relative_to="pkgsource",
            )

            if cflags:
                build.sh_append_flags(env, "CFLAGS", cflags)

            ldflags = build.sh_get_bundled_shlibs_ldflags(
                build_deps,
                relative_to="pkgsource",
            )

            if ldflags:
                build.sh_append_flags(env, "LDFLAGS", ldflags)

            binary = True

        all_build_deps = build.get_packages(dep_names, recursive=True)
        env_str = build.sh_format_command("env", env, force_args_eq=True)
        env_str += " " + " ".join(build.get_ld_env(all_build_deps, "${_wd}"))

        return textwrap.dedent(f"""\
            _wheeldir=$("{build_python}" -c '{wheeldir_script}')
            _target=$("{build_python}" -c '{sitescript}')
            _sitepkg_from_src=$("{build_python}" -c '{src_sitescript}')
            _wd=$("{build_python}" -c '{abspath}' "$(pwd)")
            (cd "{sdir}"; \\
             {env_str} \\
                 {build_command})
            "{build_python}" -m pip install \\
                --no-build-isolation \\
                --no-warn-script-location \\
                --no-index \\
                --no-deps \\
                --upgrade \\
                -f "file://${{_wheeldir}}" \\
                {'--only-binary' if binary else '--no-binary'} :all: \\
                --target "${{_target}}" \\
                "{pkgname}"
        """)