Idean / sonar-swift

Open source Swift plugin for SonarQube (also supports Objective-C)
Other
896 stars 276 forks source link

[ObjectiveC] ERROR - Command oclint-json-compilation-database failed with error code: 6 #303

Closed arlovip closed 2 years ago

arlovip commented 2 years ago

New Issue Checklist

Issue Description

Run run-sonar.sh in the root directory of a new pure Objective-C project. It failed with the exit code: 6 as follows:

.....
1 error generated.
1 error generated.
1 error generated.
11 errors generated.
ERROR - Command 'oclint-json-compilation-database -v --include ../OCLintDemo/OCLintDemo -- -rc LONG_LINE=250 -max-priority-1 10000 
-max-priority-2 10000 -max-priority-3 10000 -report-type pmd -o sonar-reports/OCLintDemo-oclint.xml' 
failed with error code: 6

Note: I can run run-sonar-swift.sh successfully in a new pure Swift project and upload the result to sonar web server.

Command executed

Run command: run-sonar.sh

Complete output when running fastlane, including the stack trace and command used
 ➜  OCLintDemo ./run-sonar.sh      
Running run-sonar.sh...
-n .
-n Extracting Xcode project information
objc[61332]: Class AMSupportURLConnectionDelegate is implemented in both /usr/lib/libamsupport.dylib (0x208a17130) and /Library/Apple/System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice (0x1064482c8). One of the two will be used. Which one is undefined.
objc[61332]: Class AMSupportURLSession is implemented in both /usr/lib/libamsupport.dylib (0x208a17180) and /Library/Apple/System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice (0x106448318). One of the two will be used. Which one is undefined.

▸ Clean Succeeded
▸ Analyzing
▸ Processing Pods-OCLintDemo-Info.plist
▸ Copying Pods-OCLintDemo-umbrella.h
▸ Compiling Pods-OCLintDemo-dummy.m
▸ Compiling Pods_OCLintDemo_vers.c
▸ Touching Pods_OCLintDemo.framework (in target 'Pods-OCLintDemo' from project 'Pods')
▸ Running script '[CP] Check Pods Manifest.lock'
▸ Compiling ViewController.m

⚠️  /Users/long.chen28/Desktop/OCLintDemo/OCLintDemo/ViewController.m:21:11: performSelector may cause a leak because its selector is unknown [-Warc-performSelector-leaks]

    [self performSelector:NSSelectorFromString(@"fuck")];
          ^

⚠️  /Users/long.chen28/Desktop/OCLintDemo/OCLintDemo/ViewController.m:36:38: 'openURL:' is deprecated: first deprecated in iOS 10.0 [-Wdeprecated-declarations]

    [UIApplication.sharedApplication openURL:nil];
                          ^

⚠️  /Users/long.chen28/Desktop/OCLintDemo/OCLintDemo/ViewController.m:32:15: unused variable 'result' [-Wunused-variable]

    NSString *result;
^

⚠️  /Users/long.chen28/Desktop/OCLintDemo/OCLintDemo/ViewController.m:34:12: unused variable 'b' [-Wunused-variable]

    double b = -1;
              ^

⚠️  /Users/long.chen28/Desktop/OCLintDemo/OCLintDemo/ViewController.m:36:38: null passed to a callee that requires a non-null argument [-Wnonnull]

    [UIApplication.sharedApplication openURL:nil];
           ^

⚠️  /Users/long.chen28/Desktop/OCLintDemo/OCLintDemo/ViewController.m:67:38: 'openURL:' is deprecated: first deprecated in iOS 10.0 [-Wdeprecated-declarations]

    [UIApplication.sharedApplication openURL:nil];
                                     ^       ~~~

⚠️  /Users/long.chen28/Desktop/OCLintDemo/OCLintDemo/ViewController.m:63:15: unused variable 'result' [-Wunused-variable]

    NSString *result;
^

⚠️  /Users/long.chen28/Desktop/OCLintDemo/OCLintDemo/ViewController.m:65:12: unused variable 'b' [-Wunused-variable]

    double b = -1;
              ^

⚠️  /Users/long.chen28/Desktop/OCLintDemo/OCLintDemo/ViewController.m:67:38: null passed to a callee that requires a non-null argument [-Wnonnull]

    [UIApplication.sharedApplication openURL:nil];
           ^

