-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuilder.py
More file actions
85 lines (74 loc) · 3 KB
/
builder.py
File metadata and controls
85 lines (74 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# builder.py
import subprocess
import time
from pathlib import Path
"""
For debugging.
# Run container with a package:
docker run --rm -it -v $HOME/conan-center-index/recipes/flex/all:/workspace/recipe:ro \
-v $HOME/code/rvnative/conan_profiles:/profiles:ro \
-v $HOME/code/rvnative/conan_cache2:/root/.conan2 \
--platform=linux/riscv64 \
conan-builder /bin/bash
# In container:
cd /workspace/recipe && cp -r test_package /tmp/test_package && conan create . --name flex --version 2.6.4 \
--profile /profiles/riscv64-linux-gcc --profile:build=/profiles/riscv64-linux-gcc \
--build missing --test-folder /tmp/test_package -c tools.system.package_manager:mode=install
"""
def build_docker_image(image_name, platform="linux/riscv64", dockerfile_path="."):
"""Build the Docker image using buildx for specified platform"""
print(f"Building Docker image '{image_name}' for {platform} platform...")
cmd = [
"docker", "buildx", "build",
f"--platform={platform}",
"-t", image_name,
dockerfile_path
]
try:
# Show build output in real-time instead of capturing it
result = subprocess.run(cmd, check=True, text=True)
print(f"Successfully built Docker image '{image_name}'")
return True
except subprocess.CalledProcessError as e:
print(f"Error building Docker image: {e}")
return False
except FileNotFoundError:
print("Error: docker command not found. Please install Docker.")
return False
def build_in_docker(package: str, version: str, recipe_path: Path, profile: Path, image: str, platform: str, cache_dir: Path, logs_dir: Path):
log_file = logs_dir / f"{package}.log"
# Create the conan create command
conan_cmd = (
f"cd /workspace/recipe && "
f"cp -r test_package /tmp/test_package && "
f"conan create . --name {package} --version {version} "
f"--profile /profiles/{profile.name} "
f"--profile:build=/profiles/{profile.name} "
f"--build missing "
f"--test-folder /tmp/test_package "
f"-c tools.system.package_manager:mode=install"
# f"-c tools.system.package_manager:sudo=True" # When run under non-root user
)
cmd = [
"docker", "run", "--rm",
"--cpus", "2", # Limit to 2 CPU cores
"-v", f"{recipe_path.absolute()}:/workspace/recipe:ro",
"-v", f"{profile.parent.absolute()}:/profiles:ro",
"-v", f"{cache_dir.absolute()}:/root/.conan2",
f"--platform={platform}",
image,
"bash", "-c", conan_cmd
]
# print (" ".join(cmd))
start = time.time()
with open(log_file, "w") as f:
proc = subprocess.run(cmd, stdout=f, stderr=subprocess.STDOUT, text=True)
duration = time.time() - start
return {
"package": package,
"version": version,
"platform": platform,
"status": "success" if proc.returncode == 0 else "failure",
"duration": duration,
"log_path": str(log_file),
}