Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
]
name = "pixi-build-cmake"
version = "*"

[package.host-dependencies]
# This ensures that SDL2 is available at build time.
sdl2 = ">=2.26.5,<3.0"
5 changes: 2 additions & 3 deletions tests/integration_python/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import shutil
from pathlib import Path
from typing import Any, cast
from urllib.parse import unquote, urlparse
from urllib.request import url2pathname

import dotenv
import pytest

from urllib.parse import urlparse, unquote
from urllib.request import url2pathname

from .common import (
CURRENT_PLATFORM,
Workspace,
Expand Down
9 changes: 6 additions & 3 deletions tests/integration_python/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,13 +459,17 @@ def test_source_path(pixi: Path, build_data: Path, tmp_pixi_workspace: Path) ->
"""
Test path in `[package.build.source]`
"""
project = "cpp-with-path-to-source"
test_data = build_data.joinpath(project)
test_data = build_data.joinpath("minimal-backend-workspaces", "pixi-build-cmake")

copytree_with_local_backend(
test_data, tmp_pixi_workspace, dirs_exist_ok=True, copy_function=copy_manifest
)

manifest_path = tmp_pixi_workspace.joinpath("pixi.toml")
manifest = tomllib.loads(manifest_path.read_text())
manifest.setdefault("package", {}).setdefault("build", {})["source"] = {"path": "."}
manifest_path.write_text(tomli_w.dumps(manifest))

verify_cli_command(
[
pixi,
Expand Down Expand Up @@ -512,7 +516,6 @@ def test_target_specific_dependency(
) -> None:
"""
Check that target-specific dependencies are not solved for on other targets.
Regression test for prefix-dev/pixi#4542.
"""
project = "target-specific"
test_data = build_data.joinpath(project)
Expand Down
Empty file.
90 changes: 90 additions & 0 deletions tests/integration_python/test_specified_build_source/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import subprocess
from dataclasses import dataclass
from pathlib import Path

import pytest

from ..common import copytree_with_local_backend


@dataclass(frozen=True)
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 the minimal pixi-build-cmake workspace so tests can
exercise git sources without touching the network.
"""

source_root = build_data.joinpath("minimal-backend-workspaces", "pixi-build-cmake")
repo_root = tmp_path_factory.mktemp("git-repo")
repo_path = repo_root.joinpath("repo")
copytree_with_local_backend(source_root, repo_path)

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

main_source_path = repo_path.joinpath("src", "main.cpp")
original_source = main_source_path.read_text(encoding="utf-8")

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")
feature_text = original_source.replace(
"Build backend works", "Build backend works from other-feature branch"
)
if feature_text == original_source:
feature_text = original_source + "\n// other-feature branch tweak\n"
main_source_path.write_text(feature_text)
run_git("add", main_source_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")
main_update_text = original_source.replace(
"Build backend works", "Build backend works on main branch"
)
if main_update_text == original_source:
main_update_text = original_source + "\n// main branch tweak\n"
main_source_path.write_text(main_update_text)
run_git("add", main_source_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