⚠️  /Users/long.chen28/Desktop/OCLintDemo/OCLintDemo/ViewController.m:89:38: 'openURL:' is deprecated: first deprecated in iOS 10.0 [-Wdeprecated-declarations]

    [UIApplication.sharedApplication openURL:nil];
                                     ^       ~~~

⚠️  /Users/long.chen28/Desktop/OCLintDemo/OCLintDemo/ViewController.m:85:15: unused variable 'result' [-Wunused-variable]

    NSString *result;
^

⚠️  /Users/long.chen28/Desktop/OCLintDemo/OCLintDemo/ViewController.m:87:12: unused variable 'b' [-Wunused-variable]

    double b = -1;
              ^

⚠️  /Users/long.chen28/Desktop/OCLintDemo/OCLintDemo/ViewController.m:89:38: null passed to a callee that requires a non-null argument [-Wnonnull]

    [UIApplication.sharedApplication openURL:nil];
           ^

⚠️  /Users/long.chen28/Desktop/OCLintDemo/OCLintDemo/ViewController.m:111:38: 'openURL:' is deprecated: first deprecated in iOS 10.0 [-Wdeprecated-declarations]

    [UIApplication.sharedApplication openURL:nil];
                                     ^       ~~~

⚠️  /Users/long.chen28/Desktop/OCLintDemo/OCLintDemo/ViewController.m:107:15: unused variable 'result' [-Wunused-variable]

    NSString *result;
^

⚠️  /Users/long.chen28/Desktop/OCLintDemo/OCLintDemo/ViewController.m:109:12: unused variable 'b' [-Wunused-variable]

    double b = -1;
              ^

⚠️  /Users/long.chen28/Desktop/OCLintDemo/OCLintDemo/ViewController.m:111:38: null passed to a callee that requires a non-null argument [-Wnonnull]

    [UIApplication.sharedApplication openURL:nil];
           ^

