Skip to content

pkg/pkg.mk: Avoid doing a git fetch if we already have the commit.#11491

Closed
jcarrano wants to merge 2 commits intoRIOT-OS:masterfrom
jcarrano:pkg-avoid-empty-fetch
Closed

pkg/pkg.mk: Avoid doing a git fetch if we already have the commit.#11491
jcarrano wants to merge 2 commits intoRIOT-OS:masterfrom
jcarrano:pkg-avoid-empty-fetch

Conversation

@jcarrano
Copy link
Copy Markdown
Contributor

@jcarrano jcarrano commented May 6, 2019

Contribution description

D'oh! I screwed up a little in #11129 and a git fetch was being done for each package every time the user ran make.

If the commit is already in the local repo, we should not need to do any network operation.

Testing procedure

Type make twice in any example that uses packages. See how it is fetched twice. With this patch it is not.

Issues/PRs references

Bug introduced in #11129.

If the commit is already in the local repo, we should not need to
do any network operation.
@jcarrano jcarrano added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Area: build system Area: Build system Area: pkg Area: External package ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels May 6, 2019
@jcarrano jcarrano requested review from cladmi and kaspar030 May 6, 2019 09:20
pkg/pkg.mk Outdated
if [ $(shell git -C $(PKG_BUILDDIR) rev-parse HEAD) != $(PKG_VERSION) ] ; then \
git -C $(PKG_BUILDDIR) clean -xdff ; \
git -C $(PKG_BUILDDIR) fetch "$(PKG_URL)" "$(PKG_VERSION)" ; \
if git cat-file -e -t '$(PKG_VERSION)^{commit}' ; then \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

On ubuntu bionic, git does not like -e -t.
error: switch t' : incompatible with -e`.

I would like to maybe put it outside in a "git_check_version_is_a_commit" so document that it detects branches.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

git cat-file -e 2019.04^{commit} && echo commit
commit
git cat-file -e 2019.04-branch^{commit}
fatal: Not a valid object name 2019.04-branch^{commit}

Also works with a hash as expected.

Copy link
Copy Markdown
Contributor

@cladmi cladmi left a comment

Choose a reason for hiding this comment

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

Does not work with ubuntu bionic and comments inline.

I forgot the -C in git, also negate the condition and remove the -t.
@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented May 20, 2019

It does not re-fetch with tests/pkg_c25519 in master already.

@cladmi cladmi requested a review from dylad May 20, 2019 12:45
@kaspar030
Copy link
Copy Markdown
Contributor

t does not re-fetch with tests/pkg_c25519 in master already.

c25519 is not using git.

@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented May 20, 2019

t does not re-fetch with tests/pkg_c25519 in master already.

c25519 is not using git.

Ahhhh did not pay attention to that ><

@kaspar030
Copy link
Copy Markdown
Contributor

This PR is an improvement (unnecessary fetches are avoided). ACK.

@kaspar030
Copy link
Copy Markdown
Contributor

please rebase & squash!

@kaspar030
Copy link
Copy Markdown
Contributor

There are some other issues with "git_ensure_version":

  1. if the package specifies a tag (instead of commit hash), the initial comparison always fails.

  2. if the package is using patches, the initial comparison always fails.

The following "git clean" removes ".git_downloaded" and ".git_patched" unconditionally, causing any recursive make to re-do the clean and patch again.

@kaspar030
Copy link
Copy Markdown
Contributor

kaspar030 commented Jul 10, 2019

I found another issue: this currently does git -C<pkgdir> clean -xdff. If, for any reason, the pkgdir is not a git folder, git climbs up all the way to the RIOT checkout (looking for the git folder), then cleans that.

A check whether the to-be-cleaned folder is a git checkout needs to be added.

@jcarrano @MrKevinWeiss I think this is release critical, I lost quite some work because of this.

@MrKevinWeiss
Copy link
Copy Markdown
Contributor

MrKevinWeiss commented Jul 10, 2019

I think this is release critical, I lost quite some work because of this.

Noted, I push for it

@MrKevinWeiss MrKevinWeiss added the Process: needs backport Integration Process: The PR is required to be backported to a release or feature branch label Jul 10, 2019
@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Jul 10, 2019

I found another issue: this currently does git -C<pkgdir> clean -xdff. If, for any reason, the pkgdir is not a git folder, git climbs up all the way to the RIOT checkout (looking for the git folder), then cleans that.

All the code from pkg.mk supposes it is a git repository. The clean target does the same. Why would it not be one ?

@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Jul 10, 2019

For security To be safe, the git command could be replaced by git --git-dir=.git -C $(PKGDIR) as PKGDIR is supposed to be the root of the repository here.

However, this is somehow unrelated

@MrKevinWeiss
Copy link
Copy Markdown
Contributor

@jcarrano Is there anything holding up the squash?

@fjmolinas
Copy link
Copy Markdown
Contributor

I can't reproduce this issue in master, I believe this is fixed, can I close?

@fjmolinas fjmolinas added this to the Release 2020.01 milestone Jan 8, 2020
@fjmolinas fjmolinas removed the Process: needs backport Integration Process: The PR is required to be backported to a release or feature branch label Jan 8, 2020
@kaspar030
Copy link
Copy Markdown
Contributor

I can't reproduce this issue in master, I believe this is fixed, can I close?

nope, it is just quieted. Use e.g., this patch: https://gist.github.com/kaspar030/d0bcf4f38d91d2b7e785b8327da608be/raw

... then type make a couple of times in a git package with patches, e.g., tests/pkg_heatshrink.

@fjmolinas
Copy link
Copy Markdown
Contributor

@fjmolinas
Copy link
Copy Markdown
Contributor

  • First build:
make: Entering directory '/home/francisco/workspace/RIOT/tests/pkg_heatshrink'
Building application "tests_pkg_heatshrink" for "native" with MCU "native".

[INFO] cloning heatshrink
Cloning into '/home/francisco/workspace/RIOT/tests/pkg_heatshrink/bin/pkg/native/heatshrink'...
remote: Enumerating objects: 442, done.
remote: Total 442 (delta 0), reused 0 (delta 0), pack-reused 442
Receiving objects: 100% (442/442), 177.36 KiB | 868.00 KiB/s, done.
Resolving deltas: 100% (264/264), done.
HEAD is now at 7d419e1 Update contact info.
[INFO] updating heatshrink /home/francisco/workspace/RIOT/tests/pkg_heatshrink/bin/pkg/native/heatshrink/.pkg-state.git-downloaded
echo 7d419e1fa4830d0b919b9b6a91fe2fb786cf3280 > /home/francisco/workspace/RIOT/tests/pkg_heatshrink/bin/pkg/native/heatshrink/.pkg-state.git-downloaded
[INFO] patch heatshrink
"make" -C /home/francisco/workspace/RIOT/pkg/heatshrink
"make" -C /home/francisco/workspace/RIOT/tests/pkg_heatshrink/bin/pkg/native/heatshrink -f /home/francisco/workspace/RIOT/pkg/heatshrink/Makefile.heatshrink
"make" -C /home/francisco/workspace/RIOT/boards/native
"make" -C /home/francisco/workspace/RIOT/boards/native/drivers
"make" -C /home/francisco/workspace/RIOT/core
"make" -C /home/francisco/workspace/RIOT/cpu/native
"make" -C /home/francisco/workspace/RIOT/cpu/native/periph
"make" -C /home/francisco/workspace/RIOT/cpu/native/stdio_native
"make" -C /home/francisco/workspace/RIOT/cpu/native/vfs
"make" -C /home/francisco/workspace/RIOT/drivers
"make" -C /home/francisco/workspace/RIOT/drivers/periph_common
"make" -C /home/francisco/workspace/RIOT/sys
"make" -C /home/francisco/workspace/RIOT/sys/auto_init
"make" -C /home/francisco/workspace/RIOT/sys/embunit
"make" -C /home/francisco/workspace/RIOT/sys/test_utils/interactive_sync
   text    data     bss     dec     hex filename
  39465     668   50088   90221   1606d /home/francisco/workspace/RIOT/tests/pkg_heatshrink/bin/native/tests_pkg_heatshrink.elf
make: Leaving directory '/home/francisco/workspace/RIOT/tests/pkg_heatshrink'
  • second:
make: Entering directory '/home/francisco/workspace/RIOT/tests/pkg_heatshrink'
Building application "tests_pkg_heatshrink" for "native" with MCU "native".

make[1]: Nothing to be done for 'prepare'.
"make" -C /home/francisco/workspace/RIOT/pkg/heatshrink
"make" -C /home/francisco/workspace/RIOT/tests/pkg_heatshrink/bin/pkg/native/heatshrink -f /home/francisco/workspace/RIOT/pkg/heatshrink/Makefile.heatshrink
"make" -C /home/francisco/workspace/RIOT/boards/native
"make" -C /home/francisco/workspace/RIOT/boards/native/drivers
"make" -C /home/francisco/workspace/RIOT/core
"make" -C /home/francisco/workspace/RIOT/cpu/native
"make" -C /home/francisco/workspace/RIOT/cpu/native/periph
"make" -C /home/francisco/workspace/RIOT/cpu/native/stdio_native
"make" -C /home/francisco/workspace/RIOT/cpu/native/vfs
"make" -C /home/francisco/workspace/RIOT/drivers
"make" -C /home/francisco/workspace/RIOT/drivers/periph_common
"make" -C /home/francisco/workspace/RIOT/sys
"make" -C /home/francisco/workspace/RIOT/sys/auto_init
"make" -C /home/francisco/workspace/RIOT/sys/embunit
"make" -C /home/francisco/workspace/RIOT/sys/test_utils/interactive_sync
   text    data     bss     dec     hex filename
  39465     668   50088   90221   1606d /home/francisco/workspace/RIOT/tests/pkg_heatshrink/bin/native/tests_pkg_heatshrink.elf
make: Leaving directory '/home/francisco/workspace/RIOT/tests/pkg_heatshrink'

@fjmolinas
Copy link
Copy Markdown
Contributor

nope, it is just quieted. Use e.g., this patch: https://gist.github.com/kaspar030/d0bcf4f38d91d2b7e785b8327da608be/raw

That is not master.

Or maybe this one is still a smarter way of fetching event if its not fetch on each make incocation?

@aabadie
Copy link
Copy Markdown
Contributor

aabadie commented Jun 26, 2020

The problem targeted by this PR was fixed by #13036, which is already merged. I'm closing this one but feel free to re-open if you disagree.

@aabadie aabadie closed this Jun 26, 2020
@fjmolinas
Copy link
Copy Markdown
Contributor

I don't thing it is fixed #13036 does not address smart fetching.

@aabadie aabadie reopened this Jun 26, 2020
@aabadie
Copy link
Copy Markdown
Contributor

aabadie commented Jun 28, 2020

I don't thing it is fixed #13036 does not address smart fetching.

Can you elaborate on this ? I'm trying to reproduce the issue on master and I can't: git fetch is not called anymore on a package that is already cloned/patched.

@maribu
Copy link
Copy Markdown
Member

maribu commented Jul 15, 2020

@fjmolinas: Ping?

@kaspar030
Copy link
Copy Markdown
Contributor

Is this still a thing? Anyhow, I'll postpone this as it doesn't seem to break anything ATM.

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

Labels

Area: build system Area: Build system Area: pkg Area: External package ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants