这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@twaik
Copy link
Member

@twaik twaik commented Feb 27, 2025

Since this change is more or less harmless and will not affect most build cases except batch rebuilding I am going to merge this in 12 hours if there are no objections.

Also in this PR I am bumping abseil-cpp to test if cleaning up works because there are enough packages being rebuilt to fill the whole disk during CI run.

@twaik twaik requested a review from robertkirkman February 27, 2025 05:21
@twaik twaik force-pushed the termux_step_cleanup_packages branch 2 times, most recently from aca6ed6 to 53bc2a3 Compare February 27, 2025 05:30
@twaik
Copy link
Member Author

twaik commented Feb 27, 2025

CI finished building so I assume the solution works fine.
I see INFO: cleaning up some disk space for building "python-onnxruntime". in the log so we know we ran out of space and build system triggered cleanup successfully.

I will merge it in ~10 hours or after it gets 2+ approves.

@twaik twaik force-pushed the termux_step_cleanup_packages branch from 53bc2a3 to 67d913b Compare February 27, 2025 07:43
@twaik twaik merged commit d80704e into master Feb 27, 2025
11 checks passed
@twaik twaik deleted the termux_step_cleanup_packages branch February 27, 2025 14:11
@agnostic-apollo
Copy link
Member

agnostic-apollo commented Feb 27, 2025

This behavior should be enabled for ci with a env variable, not for local builds. Users may be building bootstrap with lot of packages, which may need to be rebuilt again, and deleting built files is a no go.

@truboxl
Copy link
Contributor

truboxl commented Feb 27, 2025

Zzz breaks on device build

