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 server build script by using more portable and safer bash and rely on PATH when no ANDROID_HOME #1716

Closed
wants to merge 4 commits into from

Conversation

ljmf00
Copy link
Contributor

@ljmf00 ljmf00 commented Aug 27, 2020

See the commit messages.

This patch should increase the portability of bash scripts across various *nix systems
such as BSD-like distributions.

Signed-off-by: Luís Ferreira <contact@lsferreira.net>
When $ANDROID_HOME variable is missing, you should rely on $PATH. This
make things easier to build from scratch on distros like Arch Linux or
Gentoo.

Signed-off-by: Luís Ferreira <contact@lsferreira.net>
The bash shell normally only looks at the exit code of the last command of a
pipeline. This behavior is not ideal as it causes the -e option to only be
able to act on the exit code of a pipeline’s last command. This is where -o
pipefail comes in. This particular option sets the exit code of a pipeline
to that of the rightmost command to exit with a non-zero status, or to zero if
all commands of the pipeline exit successfully.

See more about safer bash scripts:
https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/

Signed-off-by: Luís Ferreira <contact@lsferreira.net>
@@ -9,14 +9,24 @@
#
# BUILD_DIR=my_build_dir ./build_without_gradle.sh

set -e
set -eo pipefail
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it too violent?

set -eo pipefail
result=$(echo a | grep b)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends on what behavior you want here. You might want something like this:echo a | grep b || true, instead.

@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ref #426

OK, I don't know which one is good practice (/bin/bash seems less risky to me, but why not).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends of the portability you want to have here. I do think it's a good practice for 2 major reasons:

  1. All Linux distributions I'm aware of are compatible with the approach I described in the patch.

  2. Some BSD-based distributions like FreeBSD doesn't support your approach. See here: https://forums.freebsd.org/threads/bash-not-found.31849/ .

The env binary simply search for the executable in the provided PATH environment variable, so, here, you rely on it instead of providing the full path.

I didn't noticed the previous patch you referred, so if you're good with this, I can rebase and drop it.

[ -x "$(which aidl)" ] && AIDL="aidl" \
|| (echo "Please provide \$ANDROID_HOME or set \$PATH to include 'aidl' executable"; exit 1)
fi

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For info, why do you need this? Where do your dx and aidl come from?

(That way, the dx and aidl version are not necessarily from the expected platform.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For info, why do you need this? Where do your dx and aidl come from?

The problem I'm trying to solve here is building scrcpy completely from scratch with android-tools compiled from source. On Arch Linux scrcpy is built using a prebuilt scrcpy-server.

Because AOSP source has a huge and monolithic build system and because there's no proper tagging, Arch Linux, to build everything from source, need to do this: https://github.com/archlinux/svntogit-community/blob/packages/android-tools/trunk/generate_build.rb#L3 .

(That way, the dx and aidl version are not necessarily from the expected platform.)

You're right. In fact, I didn't covered this, if you depend on a specific $PLATFORM and $BUILD_TOOLS versions, then, this is a problem.

Signed-off-by: Luís Ferreira <contact@lsferreira.net>
@ljmf00
Copy link
Contributor Author

ljmf00 commented Aug 27, 2020

I added 3e0dfb1 patch to complete 1cf5918 .

rom1v pushed a commit that referenced this pull request Sep 15, 2020
This should increase the portability of bash scripts across various *nix
systems such as BSD-like distributions.

PR #1716 <#1716>

Signed-off-by: Luís Ferreira <contact@lsferreira.net>
Signed-off-by: Romain Vimont <rom@rom1v.com>
rom1v added a commit that referenced this pull request Sep 15, 2020
@rom1v
Copy link
Collaborator

rom1v commented Sep 15, 2020

I merged the "shebang" patch (02a882a) in to dev, as well as #426 and 1c44dc2.

vanhoagtu72 added a commit to vanhoagtu72/scrcpy that referenced this pull request May 15, 2021
vanhoagtu72 added a commit to vanhoagtu72/scrcpy that referenced this pull request May 15, 2021
vanhoagtu72 added a commit to vanhoagtu72/scrcpy that referenced this pull request May 15, 2021
@ljmf00
Copy link
Contributor Author

ljmf00 commented Jun 6, 2022

I merged the "shebang" patch (02a882a) in to dev, as well as #426 and 1c44dc2.

That said, I'm closing this.

@ljmf00 ljmf00 closed this Jun 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants