Esempio n. 1
0
    def ensure_rust_modern(self):
        modern, version = self.is_rust_modern()

        if modern:
            print('Your version of Rust (%s) is new enough.' % version)
            return

        if not version:
            # Rust wasn't in PATH. Try the standard path.
            cargo_home = os.environ.get(
                'CARGO_HOME', os.path.expanduser(os.path.join('~', '.cargo')))
            cargo_bin = os.path.join(cargo_home, 'bin')
            try_rustc = os.path.join(cargo_bin, 'rustc' + rust.exe_suffix())
            try_cargo = os.path.join(cargo_bin, 'cargo' + rust.exe_suffix())
            have_rustc = os.path.exists(try_rustc)
            have_cargo = os.path.exists(try_cargo)
            if have_rustc or have_cargo:
                print(RUST_NOT_IN_PATH % {
                    'cargo_bin': cargo_bin,
                    'cargo_home': cargo_home
                })
                sys.exit(1)

        rustup = self.which('rustup')
        if rustup:
            rustup_version = self._parse_version(rustup)
            if not rustup_version:
                print(RUSTUP_OLD)
                sys.exit(1)
            if not version:
                # We have rustup but no rustc.
                # Try running rustup; maybe it will fix things.
                print('Found rustup. Will try to upgrade.')
            else:
                # We have both rustup and rustc.
                print(
                    'Your version of Rust (%s) is too old. Will try to upgrade.'
                    % version)
            self.upgrade_rust(rustup)
        else:
            # No rustc or rustup.
            print('Will try to install Rust.')
            self.install_rust()

        modern, after = self.is_rust_modern()

        if not modern:
            print(RUST_UPGRADE_FAILED % (MODERN_RUST_VERSION, after))
            sys.exit(1)
Esempio n. 2
0
    def ensure_rust_modern(self):
        modern, version = self.is_rust_modern()

        if modern:
            print("Your version of Rust (%s) is new enough." % version)
            return

        if not version:
            # Rust wasn't in PATH. Try the standard path.
            cargo_home, cargo_bin = self.cargo_home()
            try_rustc = os.path.join(cargo_bin, "rustc" + rust.exe_suffix())
            try_cargo = os.path.join(cargo_bin, "cargo" + rust.exe_suffix())
            have_rustc = os.path.exists(try_rustc)
            have_cargo = os.path.exists(try_cargo)
            if have_rustc or have_cargo:
                print(RUST_NOT_IN_PATH % {"cargo_bin": cargo_bin})
                print(RUST_PATH_ADVICE % {"cargo_home": cargo_home})
                sys.exit(1)

        rustup = self.which("rustup")
        if rustup:
            rustup_version = self._parse_version(rustup)
            if not rustup_version:
                print(RUSTUP_OLD)
                sys.exit(1)
            if not version:
                # We have rustup but no rustc.
                # Try running rustup; maybe it will fix things.
                print("Found rustup. Will try to upgrade.")
            else:
                # We have both rustup and rustc.
                print("Your version of Rust (%s) is too old. Will try to upgrade." % version)
            self.upgrade_rust(rustup)

            modern, after = self.is_rust_modern()
            if not modern:
                print(RUST_UPGRADE_FAILED % (MODERN_RUST_VERSION, after))
                sys.exit(1)
        else:
            # No rustc or rustup.
            print("Will try to install Rust.")
            self.install_rust()
Esempio n. 3
0
    def ensure_rust_modern(self):
        modern, version = self.is_rust_modern()

        if modern:
            print('Your version of Rust (%s) is new enough.' % version)
            rustup = self.which('rustup')
            if rustup:
                self.ensure_rust_targets(rustup)
            return

        if not version:
            # Rust wasn't in PATH. Check the standard location.
            cargo_home, cargo_bin = self.cargo_home()
            try_rustc = os.path.join(cargo_bin, 'rustc' + rust.exe_suffix())
            try_cargo = os.path.join(cargo_bin, 'cargo' + rust.exe_suffix())
            have_rustc = os.path.exists(try_rustc)
            have_cargo = os.path.exists(try_cargo)
            if have_rustc or have_cargo:
                self.print_rust_path_advice(RUST_NOT_IN_PATH, cargo_home,
                                            cargo_bin)
                sys.exit(1)
        else:
            print('Your version of Rust (%s) is too old.' % version)

        rustup = self.which('rustup')
        if rustup:
            rustup_version = self._parse_version(rustup)
            if not rustup_version:
                print(RUSTUP_OLD)
                sys.exit(1)
            print('Found rustup. Will try to upgrade.')
            self.upgrade_rust(rustup)

            modern, after = self.is_rust_modern()
            if not modern:
                print(RUST_UPGRADE_FAILED % (MODERN_RUST_VERSION, after))
                sys.exit(1)
        else:
            # No rustup. Download and run the installer.
            print('Will try to install Rust.')
            self.install_rust()
Esempio n. 4
0
    def ensure_rust_modern(self):
        modern, version = self.is_rust_modern()

        if modern:
            print('Your version of Rust (%s) is new enough.' % version)
            rustup = self.which('rustup')
            if rustup:
                self.ensure_rust_targets(rustup)
            return

        if not version:
            # Rust wasn't in PATH. Check the standard location.
            cargo_home, cargo_bin = self.cargo_home()
            try_rustc = os.path.join(cargo_bin, 'rustc' + rust.exe_suffix())
            try_cargo = os.path.join(cargo_bin, 'cargo' + rust.exe_suffix())
            have_rustc = os.path.exists(try_rustc)
            have_cargo = os.path.exists(try_cargo)
            if have_rustc or have_cargo:
                self.print_rust_path_advice(RUST_NOT_IN_PATH,
                                            cargo_home, cargo_bin)
                sys.exit(1)
        else:
            print('Your version of Rust (%s) is too old.' % version)

        rustup = self.which('rustup')
        if rustup:
            rustup_version = self._parse_version(rustup)
            if not rustup_version:
                print(RUSTUP_OLD)
                sys.exit(1)
            print('Found rustup. Will try to upgrade.')
            self.upgrade_rust(rustup)

            modern, after = self.is_rust_modern()
            if not modern:
                print(RUST_UPGRADE_FAILED % (MODERN_RUST_VERSION, after))
                sys.exit(1)
        else:
            # No rustup. Download and run the installer.
            print('Will try to install Rust.')
            self.install_rust()