Skip to content

Commit 60e226f

Browse files
authored
Merge branch 'master' into master
2 parents 4184d57 + f6b1910 commit 60e226f

File tree

9 files changed

+381
-142
lines changed

9 files changed

+381
-142
lines changed

.github/codeql/codeql-config.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ query-filters:
2020
problem.severity:
2121
- recommendation
2222
- exclude:
23-
id: tob/cpp/use-of-legacy-algorithm
23+
id: tob/cpp/use-of-legacy-algorithm # We use legacy algorithms in many places for integrity checks
24+
- exclude:
25+
id: cpp/dead-code-goto # Too many false positives in no-build mode
2426

2527
paths-ignore:
2628
- tests/**

.github/scripts/process_sarif.py

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#!/usr/bin/env python3
2+
3+
# This script is used to process the SARIF file generated by CodeQL and
4+
# to rename files back to .ino and adjust line numbers to match the original .ino files.
5+
6+
import json
7+
import sys
8+
import os
9+
10+
def process_artifact_location(artifact_location, renamed_files):
11+
"""
12+
Process a single artifact location to rename .cpp files back to .ino
13+
"""
14+
if 'uri' in artifact_location:
15+
uri = artifact_location['uri']
16+
if uri in renamed_files:
17+
print(f"Renaming file: {uri} -> {renamed_files[uri]}")
18+
artifact_location['uri'] = renamed_files[uri]
19+
return True
20+
return False
21+
22+
def process_region(region):
23+
"""
24+
Adjust line numbers in a region by decreasing them by 1
25+
"""
26+
if 'startLine' in region:
27+
region['startLine'] = max(1, region['startLine'] - 1)
28+
if 'endLine' in region:
29+
region['endLine'] = max(1, region['endLine'] - 1)
30+
31+
def process_physical_location(physical_location, renamed_files):
32+
"""
33+
Process a physical location to rename files and adjust line numbers
34+
"""
35+
file_renamed = False
36+
37+
if 'artifactLocation' in physical_location:
38+
if process_artifact_location(physical_location['artifactLocation'], renamed_files):
39+
file_renamed = True
40+
41+
# Adjust line numbers if the file was renamed
42+
if file_renamed and 'region' in physical_location:
43+
process_region(physical_location['region'])
44+
45+
return file_renamed
46+
47+
48+
def process_sarif_file(sarif_file, renamed_files_file):
49+
"""
50+
Process SARIF file to rename files back to .ino and adjust line numbers
51+
"""
52+
# Read the renamed files mapping
53+
with open(renamed_files_file, 'r') as f:
54+
renamed_files = json.load(f)
55+
56+
print(f"Loaded {len(renamed_files)} file mappings:")
57+
for cpp_file, ino_file in renamed_files.items():
58+
print(f" {cpp_file} -> {ino_file}")
59+
60+
61+
# Read the SARIF file
62+
with open(sarif_file, 'r') as f:
63+
sarif_data = json.load(f)
64+
65+
files_processed = 0
66+
67+
# Process each run
68+
if 'runs' in sarif_data:
69+
for run in sarif_data['runs']:
70+
# Process results
71+
if 'results' in run:
72+
for result in run['results']:
73+
# Process all locations in the result
74+
if 'locations' in result:
75+
for location in result['locations']:
76+
if 'physicalLocation' in location:
77+
if process_physical_location(location['physicalLocation'], renamed_files):
78+
files_processed += 1
79+
80+
# Process related locations if they exist
81+
if 'relatedLocations' in result:
82+
for location in result['relatedLocations']:
83+
if 'physicalLocation' in location:
84+
if process_physical_location(location['physicalLocation'], renamed_files):
85+
files_processed += 1
86+
87+
# Process artifacts if they exist
88+
if 'artifacts' in run:
89+
for artifact in run['artifacts']:
90+
if 'location' in artifact and 'uri' in artifact['location']:
91+
uri = artifact['location']['uri']
92+
if uri in renamed_files:
93+
artifact['location']['uri'] = renamed_files[uri]
94+
files_processed += 1
95+
96+
print(f"Processed {files_processed} file references")
97+
98+
# Write the processed SARIF file
99+
with open(sarif_file, 'w') as f:
100+
json.dump(sarif_data, f, indent=2)
101+
102+
def main():
103+
if len(sys.argv) != 3:
104+
print("Usage: python3 sarif_nobuild.py <sarif_file> <renamed_files_file>")
105+
sys.exit(1)
106+
107+
sarif_file = sys.argv[1]
108+
renamed_files_file = sys.argv[2]
109+
110+
# Check if files exist
111+
if not os.path.exists(sarif_file):
112+
print(f"SARIF file not found: {sarif_file}")
113+
sys.exit(1)
114+
115+
if not os.path.exists(renamed_files_file):
116+
print(f"Renamed files mapping not found: {renamed_files_file}")
117+
sys.exit(1)
118+
119+
try:
120+
process_sarif_file(sarif_file, renamed_files_file)
121+
print("SARIF file processed successfully")
122+
except Exception as e:
123+
print(f"Error processing SARIF file: {e}")
124+
import traceback
125+
traceback.print_exc()
126+
sys.exit(1)
127+
128+
if __name__ == "__main__":
129+
main()

.github/scripts/set_push_chunks.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ chunks+="]"
7878
echo "build_all=$build_all"
7979
echo "build_libraries=$BUILD_LIBRARIES"
8080
echo "build_static_sketches=$BUILD_STATIC_SKETCHES"
81-
echo "build_idf=$BUILD_IDF"
8281
echo "chunk_count=$chunks_count"
8382
echo "chunks=$chunks"
8483
} >> "$GITHUB_OUTPUT"

.github/workflows/build_component.yml

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
name: Arduino as ESP-IDF Component
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
idf_ver:
7+
description: "IDF Versions"
8+
default: "release-v5.3,release-v5.4,release-v5.5"
9+
type: "string"
10+
required: true
11+
idf_targets:
12+
description: "IDF Targets"
13+
default: "esp32,esp32s2,esp32s3,esp32c2,esp32c3,esp32c6,esp32h2,esp32p4"
14+
type: "string"
15+
required: true
16+
push:
17+
branches:
18+
- master
19+
- release/*
20+
pull_request:
21+
paths:
22+
- "cores/**"
23+
- "libraries/**/*.cpp"
24+
- "libraries/**/*.c"
25+
- "libraries/**/*.h"
26+
- "libraries/**/*.ino"
27+
- "libraries/**/ci.json"
28+
- "idf_component_examples/**"
29+
- "idf_component.yml"
30+
- "Kconfig.projbuild"
31+
- "CMakeLists.txt"
32+
- ".github/workflows/build_component.yml"
33+
- ".github/scripts/check-cmakelists.sh"
34+
- ".github/scripts/on-push-idf.sh"
35+
- ".github/scripts/sketch_utils.sh"
36+
- "variants/esp32/**"
37+
- "variants/esp32c2/**"
38+
- "variants/esp32c3/**"
39+
- "variants/esp32c6/**"
40+
- "variants/esp32h2/**"
41+
- "variants/esp32p4/**"
42+
- "variants/esp32s2/**"
43+
- "variants/esp32s3/**"
44+
- "!*.md"
45+
- "!*.txt"
46+
- "!*.properties"
47+
48+
concurrency:
49+
group: build-component-${{github.event.pull_request.number || github.ref}}
50+
cancel-in-progress: true
51+
52+
jobs:
53+
cmake-check:
54+
name: Check CMakeLists
55+
runs-on: ubuntu-latest
56+
if: ${{ !(github.event_name == 'pull_request' && startsWith(github.head_ref, 'release/')) }}
57+
steps:
58+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
59+
- run: bash ./.github/scripts/check-cmakelists.sh
60+
61+
set-matrix:
62+
name: Set Matrix
63+
runs-on: ubuntu-latest
64+
if: ${{ !(github.event_name == 'pull_request' && startsWith(github.head_ref, 'release/')) }}
65+
outputs:
66+
idf_ver: ${{ steps.set-matrix.outputs.idf_ver }}
67+
idf_target: ${{ steps.set-matrix.outputs.idf_target }}
68+
steps:
69+
- name: Get IDF Version and Targets
70+
id: set-matrix
71+
run: |
72+
# Default values
73+
idf_ver="release-v5.3,release-v5.4,release-v5.5"
74+
idf_targets="esp32,esp32s2,esp32s3,esp32c2,esp32c3,esp32c6,esp32h2,esp32p4"
75+
76+
# Override with inputs if provided
77+
if [[ -n "${{ inputs.idf_ver }}" ]]; then
78+
idf_ver="${{ inputs.idf_ver }}"
79+
fi
80+
if [[ -n "${{ inputs.idf_targets }}" ]]; then
81+
idf_targets="${{ inputs.idf_targets }}"
82+
fi
83+
84+
# Convert comma-separated strings to JSON arrays using a more robust method
85+
idf_ver_json=$(printf '%s\n' "$idf_ver" | tr ',' '\n' | jq -R . | jq -s . | jq -c .)
86+
idf_targets_json=$(printf '%s\n' "$idf_targets" | tr ',' '\n' | jq -R . | jq -s . | jq -c .)
87+
88+
# Debug: Print the JSON for verification
89+
echo "Debug - idf_ver_json: $idf_ver_json"
90+
echo "Debug - idf_targets_json: $idf_targets_json"
91+
92+
# Set outputs - ensure no extra whitespace
93+
printf "idf_ver=%s\n" "$idf_ver_json" >> $GITHUB_OUTPUT
94+
printf "idf_target=%s\n" "$idf_targets_json" >> $GITHUB_OUTPUT
95+
96+
build-esp-idf-component:
97+
name: Build IDF ${{ matrix.idf_ver }} for ${{ matrix.idf_target }}
98+
runs-on: ubuntu-latest
99+
needs: set-matrix
100+
strategy:
101+
fail-fast: false
102+
matrix:
103+
# The version names here correspond to the versions of espressif/idf Docker image.
104+
# See https://hub.docker.com/r/espressif/idf/tags and
105+
# https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-docker-image.html
106+
# for details.
107+
idf_ver: ${{ fromJson(needs.set-matrix.outputs.idf_ver) }}
108+
idf_target: ${{ fromJson(needs.set-matrix.outputs.idf_target) }}
109+
container: espressif/idf:${{ matrix.idf_ver }}
110+
steps:
111+
- name: Check out arduino-esp32 as a component
112+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
113+
with:
114+
submodules: recursive
115+
path: components/arduino-esp32
116+
117+
- name: Setup jq
118+
uses: dcarbone/install-jq-action@e397bd87438d72198f81efd21f876461183d383a # v3.0.1
119+
120+
- name: Build
121+
env:
122+
IDF_TARGET: ${{ matrix.idf_target }}
123+
shell: bash
124+
run: |
125+
chmod a+x ./components/arduino-esp32/.github/scripts/*
126+
./components/arduino-esp32/.github/scripts/on-push-idf.sh
127+
128+
- name: Upload generated sdkconfig files for debugging
129+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
130+
if: always()
131+
with:
132+
name: sdkconfig-${{ matrix.idf_ver }}-${{ matrix.idf_target }}
133+
path: ./components/arduino-esp32/idf_component_examples/**/sdkconfig

