9

我有一个框架和一个项目,我在其中使用我的框架。我正在尝试使用在开发过程中本地构建的框架。有没有办法做类似的事情:

如果my-local-library-path存在,请执行以下操作:

pod 'MyLibraryName', :path => "my-local-library-path"

否则,请执行以下操作:

pod 'MyLibraryName', git: 'https://github.com/mygithuburl', tag: '0.0.1'
4

2 回答 2

12

由于 Podfile 实际上是 Ruby 代码,让我们检查文件是否存在:

if File.exist?("complete-path-to-a-library-file")
    pod 'MyLibraryName', :path => "my-local-library-path"
else
    pod 'MyLibraryName', git: 'https://github.com/mygithuburl', tag: '0.0.1'
end
于 2016-10-17T12:58:54.210 回答
0

我可以提供我使用了很长时间的解决方案。cocoapods 命令周围有脚本包装器,可简化在本地文件夹或远程仓库之间选择安装源。这是在 Github 上。在这里复制,但更新版本可能在 repo 中可用

#!/usr/bin/env bash

# Assume default values
# By default install pods from remote
LOCAL=0

# By default don't delete Pods folder and Podfile.lock
DELETE=0 

# By default do pod install with verbose flag and tell it to grab latest specs from the podspec repo (otherwise we can end up with different states on 
# different people's machines)
COMMAND="pod install --verbose"

# By default do not tell cocoapods to grab latest specs from the podspec repo (otherwise we can end up with different states on different people's machines)
# Designed as separate operation and disabled by default because it is rather long operation and cocoapods itself remove this command from 'pod install' by default
REPO_UPDATE=0

# By default do not show help message
SHOW_HELP=0

# Parse parameters 
while [[ $# > 0 ]]
do
key="$1"

case $key in
    -r|--remove)
    DELETE=1
    ;;
    -l|--local)
    LOCAL=1
    ;;
    -c|--command)
    COMMAND="$2"
    shift # past argument
    ;;
    -u|--update)
    REPO_UPDATE=1
    ;;
    -h|--help)
    SHOW_HELP=1
    ;;
    *)
    # unknown option
    ;;
esac
shift # past argument or value
done

if [ $SHOW_HELP != 0 ] ; then
    echo "podrun script designed as a solution to implement easy installation of pods choosing source from remote or local path."
    echo
    echo "podrun script can run pre- and post-run scripts. To run pre-run script create 'pre-run.sh' file at the same directory as podrun script. \ 
To run post-run script create 'post-run.sh' file at the same directory as podrun script. No parameters can be passed to them. \
To pass parameters you can run another script from 'pre-run.sh' and 'post-run.sh' with parameters, described in them."
    echo
    echo "Usage:"
    echo "podrun [-c cocoapods_command|-l|-r|-d|-u|-h]"
    echo
    echo "-с (--command) Specifies command to be evaluated by Cocoapods. If omitted, 'pod install --verbose' command runs by the default."
    echo
    echo "-l (--local) Makes Cocoapods to install pods from local paths. This is done by installing DC_INSTALL_LOCALLY environment variable to 'true' value.\
 To achieve using this check in podfile value of its variable. If omitted, DC_INSTALL_LOCALLY will be set to 'false' value. This means, that pods will be installed from the remote."
    echo
    echo "-r (--remove) Deletes Podfile.lock file and Pods folder from the current path. By default these files won't be deleted (if flag is omitted)."
    echo
    echo "-u (--update) Makes cocoapods to update specs repos before installing pods (this operation may be rather long)."
    echo
    echo "-h (--help) Shows help (this message)."
    exit 0
fi

# Print out parameters for debug case
echo DELETE  = "${DELETE}"
echo LOCAL   = "${LOCAL}"
echo COMMAND = "${COMMAND}"
echo REPO_UPDATE = "${REPO_UPDATE}"

# Check if we have Podfile in our working folder 
# (a kind of protection, that we won't remove unexpected Pods folder)
# If we are in the wrong folder, we'll get error later from Cocoapods nevertheless
# this is preventive
PODFILE="Podfile"
if [ -f "$PODFILE" ] ; then
    echo "$PODFILE found."
else
    echo "$PODFILE not found. It seems, that you're in a wrong directory. Aborting..."
    exit 1
fi

# Set temporary environment variable that allows us to choose podfile variant
if [ $LOCAL != 0 ] ; then
    export DC_INSTALL_LOCALLY=true
else
    export DC_INSTALL_LOCALLY=false
fi

# Delete Pods folder and Podfile.lock file, if necessary
if [ $DELETE != 0 ] ; then
    rm -rf Pods
    rm -f Podfile.lock
fi

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# Run pre-run.sh script
echo "Start pre-run script"
pushd $DIR
sh pre-run.sh
popd

# Run update of repos to grab latest specs from the podspec repo (otherwise we can end up with different states on 
# different people's machines)
if [ $REPO_UPDATE != 0 ] ; then
    pod repo update
fi

# Run command
${COMMAND}
if [ $? -ne 0 ]; then
    exit 1
fi

# Run post-run.sh script
echo "Start post-run script"
pushd $DIR
sh post-run.sh
popd

# Unset temporary environment variable that allows us to choose podfile variant
unset DC_INSTALL_LOCALLY

使用步骤:

  1. 从 Github下载脚本或克隆存储库。使用您的 podfile 将脚本添加到文件夹中或放置在其他位置并将其路径添加到您的PATH变量中。
  2. 使用以下格式编辑或创建您的 podfile:

    if "#{ENV['DC_INSTALL_LOCALLY']}" == "true"
        puts "Using local pods"
        pod "SomePod", :path => "<SomePod_local_path>"
    else
        puts "Using remote pods"
        pod 'SomePod'
    end
    
  3. 使用 podfile 文件夹打开终端并运行podrun -l以在本地安装 pod 或podrun从远程安装。

跑去podrun -h求救。

于 2018-02-19T20:27:34.810 回答