Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix idf_as_lib example (IDFGH-14655) #15401

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Dazza0
Copy link
Contributor

@Dazza0 Dazza0 commented Feb 15, 2025

Description

The current idf_as_lib example doesn't work out of the box for target and Linux builds. This PR fixes the following issues with the example:

  • Invalid file permissions: git ls-files -s shows *.sh files have a file mode of 120000 (non-executable symbolic link). Replaced with file mode 100755
  • Execute as source: Wrapper scripts (e.g., build-esp32.sh) need to call base scripts (e.g., build.sh) as source, otherwise the current argument parsing doesn't work.
  • Add missing shebang to bash scripts
  • Fix Linux build: a690a87 migrated IDF to use a new flash API (i.e., esp_flash_get_size()). However the Linux stub_spi_flash library still uses the legacy API (i.e., spi_flash_get_chip_size()). Updated stub_spi_flash to provide esp_flash_get_size().

On a related note, the example would probably be more clear if did away with the build and run bash scripts, and just required uses to call the underlying cmake .. -GNinja command directly. This workflow is more inline with the intended use case of this example (i.e., integrating IDF into an existing CMake project). Likewise, doing away with the linux stubs and providing an example of how to integrate the IDF Linux simulator into an existing CMake project would be more clear. However, these points can be addressed in a separate PR (if at all).

Related

Testing

  • Ran ./build-esp32.sh and run-esp32.sh to test example for a real target
  • Ran ./build.sh and run.sh to test example for Linux simulator target

Checklist

Before submitting a Pull Request, please ensure the following:

  • 🚨 This PR does not introduce breaking changes.
  • All CI checks (GH Actions) pass.
  • Documentation is updated as needed.
  • Tests are updated or added as necessary.
  • Code is well-commented, especially in complex areas.
  • Git history is clean — commits are squashed to the minimum necessary.

Copy link

github-actions bot commented Feb 15, 2025

Messages
📖 You might consider squashing your 3 commits (simplifying branch history).

👋 Hello Dazza0, we appreciate your contribution to this project!


📘 Please review the project's Contributions Guide for key guidelines on code, documentation, testing, and more.

🖊️ Please also make sure you have read and signed the Contributor License Agreement for this project.

Click to see more instructions ...


This automated output is generated by the PR linter DangerJS, which checks if your Pull Request meets the project's requirements and helps you fix potential issues.

DangerJS is triggered with each push event to a Pull Request and modify the contents of this comment.

Please consider the following:
- Danger mainly focuses on the PR structure and formatting and can't understand the meaning behind your code or changes.
- Danger is not a substitute for human code reviews; it's still important to request a code review from your colleagues.
- Addressing info messages (📖) is strongly recommended; they're less critical but valuable.
- To manually retry these Danger checks, please navigate to the Actions tab and re-run last Danger workflow.

Review and merge process you can expect ...


We do welcome contributions in the form of bug reports, feature requests and pull requests via this public GitHub repository.

This GitHub project is public mirror of our internal git repository

1. An internal issue has been created for the PR, we assign it to the relevant engineer.
2. They review the PR and either approve it or ask you for changes or clarifications.
3. Once the GitHub PR is approved, we synchronize it into our internal git repository.
4. In the internal git repository we do the final review, collect approvals from core owners and make sure all the automated tests are passing.
- At this point we may do some adjustments to the proposed change, or extend it by adding tests or documentation.
5. If the change is approved and passes the tests it is merged into the default branch.
5. On next sync from the internal git repository merged change will appear in this public GitHub repository.

Generated by 🚫 dangerJS against 3b28818

@github-actions github-actions bot changed the title Fix idf_as_lib example Fix idf_as_lib example (IDFGH-14655) Feb 15, 2025
@espressif-bot espressif-bot added the Status: Opened Issue is new label Feb 15, 2025
@dobairoland dobairoland requested a review from fhrbata February 17, 2025 07:44
@fhrbata
Copy link
Collaborator

fhrbata commented Feb 18, 2025

Hello @Dazza0 ,
thank you very much for your contribution. The stub changes related to the spi_flash modifications introduced in a690a87 seem ok to me, but I have a few comments regarding the script changes.

Invalid file permissions: git ls-files -s shows *.sh files have a file mode of 120000 (non-executable symbolic link). Replaced with file mode 100755

What makes you believe the permissions are incorrect? When symlinks are checked out into the working directory by git, they will have rwx permissions. The only issue I notice is that the esp32p4 scripts, build-esp32p4.sh and run-esp32p4.sh, were added as regular files instead of symlinks in commit 5bd6449.