▸ Compiling SceneDelegate.m
▸ Compiling AppDelegate.m
▸ Compiling main.m
▸ Linking OCLintDemo normal (in target 'OCLintDemo' from
▸ Compiling LaunchScreen.storyboard
▸ Compiling Main.storyboard
▸ Processing Info.plist
▸ Touching OCLintDemo.app (in target 'OCLintDemo' from project 'OCLintDemo')
▸ Build Succeeded
Skipping surefire!
-n Running OCLint...
------------------------------ OCLint ------------------------------
/opt/homebrew/bin/oclint -p /Users/long.chen28/Desktop/OCLintDemo -rc LONG_LINE=250 -max-priority-1 10000 -max-priority-2 10000 -max-priority-3 10000 -report-type pmd -o sonar-reports/OCLintDemo-oclint.xml /Users/long.chen28/Desktop/OCLintDemo/OCLintDemo/ViewController.m /Users/long.chen28/Desktop/OCLintDemo/OCLintDemo/SceneDelegate.m /Users/long.chen28/Desktop/OCLintDemo/OCLintDemo/AppDelegate.m /Users/long.chen28/Desktop/OCLintDemo/OCLintDemo/main.m
--------------------------------------------------------------------
-n .
2 errors generated.
1 error generated.
1 error generated.
1 error generated.
4 errors generated.
5 errors generated.
1 error generated.
1 error generated.
1 error generated.
11 errors generated.
2 errors generated.
1 error generated.
1 error generated.
1 error generated.
4 errors generated.
5 errors generated.
1 error generated.
1 error generated.
1 error generated.
11 errors generated.
2 errors generated.
1 error generated.
1 error generated.
1 error generated.
4 errors generated.
5 errors generated.
1 error generated.
1 error generated.
1 error generated.
11 errors generated.
2 errors generated.
1 error generated.
1 error generated.
1 error generated.
4 errors generated.
5 errors generated.
1 error generated.
1 error generated.
1 error generated.
11 errors generated.
ERROR - Command 'oclint-json-compilation-database -v --include ../OCLintDemo/OCLintDemo -- -rc LONG_LINE=250 -max-priority-1 10000 -max-priority-2 10000 -max-priority-3 10000 -report-type pmd -o sonar-reports/OCLintDemo-oclint.xml' failed with error code: 6 

Environment

 
➜  OCLintDemo sonar-scanner --version
INFO: Scanner configuration file: /opt/homebrew/Cellar/sonar-scanner/4.6.2.2472_1/libexec/conf/sonar-scanner.properties
INFO: Project root configuration file: /Users/long.chen28/Desktop/OCLintDemo/sonar-project.properties
INFO: SonarScanner 4.6.2.2472
INFO: Java 11.0.12 Homebrew (64-bit)
INFO: Mac OS X 12.0.1 aarch64

➜  OCLintDemo xcpretty --version
0.2.2
➜  OCLintDemo slather version
slather 2.7.2
➜  OCLintDemo lizard --version
1.17.9
➜  OCLintDemo oclint --version
OCLint (http://oclint.org/):
  OCLint version 20.11.
  Built Nov 14 2020 (10:19:05).
sonar-swift-0.4.6 2 sonarqube-8.9.7.52159 ### sonar-project.properties content: sonar.projectKey=OCLintDemoProjKey sonar.projectName=OCLintDemo sonar.projectVersion=1.0 sonar.projectDescription="Test oclint" sonar.sources=OCLintDemo sonar.objectivec.simulator=platform=iOS Simulator,name=iPhone 13,OS=15.2 sonar.objectivec.project=OCLintDemo.xcodeproj sonar.objectivec.workspace=OCLintDemo.xcworkspace sonar.objectivec.appScheme=OCLintDemo sonar.objectivec.appConfiguration=Debug sonar.sourceEncoding=UTF-8 sonar.language=objc sonar.objectivec.tailor.config=--no-color --max-line-length=100 --max-file-length=500 --max-name-length=40 --max-name-length=40 --min-name-length=4 sonar.host.url=http://localhost:9000 sonar.login=dbe0f3944f65563094e86a81bf041a4edfbee873

It seems that oclint-json-compilation-database -v --include ... in run-sonar.sh script failed with error code: 6. Besides, it ran successfully if I replace the script content in run-sonar.sh with the following and there is nothing under sonar-reports dir:

### run-sonar.sh ####
#!/bin/bash

PROJECT_NAME="OCLintDemo.xcworkspace"
TARGET_NAME="OCLintDemo"

TEST_TARGET_NAME="OCLintDemoTests"
UITEST_TARGET_NAME="OCLintDemoUITests"

rm -rf sonar-reports

mkdir sonar-reports

rm -rf ./build/derivedData

xcodebuild clean -UseModernBuildSystem=NO

xcodebuild -workspace ${PROJECT_NAME} -scheme ${TARGET_NAME} -UseModernBuildSystem=NO -derivedDataPath ./build/derivedData -configuration Debug COMPILER_INDEX_STORE_ENABLE=NO | xcpretty -r json-compilation-database -o compile_commands.json

oclint-json-compilation-database -e Pods -- -report-type html -o oclintReport.html
oclint-json-compilation-database -e Pods -- -report-type pmd -o sonar-reports/oclint.xml \
-max-priority-1=9999 \
-max-priority-2=9999 \
-max-priority-3=9999 \

xcodebuild -workspace ${PROJECT_NAME} -scheme ${TEST_TARGET_NAME} -configuration Debug -enableCodeCoverage YES -destination 'platform=iOS Simulator,name=iPhone 13' test
slather coverage -x --output-directory sonar-reports --scheme ${TARGET_NAME} --workspace ${PROJECT_NAME} OCLintDemo.xcodeproj

mv sonar-reports/cobertura.xml sonar-reports/coverage.xml

/bin/sh sonar-scanner -X

My questions:

How to fix the error above? It does not seem to be OCLint's problem but the run-sonar.sh provided by sonar-swift.

How do I use sonar-swift in a mixed project with both Swift and Objective-C?

When I added an OC file to a pure Swift project, the run-sonar-swift.sh won't work as expected. From now on, I just get it work in a pure Swift project. But I'd like to have it work in a mixed objc and swift project.

Any help will be appreciated so much.

arlovip commented 2 years ago

The fact that it's a OCLint version problem. I'm using Xcode 13.2.1, but my OCLint version is 20.01. So I have to upgrade OCLint version to 22.02 compatible for Xcode version. Sorry for this issue. It's not sonar-swift problem. Thanks for this free plugin. Closing the issue.