Skip to content

Commit 1bdd490

Browse files
authored
Merge branch 'espressif:esp-idf-v5.1-libs' into esp-idf-v5.1-libs
2 parents 6030d07 + e343918 commit 1bdd490

File tree

7 files changed

+246
-2
lines changed

7 files changed

+246
-2
lines changed

.github/pytools/Sign-File.ps1

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
[CmdletBinding()]
2+
param (
3+
[Parameter()]
4+
[String]
5+
$Path
6+
)
7+
8+
9+
function FindSignTool {
10+
$SignTool = "signtool.exe"
11+
if (Get-Command $SignTool -ErrorAction SilentlyContinue) {
12+
return $SignTool
13+
}
14+
$SignTool = "${env:ProgramFiles(x86)}\Windows Kits\10\bin\x64\signtool.exe"
15+
if (Test-Path -Path $SignTool -PathType Leaf) {
16+
return $SignTool
17+
}
18+
$SignTool = "${env:ProgramFiles(x86)}\Windows Kits\10\bin\x86\signtool.exe"
19+
if (Test-Path -Path $SignTool -PathType Leaf) {
20+
return $SignTool
21+
}
22+
$sdkVers = "10.0.22000.0", "10.0.20348.0", "10.0.19041.0", "10.0.17763.0"
23+
Foreach ($ver in $sdkVers)
24+
{
25+
$SignTool = "${env:ProgramFiles(x86)}\Windows Kits\10\bin\${ver}\x64\signtool.exe"
26+
if (Test-Path -Path $SignTool -PathType Leaf) {
27+
return $SignTool
28+
}
29+
}
30+
"signtool.exe not found"
31+
Exit 1
32+
}
33+
34+
function SignEsptool {
35+
param(
36+
[Parameter()]
37+
[String]
38+
$Path
39+
)
40+
41+
$SignTool = FindSignTool
42+
"Using: $SignTool"
43+
$CertificateFile = [system.io.path]::GetTempPath() + "certificate.pfx"
44+
45+
if ($null -eq $env:CERTIFICATE) {
46+
"CERTIFICATE variable not set, unable to sign the file"
47+
Exit 1
48+
}
49+
50+
if ("" -eq $env:CERTIFICATE) {
51+
"CERTIFICATE variable is empty, unable to sign the file"
52+
Exit 1
53+
}
54+
55+
$SignParameters = @("sign", "/tr", 'http://timestamp.digicert.com', "/td", "SHA256", "/f", $CertificateFile, "/fd", "SHA256")
56+
if ($env:CERTIFICATE_PASSWORD) {
57+
"CERTIFICATE_PASSWORD detected, using the password"
58+
$SignParameters += "/p"
59+
$SignParameters += $env:CERTIFICATE_PASSWORD
60+
}
61+
$SignParameters += $Path
62+
63+
[byte[]]$CertificateBytes = [convert]::FromBase64String($env:CERTIFICATE)
64+
[IO.File]::WriteAllBytes($CertificateFile, $CertificateBytes)
65+
66+
&$SignTool $SignParameters
67+
68+
if (0 -eq $LASTEXITCODE) {
69+
Remove-Item $CertificateFile
70+
} else {
71+
Remove-Item $CertificateFile
72+
"Signing failed"
73+
Exit 1
74+
}
75+
76+
}
77+
78+
SignEsptool ${Path}

.github/pytools/espressif.ico

115 KB
Binary file not shown.

.github/scripts/upload_py_tools.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
CHANGED_FILES=$1
3+
echo "Pushing '$CHANGED_FILES' as $GITHUB_ACTOR"
4+
git config --global github.user "$GITHUB_ACTOR"
5+
git config --global user.name "$GITHUB_ACTOR"
6+
git config --global user.email "$GITHUB_ACTOR@users.noreply.github.com"
7+
for tool in $CHANGED_FILES; do
8+
git add tools/$tool.exe
9+
done
10+
git commit -m "Push binary to tools"
11+
git push

.github/workflows/build_py_tools.yml

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
name: Build Python Tools
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'tools/get.py'
7+
- 'tools/espota.py'
8+
- 'tools/gen_esp32part.py'
9+
- 'tools/gen_insights_package.py'
10+
11+
jobs:
12+
find-changed-tools:
13+
name: Check if tools have been changed
14+
runs-on: ubuntu-20.04
15+
outputs:
16+
any_changed: ${{ steps.verify-changed-files.outputs.any_changed }}
17+
all_changed_files: ${{ steps.verify-changed-files.outputs.all_changed_files }}
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v3
21+
with:
22+
fetch-depth: 2
23+
ref: ${{ github.event.pull_request.head.ref }}
24+
- name: Verify Python Tools Changed
25+
uses: tj-actions/changed-files@v36
26+
id: verify-changed-files
27+
with:
28+
fetch_depth: '2'
29+
since_last_remote_commit: 'true'
30+
files: |
31+
tools/get.py
32+
tools/espota.py
33+
tools/gen_esp32part.py
34+
tools/gen_insights_package.py
35+
- name: List all changed files
36+
shell: bash
37+
run: |
38+
for file in ${{ steps.verify-changed-files.outputs.all_changed_files }}; do
39+
echo "$file was changed"
40+
done
41+
42+
build-pytools-binaries:
43+
name: Build python tools binaries for ${{ matrix.os }}
44+
runs-on: ${{ matrix.os }}
45+
needs: find-changed-tools
46+
if: needs.find-changed-tools.outputs.any_changed == 'true'
47+
strategy:
48+
fail-fast: false
49+
matrix:
50+
os: [windows-latest, macos-latest, ubuntu-20.04, ARM, ARM64]
51+
include:
52+
- os: windows-latest
53+
TARGET: win64
54+
EXTEN: .exe
55+
SEPARATOR: ';'
56+
- os: macos-latest
57+
TARGET: macos
58+
SEPARATOR: ':'
59+
- os: ubuntu-20.04
60+
TARGET: linux-amd64
61+
SEPARATOR: ':'
62+
- os: ARM
63+
CONTAINER: python:3.8-bullseye
64+
TARGET: arm
65+
SEPARATOR: ':'
66+
- os: ARM64
67+
CONTAINER: python:3.8-bullseye
68+
TARGET: arm64
69+
SEPARATOR: ':'
70+
container: ${{ matrix.CONTAINER }} # use python container on ARM
71+
env:
72+
DISTPATH: pytools-${{ matrix.TARGET }}
73+
PIP_EXTRA_INDEX_URL: "https://dl.espressif.com/pypi"
74+
steps:
75+
- name: List changed tools
76+
shell: bash
77+
run: |
78+
CHANGED_FILES=()
79+
for file in ${{ needs.find-changed-tools.outputs.all_changed_files }}; do
80+
file="${file#*\/}"
81+
file="${file%\.*}"
82+
CHANGED_FILES+=("$file")
83+
done
84+
CHANGED_FILES="${CHANGED_FILES[@]}"
85+
echo "CHANGED_TOOLS=$CHANGED_FILES" >> "$GITHUB_ENV"
86+
for tool in ${{ env.CHANGED_TOOLS }}; do
87+
echo "tool $tool was changed"
88+
done
89+
- name: Checkout repository
90+
uses: actions/checkout@v3
91+
with:
92+
ref: ${{ github.event.pull_request.head.ref }}
93+
- name: Set up Python 3.8
94+
# Skip setting python on ARM because of missing compatibility: https://github.com/actions/setup-python/issues/108
95+
if: matrix.os != 'ARM' && matrix.os != 'ARM64'
96+
uses: actions/setup-python@master
97+
with:
98+
python-version: 3.8
99+
- name: Install dependencies
100+
run: |
101+
python -m pip install --upgrade pip
102+
pip install pyinstaller requests
103+
- name: Build with PyInstaller
104+
shell: bash
105+
run: |
106+
for tool in ${{ env.CHANGED_TOOLS }}; do
107+
pyinstaller --distpath ./${{ env.DISTPATH }} -F --icon=.github/pytools/espressif.ico tools/$tool.py
108+
done
109+
- name: Sign binaries
110+
if: matrix.os == 'windows-latest'
111+
env:
112+
CERTIFICATE: ${{ secrets.CERTIFICATE }}
113+
CERTIFICATE_PASSWORD: ${{ secrets.CERTIFICATE_PASSWORD }}
114+
shell: pwsh
115+
run: |
116+
$data = Write-Output ${{ env.CHANGED_TOOLS }}
117+
foreach ( $node in $data )
118+
{
119+
./.github/pytools/Sign-File.ps1 -Path ./${{ env.DISTPATH }}/$node.exe
120+
}
121+
- name: Test binaries
122+
shell: bash
123+
run: |
124+
for tool in ${{ env.CHANGED_TOOLS }}; do
125+
./${{ env.DISTPATH }}/$tool${{ matrix.EXTEN }} -h
126+
done
127+
- name: Push binary to tools
128+
if: matrix.os == 'windows-latest'
129+
env:
130+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
131+
shell: bash
132+
run: |
133+
for tool in ${{ env.CHANGED_TOOLS }}; do
134+
cp -f ./${{ env.DISTPATH }}/$tool.exe tools/$tool.exe
135+
done
136+
bash .github/scripts/upload_py_tools.sh "${{ env.CHANGED_TOOLS }}"
137+
- name: Archive artifact
138+
uses: actions/upload-artifact@master
139+
with:
140+
name: ${{ env.DISTPATH }}
141+
path: ${{ env.DISTPATH }}