df: Unknown option 'B' (see "df --help")
/data/data/com.termux/files/home/termux-package/scripts/build/termux_step_cleanup_packages.sh: line 8: [: : integer expression expected

@robertkirkman
Copy link
Member

This behavior should be enabled for ci with a env variable, not for local builds. Users may be building bootstrap with lot of packages, which may need to be rebuilt again, and deleting built files is a no go.

i can't think of a scenario in which building a bootstrap locally with this change would cause packages to be rebuilt multiple times, is that what you meant or do you mean something a little different?

If you mean that someone might be editing the code of packages and somehow repeatedly recompiling them intentionally without storing the changes as .patch files, then I see what you mean, I am just not sure whether many people do that.

@robertkirkman
Copy link
Member

df: Unknown option 'B'

In code I wrote in the past, there is a block for detecting available space on device that has been very heavily tested on many of my devices and others' devices, so it should not be affected by the same problem on any device. I'm sorry I should have mentioned it earlier but I forgot about it.

BLOCKS_FREE=$(awk -F ' ' '{print $4}' <(df ~ | tail -1))
if (( 5242880 > BLOCKS_FREE )); then
    echo "less than 5 GB available"
fi

if you end up keeping the termux_step_cleanup_packages() enabled in on device builds, this example might be adaptable to implement that.

@twaik
Copy link
Member Author

twaik commented Feb 27, 2025

We already use

local space_available="$(df -P "/var/lib/docker" | awk 'NR==2 {print $4}')"
and
if [[ "${big_package}" == "true" ]] || (( space_available <= 2 * 1024 ** 2 )); then
so we can reuse these lines here. They are compatible.

@TomJo2000
Copy link
Member

df: Unknown option 'B'

In code I wrote in the past, there is a block for detecting available space on device that has been very heavily tested on many of my devices and others' devices, so it should not be affected by the same problem on any device. I'm sorry I should have mentioned it earlier but I forgot about it.

BLOCKS_FREE=$(awk -F ' ' '{print $4}' <(df ~ | tail -1))
if (( 5242880 > BLOCKS_FREE )); then
    echo "less than 5 GB available"
fi

if you end up keeping the termux_step_cleanup_packages() enabled in on device builds, this example might be adaptable to implement that.

Could we replace that magic number with a named constant, or a equation and comment, or both.
e.g.
CLEANUP_THRESHOLD="$(( 5 * 1024 ** 3 ))"

@twaik
Copy link
Member Author

twaik commented Feb 27, 2025

CLEANUP_THRESHOLD="$(( 5 * 1024 ** 3 ))"

df outputs size in 1024 byte blocks. So `$(( 5 * 1024 ** 2 )).

@TomJo2000
Copy link
Member

forgot again

@twaik
Copy link
Member Author

twaik commented Feb 27, 2025

#23530

@agnostic-apollo
Copy link
Member

i can't think of a scenario in which building a bootstrap locally with this change would cause packages to be rebuilt multiple times

If you delete output directory with debs, then packages need to be rebuilt, and if you delete build progress, builds will start from scratch, which can take hours. Additionally, free disk space can vary on mobile device/docker, etc, and cleanup may not be required anyways for small packages. Any deletion should not be automatic, even force builds that cleanup packages require -f to be passed. Note that if you use a flag, the nested calls for dependencies will need to be forwarded the flag.

@twaik
Copy link
Member Author

twaik commented Feb 27, 2025

I do not see an option to pass environment variable from CI to build-package.sh in both docker and non-docker codepath. Can you provide an example?

@agnostic-apollo
Copy link
Member

agnostic-apollo commented Feb 27, 2025

if [ "$DOCKER_BUILD" == 'false' ]; then
NDK=$ANDROID_NDK ANDROID_HOME=$ANDROID_SDK_ROOT ./build-package.sh -I -a ${{ matrix.target_arch }} $packages
elif [ -n "$packages" ]; then
./scripts/run-docker.sh ./build-package.sh -I -a ${{ matrix.target_arch }} $packages
fi

@twaik
Copy link
Member Author

twaik commented Feb 27, 2025

Yes, I've seen it. But in this case ./build-package.sh does not receive it as environment variable, it is passed as a part of commandline.

@robertkirkman
Copy link
Member

If you delete output directory with debs, then packages need to be rebuilt

i might be wrong, but i did not think this change deletes the output directory with debs.

Any deletion should not be automatic

I agree with this concept, but I was not sure how important it is in this situation since twaik moved forward with a version that always runs regardless of whether it is in CI or not. If you think that this concept is very important to make sure that the data of people who are building packages with unknown custom configurations locally is not lost, then I agree with your opinion.

@twaik
Copy link
Member Author

twaik commented Feb 27, 2025

i might be wrong, but i did not think this change deletes the output directory with debs.

It does not.

If you think that this concept is very important to make sure that the data of people who are building packages with unknown custom configurations locally is not lost, then I agree with your opinion.

I agree too, but currently I am not really sure how to make it cleanup packages only in CI.

@agnostic-apollo
Copy link
Member

i might be wrong, but i did not think this change deletes the output directory with debs.

No it wont, but if someone deletes the deb/output directory as there are older or unneeded debs, etc, and then wants to rebuild them again, in that case if built progress was lost, then it will require rebuilding everything from scratch.

Yes, this cleanup must not be automatic. It needs to be specifically enabled for CI or if a user wants to.

@robertkirkman
Copy link
Member

I agree too, but currently I am not really sure how to make it cleanup packages only in CI.

It would be necessary to edit build-package.sh to have an additional argument for enabling the cleaning up packages step, and have the step only run when that argument is specified, then invoke build-package.sh with that argument in all locations where build-package.sh is called from CI, and also pass the argument to nested invocations of build-package.sh like agnostic-apollo mentioned.

@twaik
Copy link
Member Author

twaik commented Feb 27, 2025

Yes, this cleanup must not be automatic. It needs to be specifically enabled for CI or if a user wants to.

So how exactly should it be enabled? With additional argument or environment variable or something similar?

@agnostic-apollo
Copy link
Member

Yes, I've seen it. But in this case ./build-package.sh does not receive it as environment variable, it is passed as a part of commandline.

Pass an additional flag just like -I, I don't see an issue, it will need to be forwarded for build-package.sh call for dependencies. Env variables are also being passed for ndk.

@agnostic-apollo
Copy link
Member

Pass a flag like --cleanup-built-packages-on-low-storage.

@twaik
Copy link
Member Author

twaik commented Feb 27, 2025

@agnostic-apollo I pushed this change to #23530 as a part of fixing on-device building.

@agnostic-apollo
Copy link
Member

Thanks, should be fine. Continue build help entry will need to be removed from my pull though.

@twaik
Copy link
Member Author

twaik commented Feb 27, 2025

Thanks, should be fine

It would be an absolute honor if you hit that 'Approve' button for me! (I still not decided if it should be a joke or I am serious, but anyway it will be a pleasure to me).

@agnostic-apollo
Copy link
Member

lolz, there are other changes I haven't reviewed, I am away from laptop right now. You can consider the part of the flag as approved.

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.

6 participants