Skip to content

Commit

Permalink
Generate API review for C++ using new parser
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenkuttappan committed Jan 30, 2023
1 parent d6a2fed commit 49613a3
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 17 deletions.
19 changes: 19 additions & 0 deletions eng/pipelines/templates/jobs/archetype-sdk-client.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# cSpell:ignore vsts
# cSpell:ignore parseazuresdkcpp

parameters:
- name: Artifacts
type: object
Expand Down Expand Up @@ -84,6 +87,20 @@ jobs:

- template: /eng/common/pipelines/templates/steps/set-default-branch.yml

- task: UniversalPackages@0
displayName: Download ApiView Parser.
inputs:
command: download
vstsFeed: 'internal/AzureSDKForCpp'
vstsFeedPackage: 'parseazuresdkcpp'
downloadDirectory: '$(System.DefaultWorkingDirectory)/parser'
vstsPackageVersion: 0.6.0
condition: >-
and(
succeeded(),
ne(variables['Skip.CreateApiReview'], 'true'),eq(variables['System.TeamProject'], 'internal')
)
- task: Powershell@2
inputs:
filePath: $(System.DefaultWorkingDirectory)/eng/scripts/Create-APIReview.ps1
Expand All @@ -96,6 +113,8 @@ jobs:
-SourceBranch $(Build.SourceBranchName)
-DefaultBranch $(DefaultBranch)
-ConfigFileDir $(Build.ArtifactStagingDirectory)/PackageInfo
-ParserPath $(System.DefaultWorkingDirectory)/parser/RelWithDebInfo/ParseAzureSdkCpp.exe
-SourcePath $(Build.SourcesDirectory)/sdk/${{ parameters.ServiceDirectory }}/${{ artifact.name }}/inc
pwsh: true
workingDirectory: $(Pipeline.Workspace)
displayName: Create API Review for ${{ artifact.name }}
Expand Down
33 changes: 17 additions & 16 deletions eng/scripts/Create-APIReview.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,31 @@ Param(
[Parameter(Mandatory=$True)]
[string] $DefaultBranch,
[Parameter(Mandatory=$True)]
[string] $ConfigFileDir
[string] $ConfigFileDir,
[Parameter(Mandatory=$True)]
[string] $ParserPath,
[Parameter(Mandatory=$True)]
[string] $SourcePath
)

Write-Host "$PSScriptRoot"
. (Join-Path $PSScriptRoot .. common scripts common.ps1)
$createReviewScript = (Join-Path $PSScriptRoot .. common scripts Create-APIReview.ps1)
Set-Location $PSScriptRoot

Write-Host "Creating API review artifact for $ArtifactName"
New-Item -ItemType Directory -Path $OutPath/$ArtifactName -force
$apiviewSettings = Join-Path $SourcePath "ApiViewSettings.json"
if (!(Test-Path $apiviewSettings))
{
Write-Host "ApiViewSettings.json file is not found in $($SourcePath). APIView settings file is required to generate API review file."
exit 1
}

$gitroot = Join-Path $PSScriptRoot .. ..
Write-Host "Get-ApiViewCommandLine.ps1 $gitroot $ArtifactName"
$cmdLine = & $PSScriptRoot/Get-ApiViewCommandLine.ps1 $gitroot $ArtifactName
Write-Host "Executing clang++ command:"
Write-Host $cmdLine
$cmd, $cmdArgs = $cmdLine -split ' '
# Get-ApiViewCommandLine.ps1 returns a string representing a clang++ command that needs to be run, e.g.
# clang++ <space separated list of header files> -Xclang -ast-dump -I <space separated list of header files>
# ApiView expects a zip of this ast as the format for a C++ language artifact.
& $cmd $cmdArgs > clangAstOutput
Write-Host "Creating API review artifact for $($ArtifactName)"
New-Item -ItemType Directory -Path $OutPath/$ArtifactName -force
$parentPath = Split-Path $ParserPath -Parent
Write-Host "Contents in $($parentPath)"
Get-ChildItem -Path $parentPath -Recurse

Compress-Archive -Path clangAstOutput -DestinationPath $OutPath/$ArtifactName/$ArtifactName
Rename-Item $OutPath/$ArtifactName/$ArtifactName.zip -NewName "$ArtifactName.cppast"
& $ParserPath -o $OutPath/$ArtifactName/$ArtifactName.json $SourcePath

Write-Host "Send request to APIView to create review for $ArtifactName"
&($createReviewScript) -ArtifactPath $OutPath -APIViewUri $ApiviewUri -APIKey $ApiKey -APILabel $ApiLabel -PackageName $ArtifactName -SourceBranch $SourceBranch -DefaultBranch $DefaultBranch -ConfigFileDir $ConfigFileDir
2 changes: 1 addition & 1 deletion eng/scripts/Language-Settings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function SetPackageVersion ($PackageName, $Version, $ServiceDirectory, $ReleaseD

function Find-cpp-Artifacts-For-Apireview($ArtifactPath, $PackageName)
{
$artifact = Get-ChildItem -Path (Join-Path $ArtifactPath $PackageName) -Filter "*.cppast"
$artifact = Get-ChildItem -Path (Join-Path $ArtifactPath $PackageName) -Filter "*.json"
if ($artifact)
{
$packages = @{
Expand Down
16 changes: 16 additions & 0 deletions sdk/template/azure-template/inc/ApiViewSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"sourceFilesToProcess": null,
"sourceFilesToSkip": [
],
"additionalIncludeDirectories": [
"../../../core/azure-core/inc"
],
"additionalCompilerSwitches": [],
"allowInternal": false,
"includeDetail": false,
"includePrivate": false,
"filterNamespace": "Azure::",
"reviewName": "Azure Template API Review",
"serviceName": "Azure Template",
"packageName": "azure-template"
}

0 comments on commit 49613a3

Please sign in to comment.