-
Notifications
You must be signed in to change notification settings - Fork 22
Add install-emscripten CLI command #243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bulenty584
wants to merge
13
commits into
pyodide:main
Choose a base branch
from
bulenty584:feat/add-install-emscripten-cli
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
29ae702
Add install-emscripten CLI command
bulenty584 d71ae08
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] ea08570
Emsdk installation comments fixed in xbuildenv.py and unneeded tests …
bulenty584 d86a11d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 8f20c44
TestInstallEmscripten class removed from test_install_emscripten.py a…
bulenty584 8041a1a
Following @ryanking's comments,
bulenty584 709ef84
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 7b4736b
Fixed integration test command to use xbuildenv and activate emsdk
bulenty584 83fddb9
1. emsdk activation directory changed in main.yml
bulenty584 41ffece
Merge branch 'main' into feat/add-install-emscripten-cli
ryanking13 abfe731
1. Fixed unittests to follow new code changes
bulenty584 1fd6457
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 8b52aa5
Updated Python version to 3.13 for xbuildenv and changed back lines 9…
bulenty584 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,224 @@ | ||
"""Tests for install-emscripten CLI command""" | ||
|
||
import subprocess | ||
from pathlib import Path | ||
|
||
from typer.testing import CliRunner | ||
|
||
from pyodide_build.cli import xbuildenv | ||
|
||
runner = CliRunner() | ||
|
||
|
||
def test_install_emscripten_no_xbuildenv(tmp_path): | ||
"""Test that install-emscripten fails when no xbuildenv exists""" | ||
envpath = Path(tmp_path) / ".xbuildenv" | ||
|
||
result = runner.invoke( | ||
xbuildenv.app, | ||
[ | ||
"install-emscripten", | ||
"--path", | ||
str(envpath), | ||
], | ||
) | ||
|
||
assert result.exit_code != 0, result.stdout | ||
assert "Cross-build environment not found" in result.stdout, result.stdout | ||
|
||
|
||
def test_install_emscripten_default_version(tmp_path, monkeypatch): | ||
"""Test installing Emscripten with default version""" | ||
envpath = Path(tmp_path) / ".xbuildenv" | ||
envpath.mkdir() | ||
|
||
monkeypatch.setattr( | ||
"pyodide_build.cli.xbuildenv.get_build_flag", | ||
lambda name: "3.1.46", | ||
) | ||
|
||
called = {} | ||
|
||
def fake_install(self, version): | ||
called["version"] = version | ||
return self.env_dir / "emsdk" | ||
|
||
monkeypatch.setattr( | ||
"pyodide_build.xbuildenv.CrossBuildEnvManager.install_emscripten", | ||
fake_install, | ||
) | ||
|
||
result = runner.invoke( | ||
xbuildenv.app, | ||
[ | ||
"install-emscripten", | ||
"--path", | ||
str(envpath), | ||
], | ||
) | ||
|
||
assert result.exit_code == 0, result.stdout | ||
assert "Installing emsdk..." in result.stdout, result.stdout | ||
assert "Installing emsdk complete." in result.stdout, result.stdout | ||
assert "Use `source" in result.stdout, result.stdout | ||
assert "emsdk_env.sh` to set up the environment." in result.stdout, result.stdout | ||
assert called["version"] == "3.1.46" | ||
|
||
|
||
def test_install_emscripten_specific_version(tmp_path, monkeypatch): | ||
"""Test installing Emscripten with a specific version""" | ||
envpath = Path(tmp_path) / ".xbuildenv" | ||
envpath.mkdir() | ||
|
||
called = {} | ||
|
||
def fake_install(self, version): | ||
called["version"] = version | ||
return self.env_dir / "emsdk" | ||
|
||
monkeypatch.setattr( | ||
"pyodide_build.xbuildenv.CrossBuildEnvManager.install_emscripten", | ||
fake_install, | ||
) | ||
|
||
emscripten_version = "3.1.46" | ||
result = runner.invoke( | ||
xbuildenv.app, | ||
[ | ||
"install-emscripten", | ||
"--version", | ||
emscripten_version, | ||
"--path", | ||
str(envpath), | ||
], | ||
) | ||
|
||
assert result.exit_code == 0, result.stdout | ||
assert "Installing emsdk..." in result.stdout, result.stdout | ||
assert "Installing emsdk complete." in result.stdout, result.stdout | ||
assert called["version"] == emscripten_version | ||
|
||
|
||
def test_install_emscripten_with_existing_emsdk(tmp_path, monkeypatch): | ||
"""Test installing Emscripten when emsdk already exists (should pull updates)""" | ||
envpath = Path(tmp_path) / ".xbuildenv" | ||
envpath.mkdir() | ||
|
||
existing_emsdk = envpath / "emsdk" | ||
existing_emsdk.mkdir() | ||
|
||
monkeypatch.setattr( | ||
"pyodide_build.cli.xbuildenv.get_build_flag", | ||
lambda name: "latest", | ||
) | ||
|
||
def fake_install(self, version): | ||
assert version == "latest" | ||
assert existing_emsdk.exists() | ||
return existing_emsdk | ||
|
||
monkeypatch.setattr( | ||
"pyodide_build.xbuildenv.CrossBuildEnvManager.install_emscripten", | ||
fake_install, | ||
) | ||
|
||
result = runner.invoke( | ||
xbuildenv.app, | ||
[ | ||
"install-emscripten", | ||
"--path", | ||
str(envpath), | ||
], | ||
) | ||
|
||
assert result.exit_code == 0, result.stdout | ||
assert "Installing emsdk..." in result.stdout, result.stdout | ||
assert "Installing emsdk complete." in result.stdout, result.stdout | ||
assert str(existing_emsdk / "emsdk_env.sh") in result.stdout | ||
|
||
|
||
def test_install_emscripten_git_failure(tmp_path, monkeypatch): | ||
"""Test handling of git clone failure""" | ||
envpath = Path(tmp_path) / ".xbuildenv" | ||
envpath.mkdir() | ||
|
||
monkeypatch.setattr( | ||
"pyodide_build.xbuildenv.CrossBuildEnvManager.install_emscripten", | ||
lambda self, version: (_ for _ in ()).throw( | ||
subprocess.CalledProcessError(1, "git clone") | ||
), | ||
) | ||
|
||
result = runner.invoke( | ||
xbuildenv.app, | ||
[ | ||
"install-emscripten", | ||
"--path", | ||
str(envpath), | ||
], | ||
) | ||
|
||
# Should fail due to git clone error | ||
assert result.exit_code != 0 | ||
assert isinstance(result.exception, subprocess.CalledProcessError) | ||
|
||
|
||
def test_install_emscripten_emsdk_install_failure(tmp_path, monkeypatch): | ||
"""Test handling of emsdk install command failure""" | ||
envpath = Path(tmp_path) / ".xbuildenv" | ||
envpath.mkdir() | ||
|
||
monkeypatch.setattr( | ||
"pyodide_build.xbuildenv.CrossBuildEnvManager.install_emscripten", | ||
lambda self, version: (_ for _ in ()).throw( | ||
subprocess.CalledProcessError(1, "./emsdk install") | ||
), | ||
) | ||
|
||
result = runner.invoke( | ||
xbuildenv.app, | ||
[ | ||
"install-emscripten", | ||
"--path", | ||
str(envpath), | ||
], | ||
) | ||
|
||
# Should fail due to emsdk install error | ||
assert result.exit_code != 0 | ||
assert isinstance(result.exception, subprocess.CalledProcessError) | ||
|
||
|
||
def test_install_emscripten_output_format(tmp_path, monkeypatch): | ||
"""Test that the output message format is correct""" | ||
envpath = Path(tmp_path) / ".xbuildenv" | ||
envpath.mkdir() | ||
|
||
monkeypatch.setattr( | ||
"pyodide_build.cli.xbuildenv.get_build_flag", | ||
lambda name: "latest", | ||
) | ||
|
||
expected_path = envpath / "emsdk" | ||
|
||
monkeypatch.setattr( | ||
"pyodide_build.xbuildenv.CrossBuildEnvManager.install_emscripten", | ||
lambda self, version: expected_path, | ||
) | ||
|
||
result = runner.invoke( | ||
xbuildenv.app, | ||
[ | ||
"install-emscripten", | ||
"--path", | ||
str(envpath), | ||
], | ||
) | ||
|
||
assert result.exit_code == 0, result.stdout | ||
|
||
# Verify output format - check for key messages (logger adds extra lines) | ||
assert "Installing emsdk..." in result.stdout | ||
assert "Installing emsdk complete." in result.stdout | ||
assert "Use `source" in result.stdout | ||
assert "emsdk_env.sh` to set up the environment." in result.stdout |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of requiring people to manually source the directory, it would be nice to detect the emscripten installation directory and use it during the build.
Let's do that in a separate PR to reduce the diff, for now, it looks good.