Skip to content
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

Feature/ci with build requires #80

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions features/lockfiles/ci_build_require/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
release/
tmp/
locks/
bo*.json
8 changes: 8 additions & 0 deletions features/lockfiles/ci_build_require/app1/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

from conans import ConanFile

required_conan_version = ">=1.28"

class App1Conan(ConanFile):
settings = "build_type"
requires = "libd/[>0.0 <1.0]@user/testing"
8 changes: 8 additions & 0 deletions features/lockfiles/ci_build_require/app2/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

from conans import ConanFile

required_conan_version = ">=1.28"

class App2Conan(ConanFile):
settings = "build_type"
requires = "libc/[>0.0 <1.0]@user/testing"
1 change: 1 addition & 0 deletions features/lockfiles/ci_build_require/build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python build.py
124 changes: 124 additions & 0 deletions features/lockfiles/ci_build_require/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import os, json, shutil
import subprocess
from contextlib import contextmanager


def run(cmd, assert_error=False):
print("*********** Running: %s" % cmd)
ret = os.system(cmd)
if ret == 0 and assert_error:
raise Exception("Command unexpectedly succedeed: %s" % cmd)
if ret != 0 and not assert_error:
raise Exception("Failed command: %s" % cmd)

def load(filename):
with open(filename, "r") as f:
return f.read()

def save(filename, content):
with open(filename, "w") as f:
return f.write(content)


def rm(path):
if os.path.isfile(path):
os.remove(path)
elif os.path.isdir(path):
shutil.rmtree(path)

@contextmanager
def chdir(path):
current_path = os.getcwd()
try:
os.chdir(path)
yield
finally:
os.chdir(current_path)

@contextmanager
def setenv(key, value):
old_value = os.environ.get(key)
os.environ[key] = value
try:
yield
finally:
if old_value is not None:
os.environ[key] = old_value


def clean():
rm("tmp")
rm("locks")
rm("bo_release.json")
rm("bo_debug.json")


def ci_pipeline():
clean()
run("conan config set general.default_package_id_mode=full_version_mode")
for config in ("Release", "Debug"):
run("conan create tool tool1/0.1@user/testing -s build_type=%s" % config)
run("conan create tool tool2/0.1@user/testing -s build_type=%s" % config)
run("conan create liba liba/0.1@user/testing -s build_type=%s" % config)
run("conan create libb libb/0.1@user/testing -s build_type=%s" % config)
run("conan create libc libc/0.1@user/testing -s build_type=%s" % config)
run("conan create libd libd/0.1@user/testing -s build_type=%s" % config)
run("conan create app1 app1/0.1@user/testing -s build_type=%s" % config)
run("conan create app2 app2/0.1@user/testing -s build_type=%s" % config)

# A developer does some change to the libb
with chdir("libb"):
libb = load("conanfile.py")
libb = libb + "# Some changes"
save("conanfile.py", libb)

run("conan lock create conanfile.py --name=libb --version=0.2 "
"--user=user --channel=testing --lockfile-out=../locks/libb_deps_base.lock --base")

# Even if liba gets a new 0.2 version, the lockfile will avoid it
run("conan create liba liba/0.2@user/testing")
with chdir("libb"):
# This will be useful to capture the revision
run("conan export . libb/0.2@user/testing --lockfile=../locks/libb_deps_base.lock "
"--lockfile-out=../locks/libb_base.lock")
print(load("../locks/libb_base.lock"))
# Capture the configuration lockfiles, one per configuration
run("conan lock create conanfile.py --name=libb --version=0.2 --profile=../profile -s build_type=Debug "
"--user=user --channel=testing --lockfile=../locks/libb_base.lock --lockfile-out=../locks/libb_deps_debug.lock")
run("conan lock create conanfile.py --name=libb --version=0.2 --profile=../profile -s build_type=Release "
"--user=user --channel=testing --lockfile=../locks/libb_base.lock --lockfile-out=../locks/libb_deps_release.lock")
print(load("../locks/libb_deps_release.lock"))
print(load("../locks/libb_deps_debug.lock"))
# Now build libb
run("conan create . libb/0.2@user/testing --lockfile=../locks/libb_deps_release.lock")
run("conan create . libb/0.2@user/testing --lockfile=../locks/libb_deps_debug.lock")

# Capture the app1 base lockfile
run("conan lock create --reference=app1/0.1@user/testing --lockfile=locks/libb_base.lock "
"--lockfile-out=locks/app1_base.lock --base")
# And one lockfile per configuration
run("conan lock create --reference=app1/0.1@user/testing --lockfile=locks/app1_base.lock "
"--lockfile-out=locks/app1_release.lock -s build_type=Release --profile=profile")
run("conan lock create --reference=app1/0.1@user/testing --lockfile=locks/app1_base.lock "
"--lockfile-out=locks/app1_debug.lock -s build_type=Debug --profile=profile")

run("conan lock build-order locks/app1_release.lock --json=bo_release.json")
run("conan lock build-order locks/app1_debug.lock --json=bo_debug.json")
build_order_release = json.loads(load("bo_release.json"))
build_order_debug = json.loads(load("bo_debug.json"))

for level in build_order_release:
for item in level:
ref, pid, context, id_ = item
print(item)
run("conan install %s --build=%s --lockfile=locks/app1_release.lock "
"--lockfile-out=locks/app1_release_updated.lock" % (ref, ref))
run("conan lock update locks/app1_release.lock locks/app1_release_updated.lock")

print(load("locks/app1_release.lock"))
clean()

if __name__ == '__main__':
home = os.path.abspath(os.path.join(os.path.dirname(__file__), "tmp"))
with setenv("CONAN_USER_HOME", home):
ci_pipeline()
5 changes: 5 additions & 0 deletions features/lockfiles/ci_build_require/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

set -ex

python build.py
6 changes: 6 additions & 0 deletions features/lockfiles/ci_build_require/liba/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from conans import ConanFile, tools

required_conan_version = ">=1.28.0"

class PkgaConan(ConanFile):
settings = "build_type"
7 changes: 7 additions & 0 deletions features/lockfiles/ci_build_require/libb/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from conans import ConanFile

required_conan_version = ">=1.28"

class LibBConan(ConanFile):
settings = "build_type"
requires = "liba/[>0.0 <1.0]@user/testing"
7 changes: 7 additions & 0 deletions features/lockfiles/ci_build_require/libc/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from conans import ConanFile

required_conan_version = ">=1.28"

class LibCConan(ConanFile):
settings = "build_type"
requires = "liba/[>0.0 <1.0]@user/testing"
8 changes: 8 additions & 0 deletions features/lockfiles/ci_build_require/libd/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

from conans import ConanFile

required_conan_version = ">=1.28"

class LibDConan(ConanFile):
settings = "build_type"
requires = "libb/[>0.0 <1.0]@user/testing", "libc/[>0.0 <1.0]@user/testing"
3 changes: 3 additions & 0 deletions features/lockfiles/ci_build_require/profile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build_requires]
tool1/0.1@user/testing
tool2/0.1@user/testing
6 changes: 6 additions & 0 deletions features/lockfiles/ci_build_require/tool/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from conans import ConanFile

required_conan_version = ">=1.28.0"

class PkgaConan(ConanFile):
settings = "build_type"