.github/workflows/codeql.yml

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ on:
77
- master
88
pull_request:
99
paths:
10+
- "**/*.c"
11+
- "**/*.cpp"
12+
- "**/*.h"
13+
- "**/*.ino"
1014
- "**/*.py"
1115
- ".github/workflows/*.yml"
1216
- ".github/workflows/*.yaml"
@@ -17,19 +21,68 @@ jobs:
1721
runs-on: ubuntu-latest
1822
strategy:
1923
matrix:
20-
language: [python, actions]
24+
language: [python, actions, cpp]
2125

2226
steps:
2327
- name: Checkout repository
2428
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2529

30+
- name: Process .ino files
31+
if: matrix.language == 'cpp'
32+
run: |
33+
# Create a mapping file to track renamed files
34+
echo "{}" > renamed_files.json
35+
36+
# Find all .ino files and process them
37+
find . -name "*.ino" -type f | while read -r file; do
38+
echo "Processing $file"
39+
40+
# Get the relative path from repository root
41+
rel_path=$(realpath --relative-to=. "$file")
42+
cpp_path="${rel_path%.ino}.cpp"
43+
44+
# Create new .cpp file with Arduino.h include
45+
echo "#include <Arduino.h>" > "$cpp_path"
46+
47+
# Append the original content
48+
cat "$file" >> "$cpp_path"
49+
50+
# Update the mapping file
51+
jq --arg ino "$rel_path" --arg cpp "$cpp_path" '. += {($cpp): $ino}' renamed_files.json > temp.json && mv temp.json renamed_files.json
52+
53+
# Remove the original .ino file
54+
rm "$file"
55+
56+
echo "Converted $file to $cpp_path"
57+
done
58+
59+
echo "Renamed files mapping:"
60+
cat renamed_files.json
61+
2662
- name: Initialize CodeQL
2763
uses: github/codeql-action/init@181d5eefc20863364f96762470ba6f862bdef56b # v3.29.2
2864
with:
65+
build-mode: none
2966
languages: ${{ matrix.language }}
3067
config-file: ./.github/codeql/codeql-config.yml
3168

3269
- name: Run CodeQL Analysis
3370
uses: github/codeql-action/analyze@181d5eefc20863364f96762470ba6f862bdef56b # v3.29.2
3471
with:
3572
category: "/language:${{ matrix.language }}"
73+
output: sarif-results
74+
upload: failure-only
75+
76+
- name: Process SARIF file
77+
if: matrix.language == 'cpp'
78+
run: |
79+
sarif_file="sarif-results/${{ matrix.language }}.sarif"
80+
81+
# Run the Python script to process the SARIF file
82+
python3 .github/scripts/process_sarif.py "$sarif_file" "renamed_files.json"
83+
84+
- name: Upload SARIF file
85+
uses: github/codeql-action/upload-sarif@181d5eefc20863364f96762470ba6f862bdef56b # v3.29.2
86+
with:
87+
sarif_file: sarif-results/${{ matrix.language }}.sarif
88+
category: "/language:${{ matrix.language }}"

0 commit comments

Comments
 (0)