| 1 |
""" |
| 2 |
Publish a crate that is nested inside a git repository, get/build it and also |
| 3 |
use it as a dependency |
| 4 |
""" |
| 5 |
|
| 6 |
import os |
| 7 |
import shutil |
| 8 |
|
| 9 |
from drivers.alr import run_alr, init_local_crate, alr_with, alr_publish |
| 10 |
from drivers.helpers import init_git_repo, on_windows |
| 11 |
# from drivers.asserts import assert_eq, assert_match |
| 12 |
from subprocess import run |
| 13 |
|
| 14 |
# We create a repository with the nested crate that will act as the upstream |
| 15 |
# remote repository: |
| 16 |
start_dir = os.getcwd() |
| 17 |
os.mkdir("monoproject.upstream") |
| 18 |
os.chdir("monoproject.upstream") |
| 19 |
init_local_crate("mycrate", enter=False) |
| 20 |
os.chdir(start_dir) |
| 21 |
commit = init_git_repo("monoproject.upstream") |
| 22 |
|
| 23 |
# We clone the project to obtain our local copy |
| 24 |
assert run(["git", "clone", |
| 25 |
"monoproject.upstream", "monoproject"]).returncode == 0 |
| 26 |
|
| 27 |
# We enter the clone and verify that attempting to publish from the root fails, |
| 28 |
# as there is no crate at the git root |
| 29 |
os.chdir("monoproject") |
| 30 |
p = run_alr("publish", complain_on_error=False) |
| 31 |
assert p.status != 0, "alr failed to err as expected" |
| 32 |
assert "No Alire workspace found" in p.out, "Unexpected output: " + p.out |
| 33 |
|
| 34 |
# We enter the crate nested inside and publish. |
| 35 |
# We are now at monoproject/mycrate. |
| 36 |
os.chdir("mycrate") |
| 37 |
run_alr("show") # Verify the crate is detected properly |
| 38 |
|
| 39 |
# This call creates the manifest and puts it in place in the index |
| 40 |
alr_publish("mycrate", "0.1.0-dev", index_path=os.path.join(start_dir, "my_index")) |
| 41 |
|
| 42 |
# Verify that the crate can be got and compiled, and expected location |
| 43 |
os.chdir(start_dir) |
| 44 |
run_alr("get", "--build", "mycrate") |
| 45 |
assert os.path.isdir(os.path.join(f"monoproject_{commit[:8]}", "mycrate")), \ |
| 46 |
"Expected directory does not exist" |
| 47 |
|
| 48 |
# Verify that the crate is usable as a dependency, and expected binary location |
| 49 |
init_local_crate("top") |
| 50 |
alr_with("mycrate") |
| 51 |
run_alr("build") |
| 52 |
assert os.path.isfile(os.path.join( |
| 53 |
"alire", "cache", "dependencies", |
| 54 |
f"monoproject_{commit[:8]}", "mycrate", "bin", |
| 55 |
f"mycrate{'.exe' if on_windows() else ''}")), \ |
| 56 |
"Expected binary does not exist" |
| 57 |
|
| 58 |
# Also that the info file is there |
| 59 |
assert os.path.isfile(os.path.join( |
| 60 |
"alire", "cache", "dependencies", |
| 61 |
f"mycrate_0.1.0_in_monoproject_{commit[:8]}")), \ |
| 62 |
"Expected info file does not exist" |
| 63 |
|
| 64 |
print('SUCCESS') |