# Buggy code
def _build_one_legacy(self, req, tempd, python_tag=None):
    """Build one InstallRequirement using the "legacy" build process.

    Returns path to wheel if successfully built. Otherwise, returns None.
    """
    base_args = self._base_setup_args(req)

    spin_message = "Building wheel for %s (setup.py)" % (req.name,)
    with open_spinner(spin_message) as spinner:
        logger.debug("Destination directory: %s", tempd)
        wheel_args = base_args + ["bdist_wheel", "-d", tempd] + self.build_options

        if python_tag is not None:
            wheel_args += ["--python-tag", python_tag]

        try:
            call_subprocess(
                wheel_args, cwd=req.setup_py_dir, show_stdout=False, spinner=spinner
            )
        except Exception:
            spinner.finish("error")
            logger.error("Failed building wheel for %s", req.name)
            return None
        # listdir's return value is sorted to be deterministic
        return os.path.join(tempd, sorted(os.listdir(tempd))[0])


# Traceback (IndexError)
Stored in directory: /Users/travis/Library/Caches/pip/wheels/1d/2f/99/1594715f229f93f235d8b370a3b6f16e2b00fbac1087a99902
Building wheel for scs (setup.py) ... done
Exception:
Traceback (most recent call last):
File "/Users/travis/miniconda3/envs/workshop/lib/python3.6/site-packages/pip/_internal/cli/base_command.py", line 179, in main
status = self.run(options, args)
File "/Users/travis/miniconda3/envs/workshop/lib/python3.6/site-packages/pip/_internal/commands/install.py", line 355, in run
session=session, autobuilding=True
File "/Users/travis/miniconda3/envs/workshop/lib/python3.6/site-packages/pip/_internal/wheel.py", line 980, in build
python_tag=python_tag,
File "/Users/travis/miniconda3/envs/workshop/lib/python3.6/site-packages/pip/_internal/wheel.py", line 813, in _build_one
python_tag=python_tag)
File "/Users/travis/miniconda3/envs/workshop/lib/python3.6/site-packages/pip/_internal/wheel.py", line 821, in _build_one_inside_env
wheel_path = builder(req, temp_dir.path, python_tag=python_tag)
File "/Users/travis/miniconda3/envs/workshop/lib/python3.6/site-packages/pip/_internal/wheel.py", line 898, in _build_one_legacy
return os.path.join(tempd, sorted(os.listdir(tempd))[0])
IndexError: list index out of range

# Fixed code
def _build_one_legacy(self, req, tempd, python_tag=None):
    """Build one InstallRequirement using the "legacy" build process.

    Returns path to wheel if successfully built. Otherwise, returns None.
    """
    base_args = self._base_setup_args(req)

    spin_message = "Building wheel for %s (setup.py)" % (req.name,)
    with open_spinner(spin_message) as spinner:
        logger.debug("Destination directory: %s", tempd)
        wheel_args = base_args + ["bdist_wheel", "-d", tempd] + self.build_options

        if python_tag is not None:
            wheel_args += ["--python-tag", python_tag]

        try:
            output = call_subprocess(
                wheel_args, cwd=req.setup_py_dir, show_stdout=False, spinner=spinner
            )
        except Exception:
            spinner.finish("error")
            logger.error("Failed building wheel for %s", req.name)
            return None
        names = os.listdir(tempd)
        wheel_path = get_legacy_build_wheel_path(
            names=names,
            temp_dir=tempd,
            req=req,
            command_args=wheel_args,
            command_output=output,
        )
        return wheel_path