def upload_packages(self): if not self._upload_enabled(): return self.login("upload_repo") all_refs = set( [ref for _, _, _, _, ref in self.builds_in_current_page]) if not all_refs: all_refs = [self.reference] if not all_refs: print_message("NOT REFERENCES TO UPLOAD!!") if self._platform_info.system() == "Linux" and self.use_docker: data_dir = os.path.expanduser(self.data_home) self.runner("%s chmod -R 777 %s" % (self.sudo_command, data_dir)) for ref in all_refs: command = "conan upload %s --retry %s --all --force --confirm -r=upload_repo" % ( str(ref), self.upload_retry) print_message("RUNNING UPLOAD COMMAND", "$ %s" % command) ret = self.runner(command) if ret != 0: raise Exception("Error uploading")
def builds(self): # Retrocompatibility iterating print_message( "WARNING", "\n\n\n******** ITERATING THE CONAN_PACKAGE_TOOLS BUILDS WITH " ".builds is deprecated use .items() instead (unpack 5 elements: " "settings, options, env_vars, build_requires, reference **********\n\n\n" ) return [elem[0:4] for elem in self._builds]
def pull_image(self): datadir = os.path.expanduser(self.data_home) if not os.path.exists(datadir): mkdir(datadir) if platform.system() != "Windows": self._runner("chmod -R 777 %s" % datadir) with foldable_output("docker pull"): print_message("Pulling docker image %s" % self.docker_image) self._runner("%s docker pull %s" % (self.sudo_command, self.docker_image))
def run(self, profile_name=None): print_message("Running builds...") if self.ci_manager.skip_builds(): print("Skipped builds due [skip ci] commit message") return 99 if self.conan_pip_package: with foldable_output("pip_update"): self.runner('%s pip install %s' % (self.sudo_command, self.conan_pip_package)) if not self.skip_check_credentials and self._upload_enabled(): self.login("upload_repo") self.run_builds(profile_name=profile_name) self.upload_packages()
def _get_channel(self, specified_channel, stable_channel): pattern = self.stable_branch_pattern or "master" prog = re.compile(pattern) branch = self.ci_manager.get_branch() print_message("Branch detected", branch) if branch and prog.match(branch): print_message( "Info", "Redefined channel by CI branch matching with '%s', " "setting CONAN_CHANNEL to '%s'" % (pattern, stable_channel)) self.username = os.getenv("CONAN_STABLE_USERNAME", self.username) self.password = os.getenv("CONAN_STABLE_PASSWORD", self.password) return stable_channel return specified_channel
def add_remote_safe(self, name, url, insert=False): # FIXME: Use conan api when prepared to call """Add a remove previoulsy removing if needed an already configured repository with the same URL""" existing_name = self.get_remote_name(url) if existing_name: self.runner("conan remote remove %s" % existing_name) if insert: if self.runner("conan remote add %s %s --insert" % (name, url)) != 0: print_message( "Info", "Remote add with insert failed... trying to add at the end" ) else: return 0 self.runner("conan remote add %s %s" % (name, url)) # Retrocompatibility
def login(self, remote_name, user=None, password=None, force=False): if force or not self._logged_user_in_remote[remote_name]: the_user = user or self.login_username user_command = 'conan user %s -p="%s" -r=%s' % ( user or self.login_username, password or self.password, remote_name) print_message("VERIFYING YOUR CREDENTIALS...") if self._platform_info.system() == "Linux" and self.use_docker: data_dir = os.path.expanduser(self.data_home) self.runner("%s chmod -R 777 %s" % (self.sudo_command, data_dir)) ret = self.runner(user_command) if ret != 0: raise Exception("Error with user credentials for remote %s" % remote_name) print_message("OK! '%s' user logged in '%s' " % (the_user, remote_name)) self._logged_user_in_remote[remote_name] = True
def __init__(self, args=None, username=None, channel=None, runner=None, gcc_versions=None, visual_versions=None, visual_runtimes=None, apple_clang_versions=None, archs=None, use_docker=None, curpage=None, total_pages=None, docker_image=None, reference=None, password=None, remote=None, remotes=None, upload=None, stable_branch_pattern=None, vs10_x86_64_enabled=False, mingw_configurations=None, stable_channel=None, platform_info=None, upload_retry=None, clang_versions=None, login_username=None, upload_only_when_stable=False, build_types=None, skip_check_credentials=False, allow_gcc_minors=False, exclude_vcvars_precommand=False, docker_image_skip_update=False, docker_entry_script=None, docker_32_images=None, build_policy=None): print_rule() print_ascci_art() self.ci_manager = CIManager() build_policy = build_policy or \ self.ci_manager.get_commit_build_policy() or \ os.getenv("CONAN_BUILD_POLICY", None) if build_policy: if build_policy.lower() not in ("never", "outdated", "missing"): raise Exception( "Invalid build policy, valid values: never, outdated, missing" ) self.build_policy = build_policy self.sudo_command = "" if "CONAN_DOCKER_USE_SUDO" in os.environ: if get_bool_from_env("CONAN_DOCKER_USE_SUDO"): self.sudo_command = "sudo" elif platform.system() == "Linux": self.sudo_command = "sudo" self.exclude_vcvars_precommand = exclude_vcvars_precommand or os.getenv( "CONAN_EXCLUDE_VCVARS_PRECOMMAND", False) self.docker_image_skip_update = docker_image_skip_update or os.getenv( "CONAN_DOCKER_IMAGE_SKIP_UPDATE", False) self.allow_gcc_minors = allow_gcc_minors or os.getenv( "CONAN_ALLOW_GCC_MINORS", False) self._builds = [] self._named_builds = {} self._platform_info = platform_info or PlatformInfo() self.runner = runner or os.system self.output_runner = ConanOutputRunner() self.args = args or " ".join(sys.argv[1:]) self.username = username or os.getenv("CONAN_USERNAME", None) self.login_username = login_username or os.getenv( "CONAN_LOGIN_USERNAME", None) or self.username if not self.username: raise Exception("Instance ConanMultiPackage with 'username' " "parameter or use CONAN_USERNAME env variable") # Upload related variables self.upload_retry = upload_retry or os.getenv("CONAN_UPLOAD_RETRY", 3) self.reference = reference or os.getenv("CONAN_REFERENCE", None) self.password = password or os.getenv("CONAN_PASSWORD", None) self.remote = remote or os.getenv("CONAN_REMOTE", None) # User is already logged self._logged_user_in_remote = defaultdict(lambda: False) if self.remote: raise Exception(''' 'remote' argument is deprecated. Use: - 'upload' argument to specify the remote URL to upload your packages (or None to disable upload) - 'remotes' argument to specify additional remote URLs, for example, different user repositories. ''') self.remotes = remotes or os.getenv("CONAN_REMOTES", []) self.upload = upload if upload is not None else os.getenv( "CONAN_UPLOAD", None) self.stable_branch_pattern = stable_branch_pattern or \ os.getenv("CONAN_STABLE_BRANCH_PATTERN", None) self.specified_channel = channel or os.getenv("CONAN_CHANNEL", "testing") self.specified_channel = self.specified_channel.rstrip() self.stable_channel = stable_channel or os.getenv( "CONAN_STABLE_CHANNEL", "stable") self.stable_channel = self.stable_channel.rstrip() self.channel = self._get_channel(self.specified_channel, self.stable_channel) if self.reference: self.reference = ConanFileReference.loads( "%s@%s/%s" % (self.reference, self.username, self.channel)) self.upload_only_when_stable = upload_only_when_stable or \ os.getenv("CONAN_UPLOAD_ONLY_WHEN_STABLE", False) self.skip_check_credentials = skip_check_credentials or \ os.getenv("CONAN_SKIP_CHECK_CREDENTIALS", False) self.docker_entry_script = docker_entry_script or \ os.getenv("CONAN_DOCKER_ENTRY_SCRIPT", None) if self.upload: if self.upload in ("0", "None", "False"): self.upload = None elif self.upload == "1": raise Exception( "WARNING! 'upload' argument has changed. Use 'upload' argument or " "CONAN_UPLOAD environment variable to specify a remote URL to " "upload your packages. e.j: " "upload='https://api.bintray.com/conan/myuser/myconanrepo'" ) os.environ["CONAN_CHANNEL"] = self.channel self.clang_versions = clang_versions or split_colon_env( "CONAN_CLANG_VERSIONS") self.gcc_versions = gcc_versions or split_colon_env( "CONAN_GCC_VERSIONS") # If there are some GCC versions declared then we don't default the clang # versions if not self.clang_versions and not self.gcc_versions: self.clang_versions = self.default_clang_versions # If there are some CLANG versions declared then we don't default the gcc # versions if not self.gcc_versions and self.clang_versions == self.default_clang_versions: self.gcc_versions = self.default_gcc_versions if self.gcc_versions and not self.allow_gcc_minors: for a_version in self.gcc_versions: if Version(a_version) >= Version("5") and "." in a_version: raise Exception(""" ******************* DEPRECATED GCC MINOR VERSIONS! *************************************** - The use of gcc versions >= 5 and specifying the minor version (e.j "5.4") is deprecated. - The ABI of gcc >= 5 (5, 6, and 7) is compatible between minor versions (e.j 5.3 is compatible with 5.4) - Specify only the major in your script: - CONAN_GCC_VERSIONS="5,6,7" if you are using environment variables. - gcc_versions=["5", "6", "7"] if you are using the constructor parameter. You can still keep using the same docker images, or use the new "lasote/conangcc5", "lasote/conangcc6", "lasote/conangcc7" If you still want to keep the old behavior, set the environment var CONAN_ALLOW_GCC_MINORS or pass the "allow_gcc_minors=True" parameter. But it is not recommended, if your packages are public most users won't be able to use them. ****************************************************************************************** """) if visual_versions is not None: self.visual_versions = visual_versions else: self.visual_versions = split_colon_env("CONAN_VISUAL_VERSIONS") if not self.visual_versions and not mingw_configurations and not get_mingw_config_from_env( ): self.visual_versions = self.default_visual_versions elif mingw_configurations or get_mingw_config_from_env(): self.visual_versions = [] self.visual_runtimes = visual_runtimes or split_colon_env("CONAN_VISUAL_RUNTIMES") or \ self.default_visual_runtimes self.apple_clang_versions = apple_clang_versions or \ split_colon_env("CONAN_APPLE_CLANG_VERSIONS") or \ self.default_apple_clang_versions self.mingw_configurations = mingw_configurations or get_mingw_config_from_env( ) env_ref = os.getenv("CONAN_MINGW_INSTALLER_REFERENCE") self.mingw_installer_reference = ConanFileReference.loads( env_ref or "mingw_installer/1.0" "@conan/stable") if not archs and not os.getenv("CONAN_ARCHS") and platform.system( ) == "Darwin": self.default_archs = [ "x86_64" ] # No longer supported (by default) x86 macos self.archs = archs or split_colon_env( "CONAN_ARCHS") or self.default_archs self.build_types = build_types or split_colon_env("CONAN_BUILD_TYPES") or \ self.default_build_types # If CONAN_DOCKER_IMAGE is speified, then use docker is True self.use_docker = use_docker or os.getenv("CONAN_USE_DOCKER", False) or \ (os.getenv("CONAN_DOCKER_IMAGE", None) is not None) if docker_32_images is not None: self.docker_32_images = docker_32_images else: self.docker_32_images = os.getenv("CONAN_DOCKER_32_IMAGES", False) self.curpage = curpage or os.getenv("CONAN_CURRENT_PAGE", 1) self.total_pages = total_pages or os.getenv("CONAN_TOTAL_PAGES", 1) self.docker_image = docker_image or os.getenv("CONAN_DOCKER_IMAGE", None) if self.password: self.password = self.password.replace('"', '\\"') self.conan_pip_package = os.getenv("CONAN_PIP_PACKAGE", "conan==%s" % client_version) self.vs10_x86_64_enabled = vs10_x86_64_enabled # Set the remotes if self.remotes: if not isinstance(self.remotes, list): self.remotes = [ r.strip() for r in self.remotes.split(",") if r.strip() ] for counter, remote in enumerate(reversed(self.remotes)): remote_name = "remote%s" % counter if remote != self.upload else "upload_repo" self.add_remote_safe(remote_name, remote, insert=True) self.runner("conan remote list") else: print_message("Info", "Not additional remotes declared...") if self.upload and self.upload not in self.remotes: # If you specify the upload as a remote, put it first # this way we can cover all the possibilities self.add_remote_safe("upload_repo", self.upload, insert=False) _, client_cache, _ = Conan.factory() self.data_home = client_cache.store self.builds_in_current_page = [] def valid_pair(var, value): return (isinstance(value, six.string_types) or isinstance(value, bool) or isinstance(value, list) ) and not var.startswith("_") and "password" not in var with foldable_output("local_vars"): print_dict({ var: value for var, value in self.__dict__.items() if valid_pair(var, value) })
def __init__(self): print_message("CI detected: Jenkins")
def run(self, pull_image=True, docker_entry_script=None): if pull_image: self.pull_image() if not self.docker_image_skip_update: # Update the downloaded image with foldable_output("update conan"): command = "%s docker run --name conan_runner %s /bin/sh -c " \ "\"sudo pip install conan_package_tools==%s " \ "--upgrade" % (self.sudo_command, self.docker_image, package_tools_version) if self._conan_pip_package: command += " && sudo pip install %s\"" % self._conan_pip_package else: command += " && sudo pip install conan --upgrade\"" print_command(command) self._runner(command) # Save the image with the updated installed # packages and remove the intermediate container command = "%s docker commit conan_runner %s" % ( self.sudo_command, self.docker_image) print_message(command) self._runner(command) command = "%s docker rm conan_runner" % self.sudo_command print_command(command) self._runner(command) # Run the build serial = pipes.quote(self.serialize()) env_vars = "-e CONAN_RUNNER_ENCODED=%s -e CONAN_USERNAME=%s " \ "-e CONAN_CHANNEL=%s" % (serial, self._username, self._channel) conan_env_vars = { key: value for key, value in os.environ.items() if key.startswith("CONAN_") and key not in ["CONAN_CHANNEL", "CONAN_USERNAME", "CONAN_USER_HOME"] } env_vars += " " + " ".join([ '-e %s="%s"' % (key, value) for key, value in conan_env_vars.items() ]) command = "%s docker run --rm -v %s:/home/conan/project -v " \ "%s:/home/conan/.conan %s %s /bin/sh -c \"" \ "rm -f /home/conan/.conan/conan.conf && cd project && " \ "rm -f /home/conan/.conan/profiles/default && " \ "(conan profile new default --detect || true) && " \ "run_create_in_docker\"" % (self.sudo_command, os.getcwd(), self.conan_home, env_vars, self.docker_image) # Push entry command before to build if docker_entry_script: command = command.replace( "run_create_in_docker", "%s && run_create_in_docker" % docker_entry_script) self.clear_system_requirements() ret = self._runner(command) if ret != 0: raise Exception("Error building: %s" % command)
def __init__(self): print_message("CI detected: Gitlab")
def __init__(self): print_message("CI detected: Circle CI")
def __init__(self): print_message("CI detected: Bamboo")
def __init__(self): print_message("- CI detected: Appveyor")
def __init__(self): print_message("- CI detected: Travis CI")