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

started with conflicts examples #2

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions .ci/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@ List<Map> getBranchesInstalls() {
def runExample(Map ctxt, String example) {
for (extension in ctxt.extensions) {
if (example.contains(extension)) {
def command = example.contains(".py") ? "python ${example}" : "${example}"
ctxt.shFunction(command)
example = example.replace("\\","/")
split_path = example.split('/')
String script = split_path[split_path.length-1]
String path = example - script
script = isUnix() ? "./${script}" : "${script}"
String command = script.contains(".py") ? "python ${script}" : "${script}"
ctxt.shFunction("cd ${path} && ${command}")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from conan import ConanFile

class Pkg(ConanFile):
name = "engine"
version = "1.0"

requires = "math/1.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from conan import ConanFile

class Pkg(ConanFile):
name = "game"
version = "1.0"

def requirements(self):
self.requires("engine/1.0")
self.requires("math/2.0")
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from conan import ConanFile

class Pkg(ConanFile):
name = "math"
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import os
import subprocess

def run(cmd, error=False):
# Used by tools/scm check_repo only (see if repo ok with status)
print("Running: {}".format(cmd))
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
out, err = process.communicate()
out = out.decode("utf-8")
err = err.decode("utf-8")
ret = process.returncode

output = err + out
if ret != 0 and not error:
raise Exception("Failed cmd: {}\n{}".format(cmd, output))
if ret == 0 and error:
raise Exception("Cmd succeded (failure expected): {}\n{}".format(cmd, output))
return output


# This is a half diamond
# game -> engine -> math/1.0
# \--------------> math/2.0 (conflict)
# solved with force=True

# Demo the conflict
run('conan remove "*" -f') # Make sure no packages from last run
run("conan create math --version=1.0")
run("conan create math --version=2.0")
run("conan create engine")
out = run("conan install game", error=True)
assert "ERROR: Version conflict: engine/1.0->math/1.0, game/1.0->math/2.0" in out

# Add the requires "force=True" fixes it
content = open("game/conanfile.py").read()
new_content = content.replace('self.requires("math/2.0")',
'self.requires("math/2.0", force=True)')
open("game/conanfile.py", "w").write(new_content)
# The jump in major version requires building a new engine/1.0 binary
out = run("conan install game", error=True) # binary missing
assert "ERROR: Missing binary: engine/1.0" in out

# With force=True and --build=missing, it works
run("conan install game --build=missing")

# restore the original contents:
open("game/conanfile.py", "w").write(content)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from conan import ConanFile

class Pkg(ConanFile):
name = "ai"
version = "1.0"

requires = "math/2.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from conan import ConanFile

class Pkg(ConanFile):
name = "engine"
version = "1.0"

requires = "math/1.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from conan import ConanFile

class Pkg(ConanFile):
name = "game"
version = "1.0"

def requirements(self):
self.requires("engine/1.0")
self.requires("ai/1.0")
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from conan import ConanFile

class Pkg(ConanFile):
name = "math"
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os
import subprocess

def run(cmd, error=False):
# Used by tools/scm check_repo only (see if repo ok with status)
print("Running: {}".format(cmd))
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
out, err = process.communicate()
out = out.decode("utf-8")
err = err.decode("utf-8")
ret = process.returncode

output = err + out
if ret != 0 and not error:
raise Exception("Failed cmd: {}\n{}".format(cmd, output))
if ret == 0 and error:
raise Exception("Cmd succeded (failure expected): {}\n{}".format(cmd, output))
return output


# This is a full diamond
# game -> engine -> math/1.0
# \----> ai -----> math/2.0 (conflict)
# solved with override=True

# Demo the conflict
run('conan remove "*" -f') # Make sure no packages from last run
run("conan create math --version=1.0")
run("conan create math --version=2.0")
run("conan create engine")
run("conan create ai")
out = run("conan install game", error=True)
# NOTE This output shows the downstream conflict not the immediate
assert "ERROR: Version conflict: ai/1.0->math/2.0, game/1.0->math/1.0" in out
Copy link
Contributor

Choose a reason for hiding this comment

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

that is weird. I would have expected now something like below:

Suggested change
assert "ERROR: Version conflict: ai/1.0->math/2.0, game/1.0->math/1.0" in out
assert "ERROR: Version conflict: ai/1.0->math/2.0, engine/1.0->math/1.0" in out

what am I missing?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nop, this is the current implementation. The conflict shown is because the engine->math conflict is propagated down to game. If it wasn't propagated it wouldn't conflict, so the conflict needs to be tracked down from game.

At least this is the current implementation, we can try to improve the information there, but that would require changes in code.

This will be run by CI, so we will make sure that the examples work and they align with the release.


# Add the requires "force=True" fixes it
content = open("game/conanfile.py").read()
new_content = content + ' self.requires("math/2.0", override=True)\n'
open("game/conanfile.py", "w").write(new_content)
# The jump in major version requires building a new engine/1.0 binary
out = run("conan install game", error=True) # binary missing
assert "ERROR: Missing binary: engine/1.0" in out

# With force=True and --build=missing, it works
run("conan install game --build=missing")

# restore the original contents:
open("game/conanfile.py", "w").write(content)