tools/espota.exe

2.22 MB
Binary file not shown.

tools/get.exe

1.62 MB
Binary file not shown.

tools/get.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@
3535
if 'Windows' in platform.system():
3636
import requests
3737

38-
current_dir = os.path.dirname(os.path.realpath(unicode(__file__)))
38+
# determine if application is a script file or frozen exe
39+
if getattr(sys, 'frozen', False):
40+
current_dir = os.path.dirname(os.path.realpath(unicode(sys.executable)))
41+
elif __file__:
42+
current_dir = os.path.dirname(os.path.realpath(unicode(__file__)))
43+
44+
#current_dir = os.path.dirname(os.path.realpath(unicode(__file__)))
3945
dist_dir = current_dir + '/dist/'
4046

4147
def sha256sum(filename, blocksize=65536):
@@ -88,6 +94,8 @@ def unpack(filename, destination):
8894

8995
# a little trick to rename tool directories so they don't contain version number
9096
rename_to = re.match(r'^([a-z][^\-]*\-*)+', dirname).group(0).strip('-')
97+
if rename_to == dirname and dirname.startswith('esp32-arduino-libs-'):
98+
rename_to = 'esp32-arduino-libs'
9199
if rename_to != dirname:
92100
print('Renaming {0} to {1} ...'.format(dirname, rename_to))
93101
if os.path.isdir(rename_to):
@@ -217,10 +225,16 @@ def identify_platform():
217225
return arduino_platform_names[sys_name][bits]
218226

219227
if __name__ == '__main__':
228+
is_test = (len(sys.argv) > 1 and sys.argv[1] == '-h')
229+
if is_test:
230+
print('Test run!')
220231
identified_platform = identify_platform()
221232
print('Platform: {0}'.format(identified_platform))
222233
tools_to_download = load_tools_list(current_dir + '/../package/package_esp32_index.template.json', identified_platform)
223234
mkdir_p(dist_dir)
224235
for tool in tools_to_download:
225-
get_tool(tool)
236+
if is_test:
237+
print('Would install: {0}'.format(tool['archiveFileName']))
238+
else:
239+
get_tool(tool)
226240
print('Platform Tools Installed')

0 commit comments

Comments
 (0)