diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 251b9360..2e43134d 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -68,27 +68,9 @@ jobs: else { # build NOT from PR - Write-Host "Build NOT from PR, commit ID: $env:Build_SourceVersion" - - # get PR associated with commit - $prUrl = "https://api.github.com/repos/$env:Build_Repository_Name/commits/$env:Build_SourceVersion/pulls" - $commit = Invoke-RestMethod -Uri $prUrl -ContentType "application/json" -Headers @{"Accept"="application/vnd.github.groot-preview+json"} -Method GET - - if($commit -ne $null) - { - # there is a PR, check labels - $updateDependents = $commit.labels | where {$_.Name -eq 'CI: Update Dependents'} - if($updateDependents -ne $null) - { - $update = $true - } - } + Write-Host "Build NOT from PR, commit ID: $env:Build_SourceVersion" } - } - - # set variable to foward to jobs - echo "##vso[task.setvariable variable=RUN_UPDATE_DEPENDENTS;isOutput=true]$update" - + } name: BuildOptions displayName: Evaluate build options @@ -187,8 +169,6 @@ jobs: value: 'Release' - name: solution value: 'nanoFirmwareFlasher.sln' - - name: run_update_dependents - value: $[dependencies.Check_Build_Options.outputs['BuildOptions.RUN_UPDATE_DEPENDENTS']] steps: @@ -473,21 +453,6 @@ jobs: { "label" : "Type: documentation", "displayName" : "Documentation", "state" : "closed" } ] - # update dependents - - task: PowerShell@2 - condition: >- - or( - eq(variables['System.PullRequest.PullRequestId'], ''), - eq(variables['UPDATE_DEPENDENTS'], 'true'), - eq(variables['run_update_dependents'], 'true') - ) - displayName: Update dependent tools - inputs: - targetType: filePath - filePath: azure-pipelines/update-dependents.ps1 - env: - GH_TOKEN: $(GitHubToken) - ################################## # report build failure to Discord - job: Report_Build_Failure diff --git a/azure-pipelines/update-dependents.ps1 b/azure-pipelines/update-dependents.ps1 deleted file mode 100644 index 399db064..00000000 --- a/azure-pipelines/update-dependents.ps1 +++ /dev/null @@ -1,118 +0,0 @@ -"Updating dependency at nf-VS Code Extension" | Write-Host - -# compute authorization header in format "AUTHORIZATION: basic 'encoded token'" -# 'encoded token' is the Base64 of the string "nfbot:personal-token" -$auth = "basic $([System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("nfbot:$env:GH_TOKEN")))" - -# init/reset these -$commitMessage = "" -$prTitle = "" -$newBranchName = "develop-nfbot/update-dependencies/" + [guid]::NewGuid().ToString() -$packageTargetVersion = gh release view --json tagName --jq .tagName - -# working directory is agent temp directory -Write-Debug "Changing working directory to $env:Agent_TempDirectory" -Set-Location "$env:Agent_TempDirectory" | Out-Null - -$repoName = 'nf-VSCodeExtension' - -# clone repo and checkout main branch -Write-Debug "Init and featch $repoName repo" - -git clone --recurse-submodules --depth 1 https://github.com/nanoframework/$repoName repo -Set-Location repo | Out-Null -git config --global gc.auto 0 -git config --global user.name nfbot -git config --global user.email nanoframework@outlook.com -git config --global core.autocrlf true - -Write-Host "Checkout main branch..." -git checkout --quiet main | Out-Null - -#################### -# VS Code extension - -Write-Host "Updating nanoFramework.Tools.FirmwareFlasher version in VS Code extension..." - -Set-Location nanoFirmwareFlasher | Out-Null - -git checkout --quiet tags/$packageTargetVersion - -Set-Location .. | Out-Null - -##################### - -"Bumping nanoFramework.Tools.FirmwareFlasher to $packageTargetVersion." | Write-Host -ForegroundColor Cyan - -# build commit message -$commitMessage += "Bumps nanoFramework.Tools.FirmwareFlasher to $packageTargetVersion.`n" -# build PR title -$prTitle = "Bumps nanoFramework.Tools.FirmwareFlasher to $packageTargetVersion" - -# need this line so nfbot flags the PR appropriately -$commitMessage += "`n[version update]`n`n" - -# better add this warning line -$commitMessage += "### :warning: This is an automated update. Merge only after all tests pass. :warning:`n" - -# check if anything was changed -$repoStatus = "$(git status --short --porcelain)" - -if ($repoStatus -ne "") -{ - Write-Debug "Git branch" - - # create branch to perform updates - git branch $newBranchName - - Write-Debug "Checkout branch" - - # checkout branch - git checkout $newBranchName - - Write-Debug "Add changes" - - # commit changes - git add -A > $null - - Write-Debug "Commit changed files" - - git commit -m "$prTitle ***NO_CI***" -m "$commitMessage" > $null - - Write-Debug "Push changes" - - git -c http.extraheader="AUTHORIZATION: $auth" push --set-upstream origin $newBranchName > $null - - # start PR - # we are hardcoding to 'main' branch to have a fixed one - # this is very important for tags (which don't have branch information) - # considering that the base branch can be changed at the PR there is no big deal about this - $prRequestBody = @{title="$prTitle";body="$commitMessage";head="$newBranchName";base="main"} | ConvertTo-Json - $githubApiEndpoint = "https://api.github.com/repos/nanoframework/$repoName/pulls" - [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 - - $headers = @{} - $headers.Add("Authorization","$auth") - $headers.Add("Accept","application/vnd.github.symmetra-preview+json") - - try - { - $result = Invoke-RestMethod -Method Post -UserAgent [Microsoft.PowerShell.Commands.PSUserAgent]::InternetExplorer -Uri $githubApiEndpoint -Header $headers -ContentType "application/json" -Body $prRequestBody - 'Started PR with dependencies update...' | Write-Host -NoNewline - 'OK' | Write-Host -ForegroundColor Green - } - catch - { - $result = $_.Exception.Response.GetResponseStream() - $reader = New-Object System.IO.StreamReader($result) - $reader.BaseStream.Position = 0 - $reader.DiscardBufferedData() - $responseBody = $reader.ReadToEnd(); - - throw "Error creating PR: $responseBody" - } -} -else -{ - Write-Host "Nothing udpate at $repoName." -} diff --git a/lib/jlink/JLink.exe b/lib/jlink/JLink.exe index 52c8bc62..dc9818c4 100644 Binary files a/lib/jlink/JLink.exe and b/lib/jlink/JLink.exe differ diff --git a/lib/jlink/JLink_x64.dll b/lib/jlink/JLink_x64.dll index 86dd9267..4d10117f 100644 Binary files a/lib/jlink/JLink_x64.dll and b/lib/jlink/JLink_x64.dll differ diff --git a/lib/jlinkLinux/JLinkExe b/lib/jlinkLinux/JLinkExe index 3193251e..bf282d19 100644 Binary files a/lib/jlinkLinux/JLinkExe and b/lib/jlinkLinux/JLinkExe differ diff --git a/lib/jlinkMac/JLinkExe b/lib/jlinkMac/JLinkExe index 73d05920..1f74da2e 100644 Binary files a/lib/jlinkMac/JLinkExe and b/lib/jlinkMac/JLinkExe differ diff --git a/nanoFirmwareFlasher.Library/JLinkCli.cs b/nanoFirmwareFlasher.Library/JLinkCli.cs index c483d13d..d2453f85 100644 --- a/nanoFirmwareFlasher.Library/JLinkCli.cs +++ b/nanoFirmwareFlasher.Library/JLinkCli.cs @@ -136,10 +136,13 @@ public ExitCodes ExecuteFlashBinFiles( IList addresses, string probeId) { - // check file existence - if (files.Any(f => !File.Exists(f))) + List shadowFiles = []; + + var processFileResult = ProcessFilePaths(files, shadowFiles); + + if (processFileResult != ExitCodes.OK) { - return ExitCodes.E5004; + return processFileResult; } // perform check on address(es) @@ -179,10 +182,6 @@ public ExitCodes ExecuteFlashBinFiles( } } - List shadowFiles = []; - - ProcessFilePaths(files, shadowFiles); - // erase flash if (DoMassErase) { @@ -281,42 +280,20 @@ public ExitCodes ExecuteFlashBinFiles( Console.ForegroundColor = ConsoleColor.White; - return ExitCodes.OK; - } - - private void ProcessFilePaths(IList files, List shadowFiles) - { - // J-Link can't handle diacritc chars - // developer note: reported to Segger (Case: 60276735) and can be removed if this is fixed/improved - foreach (string binFile in files) + // be nice and clean up shadow files + try { - // make sure path is absolute - var binFilePath = Utilities.MakePathAbsolute( - Environment.CurrentDirectory, - binFile); - - if (!binFilePath.IsNormalized(NormalizationForm.FormD) - || binFilePath.Contains(' ')) + foreach (string shadowFile in shadowFiles) { - var tempFile = Path.Combine( - Environment.GetEnvironmentVariable("TEMP", EnvironmentVariableTarget.Machine), - Path.GetFileName(binFilePath)); - - // copy file to shadow file - File.Copy( - binFilePath, - tempFile, - true); - - shadowFiles.Add(tempFile); - } - else - { - // copy file to shadow list - shadowFiles.Add(binFile); + File.Delete(shadowFile); } - } + catch (Exception) + { + // ignore any exception here + } + + return ExitCodes.OK; } /// @@ -329,15 +306,14 @@ public ExitCodes ExecuteFlashHexFiles( IList files, string probeId) { - // check file existence - if (files.Any(f => !File.Exists(f))) - { - return ExitCodes.E5004; - } - List shadowFiles = []; - ProcessFilePaths(files, shadowFiles); + var processFileResult = ProcessFilePaths(files, shadowFiles); + + if (processFileResult != ExitCodes.OK) + { + return processFileResult; + } // erase flash if (DoMassErase) @@ -445,10 +421,23 @@ public ExitCodes ExecuteFlashHexFiles( Console.ForegroundColor = ConsoleColor.White; + // be nice and clean up shadow files + try + { + foreach (string shadowFile in shadowFiles) + { + File.Delete(shadowFile); + } + } + catch (Exception) + { + // ignore any exception here + } + return ExitCodes.OK; } - public void ShowCLIOutput(string cliOutput) + internal void ShowCLIOutput(string cliOutput) { // show CLI output, if verbosity is diagnostic if (Verbosity == VerbosityLevel.Diagnostic) @@ -531,5 +520,47 @@ internal static string RunJLinkCLI(string cmdFile, string arguments = null) return jlinkCli.StandardOutput.ReadToEnd(); } + + private ExitCodes ProcessFilePaths(IList files, List shadowFiles) + { + // J-Link can't handle diacritc chars + // developer note: reported to Segger (Case: 60276735) and can be removed if this is fixed/improved + foreach (string binFile in files) + { + // make sure path is absolute + var binFilePath = Utilities.MakePathAbsolute( + Environment.CurrentDirectory, + binFile); + + // check file existence + if (!File.Exists(binFilePath)) + { + return ExitCodes.E5004; + } + + if (!binFilePath.IsNormalized(NormalizationForm.FormD) + || binFilePath.Contains(' ')) + { + var tempFile = Path.Combine( + Environment.GetEnvironmentVariable("TEMP", EnvironmentVariableTarget.Machine), + Path.GetFileName(binFilePath)); + + // copy file to shadow file + File.Copy( + binFilePath, + tempFile, + true); + + shadowFiles.Add(tempFile); + } + else + { + // copy file to shadow list + shadowFiles.Add(binFilePath); + } + } + + return ExitCodes.OK; + } } } diff --git a/nanoFirmwareFlasher.Tool/nanoFirmwareFlasher.Tool.csproj b/nanoFirmwareFlasher.Tool/nanoFirmwareFlasher.Tool.csproj index 3a9d0417..69a235b8 100644 --- a/nanoFirmwareFlasher.Tool/nanoFirmwareFlasher.Tool.csproj +++ b/nanoFirmwareFlasher.Tool/nanoFirmwareFlasher.Tool.csproj @@ -23,6 +23,7 @@ AnyCPU;x64 any true + 12.0 true true