| 1 |
""" |
| 2 |
Publish two crates and use them as dependencies, but at different commits of |
| 3 |
the same monorepo. The monorepo must be checked out twice and the duplicated |
| 4 |
crate must not cause trouble. |
| 5 |
""" |
| 6 |
|
| 7 |
import os |
| 8 |
import shutil |
| 9 |
|
| 10 |
from drivers.alr import run_alr, init_local_crate, alr_with, alr_publish |
| 11 |
from drivers.helpers import init_git_repo, on_windows, commit_all |
| 12 |
# from drivers.asserts import assert_eq, assert_match |
| 13 |
from subprocess import run |
| 14 |
|
| 15 |
# We create a repository with two nested crates that will act as the upstream |
| 16 |
# remote repository: |
| 17 |
start_dir = os.getcwd() |
| 18 |
os.mkdir("monoproject.upstream") |
| 19 |
os.chdir("monoproject.upstream") |
| 20 |
init_local_crate("crate1", enter=False) |
| 21 |
os.chdir(start_dir) |
| 22 |
commit1 = init_git_repo("monoproject.upstream") |
| 23 |
|
| 24 |
# We clone the project to obtain our local copy |
| 25 |
assert run(["git", "clone", |
| 26 |
"monoproject.upstream", "monoproject"]).returncode == 0 |
| 27 |
|
| 28 |
# We enter the crate nested inside and publish. |
| 29 |
# We are now at monoproject/mycrate. |
| 30 |
os.chdir("monoproject") |
| 31 |
os.chdir("crate1") |
| 32 |
alr_publish("crate1", "0.1.0-dev", index_path=os.path.join(start_dir, "my_index")) |
| 33 |
|
| 34 |
# We create a second crate at another commit |
| 35 |
os.chdir(os.path.join(start_dir, "monoproject.upstream")) |
| 36 |
init_local_crate("crate2", enter=False) |
| 37 |
os.chdir(start_dir) |
| 38 |
commit2 = commit_all("monoproject.upstream") |
| 39 |
|
| 40 |
# Check out changes and publish crate2 |
| 41 |
os.chdir("monoproject") |
| 42 |
run(["git", "pull"]).check_returncode() |
| 43 |
os.chdir("crate2") |
| 44 |
alr_publish("crate2", "0.1.0-dev", index_path=os.path.join(start_dir, "my_index")) |
| 45 |
|
| 46 |
# Verify that the crates are usable as a dependency, and expected binary |
| 47 |
# locations |
| 48 |
init_local_crate("top") |
| 49 |
alr_with("crate1") |
| 50 |
alr_with("crate2") |
| 51 |
run_alr("build") |
| 52 |
|
| 53 |
assert os.path.isfile(os.path.join( |
| 54 |
"alire", "cache", "dependencies", |
| 55 |
f"monoproject_{commit1[:8]}", "crate1", "bin", |
| 56 |
f"crate1{'.exe' if on_windows() else ''}")), \ |
| 57 |
"Expected binary does not exist" |
| 58 |
assert os.path.isfile(os.path.join( |
| 59 |
"alire", "cache", "dependencies", |
| 60 |
f"monoproject_{commit2[:8]}", "crate2", "bin", |
| 61 |
f"crate2{'.exe' if on_windows() else ''}")), \ |
| 62 |
"Expected binary does not exist" |
| 63 |
|
| 64 |
# Also that the info files are there |
| 65 |
assert os.path.isfile(os.path.join( |
| 66 |
"alire", "cache", "dependencies", |
| 67 |
f"crate1_0.1.0_in_monoproject_{commit1[:8]}")), \ |
| 68 |
"Expected info file does not exist" |
| 69 |
assert os.path.isfile(os.path.join( |
| 70 |
"alire", "cache", "dependencies", |
| 71 |
f"crate2_0.1.0_in_monoproject_{commit2[:8]}")), \ |
| 72 |
"Expected info file does not exist" |
| 73 |
|
| 74 |
print('SUCCESS') |