Author SHA1 Message Date
Manuel Gauto 43b1632877 Adjust defaulting logic for handling nil case of Credentials. Completes fix for #100. 2021-02-05 19:26:55 -05:00
Manuel Gauto e1c3e89e09 Merge remote-tracking branch https://github.com/joehinkle11/SwiftGit2.git into applesilicon-support.
Initial fix for Credentials BAD_ACCESS error.
2021-02-05 19:23:07 -05:00
Joe Hinkle 3c7c920c47 Update Credentials.swift 2020-12-17 15:40:24 -05:00
Joe Hinkle 5a56c22a97 Update Credentials.swift 2020-12-15 18:10:22 -05:00
Joe Hinkle 39f160344e Credentials fix for BAD_ACCESS
This is a fix for an old issue: https://github.com/SwiftGit2/SwiftGit2/issues/100

There's a crash caused by accessing the pointer to the creds object after libgit2 frees it. libgit2 also is calling credentialsCallback, so there is no good way to prevent the crash from happening. Interestingly, libgit2 calls the callback twice, and the result of the second one doesn't seem too important. So because we don't have control over how libgit2 chooses to free objects, I just wrote a simple change to prevent the second call of credentialsCallback from accessing the pointer to the creds object.
2020-12-03 18:42:13 -05:00
15 changed files with 125 additions and 292 deletions
-11
View File
@@ -1,11 +0,0 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
-45
View File
@@ -1,45 +0,0 @@
name: pull request
on:
push:
branches:
- master
pull_request:
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
xcode: [ Xcode_14.3, Xcode_15.2.0 ]
os: [ macos-13 ]
include:
- xcode: Xcode_15.4
os: macos-14
- xcode: Xcode_16.2
os: macos-14
steps:
- name: ls Xcode
run: ls -la /Applications/Xcode*
- name: Checkout
uses: actions/checkout@v5
with:
fetch-depth: 0
submodules: recursive
- name: get architecture
run: |
echo "ARCHITECTURE=$(uname -m)" >> $GITHUB_ENV
echo $(uname -m)
- name: Set XCode Version
run: sudo xcode-select -s /Applications/${{ matrix.xcode }}.app
- name: schemes list
run: xcodebuild -workspace SwiftGit2.xcworkspace -list
- name: update_libgit2
run: script/update_libgit2
- name: bootstrap
run: script/bootstrap
# - name: cibuild
# run: script/cibuild
- name: Build project
run: xcodebuild -workspace SwiftGit2.xcworkspace -scheme SwiftGit2-OSX -archivePath ./SwiftGit2 archive ARCHS="${{ env.ARCHITECTURE }}"
-1
View File
@@ -23,7 +23,6 @@ DerivedData
*.idea*
External/libgit2*.a
External/libgit2-mac
External/ios-openssl
External/libgit2-ios
External/libssh2-ios
+30
View File
@@ -0,0 +1,30 @@
language: objective-c
os: osx
osx_image: xcode11.4
sudo: false # Enable container-based builds
env:
matrix:
- SCHEME="SwiftGit2-OSX"
- SCHEME="SwiftGit2-iOS"
matrix:
fast_finish: true
before_install:
- gem update bundler # https://github.com/bundler/bundler/pull/4981
- gem install xcpretty
- gem install xcpretty-travis-formatter
install: script/bootstrap
script: script/cibuild
branches:
only: # whitelist
- master
notifications:
email: false
Vendored Symlink
+1
View File
@@ -0,0 +1 @@
/usr/local/opt/openssl/lib/libcrypto.a
Vendored Symlink
+1
View File
@@ -0,0 +1 @@
/usr/local/opt/openssl/lib/libssl.a
+1
View File
@@ -1,4 +1,5 @@
# SwiftGit2
[![Build Status](https://travis-ci.org/SwiftGit2/SwiftGit2.svg)](https://travis-ci.org/SwiftGit2/SwiftGit2)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](#carthage)
[![GitHub release](https://img.shields.io/github/release/SwiftGit2/SwiftGit2.svg)](https://github.com/SwiftGit2/SwiftGit2/releases)
![Swift 5.3.x](https://img.shields.io/badge/Swift-5.3.x-orange.svg)
+15 -19
View File
@@ -686,7 +686,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "script/update_libgit2_ios\n";
shellScript = script/update_libgit2_ios;
};
621E66E81C729EB800A0F352 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
@@ -699,7 +699,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "script/update_libssl_ios\n";
shellScript = script/update_libssl_ios;
};
621E66EE1C729EBB00A0F352 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
@@ -725,7 +725,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "script/update_libgit2\n";
shellScript = script/update_libgit2;
};
C9CE0DD61E0710C20053205D /* Lint Sources */ = {
isa = PBXShellScriptBuildPhase;
@@ -990,7 +990,7 @@
INSTALL_MODE_FLAG = "";
INSTALL_OWNER = "";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MACOSX_DEPLOYMENT_TARGET = 10.9;
SWIFT_VERSION = 5.0;
};
name = Debug;
@@ -1006,7 +1006,7 @@
INSTALL_MODE_FLAG = "";
INSTALL_OWNER = "";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MACOSX_DEPLOYMENT_TARGET = 10.9;
SWIFT_VERSION = 5.0;
};
name = Release;
@@ -1021,15 +1021,14 @@
);
INFOPLIST_FILE = SwiftGit2/Info.plist;
LIBRARY_SEARCH_PATHS = (
"External/libgit2-mac",
External/,
External,
"$(inherited)",
);
OTHER_LDFLAGS = (
"-lgit2",
"-force_load",
"External/libgit2-mac/libgit2-mac.a",
External/libssh2.a,
"-lgit2-mac",
External/libgit2.a,
/usr/local/lib/libssh2.a,
"-lcrypto",
"-lssl",
"-lcurl",
@@ -1037,7 +1036,6 @@
PRODUCT_BUNDLE_IDENTIFIER = "org.libgit2.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = SwiftGit2;
SWIFT_INCLUDE_PATHS = "$(SRCROOT)/libgit2";
VALID_ARCHS = "arm64 arm64e i386 x86_64\n";
};
name = Debug;
};
@@ -1051,15 +1049,14 @@
);
INFOPLIST_FILE = SwiftGit2/Info.plist;
LIBRARY_SEARCH_PATHS = (
"External/libgit2-mac",
External/,
External,
"$(inherited)",
);
OTHER_LDFLAGS = (
"-lgit2",
"-force_load",
"External/libgit2-mac/libgit2-mac.a",
External/libssh2.a,
"-lgit2-mac",
External/libgit2.a,
/usr/local/lib/libssh2.a,
"-lcrypto",
"-lssl",
"-lcurl",
@@ -1067,7 +1064,6 @@
PRODUCT_BUNDLE_IDENTIFIER = "org.libgit2.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = SwiftGit2;
SWIFT_INCLUDE_PATHS = "$(SRCROOT)/libgit2";
VALID_ARCHS = "arm64 arm64e i386 x86_64\n";
};
name = Release;
};
@@ -1076,7 +1072,7 @@
baseConfigurationReference = BEB31F531A0D75EE00F525B9 /* macOS-Application.xcconfig */;
buildSettings = {
INFOPLIST_FILE = SwiftGit2Tests/Info.plist;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MACOSX_DEPLOYMENT_TARGET = 10.10;
PRODUCT_BUNDLE_IDENTIFIER = "org.libgit2.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
@@ -1087,7 +1083,7 @@
baseConfigurationReference = BEB31F531A0D75EE00F525B9 /* macOS-Application.xcconfig */;
buildSettings = {
INFOPLIST_FILE = SwiftGit2Tests/Info.plist;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MACOSX_DEPLOYMENT_TARGET = 10.10;
PRODUCT_BUNDLE_IDENTIFIER = "org.libgit2.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
+19 -2
View File
@@ -22,8 +22,23 @@ public enum Credentials {
case plaintext(username: String, password: String)
case sshMemory(username: String, publicKey: String, privateKey: String, passphrase: String)
internal static func fromPointer(_ pointer: UnsafeMutableRawPointer) -> Credentials {
return Unmanaged<Wrapper<Credentials>>.fromOpaque(UnsafeRawPointer(pointer)).takeRetainedValue().value
private static var previouslyUsedPointer: String? = nil
internal static func fromPointer(_ pointer: UnsafeMutableRawPointer) -> Credentials? {
// check if we had just seen this pointer
if pointer.debugDescription == previouslyUsedPointer {
// we have already used this pointer, so it is likely that libgit2
// has already freed the memory and using Unmanaged<>.fromOpaque will
// result in a BAD_ACCESS crash
return nil
} else {
// mark that we have used this pointer so that
// later attempts to use it in this function will
// be blocked
previouslyUsedPointer = pointer.debugDescription
// access the pointer and convert it into a
// Credentials Swift object
return Unmanaged<Wrapper<Credentials>>.fromOpaque(UnsafeRawPointer(pointer)).takeRetainedValue().value
}
}
internal func toPointer() -> UnsafeMutableRawPointer {
@@ -55,6 +70,8 @@ internal func credentialsCallback(
result = git_cred_userpass_plaintext_new(cred, username, password)
case .sshMemory(let username, let publicKey, let privateKey, let passphrase):
result = git_cred_ssh_key_memory_new(cred, username, publicKey, privateKey, passphrase)
default:
result = git_cred_default_new(cred)
}
return (result != GIT_OK.rawValue) ? -1 : 0
+1 -9
View File
@@ -571,15 +571,7 @@ public final class Repository {
/// :param: branch The branch to get all commits from
/// :returns: Returns a result with array of branches or the error that occurred
public func commits(in branch: Branch) -> CommitIterator {
return commits(from: branch.oid)
}
/// Load all commits from the given base in topological & time order descending
///
/// :param: base The oid to get all commits from
/// :returns: Returns a result with array of branches or the error that occurred
public func commits(from base: OID) -> CommitIterator {
let iterator = CommitIterator(repo: self, root: base.oid)
let iterator = CommitIterator(repo: self, root: branch.oid.oid)
return iterator
}
+24 -52
View File
@@ -46,7 +46,6 @@ main ()
check_deps ()
{
echo "** check_deps **"
# Check if Homebrew is installed
which -s brew
local result=$?
@@ -57,21 +56,13 @@ check_deps ()
echo "Homebrew is not installed (http://brew.sh). You will need to manually ensure the following tools are installed:"
echo " $REQUIRED_TOOLS"
echo
echo "Additionally, the following libssh2 files must be symlinked under /usr/local or /opt/homebrew :"
echo "Additionally, the following libssh2 files must be symlinked under /usr/local:"
echo " lib/libssh2.a include/libssh2.h include/libssh2_sftp.h include/libssh2_publickey.h"
if [ ! -z "$CI" ]
then
echo
echo "I will try to install brew now on the github runner"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
exit $result
fi
# Ensure that we have libgit2's dependencies installed.
installed=$(brew list)
installed=`brew list`
for tool in $REQUIRED_TOOLS
do
@@ -80,7 +71,6 @@ check_deps ()
if [ "$code" -eq "0" ]
then
echo "*** $tool is available 👍"
continue
elif [ "$code" -ne "1" ]
then
@@ -91,45 +81,27 @@ check_deps ()
brew install "$tool"
done
brew_prefix=$(brew --prefix)
if [[ $(uname -m) == 'arm64' ]]; then
echo "** Running on a Apple Silicon M1"
expected_prefix=/opt/homebrew
else
echo "** Running on a Apple x86"
expected_prefix=/usr/local
brew_prefix=`brew --prefix`
expected_prefix=/usr/local
if [ "$brew_prefix" != "$expected_prefix" ]
then
echo "*** Adding soft links into $expected_prefix..."
products=(lib/libssh2.a include/libssh2.h include/libssh2_sftp.h include/libssh2_publickey.h)
for product in "${products[@]}"
do
destination="$expected_prefix/$product"
if [ -e "$destination" ]
then
continue
fi
sudo mkdir -p "$(dirname "$destination")"
sudo ln -s "$brew_prefix/$product" "$destination"
done
fi
install_path="./External"
pwd
set -x
cp "$brew_prefix"/lib/libcrypto.a $install_path
cp "$brew_prefix"/lib/libssl.a $install_path
cp "$brew_prefix"/lib/libssh2.a $install_path
set +x
if [ "$brew_prefix" != "$expected_prefix" ]
then
echo "*** Adding soft links into $expected_prefix..."
products=(lib/libssh2.a include/libssh2.h include/libssh2_sftp.h include/libssh2_publickey.h)
for product in "${products[@]}"
do
destination="$expected_prefix/$product"
if [ -e "$destination" ]
then
continue
fi
sudo mkdir -p "$(dirname "$destination")"
sudo ln -s "$brew_prefix/$product" "$destination"
done
fi
# openssl@1 is expected
#sslSource=$(find $brew_prefix -name libcrypto.a | grep openssl | sort | head -1 | xargs dirname)
#echo "Find libcrypto.a and take first $sslSource and copy to install_path=$install_path"
#cp $sslSource/* "$install_path" 2>/dev/null | echo "Copy and ignore subdirectory. This makes build work on x86 and arm64"
}
bootstrap_submodule ()
@@ -138,7 +110,7 @@ bootstrap_submodule ()
if [ -e "$bootstrap" ]
then
echo "*** Bootstrapping ..."
echo "*** Bootstrapping $name..."
"$bootstrap" >/dev/null
else
update_submodules
+2 -2
View File
@@ -57,7 +57,7 @@ if [ "$SCHEME" == "SwiftGit2-OSX" ]; then
xcodebuild -workspace "$XCWORKSPACE" \
-scheme "$SCHEME" \
"${XCODE_OPTIONS[*]}" \
${XCODE_OPTIONS[*]} \
build test \
2>&1 | xcpretty $XCPRETTY_FORMAT_OPTIONS
elif [ "$SCHEME" == "SwiftGit2-iOS" ]; then
@@ -80,7 +80,7 @@ elif [ "$SCHEME" == "SwiftGit2-iOS" ]; then
-scheme "$SCHEME" \
-destination "id=$DESTINATION_ID" \
-sdk iphonesimulator \
"${XCODE_OPTIONS[*]}" \
${XCODE_OPTIONS[*]} \
build test \
2>&1 | xcpretty $XCPRETTY_FORMAT_OPTIONS
fi
+7 -6
View File
@@ -9,7 +9,7 @@ function setup_build_environment ()
# e.g. via brew. Xcode's Run Script phase doesn't seem to honor
# ~/.MacOSX/environment.plist
PATH="/usr/local/bin:/opt/boxen/homebrew/bin:$PATH"
pushd "$SCRIPT_DIR/.." > /dev/null
ROOT_PATH="$PWD"
popd > /dev/null
@@ -22,7 +22,7 @@ function setup_build_environment ()
MACOSX_DEPLOYMENT_TARGET=""
XCODE_MAJOR_VERSION=$(xcode_major_version)
CAN_BUILD_64BIT="0"
# If IPHONEOS_DEPLOYMENT_TARGET has not been specified
@@ -32,7 +32,7 @@ function setup_build_environment ()
then
IPHONEOS_DEPLOYMENT_TARGET="6.0"
fi
# Determine if we can be building 64-bit binaries
if [ "${XCODE_MAJOR_VERSION}" -ge "5" ] && [ $(echo ${IPHONEOS_DEPLOYMENT_TARGET} '>=' 6.0 | bc -l) == "1" ]
then
@@ -51,7 +51,7 @@ function setup_build_environment ()
function build_all_archs ()
{
setup_build_environment
local setup=$1
local build_arch=$2
local finish_build=$3
@@ -80,8 +80,8 @@ function build_all_archs ()
fi
SDKNAME="${PLATFORM}${SDKVERSION}"
SDKROOT="$(sdk_path ${SDKNAME})"
SDKROOT="$(ios_sdk_path ${SDKNAME})"
echo "Building ${LIBRARY_NAME} for ${SDKNAME} ${ARCH}"
echo "Please stand by..."
@@ -92,3 +92,4 @@ function build_all_archs ()
# finish the build (usually lipo)
eval $finish_build
}
+22 -127
View File
@@ -5,139 +5,34 @@ set -e
# augment path to help it find cmake installed in /usr/local/bin,
# e.g. via brew. Xcode's Run Script phase doesn't seem to honor
# ~/.MacOSX/environment.plist
if [[ `uname -m` == 'arm64' ]]; then
echo "** Running on a Apple Silicon M1"
PATH="/opt/homebrew/bin:$PATH"
else
echo "** Running on a Apple x86"
PATH="/usr/local/bin:$PATH"
PATH="/usr/local/bin:$PATH"
if [ "External/libgit2.a" -nt "External/libgit2" ]
then
echo "No update needed."
exit 0
fi
SCRIPT_DIR=$(dirname "$0")
source "${SCRIPT_DIR}/xcode_functions.sh"
cd "External/libgit2"
function setup_build_environment ()
{
pushd "$SCRIPT_DIR/.." > /dev/null
ROOT_PATH="$PWD"
popd > /dev/null
CLANG="/usr/bin/xcrun clang"
CC="${CLANG}"
CPP="${CLANG} -E"
# We need to clear this so that cmake doesn't have a conniption
MACOSX_DEPLOYMENT_TARGET=""
XCODE_MAJOR_VERSION=$(xcode_major_version)
XCODE_MINOR_VERSION=$(xcode_minor_version)
CAN_BUILD_ARM="0"
# Determine if we can be building for ARM Macs
if [ "${XCODE_MAJOR_VERSION}" -ge "13" ]
then
CAN_BUILD_ARM="1"
elif [ "${XCODE_MAJOR_VERSION}" -eq "12" ] && [ "${XCODE_MINOR_VERSION}" -ge "2" ]
then
CAN_BUILD_ARM="1"
fi
ARCHS="x86_64"
if [ "${CAN_BUILD_ARM}" -eq "1" ]
then
ARCHS="${ARCHS} arm64 arm64e"
fi
}
function build_all_archs ()
{
setup_build_environment
local setup=$1
local build_arch=$2
local finish_build=$3
# run the prepare function
eval $setup
echo "Building for ${ARCHS}"
for ARCH in ${ARCHS}
do
PLATFORM="macosx"
SDKVERSION=$(macos_sdk_version)
SDKNAME="${PLATFORM}${SDKVERSION}"
SDKROOT="$(sdk_path ${SDKNAME})"
echo "Building ${LIBRARY_NAME} for ${SDKNAME} ${ARCH}"
echo "Please stand by..."
# run the per arch build command
eval $build_arch
done
# finish the build (usually lipo)
eval $finish_build
}
function setup ()
{
if [ "${ROOT_PATH}/External/libgit2-mac/libgit2-mac.a" -nt "${ROOT_PATH}/External/libgit2" ]
then
echo "No update needed."
exit 0
fi
LIBRARY_NAME="libgit2"
LIB_PATH="${ROOT_PATH}/External/libgit2-mac"
rm -rf "${LIB_PATH}"
pushd "${ROOT_PATH}/External/libgit2" > /dev/null
}
function build_libgit2 ()
{
if [ -d "build" ]; then
rm -rf "build"
mkdir "build"
fi
pushd "build" > /dev/null
mkdir build
cd build
# install the each built arch somewhere sane
INSTALL_PREFIX="${LIB_PATH}/${SDKNAME}-${ARCH}.sdk"
cmake -DBUILD_SHARED_LIBS:BOOL=OFF \
-DLIBSSH2_INCLUDE_DIRS:PATH=/usr/local/include/ \
-DBUILD_CLAR:BOOL=OFF \
-DTHREADSAFE:BOOL=ON \
..
cmake --build .
mkdir -p "${INSTALL_PREFIX}"
LOG="${INSTALL_PREFIX}/build-libgit2.log"
echo "$LOG"
MACOSX_DEPLOYMENT_TARGET="10.9" cmake \
-DBUILD_SHARED_LIBS:BOOL=OFF \
-DCMAKE_PREFIX_PATH:PATH="${ROOT_PATH}/External/libssh2-mac/bin/${SDKNAME}-${ARCH}.sdk" \
-DCMAKE_INSTALL_PREFIX:PATH="${INSTALL_PREFIX}/" \
-DBUILD_CLAR:BOOL=OFF \
-DTHREADSAFE:BOOL=ON \
-DCMAKE_OSX_ARCHITECTURES:STRING="${ARCH}" \
.. >> "${LOG}" 2>&1
cmake --build . --target install >> "${LOG}" 2>&1
# push the built library into the list
BUILT_LIB_PATHS+=("${INSTALL_PREFIX}/lib/libgit2.a")
popd > /dev/null
}
function fat_binary ()
{
echo "Building fat binary..."
lipo -create "${BUILT_LIB_PATHS[@]}" -output "${ROOT_PATH}/External/libgit2-mac/libgit2-mac.a"
echo "Building done."
popd > /dev/null
}
build_all_archs setup build_libgit2 fat_binary
product="libgit2.a"
install_path="../../${product}"
if [ "${product}" -nt "${install_path}" ]; then
cp -v "${product}" "${install_path}"
fi
echo "libgit2 has been updated."
+2 -18
View File
@@ -14,11 +14,6 @@ function xcode_major_version ()
xcode_version | awk -F '.' '{ print $1 }'
}
function xcode_minor_version ()
{
xcode_version | awk -F '.' '{ print $2 }'
}
# Returns the latest iOS SDK version available via xcodebuild.
function ios_sdk_version ()
{
@@ -31,22 +26,11 @@ function ios_sdk_version ()
# iPhoneSimulator9.0.sdk - Simulator - iOS 9.0 (iphonesimulator9.0)
# SDKVersion: 9.0
/usr/bin/xcodebuild -version -sdk 2> /dev/null | grep -A 1 '^iPhone' | tail -n 1 | awk '{ print $2 }'
}
function macos_sdk_version ()
{
# The grep command produces output like the following, singling out the
# SDKVersion of just the Mac SDKs:
#
# MacOSX11.0.sdk - macOS 11.0 (macosx11.0)
# SDKVersion: 11.0
# ...
/usr/bin/xcodebuild -version -sdk 2> /dev/null | grep -A 1 '^MacOSX' | tail -n 1 | awk '{ print $2 }'
/usr/bin/xcodebuild -version -sdk 2> /dev/null | grep -A 1 '^iPhone' | tail -n 1 | awk '{ print $2 }'
}
# Returns the path to the specified iOS SDK name
function sdk_path ()
function ios_sdk_path ()
{
/usr/bin/xcodebuild -version -sdk 2> /dev/null | grep -i $1 | grep 'Path:' | awk '{ print $2 }'
}