def test_force_download_after_build(self): """Test two deps on the same spec with build and download. Here we have two specs having an "build_tree" and a "download" depdendency on the same spec (spec_build). When the two are set together the scheduler cannot find a solution. """ env = BaseEnv() env.set_build("x86_64-linux", "rhes8", "mylinux") asr = AnodSpecRepository(self.spec_dir) ac = AnodContext(asr, default_env=env) ac.add_anod_action("spec_build_dep", env=ac.default_env, primitive="build") # Verify that, when scheduling this plan, the scheduler ask for # having an explicit build with pytest.raises(SchedulingError) as err: ac.schedule(ac.always_create_source_resolver) assert "A spec in the plan has a build_tree dependency on spec_build" in str( err) # Verify that after adding a download dep, the scheduler now # warns that he cannot resolve the plan ac.add_anod_action("spec_download_dep", env=ac.default_env, primitive="build") with pytest.raises(SchedulingError) as err: ac.schedule(ac.always_create_source_resolver) assert "explicit DownloadBinary decision made" in str(err)
def test_force_download_after_install(self): """Test two deps on the same spec with installation and download. Here we have two specs having an "installation" and a "download" depdendency on the same spec (spec_build). When the two are set together the scheduler find the proper solution: download. """ env = BaseEnv() env.set_build("x86_64-linux", "rhes8", "mylinux") asr = AnodSpecRepository(self.spec_dir) ac = AnodContext(asr, default_env=env) ac.add_anod_action("spec_install_dep", env=ac.default_env, primitive="build") with pytest.raises(SchedulingError) as err: ac.schedule(ac.always_create_source_resolver) assert "This plan resolver cannot decide" in str(err) ac.add_anod_action("spec_download_dep", env=ac.default_env, primitive="build") result = ac.schedule(ac.always_create_source_resolver) assert set(result.vertex_data.keys()) == { "root", "mylinux.x86_64-linux.spec_install_dep.build", "mylinux.x86_64-linux.spec_download_dep.build", "mylinux.x86_64-linux.spec_build.install", "mylinux.x86_64-linux.spec_build.download_bin", }
def test_force_download_before_install(self): """Test two deps on the same spec with installation and download. Same as test_force_download_after_install but in a different order. The end result should be the same. """ env = BaseEnv() env.set_build("x86_64-linux", "rhes8", "mylinux") asr = AnodSpecRepository(self.spec_dir) ac = AnodContext(asr, default_env=env) ac.add_anod_action("spec_download_dep", env=ac.default_env, primitive="build") result = ac.schedule(ac.always_create_source_resolver) assert set(result.vertex_data.keys()) == { "root", "mylinux.x86_64-linux.spec_download_dep.build", "mylinux.x86_64-linux.spec_build.install", "mylinux.x86_64-linux.spec_build.download_bin", } ac.add_anod_action("spec_install_dep", env=ac.default_env, primitive="build") ac.schedule(ac.always_create_source_resolver) result = ac.schedule(ac.always_create_source_resolver) assert set(result.vertex_data.keys()) == { "root", "mylinux.x86_64-linux.spec_install_dep.build", "mylinux.x86_64-linux.spec_download_dep.build", "mylinux.x86_64-linux.spec_build.install", "mylinux.x86_64-linux.spec_build.download_bin", }
def create_context(self): # Create a context for a x86-linux machine asr = AnodSpecRepository(self.spec_dir) asr.repos['spec1-git'] = 'spec1-git' asr.repos['spec8-git'] = 'spec8-git' asr.repos['spec2-git'] = 'spec2-git' env = BaseEnv() env.set_build('x86-linux', 'rhes6', 'mylinux') ac = AnodContext(asr, default_env=env) return ac
def test_configure(): class AnodConf(Anod): @Anod.primitive() def build(self): c = Configure(self) return c.cmdline() Anod.sandbox = SandBox() Anod.sandbox.root_dir = os.getcwd() Anod.sandbox.create_dirs() ac = AnodConf(qualifier="", kind="build", jobs=10) AnodDriver(anod_instance=ac, store=None).activate(Anod.sandbox, None) ac.build_space.create() # Configure() can add $CONFIG_SHELL in the command line # Check that the two other arguments are as expected assert ac.build()["cmd"][-2:] == [ "../src/configure", "--build=%s" % ac.env.build.triplet, ] # Check with canadian env canadian_env = BaseEnv() canadian_env.set_build("x86-windows") canadian_env.set_host("x86-linux") canadian_env.set_target("arm-elf") assert canadian_env.is_canadian ac2 = AnodConf(qualifier="", kind="build", jobs=10, env=canadian_env) AnodDriver(anod_instance=ac2, store=None).activate(Anod.sandbox, None) ac2.build_space.create() ac2_cmd = ac2.build()["cmd"] assert "--build=i686-pc-mingw32" in ac2_cmd assert "--host=i686-pc-linux-gnu" in ac2_cmd assert "--target=arm-eabi" in ac2_cmd # Check with cross env cross_env = BaseEnv() cross_env.set_target("arm-elf") ac3 = AnodConf(qualifier="", kind="build", jobs=10, env=cross_env) AnodDriver(anod_instance=ac3, store=None).activate(Anod.sandbox, None) ac3.build_space.create() assert "--target=arm-eabi" in ac3.build()["cmd"]
def test_force_download_before_build(self): """Test two deps on the same spec with build and download. Same as test_force_download_after_build but in a different order. The expected result is the same: an error should be raised. """ env = BaseEnv() env.set_build("x86_64-linux", "rhes8", "mylinux") asr = AnodSpecRepository(self.spec_dir) ac = AnodContext(asr, default_env=env) ac.add_anod_action("spec_download_dep", env=ac.default_env, primitive="build") ac.add_anod_action("spec_build_dep", env=ac.default_env, primitive="build") with pytest.raises(SchedulingError) as err: ac.schedule(ac.always_create_source_resolver) assert "explicit DownloadBinary decision made" in str(err)
def create_context(self, reject_duplicates=True): """Create a spec repository and anod context. :param reject_duplicates: whether to reject duplicates in plan :type reject_duplicates: bool :rtype: AnodContext """ # Create a context for a x86-linux machine asr = AnodSpecRepository(self.spec_dir) asr.repos['spec1-git'] = 'spec1-git' asr.repos['spec8-git'] = 'spec8-git' asr.repos['spec2-git'] = 'spec2-git' env = BaseEnv() env.set_build('x86-linux', 'rhes6', 'mylinux') ac = AnodContext(asr, default_env=env, reject_duplicates=reject_duplicates) return ac
def create_context(self, reject_duplicates: bool = True) -> AnodContext: """Create a spec repository and anod context. :param reject_duplicates: whether to reject duplicates in plan """ def repo_conf(name: str) -> dict[str, str]: return {"vcs": "git", "url": name, "branch": "master"} # Create a context for a x86-linux machine asr = AnodSpecRepository(self.spec_dir) asr.repos["spec1-git"] = repo_conf("spec1") asr.repos["spec8-git"] = repo_conf("spec8") asr.repos["spec2-git"] = repo_conf("spec2") asr.repos["a-git"] = repo_conf("a") env = BaseEnv() env.set_build("x86-linux", "rhes6", "mylinux") ac = AnodContext(asr, default_env=env, reject_duplicates=reject_duplicates) return ac
def test_force_download_without_require_condition(self): """Test that the force download can be done thanks to require=xxx. A require condition can be added to the build primitive to disable the build primitive for some qualifiers. """ env = BaseEnv() env.set_build("x86_64-linux", "rhes8", "mylinux") asr = AnodSpecRepository(self.spec_dir) # We start with a dependency on spec_nobuild where build primitive # require condition is True ac = AnodContext(asr, default_env=env) ac.add_anod_action( "spec_nobuild_dep", env=ac.default_env, primitive="build", ) # If both build and install are allowed the resolver will # complain and ask for an explicit choice with pytest.raises(SchedulingError) as err: ac.schedule(ac.always_create_source_resolver) assert "what to do for resolving" in str(err) # Now with a dependency making require return False, and so # disable the build primitive, the resolver will not have any # conflict: the only allowed action will be download. ac2 = AnodContext(asr, default_env=env) ac2.add_anod_action( "spec_nobuild_stable_dep", env=ac.default_env, primitive="build", ) result = ac2.schedule(ac.always_create_source_resolver) assert set(result.vertex_data.keys()) == { "root", "mylinux.x86_64-linux.spec_nobuild.download_bin", "mylinux.x86_64-linux.spec_nobuild_stable_dep.build", "mylinux.x86_64-linux.spec_nobuild.install", }
def test_force_download_without_download_primitive(self): """Test that the force download do not require the download primitive. Having a download() primitive or not should not impact this feature. """ env = BaseEnv() env.set_build("x86_64-linux", "rhes8", "mylinux") asr = AnodSpecRepository(self.spec_dir) ac = AnodContext(asr, default_env=env) ac.add_anod_action( "spec_download_dep_for_nodownloadprimitive", env=ac.default_env, primitive="build", ) result = ac.schedule(ac.always_create_source_resolver) assert set(result.vertex_data.keys()) == { "root", "mylinux.x86_64-linux.spec_download_dep_for_nodownloadprimitive.build", "mylinux.x86_64-linux.spec_nodownloadprimitive.install", "mylinux.x86_64-linux.spec_nodownloadprimitive.download_bin", }