Skip to content

Commit ea1422b

Browse files
feat: git source test (#56)
Co-authored-by: Julian Hofer <[email protected]>
1 parent 0edce8a commit ea1422b

File tree

9 files changed

+1864
-6
lines changed

9 files changed

+1864
-6
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# pixi environments
2+
.pixi
3+
4+
# The build directory
5+
.build
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Simple C++ SDL Example with specified source path
2+
3+
This is a simple pixi demo that showcases how to use C++ and SDL with specified source path.
4+
5+
## How to use?
6+
7+
Make sure you have `pixi` available in your terminal.
8+
Navigate to this directory and run:
9+
10+
```shell
11+
12+
# Start the build executable
13+
pixi run start
14+
```

tests/data/pixi_build/cpp-with-git-source/pixi.lock

Lines changed: 1291 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[workspace]
2+
channels = ["https://prefix.dev/conda-forge"]
3+
platforms = ["win-64", "linux-64", "osx-64", "osx-arm64"]
4+
preview = ["pixi-build"]
5+
6+
[dependencies]
7+
# Define a dependency on ourselves. This will invoke the build backend to build
8+
# the C++ code and install the executable in an environment ready to be used.
9+
sdl_example = { path = "." }
10+
11+
[tasks.start]
12+
cmd = "sdl_example"
13+
description = "A tasks to run the executable that is build by the package section."
14+
15+
[tasks]
16+
test = "sdl_example -h"
17+
18+
[package]
19+
authors = ["Bas Zalmstra <[email protected]>"]
20+
description = "Showcases how to create a simple C++ executable with Pixi"
21+
name = "sdl_example"
22+
version = "0.1.0"
23+
24+
[package.build.source]
25+
branch = "main"
26+
git = "https://github.com/prefix-dev/pixi-build-testsuite.git"
27+
subdirectory = "tests/data/pixi_build/cpp-with-path-to-source/project"
28+
29+
[package.build.backend]
30+
channels = [
31+
"https://prefix.dev/pixi-build-backends",
32+
"https://prefix.dev/conda-forge",
33+
]
34+
name = "pixi-build-cmake"
35+
version = "*"
36+
37+
[package.host-dependencies]
38+
# This ensures that SDL2 is available at build time.
39+
sdl2 = ">=2.26.5,<3.0"

tests/integration_python/conftest.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
import shutil
44
from pathlib import Path
55
from typing import Any, cast
6+
from urllib.parse import unquote, urlparse
7+
from urllib.request import url2pathname
68

79
import dotenv
810
import pytest
911

10-
from urllib.parse import urlparse, unquote
11-
from urllib.request import url2pathname
12-
1312
from .common import (
1413
CURRENT_PLATFORM,
1514
Workspace,

tests/integration_python/test_build.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,13 +459,17 @@ def test_source_path(pixi: Path, build_data: Path, tmp_pixi_workspace: Path) ->
459459
"""
460460
Test path in `[package.build.source]`
461461
"""
462-
project = "cpp-with-path-to-source"
463-
test_data = build_data.joinpath(project)
462+
test_data = build_data.joinpath("minimal-backend-workspaces", "pixi-build-cmake")
464463

465464
copytree_with_local_backend(
466465
test_data, tmp_pixi_workspace, dirs_exist_ok=True, copy_function=copy_manifest
467466
)
468467

468+
manifest_path = tmp_pixi_workspace.joinpath("pixi.toml")
469+
manifest = tomllib.loads(manifest_path.read_text())
470+
manifest.setdefault("package", {}).setdefault("build", {})["source"] = {"path": "."}
471+
manifest_path.write_text(tomli_w.dumps(manifest))
472+
469473
verify_cli_command(
470474
[
471475
pixi,
@@ -512,7 +516,6 @@ def test_target_specific_dependency(
512516
) -> None:
513517
"""
514518
Check that target-specific dependencies are not solved for on other targets.
515-
Regression test for prefix-dev/pixi#4542.
516519
"""
517520
project = "target-specific"
518521
test_data = build_data.joinpath(project)

tests/integration_python/test_specified_build_source/__init__.py

Whitespace-only changes.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import subprocess
2+
from dataclasses import dataclass
3+
from pathlib import Path
4+
5+
import pytest
6+
7+
from ..common import copytree_with_local_backend
8+
9+
10+
@dataclass(frozen=True)
11+
class LocalGitRepo:
12+
path: Path
13+
main_rev: str
14+
other_feature_rev: str
15+
tag: str
16+
17+
18+
@pytest.fixture
19+
def local_cpp_git_repo(
20+
pixi: Path,
21+
build_data: Path,
22+
tmp_path_factory: pytest.TempPathFactory,
23+
) -> LocalGitRepo:
24+
"""
25+
Create a local git repository mirroring the minimal pixi-build-cmake workspace so tests can
26+
exercise git sources without touching the network.
27+
"""
28+
29+
source_root = build_data.joinpath("minimal-backend-workspaces", "pixi-build-cmake")
30+
repo_root = tmp_path_factory.mktemp("git-repo")
31+
repo_path = repo_root.joinpath("repo")
32+
copytree_with_local_backend(source_root, repo_path)
33+
34+
marker = repo_path.joinpath("src", "LOCAL_MARKER.txt")
35+
marker.write_text("local git fixture marker\n", encoding="utf-8")
36+
37+
main_source_path = repo_path.joinpath("src", "main.cpp")
38+
original_source = main_source_path.read_text(encoding="utf-8")
39+
40+
def run_git(*args: str) -> str:
41+
result = subprocess.run(
42+
[str(pixi), "run", "git", *args],
43+
cwd=repo_path,
44+
capture_output=True,
45+
text=True,
46+
)
47+
if result.returncode != 0:
48+
raise RuntimeError(
49+
"git command failed ({}):\nstdout: {}\nstderr: {}".format(
50+
" ".join(args), result.stdout, result.stderr
51+
)
52+
)
53+
return result.stdout.strip()
54+
55+
run_git("init", "-b", "main")
56+
run_git("config", "user.email", "[email protected]")
57+
run_git("config", "user.name", "Pixi Build Tests")
58+
run_git("add", ".")
59+
run_git("commit", "-m", "Initial commit")
60+
61+
run_git("checkout", "-b", "other-feature")
62+
feature_text = original_source.replace(
63+
"Build backend works", "Build backend works from other-feature branch"
64+
)
65+
if feature_text == original_source:
66+
feature_text = original_source + "\n// other-feature branch tweak\n"
67+
main_source_path.write_text(feature_text)
68+
run_git("add", main_source_path.relative_to(repo_path).as_posix())
69+
run_git("commit", "-m", "Add branch change")
70+
other_feature_rev = run_git("rev-parse", "HEAD")
71+
72+
run_git("checkout", "main")
73+
main_update_text = original_source.replace(
74+
"Build backend works", "Build backend works on main branch"
75+
)
76+
if main_update_text == original_source:
77+
main_update_text = original_source + "\n// main branch tweak\n"
78+
main_source_path.write_text(main_update_text)
79+
run_git("add", main_source_path.relative_to(repo_path).as_posix())
80+
run_git("commit", "-m", "Update main")
81+
main_rev = run_git("rev-parse", "HEAD")
82+
83+
run_git("tag", "fixture-v1")
84+
85+
return LocalGitRepo(
86+
path=repo_path,
87+
main_rev=main_rev,
88+
other_feature_rev=other_feature_rev,
89+
tag="fixture-v1",
90+
)

0 commit comments

Comments
 (0)