$ git ls-tree HEAD .
100644 blob 53a0188134242bc8972b3dbc9f659d9ccd7fdba4	CMakeLists.txt
100644 blob 0cc5619a9ff85aaac6d064fa2f938cf7cd71b946	README.md
120000 blob c07a74de4fb4ebbad5a9b84a5a7b68e4f489a6e0	build-esp32.sh
120000 blob c07a74de4fb4ebbad5a9b84a5a7b68e4f489a6e0	build-esp32c2.sh
120000 blob c07a74de4fb4ebbad5a9b84a5a7b68e4f489a6e0	build-esp32c3.sh
120000 blob c07a74de4fb4ebbad5a9b84a5a7b68e4f489a6e0	build-esp32c6.sh
120000 blob c07a74de4fb4ebbad5a9b84a5a7b68e4f489a6e0	build-esp32h2.sh
100644 blob 9a18dc76db01b2cdc16aa7dc7638be16a1ce176b	build-esp32p4.sh
120000 blob c07a74de4fb4ebbad5a9b84a5a7b68e4f489a6e0	build-esp32s2.sh
120000 blob c07a74de4fb4ebbad5a9b84a5a7b68e4f489a6e0	build-esp32s3.sh
100755 blob 9a18dc76db01b2cdc16aa7dc7638be16a1ce176b	build.sh
100644 blob 379147fc5e2f1f03613b39bfdc081e9376280c70	main.c
100755 blob 3d9e0bfba5e5d5a76511ed3e3d6efc77a68bf6e2	run-esp32.sh
120000 blob cde8585ed41a85676c5b731a0dec1ebccbfca15b	run-esp32c2.sh
120000 blob cde8585ed41a85676c5b731a0dec1ebccbfca15b	run-esp32c3.sh
120000 blob cde8585ed41a85676c5b731a0dec1ebccbfca15b	run-esp32c6.sh
120000 blob cde8585ed41a85676c5b731a0dec1ebccbfca15b	run-esp32h2.sh
100644 blob 3d9e0bfba5e5d5a76511ed3e3d6efc77a68bf6e2	run-esp32p4.sh
120000 blob cde8585ed41a85676c5b731a0dec1ebccbfca15b	run-esp32s2.sh
120000 blob cde8585ed41a85676c5b731a0dec1ebccbfca15b	run-esp32s3.sh
100755 blob f7747ac0285770f56cbff59e43665143af1999ed	run.sh
040000 tree c50e046662674434f403ceea2c60f187aa170fd9	stubs

Are all the script-related changes stemming from this issue? I believe converting the esp32p4 scripts to symlinks should resolve the problem without needing to turn all the symlinks into regular files.

Execute as source: Wrapper scripts (e.g., build-esp32.sh) need to call base scripts (e.g., build.sh) as source, otherwise the current argument parsing doesn't work.

I believe this issue arises from converting the symlinks into regular files. When build.sh is executed as a script, $0 evaluates to build.sh, unless it is sourced. Therefore, you need to source it to ensure it runs in the current (wrapper) script environment, allowing $0 to reflect the correct script name. This isn't a problem when using symlinks.

Add missing shebang to bash scripts

Again, I believe this is needed just because the symlinks are changed to regular files. The base scripts, e.g., build.sh, have a shebang included.

I might be overlooking something, but the sole issue I notice with the scripts and permissions seems to be related to the esp32p4 wrappers. Please let me know if I missed something.

Thank you very much

The build-esp32p4.sh and run-esp32p4.sh scripts are not symbolic links to the
base scripts, leading to a "permission denied" error. This commit changes their
types to symbolic links, in line with the other targets.
Example linux build of the example demonstrates "esp32" and "spi_flash" stub
libraries (roughly analogous to "esp_system" and "spi_flash" components).

This commit moves the "flash_ops.c" file to the "spi_flash" stub library as it
is a flash related funciton.

Also renamed the header to "esp_flash.h" (in order to match current header name
in IDF). This is a prerequisite to fixing the linux build of this example.
The Linux build was broken after IDF flash API was updated without updating
the Linux stub library in the example. This commit updates the spi_flash stub
library such that:

- The API now matches same API as IDF's spi_flash component
- Links the stub_esp32 library to pull in basic types and defines
@Dazza0 Dazza0 force-pushed the fix/idf_as_lib_example branch from 154f9e8 to 3b28818 Compare February 19, 2025 10:42
@Dazza0
Copy link
Contributor Author

Dazza0 commented Feb 19, 2025

@fhrbata Thanks for the quick review

Regarding the symbolic links, I think you're correct. The existing symbolic link implementation works fine when I tried it on a different machine. The issue was probably on my end (maybe something to do with git config core.symlinks). I've revered the script changes and update build-esp32p4.sh and run-esp32p4.sh to be symbolic links.

@fhrbata
Copy link
Collaborator

fhrbata commented Feb 19, 2025

@fhrbata Thanks for the quick review

Regarding the symbolic links, I think you're correct. The existing symbolic link implementation works fine when I tried it on a different machine. The issue was probably on my end (maybe something to do with git config core.symlinks). I've revered the script changes and update build-esp32p4.sh and run-esp32p4.sh to be symbolic links.

Hello @Dazza0 ,

thank you very much for updating the PR and this fix. LGTM!

@fhrbata
Copy link
Collaborator

fhrbata commented Feb 19, 2025

sha=3b28818ba4f1c0ace850ddd893cf28bcf71f2407

@fhrbata fhrbata added PR-Sync-Merge Pull request sync as merge commit and removed PR-Sync-Merge Pull request sync as merge commit labels Feb 19, 2025
@espressif-bot espressif-bot added Status: Selected for Development Issue is selected for development Status: Reviewing Issue is being reviewed and removed Status: Opened Issue is new Status: Selected for Development Issue is selected for development labels Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR-Sync-Merge Pull request sync as merge commit Status: Reviewing Issue is being reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants