Skip to content

Commit

Permalink
[JENKINS-15902] Add option to allow build arguments to be passed to x…
Browse files Browse the repository at this point in the history
…code
  • Loading branch information
StuartWhelan committed Mar 10, 2013
1 parent 4dec9cd commit 216a1ff
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 7 deletions.
Expand Up @@ -41,6 +41,7 @@ public class ClangScanBuildBuilder extends Builder{
private String workspace;
private String scheme;
private String scanbuildargs;
private String xcodebuildargs;

@DataBoundConstructor
public ClangScanBuildBuilder(
Expand All @@ -51,7 +52,8 @@ public ClangScanBuildBuilder(
String xcodeProjectSubPath,
String workspace,
String scheme,
String scanbuildargs ){
String scanbuildargs,
String xcodebuildargs){

this.target = Util.fixEmptyAndTrim( target );
this.targetSdk = Util.fixEmptyAndTrim( targetSdk );
Expand All @@ -61,6 +63,7 @@ public ClangScanBuildBuilder(
this.workspace = Util.fixEmptyAndTrim( workspace );
this.scheme = Util.fixEmptyAndTrim( scheme );
this.scanbuildargs = Util.fixEmptyAndTrim( scanbuildargs );
this.xcodebuildargs = Util.fixEmptyAndTrim( xcodebuildargs );
}

public String getClangInstallationName(){
Expand Down Expand Up @@ -90,7 +93,11 @@ public String getScheme(){
public String getScanbuildargs(){
return scanbuildargs;
}


public String getXcodebuildargs(){
return xcodebuildargs;
}

/**
* Removing slashes here in case the user adds a starting slash to the path.
*/
Expand Down Expand Up @@ -127,6 +134,7 @@ public boolean perform( @SuppressWarnings("rawtypes") AbstractBuild build, Launc
xcodebuild.setTargetSdk( getTargetSdk() );
xcodebuild.setConfig( getConfig() );
xcodebuild.setAdditionalScanBuildArguments( getScanbuildargs() );
xcodebuild.setAdditionalXcodeBuildArguments( getXcodebuildargs() );
xcodebuild.setClangOutputFolder( new FilePath( build.getWorkspace(), ClangScanBuildUtils.REPORT_OUTPUT_FOLDERNAME) );
xcodebuild.setWorkspace( getWorkspace() );
xcodebuild.setScheme( getScheme() );
Expand Down
Expand Up @@ -16,7 +16,9 @@ public class ScanBuildCommand implements Command{
private String target;

private String additionalScanBuildArguments; // Passed directly to shell


private String additionalXcodeBuildArguments; // Passed directly to shell

private String workspace;
private String scheme;

Expand Down Expand Up @@ -75,6 +77,16 @@ public int execute( BuildContext context ) throws Exception {

args.add( "clean" ); // clang scan requires a clean
args.add( "build" );

String additionalXcodeBuildArgs = getAdditionalXcodeBuildArguments();
if( isNotBlank( additionalXcodeBuildArgs ) ){
// This is a hack. I can't call the standard ArgumentListBuilder.add() method because it checks for spaces with-in
// the arg and quotes the arg if a space exists. Since user's can pass commands like
// '--use-cc=`which clang`' or multiple commands...we cannot allow the quotes to be
// inserted when spaces exist. The ArgumentListBuilder.addTokenized() splits the arg on spaces and adds each piece
// which ends up reinserting the spaces when the command is assembled.
args.addTokenized( additionalXcodeBuildArgs );
}

int rc = context.waitForProcess( getProjectDirectory(), args );

Expand Down Expand Up @@ -174,4 +186,12 @@ public void setAdditionalScanBuildArguments(String additionalScanBuildArguments)
this.additionalScanBuildArguments = additionalScanBuildArguments;
}

public String getAdditionalXcodeBuildArguments() {
return additionalXcodeBuildArguments;
}

public void setAdditionalXcodeBuildArguments(String additionalXcodeBuildArguments) {
this.additionalXcodeBuildArguments = additionalXcodeBuildArguments;
}

}
Expand Up @@ -37,6 +37,10 @@
<f:entry title="Additional scan-build arguments" field="scanbuildargs">
<f:textbox default="" />
</f:entry>

<f:entry title="Additional xcode build arguments" field="xcodebuildargs">
<f:textbox default="" />
</f:entry>

</f:advanced>

Expand Down
@@ -0,0 +1,2 @@
This field can be used to pass additional arguments to clang scan-build. The arguments will appear after the xcodebuild sub command.
You can view the assembled command by viewing the job's build console.
Expand Up @@ -14,15 +14,15 @@ public void testRoundTripConfiguration() throws Exception{

FreeStyleProject p = createFreeStyleProject();

ClangScanBuildBuilder builderBefore = new ClangScanBuildBuilder( "target", "sdk", "config", "installName", "projPath", "workspace", "scheme", "someargs" );
ClangScanBuildBuilder builderBefore = new ClangScanBuildBuilder( "target", "sdk", "config", "installName", "projPath", "workspace", "scheme", "someargs", "somexcodeargs" );
p.getBuildersList().add( builderBefore );

HtmlForm form = createWebClient().getPage( p, "configure" ).getFormByName( "config" );
submit( form );

ClangScanBuildBuilder builderAfter = p.getBuildersList().get( ClangScanBuildBuilder.class );

assertEqualBeans( builderBefore, builderAfter, "target,config,targetSdk,xcodeProjectSubPath,workspace,scheme,scanbuildargs" );
assertEqualBeans( builderBefore, builderAfter, "target,config,targetSdk,xcodeProjectSubPath,workspace,scheme,scanbuildargs,xcodebuildargs" );
}

}
Expand Up @@ -98,8 +98,29 @@ public void xcode4WorkspaceSetWithSingleScanBuildArgument() throws Exception{
String expected = "/ScanBuild -k -v -v -o OutputFolder --use-cc=`which clang` xcodebuild -workspace myWorkspace -scheme myScheme -configuration myConfig -sdk myTargetSdk clean build";
Assert.assertEquals( expected, actual );
}

@Test

@Test
public void xcode4WorkspaceSetWithSingleXcodeBuildArgument() throws Exception{
// XCode 4 workspace/scheme should override unnecessary target
ScanBuildCommand command = new ScanBuildCommand();
command.setClangOutputFolder( new FilePath( new File( "OutputFolder" ) ) );
command.setClangScanBuildPath( "/ScanBuild" );
command.setConfig( "myConfig" );
command.setProjectDirectory( new FilePath( new File( "/ProjectDir" ) ) );
command.setScheme( "myScheme" );
command.setTarget( "myTarget" );
command.setTargetSdk( "myTargetSdk" );
command.setWorkspace( "myWorkspace" );
command.setAdditionalXcodeBuildArguments("VALID_ARCHS=i386" );

String actual = buildCommandAndReturn( command );

// Jenkins core quotes this due to the space in between 'which' and 'clang' . Not sure if this is OK or not... :(
String expected = "/ScanBuild -k -v -v -o OutputFolder xcodebuild -workspace myWorkspace -scheme myScheme -configuration myConfig -sdk myTargetSdk clean build VALID_ARCHS=i386";
Assert.assertEquals( expected, actual );
}

@Test
public void xcode4WorkspaceSetWithMultipleScanBuildArguments() throws Exception{
// XCode 4 workspace/scheme should override unnecessary target
ScanBuildCommand command = new ScanBuildCommand();
Expand All @@ -118,5 +139,26 @@ public void xcode4WorkspaceSetWithMultipleScanBuildArguments() throws Exception{
String expected = "/ScanBuild -k -v -v -o OutputFolder -h -x somevalue xcodebuild -workspace myWorkspace -scheme myScheme -configuration myConfig -sdk myTargetSdk clean build";
Assert.assertEquals( expected, actual );
}

@Test
public void xcode4WorkspaceSetWithMultipleXcodeBuildArguments() throws Exception{
// XCode 4 workspace/scheme should override unnecessary target
ScanBuildCommand command = new ScanBuildCommand();
command.setClangOutputFolder( new FilePath( new File( "OutputFolder" ) ) );
command.setClangScanBuildPath( "/ScanBuild" );
command.setConfig( "myConfig" );
command.setProjectDirectory( new FilePath( new File( "/ProjectDir" ) ) );
command.setScheme( "myScheme" );
command.setTarget( "myTarget" );
command.setTargetSdk( "myTargetSdk" );
command.setWorkspace( "myWorkspace" );
command.setAdditionalScanBuildArguments( "-h -x somevalue" );
command.setAdditionalXcodeBuildArguments("THIS=1 THAT=2");

String actual = buildCommandAndReturn( command );

String expected = "/ScanBuild -k -v -v -o OutputFolder -h -x somevalue xcodebuild -workspace myWorkspace -scheme myScheme -configuration myConfig -sdk myTargetSdk clean build THIS=1 THAT=2";
Assert.assertEquals( expected, actual );
}

}

0 comments on commit 216a1ff

Please sign in to comment.