Skip to content

Commit 42efe9a

Browse files
committedDec 10, 2024··
align with 17.12
2 parents fd29258 + e11d707 commit 42efe9a

File tree

5 files changed

+433
-0
lines changed

5 files changed

+433
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
parameters:
2+
overrideGuardianVersion: ''
3+
executeAllSdlToolsScript: ''
4+
overrideParameters: ''
5+
additionalParameters: ''
6+
publishGuardianDirectoryToPipeline: false
7+
sdlContinueOnError: false
8+
condition: ''
9+
10+
steps:
11+
- task: NuGetAuthenticate@1
12+
13+
- task: NuGetToolInstaller@1
14+
displayName: 'Install NuGet.exe'
15+
16+
- ${{ if ne(parameters.overrideGuardianVersion, '') }}:
17+
- pwsh: |
18+
Set-Location -Path $(Build.SourcesDirectory)\eng\common\sdl
19+
. .\sdl.ps1
20+
$guardianCliLocation = Install-Gdn -Path $(Build.SourcesDirectory)\.artifacts -Version ${{ parameters.overrideGuardianVersion }}
21+
Write-Host "##vso[task.setvariable variable=GuardianCliLocation]$guardianCliLocation"
22+
displayName: Install Guardian (Overridden)
23+
24+
- ${{ if eq(parameters.overrideGuardianVersion, '') }}:
25+
- pwsh: |
26+
Set-Location -Path $(Build.SourcesDirectory)\eng\common\sdl
27+
. .\sdl.ps1
28+
$guardianCliLocation = Install-Gdn -Path $(Build.SourcesDirectory)\.artifacts
29+
Write-Host "##vso[task.setvariable variable=GuardianCliLocation]$guardianCliLocation"
30+
displayName: Install Guardian
31+
32+
- ${{ if ne(parameters.overrideParameters, '') }}:
33+
- powershell: ${{ parameters.executeAllSdlToolsScript }} ${{ parameters.overrideParameters }}
34+
displayName: Execute SDL (Overridden)
35+
continueOnError: ${{ parameters.sdlContinueOnError }}
36+
condition: ${{ parameters.condition }}
37+
38+
- ${{ if eq(parameters.overrideParameters, '') }}:
39+
- powershell: ${{ parameters.executeAllSdlToolsScript }}
40+
-GuardianCliLocation $(GuardianCliLocation)
41+
-NugetPackageDirectory $(Build.SourcesDirectory)\.packages
42+
-AzureDevOpsAccessToken $(dn-bot-dotnet-build-rw-code-rw)
43+
${{ parameters.additionalParameters }}
44+
displayName: Execute SDL
45+
continueOnError: ${{ parameters.sdlContinueOnError }}
46+
condition: ${{ parameters.condition }}
47+
48+
- ${{ if ne(parameters.publishGuardianDirectoryToPipeline, 'false') }}:
49+
# We want to publish the Guardian results and configuration for easy diagnosis. However, the
50+
# '.gdn' dir is a mix of configuration, results, extracted dependencies, and Guardian default
51+
# tooling files. Some of these files are large and aren't useful during an investigation, so
52+
# exclude them by simply deleting them before publishing. (As of writing, there is no documented
53+
# way to selectively exclude a dir from the pipeline artifact publish task.)
54+
- task: DeleteFiles@1
55+
displayName: Delete Guardian dependencies to avoid uploading
56+
inputs:
57+
SourceFolder: $(Agent.BuildDirectory)/.gdn
58+
Contents: |
59+
c
60+
i
61+
condition: succeededOrFailed()
62+
63+
- publish: $(Agent.BuildDirectory)/.gdn
64+
artifact: GuardianConfiguration
65+
displayName: Publish GuardianConfiguration
66+
condition: succeededOrFailed()
67+
68+
# Publish the SARIF files in a container named CodeAnalysisLogs to enable integration
69+
# with the "SARIF SAST Scans Tab" Azure DevOps extension
70+
- task: CopyFiles@2
71+
displayName: Copy SARIF files
72+
inputs:
73+
flattenFolders: true
74+
sourceFolder: $(Agent.BuildDirectory)/.gdn/rc/
75+
contents: '**/*.sarif'
76+
targetFolder: $(Build.SourcesDirectory)/CodeAnalysisLogs
77+
condition: succeededOrFailed()
78+
79+
# Use PublishBuildArtifacts because the SARIF extension only checks this case
80+
# see microsoft/sarif-azuredevops-extension#4
81+
- task: PublishBuildArtifacts@1
82+
displayName: Publish SARIF files to CodeAnalysisLogs container
83+
inputs:
84+
pathToPublish: $(Build.SourcesDirectory)/CodeAnalysisLogs
85+
artifactName: CodeAnalysisLogs
86+
condition: succeededOrFailed()
+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
parameters:
2+
overrideGuardianVersion: ''
3+
executeAllSdlToolsScript: ''
4+
overrideParameters: ''
5+
additionalParameters: ''
6+
publishGuardianDirectoryToPipeline: false
7+
sdlContinueOnError: false
8+
condition: ''
9+
10+
steps:
11+
- task: NuGetAuthenticate@1
12+
13+
- task: NuGetToolInstaller@1
14+
displayName: 'Install NuGet.exe'
15+
16+
- ${{ if ne(parameters.overrideGuardianVersion, '') }}:
17+
- pwsh: |
18+
Set-Location -Path $(Build.SourcesDirectory)\eng\common\sdl
19+
. .\sdl.ps1
20+
$guardianCliLocation = Install-Gdn -Path $(Build.SourcesDirectory)\.artifacts -Version ${{ parameters.overrideGuardianVersion }}
21+
Write-Host "##vso[task.setvariable variable=GuardianCliLocation]$guardianCliLocation"
22+
displayName: Install Guardian (Overridden)
23+
24+
- ${{ if eq(parameters.overrideGuardianVersion, '') }}:
25+
- pwsh: |
26+
Set-Location -Path $(Build.SourcesDirectory)\eng\common\sdl
27+
. .\sdl.ps1
28+
$guardianCliLocation = Install-Gdn -Path $(Build.SourcesDirectory)\.artifacts
29+
Write-Host "##vso[task.setvariable variable=GuardianCliLocation]$guardianCliLocation"
30+
displayName: Install Guardian
31+
32+
- ${{ if ne(parameters.overrideParameters, '') }}:
33+
- powershell: ${{ parameters.executeAllSdlToolsScript }} ${{ parameters.overrideParameters }}
34+
displayName: Execute SDL (Overridden)
35+
continueOnError: ${{ parameters.sdlContinueOnError }}
36+
condition: ${{ parameters.condition }}
37+
env:
38+
GUARDIAN_DEFAULT_PACKAGE_SOURCE_SECRET: $(System.AccessToken)
39+
40+
- ${{ if eq(parameters.overrideParameters, '') }}:
41+
- powershell: ${{ parameters.executeAllSdlToolsScript }}
42+
-GuardianCliLocation $(GuardianCliLocation)
43+
-NugetPackageDirectory $(Build.SourcesDirectory)\.packages
44+
${{ parameters.additionalParameters }}
45+
displayName: Execute SDL
46+
continueOnError: ${{ parameters.sdlContinueOnError }}
47+
condition: ${{ parameters.condition }}
48+
env:
49+
GUARDIAN_DEFAULT_PACKAGE_SOURCE_SECRET: $(System.AccessToken)
50+
51+
- ${{ if ne(parameters.publishGuardianDirectoryToPipeline, 'false') }}:
52+
# We want to publish the Guardian results and configuration for easy diagnosis. However, the
53+
# '.gdn' dir is a mix of configuration, results, extracted dependencies, and Guardian default
54+
# tooling files. Some of these files are large and aren't useful during an investigation, so
55+
# exclude them by simply deleting them before publishing. (As of writing, there is no documented
56+
# way to selectively exclude a dir from the pipeline artifact publish task.)
57+
- task: DeleteFiles@1
58+
displayName: Delete Guardian dependencies to avoid uploading
59+
inputs:
60+
SourceFolder: $(Agent.BuildDirectory)/.gdn
61+
Contents: |
62+
c
63+
i
64+
condition: succeededOrFailed()
65+
66+
- publish: $(Agent.BuildDirectory)/.gdn
67+
artifact: GuardianConfiguration
68+
displayName: Publish GuardianConfiguration
69+
condition: succeededOrFailed()
70+
71+
# Publish the SARIF files in a container named CodeAnalysisLogs to enable integration
72+
# with the "SARIF SAST Scans Tab" Azure DevOps extension
73+
- task: CopyFiles@2
74+
displayName: Copy SARIF files
75+
inputs:
76+
flattenFolders: true
77+
sourceFolder: $(Agent.BuildDirectory)/.gdn/rc/
78+
contents: '**/*.sarif'
79+
targetFolder: $(Build.SourcesDirectory)/CodeAnalysisLogs
80+
condition: succeededOrFailed()
81+
82+
# Use PublishBuildArtifacts because the SARIF extension only checks this case
83+
# see microsoft/sarif-azuredevops-extension#4
84+
- task: PublishBuildArtifacts@1
85+
displayName: Publish SARIF files to CodeAnalysisLogs container
86+
inputs:
87+
pathToPublish: $(Build.SourcesDirectory)/CodeAnalysisLogs
88+
artifactName: CodeAnalysisLogs
89+
condition: succeededOrFailed()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
parameters:
2+
helixSource: 'undefined_defaulted_in_telemetry.yml'
3+
helixType: 'undefined_defaulted_in_telemetry.yml'
4+
buildConfig: ''
5+
runAsPublic: false
6+
maxRetries: 5
7+
retryDelay: 10 # in seconds
8+
9+
steps:
10+
- ${{ if and(eq(parameters.runAsPublic, 'false'), not(eq(variables['System.TeamProject'], 'public'))) }}:
11+
- task: AzureKeyVault@2
12+
inputs:
13+
azureSubscription: 'HelixProd_KeyVault'
14+
KeyVaultName: HelixProdKV
15+
SecretsFilter: 'HelixApiAccessToken'
16+
condition: always()
17+
- bash: |
18+
# create a temporary file
19+
jobInfo=`mktemp`
20+
21+
# write job info content to temporary file
22+
cat > $jobInfo <<JobListStuff
23+
{
24+
"QueueId": "$QueueId",
25+
"Source": "$Source",
26+
"Type": "$Type",
27+
"Build": "$Build",
28+
"Attempt": "$Attempt",
29+
"Properties": {
30+
"operatingSystem": "$OperatingSystem",
31+
"configuration": "$Configuration"
32+
}
33+
}
34+
JobListStuff
35+
36+
cat $jobInfo
37+
38+
# create a temporary file for curl output
39+
res=`mktemp`
40+
41+
accessTokenParameter="?access_token=$HelixApiAccessToken"
42+
43+
curlStatus=1
44+
retryCount=0
45+
# retry loop to harden against spotty telemetry connections
46+
# we don't retry successes and 4xx client errors
47+
until [[ $curlStatus -eq 0 || ( $curlStatus -ge 400 && $curlStatus -le 499 ) || $retryCount -ge $MaxRetries ]]
48+
do
49+
if [ $retryCount -gt 0 ]; then
50+
echo "Failed to send telemetry to Helix; waiting $RetryDelay seconds before retrying..."
51+
sleep $RetryDelay
52+
fi
53+
54+
curlResult=`
55+
cat $jobInfo |\
56+
curl --trace - --verbose --output $res --write-out "%{http_code}" \
57+
-H 'Content-Type: application/json' \
58+
-X POST "https://helix.dot.net/api/2018-03-14/telemetry/job$accessTokenParameter" -d @-`
59+
curlStatus=$?
60+
61+
if [ $curlStatus -eq 0 ]; then
62+
if [ $curlResult -gt 299 ] || [ $curlResult -lt 200 ]; then
63+
curlStatus=$curlResult
64+
fi
65+
fi
66+
67+
let retryCount++
68+
done
69+
70+
curlResult=`cat $res`
71+
72+
# validate status of curl command
73+
if [ $curlStatus -ne 0 ]; then
74+
echo "Failed To Send Job Start information after $retryCount retries"
75+
# We have to append the ## vso prefix or vso will pick up the command when it dumps the inline script into the shell
76+
vstsLogOutput="vso[task.logissue type=error;sourcepath=telemetry/start-job.sh;code=1;]Failed to Send Job Start information: $curlStatus"
77+
echo "##$vstsLogOutput"
78+
exit 1
79+
fi
80+
81+
# Set the Helix_JobToken variable
82+
export Helix_JobToken=`echo $curlResult | xargs echo` # Strip Quotes
83+
echo "##vso[task.setvariable variable=Helix_JobToken;issecret=true;]$Helix_JobToken"
84+
displayName: Send Unix Job Start Telemetry
85+
env:
86+
HelixApiAccessToken: $(HelixApiAccessToken)
87+
Source: ${{ parameters.helixSource }}
88+
Type: ${{ parameters.helixType }}
89+
Build: $(Build.BuildNumber)
90+
QueueId: $(Agent.Os)
91+
Attempt: 1
92+
OperatingSystem: $(Agent.Os)
93+
Configuration: ${{ parameters.buildConfig }}
94+
MaxRetries: ${{ parameters.maxRetries }}
95+
RetryDelay: ${{ parameters.retryDelay }}
96+
condition: and(always(), ne(variables['Agent.Os'], 'Windows_NT'))
97+
- bash: |
98+
curlStatus=1
99+
retryCount=0
100+
# retry loop to harden against spotty telemetry connections
101+
# we don't retry successes and 4xx client errors
102+
until [[ $curlStatus -eq 0 || ( $curlStatus -ge 400 && $curlStatus -le 499 ) || $retryCount -ge $MaxRetries ]]
103+
do
104+
if [ $retryCount -gt 0 ]; then
105+
echo "Failed to send telemetry to Helix; waiting $RetryDelay seconds before retrying..."
106+
sleep $RetryDelay
107+
fi
108+
109+
res=`mktemp`
110+
curlResult=`
111+
curl --verbose --output $res --write-out "%{http_code}"\
112+
-H 'Content-Type: application/json' \
113+
-H "X-Helix-Job-Token: $Helix_JobToken" \
114+
-H 'Content-Length: 0' \
115+
-X POST -G "https://helix.dot.net/api/2018-03-14/telemetry/job/build" \
116+
--data-urlencode "buildUri=$BuildUri"`
117+
curlStatus=$?
118+
119+
if [ $curlStatus -eq 0 ]; then
120+
if [ $curlResult -gt 299 ] || [ $curlResult -lt 200 ]; then
121+
curlStatus=$curlResult
122+
fi
123+
fi
124+
125+
curlResult=`cat $res`
126+
let retryCount++
127+
done
128+
129+
# validate status of curl command
130+
if [ $curlStatus -ne 0 ]; then
131+
echo "Failed to Send Build Start information after $retryCount retries"
132+
vstsLogOutput="vso[task.logissue type=error;sourcepath=telemetry/build/start.sh;code=1;]Failed to Send Build Start information: $curlStatus"
133+
echo "##$vstsLogOutput"
134+
exit 1
135+
fi
136+
137+
export Helix_WorkItemId=`echo $curlResult | xargs echo` # Strip Quotes
138+
echo "##vso[task.setvariable variable=Helix_WorkItemId]$Helix_WorkItemId"
139+
displayName: Send Unix Build Start Telemetry
140+
env:
141+
BuildUri: $(System.TaskDefinitionsUri)$(System.TeamProject)/_build/index?buildId=$(Build.BuildId)&_a=summary
142+
Helix_JobToken: $(Helix_JobToken)
143+
MaxRetries: ${{ parameters.maxRetries }}
144+
RetryDelay: ${{ parameters.retryDelay }}
145+
condition: and(always(), ne(variables['Agent.Os'], 'Windows_NT'))
146+
147+
- powershell: |
148+
$jobInfo = [pscustomobject]@{
149+
QueueId=$env:QueueId;
150+
Source=$env:Source;
151+
Type=$env:Type;
152+
Build=$env:Build;
153+
Attempt=$env:Attempt;
154+
Properties=[pscustomobject]@{ operatingSystem=$env:OperatingSystem; configuration=$env:Configuration };
155+
}
156+
157+
$jobInfoJson = $jobInfo | ConvertTo-Json
158+
159+
if ($env:HelixApiAccessToken) {
160+
$accessTokenParameter="?access_token=$($env:HelixApiAccessToken)"
161+
}
162+
Write-Host "Job Info: $jobInfoJson"
163+
164+
# Basic retry loop to harden against server flakiness
165+
$retryCount = 0
166+
while ($retryCount -lt $env:MaxRetries) {
167+
try {
168+
$jobToken = Invoke-RestMethod -Uri "https://helix.dot.net/api/2018-03-14/telemetry/job$($accessTokenParameter)" -Method Post -ContentType "application/json" -Body $jobInfoJson
169+
break
170+
}
171+
catch {
172+
$statusCode = $_.Exception.Response.StatusCode.value__
173+
if ($statusCode -ge 400 -and $statusCode -le 499) {
174+
Write-Host "##vso[task.logissue]error Failed to send telemetry to Helix (status code $statusCode); not retrying (4xx client error)"
175+
Write-Host "##vso[task.logissue]error ", $_.Exception.GetType().FullName, $_.Exception.Message
176+
exit 1
177+
}
178+
Write-Host "Failed to send telemetry to Helix (status code $statusCode); waiting $env:RetryDelay seconds before retrying..."
179+
$retryCount++
180+
sleep $env:RetryDelay
181+
continue
182+
}
183+
}
184+
185+
if ($retryCount -ge $env:MaxRetries) {
186+
Write-Host "##vso[task.logissue]error Failed to send telemetry to Helix after $retryCount retries."
187+
exit 1
188+
}
189+
190+
$env:Helix_JobToken = $jobToken
191+
Write-Host "##vso[task.setvariable variable=Helix_JobToken;issecret=true;]$env:Helix_JobToken"
192+
env:
193+
HelixApiAccessToken: $(HelixApiAccessToken)
194+
Source: ${{ parameters.helixSource }}
195+
Type: ${{ parameters.helixType }}
196+
Build: $(Build.BuildNumber)
197+
QueueId: $(Agent.Os)
198+
Attempt: 1
199+
OperatingSystem: $(Agent.Os)
200+
Configuration: ${{ parameters.buildConfig }}
201+
MaxRetries: ${{ parameters.maxRetries }}
202+
RetryDelay: ${{ parameters.retryDelay }}
203+
condition: and(always(), eq(variables['Agent.Os'], 'Windows_NT'))
204+
displayName: Send Windows Job Start Telemetry
205+
- powershell: |
206+
# Basic retry loop to harden against server flakiness
207+
$retryCount = 0
208+
while ($retryCount -lt $env:MaxRetries) {
209+
try {
210+
$workItemId = Invoke-RestMethod -Uri "https://helix.dot.net/api/2018-03-14/telemetry/job/build?buildUri=$([Net.WebUtility]::UrlEncode($env:BuildUri))" -Method Post -ContentType "application/json" -Body "" `
211+
-Headers @{ 'X-Helix-Job-Token'=$env:Helix_JobToken }
212+
break
213+
}
214+
catch {
215+
$statusCode = $_.Exception.Response.StatusCode.value__
216+
if ($statusCode -ge 400 -and $statusCode -le 499) {
217+
Write-Host "##vso[task.logissue]error Failed to send telemetry to Helix (status code $statusCode); not retrying (4xx client error)"
218+
Write-Host "##vso[task.logissue]error ", $_.Exception.GetType().FullName, $_.Exception.Message
219+
exit 1
220+
}
221+
Write-Host "Failed to send telemetry to Helix (status code $statusCode); waiting $env:RetryDelay seconds before retrying..."
222+
$retryCount++
223+
sleep $env:RetryDelay
224+
continue
225+
}
226+
}
227+
228+
if ($retryCount -ge $env:MaxRetries) {
229+
Write-Host "##vso[task.logissue]error Failed to send telemetry to Helix after $retryCount retries."
230+
exit 1
231+
}
232+
233+
$env:Helix_WorkItemId = $workItemId
234+
Write-Host "##vso[task.setvariable variable=Helix_WorkItemId]$env:Helix_WorkItemId"
235+
displayName: Send Windows Build Start Telemetry
236+
env:
237+
BuildUri: $(System.TaskDefinitionsUri)$(System.TeamProject)/_build/index?buildId=$(Build.BuildId)&_a=summary
238+
Helix_JobToken: $(Helix_JobToken)
239+
MaxRetries: ${{ parameters.maxRetries }}
240+
RetryDelay: ${{ parameters.retryDelay }}
241+
condition: and(always(), eq(variables['Agent.Os'], 'Windows_NT'))

‎src/Compiler/AbstractIL/ilread.fs

+1
Original file line numberDiff line numberDiff line change
@@ -2148,6 +2148,7 @@ and typeDefReader ctxtH : ILTypeDefStored =
21482148
ctxt.fileName.EndsWith("System.Runtime.dll")
21492149
|| ctxt.fileName.EndsWith("mscorlib.dll")
21502150
|| ctxt.fileName.EndsWith("netstandard.dll")
2151+
|| ctxt.fileName.EndsWith("System.Private.CoreLib.dll")
21512152

21522153
while attrIdx <= attrsEndIdx && not containsExtensionMethods do
21532154
let mutable addr = ctxt.rowAddr TableNames.CustomAttribute attrIdx

‎tests/FSharp.Compiler.Private.Scripting.UnitTests/FSharpScriptTests.fs

+16
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,22 @@ tInput.Length
352352
let value = opt.Value
353353
Assert.Equal(4L, downcast value.ReflectionValue)
354354

355+
[<FSharp.Test.FactForNETCOREAPP>] // usessdkrefs is not a valid option for desktop compiler
356+
member _.``ML - use assembly with ref dependencies and without refing SMemory``() =
357+
let code = """
358+
#r "nuget:Microsoft.ML.OnnxTransformer,1.4.0"
359+
360+
open System
361+
open System.Numerics.Tensors
362+
let inputValues = [| 12.0; 10.0; 17.0; 5.0 |]
363+
let tInput = new DenseTensor<float>(inputValues.AsMemory(), new ReadOnlySpan<int>([|4|]))
364+
tInput.Length
365+
"""
366+
use script = new FSharpScript(additionalArgs=[| "/usesdkrefs-" |])
367+
let opt = script.Eval(code) |> getValue
368+
let value = opt.Value
369+
Assert.Equal(4L, downcast value.ReflectionValue)
370+
355371
[<Fact>]
356372
member _.``System.Device.Gpio - Ensure we reference the runtime version of the assembly``() =
357373
let code = """

0 commit comments

Comments
 (0)
Please sign in to comment.