-
Notifications
You must be signed in to change notification settings - Fork 349
scripts: xtensa-build-all.sh: Refactor and improve script #2711
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
scripts: xtensa-build-all.sh: Refactor and improve script #2711
Conversation
|
Furthers #2631 |
89ec368 to
b4b3ae4
Compare
240c626 to
9b9370c
Compare
|
Jenkins probably uses |
|
SOFCI TEST |
9b9370c to
73a4cf9
Compare
scripts/xtensa-build-all.sh
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have also seen this typo, but since we are just now refactoring the old code this can be done in a separate PR. But now that you pointed it I think we can add a separate patch in this PR.
@crazoes Remeber that in a PR like this fixes come first, then the actual refactoring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like to treat typos the same as indentation/whitespace: don't obscure actual changes with them. However if that line changes ANYWAY in git for some other and good reason then it's a good opportunity to fix typos at the same time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marc-hb @dbaluta I have maintained the order here, fixing first and then moving the code around.
In the process I have noticed that when we order moving of code after fixes, we will always end up with merge conflicts after editing the fix commit. So what is the rationale behind ordering fixes first and refactors later?
scripts/xtensa-build-all.sh
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are associative arrays in disguise. Maybe we could add a dependency on bash version 4 in the future (not in this PR which is already fixing many other things).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I just checked out associative arrays, this whole thing can be made into a nested associative array, with keys platform names, and values as another associative array containing PLATFORM, ARCH, etc..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using PLATFORMS[@] as an array when it's not is really bad and should be fixed and tested very first thing before refactoring anything[*]. Either make PLATFORMS an actual array and fix all the missing quotes, or make it a string with whitespace. Please not a bit of both any more. I suspect actually making it an array means fewer changed lines. It's a bit overkill because I don't think platform names will ever whitespace in them but it's more consistent with SUPPORTED_PLATFORMS[@].
[*] Moving code that works by coincidence is like moving a large pile of glassware.
scripts/xtensa-build-all.sh
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a miracle this works considering PLATFORMS is not an array. This works by combining two bugs that cancel each other out:
- To list each element of the array it should be
for platform in "${PLATFORMS[@]}"with double quotes - but PLATFORMS is not an array but a string with whitespace
https://mywiki.wooledge.org/BashGuide/Arrays
Demo, ./scripts/xtensa-build-all.sh byt ABC apl with this:
--- a/scripts/xtensa-build-all.sh
+++ b/scripts/xtensa-build-all.sh
@@ -90,6 +90,19 @@ else
done
fi
+# Here's an actual array
+declare -p SUPPORTED_PLATFORMS
+printf 'SPi=%s\n' "${SUPPORTED_PLATFORMS[@]}"
+
+# Not an array, just pretending
+declare -p PLATFORMS
+# yet bash expands this a string with whitespace, amazing
+printf 'Pi=%s\n' "${PLATFORMS[@]}"
+printf 'Pi=%s\n' "${PLATFORMS[@]}"
+
+# now something even weirder
+printf '?#?=%s\n' "${#PLATFORMS[@]}"
+
# check target platform(s) have been passed in
if [ ${#PLATFORMS[@]} -eq 0 ];
then
@@ -97,6 +110,8 @@ then
exit 1
fi
+exit 0
+
if [ "x$USE_PRIVATE_KEY" == "xyes" ]
73a4cf9 to
b029ded
Compare
b029ded to
f2f0185
Compare
|
I don't know why but https://github.com/thesofproject/sof/pull/2711/commits doesn't show the right order of commit, rather ordered by dates. Making it difficult to read the actual sequence of the commits. I have checked the reviews again and verified I haven't missed any comment. However, there have been many amending and merge conflicts here so please let me know if I missed anything or if something might have lost due to wrongful merge conflict resolution on my part. |
f2f0185 to
ebce03d
Compare
`PLATFORMS` variable was used as an array while it is actually a string used incorrectly making it work accidentally. Signed-off-by: Shreeya Patel <shreeya.patel23498@gmail.com>
ebce03d to
dd29d2a
Compare
scripts/xtensa-build-all.sh
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you meant: if type xtensa-bxt-elf-gcc; then.
This explains the Travis failure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either way HOST is never set to xtensa-bxt-elf-gcc which is what is being set as the compiler. Currently unable to get the docker image because of network issues so cannot reproduce locally. Anyways, I will try removing the ! and see if it works
The CMAKE_C_COMPILER:
xtensa-bxt-elf-gcc
is not a full path and was not found in the PATH.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
huh, this does fix it. But doesn't work well with what I said earlier. Maybe the CMAKE_C_COMPILER is not derived from TOOLCHAIN which is what is using the HOST value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bxt and apl were technically different but have been used somewhat interchangeably in some contexts. If you look at commit c7edd73 you can see this logic is only backward compatibility to support who built a toolchain with the older bxt name. All SOF documentation now refers to apl
Wow, I think you discovered a new github limitation with force pushes, thanks! I added it to the list:
Yes, re-ordering commits that touch the same parts of the code will always cause painful conflicts. The rationale is that version history is sometimes painfully written once by one person (you), but then it's immutable and read, bisected, backported and used in many other ways by many other people and many tools. This "clean history" rationale is a very common rationale among git users, apparently much less common among github users, github seems to care less about history.
It's not always like this, it depends. In other cases a zero-functional change refactor is a prelude to shorten and clarify a bug fix coming immediately next and making the fix much easier to revert in case it regresses something else. In this PR the hopefully small fix(es) were completely unrelated to the refactor, so better not increase and obscure the distance between the bugs and their fixes by shuffling code in between. PS: besides root-causing the Travis failure, I haven't reviewed the latest version yet. |
dd29d2a to
53532df
Compare
Use getopts to parse the arguments instead of manual parsing to leave no room for errors, bugs, and inconsistent conventions introduced by custom implementation. Signed-off-by: Shreeya Patel <shreeya.patel23498@gmail.com>
Exits if an unknown platform is specified. Currently, there are no warnings or errors. Signed-off-by: Shreeya Patel <shreeya.patel23498@gmail.com>
Currently, "set -e" is being ignored for type command using redirections and "A && true". "A && true" is a no-op and a peculiar case where "set -e" ignores the exit code of A. Exit code of the "type" command is used in an if statement which is exactly what the function of "if" command is. Also, "set -e" ignores exit codes of commands used in if statements. Signed-off-by: Shreeya Patel <shreeya.patel23498@gmail.com>
Use switch case for testing strings instead of if statements for each case. Signed-off-by: Shreeya Patel <shreeya.patel23498@gmail.com>
Derive $ROOT from $HOST instead of explicit assignments. Signed-off-by: Shreeya Patel <shreeya.patel23498@gmail.com>
xtensa-build-all.sh expects number of cores to be used when -j option is specified. By default, it uses all the cores available which is what we want, hence, omitting the option altogether. Signed-off-by: Shreeya Patel <shreeya.patel23498@gmail.com>
53532df to
6c1f2da
Compare
|
SOFCI TEST |
|
@crazoes What the change about the |
@xiulipan Explained in another discussion here : #2711 (comment) |
|
@crazoes I will try to remove the -j option in our Jenkins CI scripts. |
lgirdwood
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xiulipan do you need to update CI before or after this is merged ?
|
CI known issues. |
|
This PR missed one case $platform in
...
TOOLCHAIN=$HOST
PATH=$pwd/../$HOST/bin:$OLDPATH
COMPILER="gcc"
case $j in
^-- SC2154: j is referenced but not assigned.
byt|cht|cnl|sue) DEFCONFIG_PATCH="_gcc";;
*) DEFCONFIG_PATCH="";;
esacI think this means the wrong (unrelated but large shellcheck noise reduced in unrelated PR #3163 ) |
Signed-off-by: Shreeya Patel shreeya.patel23498@gmail.com