@@ -73,24 +73,37 @@ mkdir -p "$DOCBUILD_DIR"
7373
7474# Build documentation using xcodebuild docbuild
7575echo " Building documentation with xcodebuild..."
76- # First, generate an Xcode project if it doesn't exist
77- if [ ! -f " $REPO_ROOT /${PACKAGE_NAME} .xcodeproj/project.pbxproj" ]; then
78- echo " Generating Xcode project..."
79- cd " $REPO_ROOT "
76+ cd " $REPO_ROOT "
77+
78+ # Resolve package dependencies first
79+ swift package resolve
80+
81+ # Try to build documentation - for Swift packages, we need to open it as a package
82+ # First try with an Xcode project if it exists
83+ if [ -f " ${PACKAGE_NAME} .xcodeproj/project.pbxproj" ]; then
84+ echo " Using existing Xcode project..."
85+ BUILD_CMD=" xcodebuild docbuild -scheme ${PACKAGE_NAME} -derivedDataPath ${DOCBUILD_DIR} -destination 'generic/platform=macOS'"
86+ elif [ -f " ${PACKAGE_NAME} .xcworkspace/contents.xcworkspacedata" ]; then
87+ echo " Using existing Xcode workspace..."
88+ BUILD_CMD=" xcodebuild docbuild -workspace ${PACKAGE_NAME} .xcworkspace -scheme ${PACKAGE_NAME} -derivedDataPath ${DOCBUILD_DIR} -destination 'generic/platform=macOS'"
89+ else
90+ echo " No Xcode project found, generating one..."
91+ # Try to generate Xcode project (may not be available in newer Swift versions)
8092 swift package generate-xcodeproj 2> /dev/null || {
81- echo " Note: generate-xcodeproj may not be available, trying direct build ..."
93+ echo " Note: generate-xcodeproj not available, will try opening package directly ..."
8294 }
95+
96+ if [ -f " ${PACKAGE_NAME} .xcodeproj/project.pbxproj" ]; then
97+ BUILD_CMD=" xcodebuild docbuild -scheme ${PACKAGE_NAME} -derivedDataPath ${DOCBUILD_DIR} -destination 'generic/platform=macOS'"
98+ else
99+ # Last resort: try opening the package directory as a project
100+ echo " Attempting to build documentation directly from package..."
101+ BUILD_CMD=" xcodebuild -resolvePackageDependencies -packagePath ${REPO_ROOT} && xcodebuild docbuild -packagePath ${REPO_ROOT} -derivedDataPath ${DOCBUILD_DIR} -destination 'generic/platform=macOS'"
102+ fi
83103fi
84104
85- # Build documentation - try with scheme first, then with package
86- if xcodebuild docbuild \
87- -scheme " $PACKAGE_NAME " \
88- -derivedDataPath " $DOCBUILD_DIR " \
89- -destination ' generic/platform=macOS' 2>&1 || \
90- xcodebuild docbuild \
91- -packagePath " $REPO_ROOT " \
92- -derivedDataPath " $DOCBUILD_DIR " \
93- -destination ' generic/platform=macOS' 2>&1 ; then
105+ # Execute the build command
106+ if eval " $BUILD_CMD " 2>&1 ; then
94107 echo -e " ${GREEN} DocC documentation built successfully${NC} "
95108
96109 # Find the .doccarchive
0 commit comments