如何使用Xcode自动构建iPhone应用程序的源代码分发?

时间:2023-01-13 00:01:42

I am looking to distribute an open source iPhone app and I have a few questions about making the source distribution:

我希望分发一个开源的iPhone应用程序,我有一些关于进行源代码分发的问题:

  1. How can I automate creating the source archive (or diskimage) with XCode? I want something along the lines of a build target which archives the source (cleaning targets first if necessary, but it would be nice if it didn't have to). I also have an external netbeans project with a ruby script that is used to build an SQL database that the program needs (but can make a separate archive of that if necessary).

    如何使用XCode自动创建源存档(或diskimage)?我想要一些构建目标的东西,这些目标存档源(如果需要,首先清理目标,但如果没有必要的话,它会很好)。我还有一个带有ruby脚本的外部netbeans项目,该脚本用于构建程序需要的SQL数据库(但如果需要可以单独存档)。

  2. What's the best way to identify the files that constitute the 'source'? Is it simply anything that's left after cleaning all targets? Any caveats with that approach (I don't quite trust IDEs to clean up all the cruft they seem to make - also is this liable to include any codesigning stuff that it shouldn't)?

    识别构成“来源”的文件的最佳方法是什么?它只是清洁所有目标后留下的任何东西吗?有这种方法的任何警告(我不太相信IDE可以清理他们似乎所做的所有瑕疵 - 这也可能包括任何不应该签署的代码签名的东西)?

4 个解决方案

#1


4  

You can add a Run Script Build Phase to any target to do postprocessing of the build. The right approach is usually to create an Aggregate Target that first builds your build product target, then runs the script on the output.

您可以将Run Script Build Phase添加到任何目标以进行构建的后处理。正确的方法通常是创建聚合目标,首先构建构建产品目标,然后在输出上运行脚本。

It's hard to identify all the "source" files. It's often everything in $(SRCROOT) but if your project is laid out in the Root -> ( src ) ( projfiles ) manner, the $(SRCROOT) will only contain your project file and not any sources. You may have to encode the knowledge of at least the top-level project layout into the script, and maintain it if it changes.

很难识别所有“源”文件。它通常是$(SRCROOT)中的所有内容,但如果您的项目以Root - >(src)(projfiles)方式布局,则$(SRCROOT)将仅包含您的项目文件而不包含任何源。您可能必须将至少*项目布局的知识编码到脚本中,并在其更改时进行维护。

Even though it's the default, you probably don't want to place your build folder in the project folder if you're going to archive the sources, because you'll often grab the intermediates, project index, and other ephemera. In your Project's Get Info inspector, General pane, set the Build Products and Intermediates directory to some common location outside the project directory. That will simplify the job of archiving your sources.

即使它是默认设置,如果您要归档源代码,也可能不希望将构建文件夹放在项目文件夹中,因为您经常会获取中间件,项目索引和其他ephemera。在项目的“获取信息”检查器的“常规”窗格中,将“构建产品和中间体”目录设置为项目目录外的某个公共位置。这将简化归档源的工作。

And Xcode has a built-in archiving mechanism, called Snapshots; you might want to use that, though it's not straightforward to automate. But Snapshots does know all about all your sources.

Xcode有一个内置的归档机制,称为快照;您可能想要使用它,尽管自动化并不简单。但是Snapshots确实了解了所有来源。

#2


3  

Set the SRCROOT environment variable to the location that you want the source archived, cd to the project directory, and execute

将SRCROOT环境变量设置为您希望源存档的位置,cd到项目目录,然后执行

xcodebuild installsrc build -configuration <configname> -target <targetname>

The "installsrc" build action copies the project source to ${SRCROOT}.

“installsrc”构建操作将项目源复制到$ {SRCROOT}。

#3


0  

Well, I've had no answers on this so far so I'm going to approach it from the other direction, using make and the command line. I'm going to use the answer to this question:

好吧,到目前为止我还没有答案,所以我将使用make和命令行从另一个方向接近它。我将使用这个问题的答案:

Building Qt Xcode Projects From the Command Line

从命令行构建Qt Xcode项目

...and then use a standard 'make' approach to build the app and the source distribution archive.

...然后使用标准的“make”方法来构建应用程序和源代码分发存档。

#4


0  

Try an aggregate target as suggested calling the following script:

根据建议调用以下脚本尝试聚合目标:

#!/bin/bash -x

cd "$BUILT_PRODUCTS_DIR"

APPFILE="$PROJECT_NAME.app"

IPAFILE="$PROJECT_NAME.ipa"

if [ "$BUILD_STYLE" = "Distribution" ]; then

if [“$ BUILD_STYLE”=“发布”];然后

rm -f "$APPFILE.zip" && zip -ry "$APPFILE.zip" "$APPFILE" && open .

elif [ "$BUILD_STYLE" = "BetaTesting" ]; then

elif [“$ BUILD_STYLE”=“BetaTesting”];然后

rm -rf "$IPAFILE" iTunesArtwork Payload && \
cp ../../Apple/iTunesArtwork . && \
mkdir Payload && cp -Rp "$APPFILE" Payload && \
zip -r "$IPAFILE" iTunesArtwork Payload && open .

fi

Err, perhaps this is the answer to a different question though...

呃,也许这是一个不同问题的答案,但......

#1


4  

You can add a Run Script Build Phase to any target to do postprocessing of the build. The right approach is usually to create an Aggregate Target that first builds your build product target, then runs the script on the output.

您可以将Run Script Build Phase添加到任何目标以进行构建的后处理。正确的方法通常是创建聚合目标,首先构建构建产品目标,然后在输出上运行脚本。

It's hard to identify all the "source" files. It's often everything in $(SRCROOT) but if your project is laid out in the Root -> ( src ) ( projfiles ) manner, the $(SRCROOT) will only contain your project file and not any sources. You may have to encode the knowledge of at least the top-level project layout into the script, and maintain it if it changes.

很难识别所有“源”文件。它通常是$(SRCROOT)中的所有内容,但如果您的项目以Root - >(src)(projfiles)方式布局,则$(SRCROOT)将仅包含您的项目文件而不包含任何源。您可能必须将至少*项目布局的知识编码到脚本中,并在其更改时进行维护。

Even though it's the default, you probably don't want to place your build folder in the project folder if you're going to archive the sources, because you'll often grab the intermediates, project index, and other ephemera. In your Project's Get Info inspector, General pane, set the Build Products and Intermediates directory to some common location outside the project directory. That will simplify the job of archiving your sources.

即使它是默认设置,如果您要归档源代码,也可能不希望将构建文件夹放在项目文件夹中,因为您经常会获取中间件,项目索引和其他ephemera。在项目的“获取信息”检查器的“常规”窗格中,将“构建产品和中间体”目录设置为项目目录外的某个公共位置。这将简化归档源的工作。

And Xcode has a built-in archiving mechanism, called Snapshots; you might want to use that, though it's not straightforward to automate. But Snapshots does know all about all your sources.

Xcode有一个内置的归档机制,称为快照;您可能想要使用它,尽管自动化并不简单。但是Snapshots确实了解了所有来源。

#2


3  

Set the SRCROOT environment variable to the location that you want the source archived, cd to the project directory, and execute

将SRCROOT环境变量设置为您希望源存档的位置,cd到项目目录,然后执行

xcodebuild installsrc build -configuration <configname> -target <targetname>

The "installsrc" build action copies the project source to ${SRCROOT}.

“installsrc”构建操作将项目源复制到$ {SRCROOT}。

#3


0  

Well, I've had no answers on this so far so I'm going to approach it from the other direction, using make and the command line. I'm going to use the answer to this question:

好吧,到目前为止我还没有答案,所以我将使用make和命令行从另一个方向接近它。我将使用这个问题的答案:

Building Qt Xcode Projects From the Command Line

从命令行构建Qt Xcode项目

...and then use a standard 'make' approach to build the app and the source distribution archive.

...然后使用标准的“make”方法来构建应用程序和源代码分发存档。

#4


0  

Try an aggregate target as suggested calling the following script:

根据建议调用以下脚本尝试聚合目标:

#!/bin/bash -x

cd "$BUILT_PRODUCTS_DIR"

APPFILE="$PROJECT_NAME.app"

IPAFILE="$PROJECT_NAME.ipa"

if [ "$BUILD_STYLE" = "Distribution" ]; then

if [“$ BUILD_STYLE”=“发布”];然后

rm -f "$APPFILE.zip" && zip -ry "$APPFILE.zip" "$APPFILE" && open .

elif [ "$BUILD_STYLE" = "BetaTesting" ]; then

elif [“$ BUILD_STYLE”=“BetaTesting”];然后

rm -rf "$IPAFILE" iTunesArtwork Payload && \
cp ../../Apple/iTunesArtwork . && \
mkdir Payload && cp -Rp "$APPFILE" Payload && \
zip -r "$IPAFILE" iTunesArtwork Payload && open .

fi

Err, perhaps this is the answer to a different question though...

呃,也许这是一个不同问题的答案,但......