def build(
        cls,
        device: Device,
        build_directory: _Path,
        workspace_path: _Path,
        credentials: AppSigningCredentials,
        clean: bool = False,
    ) -> _Path:
        """
        Build the Xcode project for the specified device.

        This method handles the entire build process, including cleaning if requested,
        setting up the build directory, and running the ``xcodebuild`` command.

        Parameters:
        -----------
        device: Device
            The target device for which to build the app.

        build_directory: Path
            The directory where build artifacts will be stored.

        workspace_path: Path
            The path to the Xcode workspace file.

        credentials: AppSigningCredentials
            The application code signing credentials.

        clean: bool
            Whether to clean the build directory before building (default is False).

        Returns
        -------
        Path
            The path to the built .app file if successful, None otherwise.

        """
        cls.check_app_signing_credentials(credentials=credentials)

        build_path = cls.get_build_path(
            device=device,
            build_directory=build_directory,
        )

        result = None
        if clean and build_path.is_dir():
            _shutil.rmtree(build_path.resolve())
        else:
            result = next(build_path.rglob("*.app"), None)

        if result is not None:
            return result

        build_path.mkdir(parents=True, exist_ok=True)

        if not workspace_path.is_dir():
            raise ValueError(f"Workspace path={workspace_path} is not a directory.")

        workspace_name = _os.path.splitext(_os.path.basename(workspace_path))[0]

        bundle_identifier = credentials.bundle_identifier
        bundle_identifier = (
            bundle_identifier if bundle_identifier is not None else "com.coremltools.modelrunnerd"
        )

        command = (
            f"xcodebuild -workspace {str(workspace_path.resolve())} "
            f"-scheme {cls.get_scheme_name(workspace_name= workspace_name, device=device)} "
            f"-sdk {cls.get_sdk_name(device, credentials)} "
            f"-destination {cls.get_destination(device)} "
            "-configuration Release "
            f"SYMROOT={build_path.resolve()} "
            "CODE_SIGN_STYLE=AUTOMATIC "
        )

        if credentials.provisioning_profile_uuid is not None:
            command += f"PROVISIONING_PROFILE={credentials.provisioning_profile_uuid} "
        else:
            command += "-allowProvisioningUpdates -allowProvisioningDeviceRegistration "

        if credentials.development_team is not None and len(credentials.development_team) > 0:
            command += f"DEVELOPMENT_TEAM={credentials.development_team} "
        else:
            command += 'CODE_SIGN_IDENTITY="-" '

        command += f"PRODUCT_BUNDLE_IDENTIFIER={bundle_identifier} "

        try:
            output = _subprocess.run(
                command,
                shell=True,
                stdout=_subprocess.PIPE,
                stderr=_subprocess.STDOUT,
                stdin=_subprocess.PIPE,
            )
            output.check_returncode()
        except _subprocess.CalledProcessError as e:
            raise _AppBuilder.Error(
                error_code=e.returncode,
                message=e.stderr,
            )

        result = next(build_path.rglob("*.app"), None)
        return result

        Build the Xcode project for the specified device.

        This method handles the entire build process, including cleaning if requested,
        setting up the build directory, and running the ``xcodebuild`` command.

        Parameters:
        -----------
        device: Device
            The target device for which to build the app.

        build_directory: Path
            The directory where build artifacts will be stored.

        workspace_path: Path
            The path to the Xcode workspace file.

        credentials: AppSigningCredentials
            The application code signing credentials.

        clean: bool
            Whether to clean the build directory before building (default is False).

        Returns
        -------
        Path
            The path to the built .app file if successful, None otherwise.

        
coremltools/models/ml_program/experimental/remote_device.py