Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Mark serial monitor as executable on Mac and Linux #1420

Merged
merged 3 commits into from
Jan 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ steps:
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.StagingDirectory)\vscode-arduino.vsix
- script: python .\build\markExecutableFiles.py
displayName: Make serial monitor executable
- task: MSBuild@1
displayName: Sign VSIX
inputs:
Expand Down
31 changes: 31 additions & 0 deletions build/markExecutableFiles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os
import zipfile

staging_directory = os.getenv('BUILD_STAGINGDIRECTORY')
input_archive_path = f"{staging_directory}/vscode-arduino.vsix"
output_archive_path = f"{staging_directory}/vscode-arduino-out.vsix"

filenames = [
"extension/out/serial-monitor-cli/darwin/main",
"extension/out/serial-monitor-cli/linux/main"
]

input_archive = zipfile.ZipFile(input_archive_path, 'r')
output_archive = zipfile.ZipFile(output_archive_path, 'w')

executable_count = 0
for info in input_archive.infolist():
data = input_archive.read(info)
if info.filename in filenames:
# Magic number from from https://stackoverflow.com/a/48435482
info.external_attr = 0o100755 << 16
executable_count += 1
output_archive.writestr(info, data)

if executable_count != len(filenames):
raise Exception(f'Expected to find {len(filenames)} executables but only found {executable_count}')

input_archive.close()
output_archive.close()

os.replace(output_archive_path, input_archive_path)