SourceKitten icon indicating copy to clipboard operation
SourceKitten copied to clipboard

Error when trying to generate for a unit test module

Open DerSeegler opened this issue 4 years ago • 8 comments

I'm trying to generate the documentation for our unit test module, and I am getting an error. It worked for the main module though, and it also worked for the tests a couple of years ago, so not sure what's changed.

My command is: sourcekitten doc --module-name [ProjectName]Test -- -workspace [ProjectName].xcworkspace -scheme "[ProjectName] Dev" clean build > swiftDoc.json

And I get the following error:

Could not parse compiler arguments from `xcodebuild` output.
Please confirm that `xcodebuild` is building a Swift module.
Saved `xcodebuild` log file: /var/folders/8w/w7k_803179l5pbqzm47mxx4c0000gn/T/xcodebuild-2EEBEE83-7072-42FB-A8C6-5688FF202D93.log
Error: Failed to generate documentation

But the xcodebuild log shows "** BUILD SUCCEEDED **" as the last line.

Sourcekitten version: 0.31.1 Xcode version 13.0

DerSeegler avatar Oct 18 '21 16:10 DerSeegler

You should check the rest of the log file: sourcekitten is saying that it doesn't contain a swiftc command to build the module [ProjectName]Test.

johnfairh avatar Oct 19 '21 07:10 johnfairh

First of all thanks for your quick answer, and sorry for my late response.

You are totally right. The command I posted doesn't build the test module. So I adapted the command to the following: sourcekitten doc --module-name [ProjectName]Test -- -workspace [ProjectName].xcworkspace -scheme "[ProjectName] Dev" -destination id=F1BC1B0A-E7DE-4FF2-89C5-F0590305FAB8 clean test > swiftDoc.json

The log now ends with:

Result bundle written to path:

/Users/[user]/Library/Developer/Xcode/DerivedData/[ProjectName]-gndxzgdzvemytffwnupttgzjqyjm/Logs/Test/Run-[ProjectName] Dev-2021.11.01_2-19-04-+0100.xcresult

** BUILD SUCCEEDED **

Testing started

But Sourcekitten still says the same error.

DerSeegler avatar Nov 01 '21 14:11 DerSeegler

The build command sourcekitten is looking for starts with /usr/bin/swiftc and contains the flag -module-name [ProjectName]Test. Maybe check through the log and see what modules are being built?

johnfairh avatar Nov 01 '21 18:11 johnfairh

Yes it contains it:

CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler (in target '[ProjectName]Tests' from project '[ProjectName]')
    cd /Users/[UserName]/[ProjectName]/src
    export DEVELOPER_DIR\=/Applications/Xcode.app/Contents/Developer
    export SDKROOT\=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.0.sdk
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -incremental -module-name [ProjectName]Tests
[...]

DerSeegler avatar Nov 05 '21 12:11 DerSeegler

That says [ProjectName]Tests but your CLI command says [ProjectName]Test (without the 's').

Is the typo in this GitHub issue or the actual problem? I'm only grasping at this nitpicky straw because it's the only thing I can think of -- this works elsewhere for loads of users!

johnfairh avatar Nov 05 '21 12:11 johnfairh

Wow great find. That was indeed the problem. Now it runs through without errors, but the resulting json only contains [].

DerSeegler avatar Nov 09 '21 14:11 DerSeegler

If that keeps happening after clearing up .build, build, and DerivedData for the project then I think that's as far as we can take it without a recreating project.

This works for me on a rare Xcode-test-setup project I have:

; sourcekitten doc --module-name TMLPersistentContainerTests -- clean build-for-testing -scheme TMLPersistentContainer-macOS > test.json
--- xcodebuild: WARNING: Using the first of multiple matching destinations:
{ platform:macOS, arch:x86_64, id:E26C7320-8430-5C92-B867-3503C5EE80F5 }
{ platform:macOS, name:Any Mac }
--- xcodebuild: WARNING: Using the first of multiple matching destinations:
{ platform:macOS, arch:x86_64, id:E26C7320-8430-5C92-B867-3503C5EE80F5 }
{ platform:macOS, name:Any Mac }
Running xcodebuild
Parsing MultiItem1_1+CoreDataClass.swift (1/35)
Parsing MultiItem1_1+CoreDataProperties.swift (2/35)
Parsing MultiItem2_1+CoreDataClass.swift (3/35)
Parsing MultiItem2_1+CoreDataProperties.swift (4/35)
[...]
Parsing TestSimpleMigrate.swift (35/35)
; wc -l test.json
   13775 test.json

johnfairh avatar Nov 10 '21 17:11 johnfairh

Hm, maybe it has something to do with the fact, that I am using an old version, because the new version enforces that signing is disabled, which makes my build fail:

: no identity found
: no identity found
: no identity found
: no identity found
: no identity found
Command PhaseScriptExecution failed with a nonzero exit code

** TEST BUILD FAILED **

DerSeegler avatar Nov 11 '21 09:11 DerSeegler