mirror of https://github.com/pyodide/pyodide.git
Add build/script for nonlib pkg (#1070)
Co-authored-by: Roman Yurchak <rth.yurchak@gmail.com> Co-authored-by: Dexter Chua <dalcde@users.noreply.github.com>
This commit is contained in:
parent
e46aa9cff6
commit
9c7ff5658f
|
@ -143,6 +143,14 @@ Extra arguments to pass to the linker when building for WebAssembly.
|
|||
|
||||
(This key is not in the Conda spec).
|
||||
|
||||
#### `build/library`
|
||||
|
||||
Should be set to true for library packages. Library packages are packages that are needed for other packages but are not Python packages themselves. For library packages, the script specified in the `build/script` section is run to compile the library. See the [zlib meta.yaml](https://github.com/iodide-project/pyodide/blob/master/packages/zlib/meta.yaml) for an example of a library package specification.
|
||||
|
||||
#### `build/script`
|
||||
|
||||
The script section is required for a library package (`build/library` set to true). For a Python package this section is optional. If it is specified for a Python package, the script section will be run before the build system runs `setup.py`. This script is run by `bash` in the directory where the tarball was extracted.
|
||||
|
||||
#### `build/post`
|
||||
|
||||
Shell commands to run after building the library. These are run inside of
|
||||
|
|
|
@ -226,8 +226,10 @@ def run_script(buildpath: Path, srcpath: Path, pkg: Dict[str, Any]):
|
|||
finally:
|
||||
os.chdir(orig_path)
|
||||
|
||||
with open(buildpath / ".packaged", "wb") as fd:
|
||||
fd.write(b"\n")
|
||||
# If library, we're done so create .packaged file
|
||||
if pkg["build"].get("library"):
|
||||
with open(buildpath / ".packaged", "wb") as fd:
|
||||
fd.write(b"\n")
|
||||
|
||||
|
||||
def needs_rebuild(pkg: Dict[str, Any], path: Path, buildpath: Path) -> bool:
|
||||
|
@ -275,6 +277,8 @@ def build_package(path: Path, args):
|
|||
if pkg.get("build", {}).get("library"):
|
||||
run_script(buildpath, srcpath, pkg)
|
||||
else:
|
||||
if pkg.get("build", {}).get("script"):
|
||||
run_script(buildpath, srcpath, pkg)
|
||||
compile(path, srcpath, pkg, args)
|
||||
package_files(buildpath, srcpath, pkg, args)
|
||||
finally:
|
||||
|
|
|
@ -3,6 +3,8 @@ import subprocess
|
|||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from pyodide_build import buildpkg, common
|
||||
|
||||
|
||||
|
@ -33,3 +35,17 @@ def test_download_and_extract(monkeypatch):
|
|||
srcpath = buildpkg.download_and_extract(buildpath, packagedir, pkg, args=None)
|
||||
|
||||
assert srcpath.name.lower().endswith(packagedir.lower())
|
||||
|
||||
|
||||
@pytest.mark.parametrize("is_library", [True, False])
|
||||
def test_run_script(is_library, tmpdir):
|
||||
build_dir = Path(tmpdir.mkdir("build"))
|
||||
src_dir = Path(tmpdir.mkdir("build/package_name"))
|
||||
script = "touch out.txt"
|
||||
pkg = {"build": {"script": script, "library": is_library}}
|
||||
buildpkg.run_script(build_dir, src_dir, pkg)
|
||||
assert (src_dir / "out.txt").exists()
|
||||
if is_library:
|
||||
assert (build_dir / ".packaged").exists()
|
||||
else:
|
||||
assert not (build_dir / ".packaged").exists()
|
||||
|
|
Loading…
Reference in New Issue