realm / jazzy

Soulful docs for Swift & Objective-C
https://realm.io
MIT License
7.35k stars 413 forks source link

Is it possible to run jazzy as a phase of XCode Build Phases? #1387

Closed satroschenko closed 6 months ago

satroschenko commented 6 months ago

If I add a new Run script phase in XCode to run jazzy I get an error:

error: unable to attach DB: error: accessing build database ".../Build/Intermediates.noindex/XCBuildData/build.db": database is locked Possibly there are two concurrent builds running in the same filesystem location.

Is it possible to run jazzy in this way?

johnfairh commented 6 months ago

Well, jazzy does run xcodebuild under the covers to figure out what to document so I guess I can understand where the Xcode error message here is coming from.

You could maybe explore having jazzy use a different DerivedData directory than your main build with --build-tool-arguments and -derivedDataPath but it's kind of a shame to build it again; or try using jazzy in symbol graph mode against your swiftmodule?

satroschenko commented 6 months ago

Thanks a lot. Yes, the first variant with different DerivedData works with some improvements. Initially I added new Build Phase. It runs jazzy. Jazzy run new build. New build runs jazzy again and I had infinite recursion.

Had to add some checking for it.

As result I have following script:

#!/bin/bash

# Check is jazzy already running to remove recursion.
if [ -z $(printenv SKIP_JAZZY) ]; then
    echo "jazzy starts..."
else
    echo "Jazzy is already running. Skip this step."
    exit 0
fi

export SKIP_JAZZY=1

TEMP_DERIVED_DIR=$(mktemp -d)
# Clean temp dir when script exits.
trap "rm -rf $TEMP_DERIVED_DIR" EXIT

jazzy --xcodebuild-arguments -derivedDataPath,$TEMP_DERIVED_DIR
johnfairh commented 6 months ago

infinite recursion

Oh haha, should have seen that coming! Glad you got it working.