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

swap order of cp in buildroot/bin/build_example #27386

Closed

Conversation

ellensp
Copy link
Contributor

@ellensp ellensp commented Aug 31, 2024

Description

Since fe56f5d#diff-ba8daaa49132ee3b4bb63ec9a5d62bd56649e76a0bf90c24e8dbed8219bace15 the script build_all_examples has been 'faking it'.

The change in buildroot/bin/build_example was innocent looking enough

cp "$BASE/config/default"/*.h    Marlin/
cp "$SUB"/Config.h            Marlin/ 2>/dev/null
cp "$SUB"/Configuration.h     Marlin/ 2>/dev/null
cp "$SUB"/Configuration_adv.h Marlin/ 2>/dev/null
cp "$SUB"/_Bootscreen.h       Marlin/ 2>/dev/null
cp "$SUB"/_Statusscreen.h     Marlin/ 2>/dev/null

was replaced with

cp "$BASE/config/default"/*.h "$SUB"/*.h Marlin/ 2>/dev/null

But on running the updated code you got weird results for eg:

Getting configuration files from ./.pio/build-import-2.1.x/config/examples/Anet/ET4X
Building example Anet/ET4X ...

Auto Build...
Detected "RAMPS 1.4 (Power outputs: Hotend, Fan, Bed)" | RAMPS_14_EFB (1020).
Selected mega2560

This is wrong. This example has BOARD_ANET_ET4 which is a env:Anet_ET4_no_bootloader

Digging into this I removed the redirecting of error to null and was presented with this error

cp: will not overwrite just-created 'Marlin/Configuration_adv.h' with './.pio/build-import-2.1.x/config/examples/Anet/ET4X/Configuration_adv.h'
cp: will not overwrite just-created 'Marlin/Configuration.h' with './.pio/build-import-2.1.x/config/examples/Anet/ET4X/Configuration.h'

Ie you cannot use it in one line like that

So what it is really doing is: It copies the $BASE/config/default"/*.h but since its on the same command it refuses to copy over "$SUB"/*.h as its the same files names.

This results in the build_all_examples script building the default config over and over while telling you its building the example configs.

So I purpose we simply swap the two operators

cp "$SUB"/*.h "$BASE/config/default"/*.h Marlin/ 2>/dev/null

So now it will copy the new configs over and only if a file is missing will it copy over the default file.

Note: I do not know if this will work on all OS's implementing bash.
This change was tested and found to work as desired on Ubuntu 24.04.1 LTS

Other operating systems may need another option like simply having two lines.

cp "$BASE/config/default"/*.h Marlin/ 2>/dev/null
cp "$SUB"/*.h Marlin/ 2>/dev/null

Requirements

Marlin

Benefits

build_all_examples script works as expected

Configurations

All example configs.

Related Issues

fe56f5d#diff-ba8daaa49132ee3b4bb63ec9a5d62bd56649e76a0bf90c24e8dbed8219bace15

@thinkyhead
Copy link
Member

Seems to be an OS-dependent implementation of cp. It works fine on some systems but not others. It's definitely is working on my own system, and the opposite order of the source files does not fix it. The way to ensure correct behavior is probably by splitting into two lines.

Did you see the same error messages if you used cp -f to force the copy?

thinkyhead added a commit to thinkyhead/Marlin that referenced this pull request Sep 1, 2024
@ellensp
Copy link
Contributor Author

ellensp commented Sep 2, 2024

-f does not help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants