Skip to content
Open
1 change: 1 addition & 0 deletions .env.ci
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PIXI_PR_NUMBER="4446"
5 changes: 5 additions & 0 deletions tests/data/pixi_build/cpp-with-git-source/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# pixi environments
.pixi

# The build directory
.build
14 changes: 14 additions & 0 deletions tests/data/pixi_build/cpp-with-git-source/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Simple C++ SDL Example with specified source path

This is a simple pixi demo that showcases how to use C++ and SDL with specified source path.

## How to use?

Make sure you have `pixi` available in your terminal.
Navigate to this directory and run:

```shell

# Start the build executable
pixi run start
```
1,291 changes: 1,291 additions & 0 deletions tests/data/pixi_build/cpp-with-git-source/pixi.lock

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions tests/data/pixi_build/cpp-with-git-source/pixi.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[workspace]
channels = ["https://prefix.dev/conda-forge"]
platforms = ["win-64", "linux-64", "osx-64", "osx-arm64"]
preview = ["pixi-build"]

[dependencies]
# Define a dependency on ourselves. This will invoke the build backend to build
# the C++ code and install the executable in an environment ready to be used.
sdl_example = { path = "." }

[tasks.start]
cmd = "sdl_example"
description = "A tasks to run the executable that is build by the package section."

[tasks]
test = "sdl_example -h"

[package]
authors = ["Bas Zalmstra <[email protected]>"]
description = "Showcases how to create a simple C++ executable with Pixi"
name = "sdl_example"
version = "0.1.0"

[package.build.source]
branch = "main"
git = "https://github.com/prefix-dev/pixi-build-testsuite.git"
subdirectory = "tests/data/pixi_build/cpp-with-path-to-source/project"

[package.build.backend]
channels = [
"https://prefix.dev/pixi-build-backends",
"https://prefix.dev/conda-forge",
]
Comment on lines +30 to +33
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The backend will be overriden anyway so no need to specify channels for it

Suggested change
channels = [
"https://prefix.dev/pixi-build-backends",
"https://prefix.dev/conda-forge",
]

name = "pixi-build-cmake"
version = "*"

[package.host-dependencies]
# This ensures that SDL2 is available at build time.
sdl2 = ">=2.26.5,<3.0"
81 changes: 81 additions & 0 deletions tests/integration_python/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import json
import os
import shutil
import subprocess
from dataclasses import dataclass
from pathlib import Path
from typing import Any, cast

Expand Down Expand Up @@ -150,6 +152,7 @@ def _validate_artifact_sources() -> None:
@pytest.fixture(scope="session", autouse=True)
def load_dotenv() -> None:
dotenv.load_dotenv(override=True)
dotenv.load_dotenv(override=True, dotenv_path=Path(__file__).parents[2].joinpath(".env.ci"))
_validate_artifact_sources()


Expand Down Expand Up @@ -334,3 +337,81 @@ def multiple_versions_channel_1(channels: Path) -> str:
@pytest.fixture
def target_specific_channel_1(channels: Path) -> str:
return channels.joinpath("target_specific_channel_1").as_uri()


@dataclass
class LocalGitRepo:
path: Path
main_rev: str
other_feature_rev: str
tag: str


@pytest.fixture
def local_cpp_git_repo(
pixi: Path,
build_data: Path,
tmp_path_factory: pytest.TempPathFactory,
) -> LocalGitRepo:
"""
Create a local git repository mirroring cpp-with-path-to-source so tests can
exercise git sources without touching the network.
"""

source_root = build_data.joinpath("cpp-with-path-to-source")
repo_root = tmp_path_factory.mktemp("git-repo")
repo_path = repo_root.joinpath("repo")
shutil.copytree(source_root, repo_path)

marker = repo_path.joinpath("project", "LOCAL_MARKER.txt")
marker.write_text("local git fixture marker\n", encoding="utf-8")

readme_path = repo_path.joinpath("README.md")

def run_git(*args: str) -> str:
result = subprocess.run(
[str(pixi), "run", "git", *args],
cwd=repo_path,
capture_output=True,
text=True,
)
if result.returncode != 0:
raise RuntimeError(
"git command failed ({}):\nstdout: {}\nstderr: {}".format(
" ".join(args), result.stdout, result.stderr
)
)
return result.stdout.strip()

run_git("init", "-b", "main")
run_git("config", "user.email", "[email protected]")
run_git("config", "user.name", "Pixi Build Tests")
run_git("add", ".")
run_git("commit", "-m", "Initial commit")

run_git("checkout", "-b", "other-feature")
readme_path.write_text(
readme_path.read_text(encoding="utf-8") + "\nLocal change on other-feature branch\n",
encoding="utf-8",
)
run_git("add", readme_path.relative_to(repo_path).as_posix())
run_git("commit", "-m", "Add branch change")
other_feature_rev = run_git("rev-parse", "HEAD")

run_git("checkout", "main")
readme_path.write_text(
readme_path.read_text(encoding="utf-8") + "\nLocal change on main\n",
encoding="utf-8",
)
run_git("add", readme_path.relative_to(repo_path).as_posix())
run_git("commit", "-m", "Update main")
main_rev = run_git("rev-parse", "HEAD")

run_git("tag", "fixture-v1")

return LocalGitRepo(
path=repo_path,
main_rev=main_rev,
other_feature_rev=other_feature_rev,
tag="fixture-v1",
)
Loading
Loading