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

make: fix possible PATH issues #1630

Merged
merged 1 commit into from
Jul 11, 2023

Conversation

benoit-pierre
Copy link
Contributor

@benoit-pierre benoit-pierre commented Jul 10, 2023

Ensure our possibly updated PATH variable is taken into account for all $(shell …) invocations.

Additionally, add a couple of sanity checks after some of those invocations). Nope, still sloppy…


This change is Reviewable

Makefile.defs Outdated
else
SHARED_STL_LIB:=$(shell PATH='$(PATH)' $(CC) -print-file-name=libstdc++.so.6)
endif
# TODO: Detect/support libc++ Clang TCs?
Copy link
Member

@NiLuJe NiLuJe Jul 10, 2023

Choose a reason for hiding this comment

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

I have some make nastiness for that, FWIW.

(Probably ripped inspired from Linux's makefiles, IIRC).

Copy link
Member

@NiLuJe NiLuJe left a comment

Choose a reason for hiding this comment

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

I like it (assuming it works ;p).

@benoit-pierre
Copy link
Contributor Author

Oh, boy… I'm afraid to look at those logs.

@benoit-pierre
Copy link
Contributor Author

Of course, can't check if one those $(shell …) invocations was successful because we may not be building and need those variables…

@benoit-pierre
Copy link
Contributor Author

Sloppy it is, then.

@NiLuJe
Copy link
Member

NiLuJe commented Jul 10, 2023

Re-reading the docs (without testing anything so far), I'm mildly confused by all those existing shell + PATH hacks: the shell function is already supposed to pickup the env (and exported variables), and the only thing that actually updates PATH inside the makefiles is the Android stuff (... at least in base, the front one doesn't use export, which is either an oversight or I'm on not on the latest code).

@benoit-pierre
Copy link
Contributor Author

I know! ¯\(ツ)

But I can reproduce it when running the android docker image locally…

@NiLuJe
Copy link
Member

NiLuJe commented Jul 10, 2023

(... at least in base, the front one doesn't use export, which is either an oversight or I'm on not on the latest code).

Yeah, the front one was broken before, but is entirely gone after koreader/koreader@3ac8a67, and it's required by the MACHINE assignment, which is how you end up with a broken tuple ;).

@NiLuJe
Copy link
Member

NiLuJe commented Jul 10, 2023

But I can reproduce it when running the android docker image locally…

Is the Android TC perhaps already in your PATH in that environment?

@NiLuJe
Copy link
Member

NiLuJe commented Jul 10, 2023

Is the Android TC perhaps already in your PATH in that environment?

Which would explain https://github.com/koreader/koreader/blob/3ac8a67c6d39ce09f0cdbdfface63498857a6f22/Makefile#L34 successfully picking up the compiler on your end and not in the CI?

@benoit-pierre
Copy link
Contributor Author

But I can reproduce it when running the android docker image locally…

Is the Android TC perhaps already in your PATH in that environment?

Nope.

And no .SHELLSTATUS either, by the way. Maybe because the make version (4.1) is too old?

@NiLuJe
Copy link
Member

NiLuJe commented Jul 10, 2023

Oh, wait, I misread

But I can reproduce it when running the android docker image locally…

as cannot reproduce, oops. :D.

@benoit-pierre
Copy link
Contributor Author

And when compiling with my local environment, the android toolchain is not in the PATH either, but it works fine, maybe, again, because the make version is newer.

@NiLuJe
Copy link
Member

NiLuJe commented Jul 11, 2023

And no .SHELLSTATUS either, by the way. Maybe because the make version (4.1) is too old?

A (very) quick SO search seems to imply it's 4.2+, yeah :/.

(.SHELLSTATUS support, I mean).

@benoit-pierre
Copy link
Contributor Author

Yeah, I hate that the make documentation does not mention the version that first introduced a feature…

@NiLuJe
Copy link
Member

NiLuJe commented Jul 11, 2023

If all else fails, I'd try removing all the explicit PATH= hacks inside shell calls (and hope make is actually working as advertised on that front), but restoring an export PATH assignment in an Android branch in front ahead of the MACHINE assignment.

@NiLuJe
Copy link
Member

NiLuJe commented Jul 11, 2023

And when compiling with my local environment, the android toolchain is not in the PATH either

Extremely sneaky but stupid idea: do you have a PATH variable set in your environment (like, at all)?

@benoit-pierre
Copy link
Contributor Author

But we already do set PATH before (around line 147) the call to set TARGET_MACHINE (around line 559).

@benoit-pierre
Copy link
Contributor Author

And when compiling with my local environment, the android toolchain is not in the PATH either

Extremely sneaky but stupid idea: do you have a PATH variable set in your environment (like, at all)?

Yes.

@NiLuJe
Copy link
Member

NiLuJe commented Jul 11, 2023

But we already do set PATH before (around line 147) the call to set TARGET_MACHINE (around line 559).

Which makefile are we talking about here? ^^

And when compiling with my local environment, the android toolchain is not in the PATH either

Extremely sneaky but stupid idea: do you have a PATH variable set in your environment (like, at all)?

Yes.

Does it work with PATH entirely unset and gone from the env?

@benoit-pierre
Copy link
Contributor Author

But we already do set PATH before (around line 147) the call to set TARGET_MACHINE (around line 559).

Which makefile are we talking about here? ^^

base/Makefile.defs.

And when compiling with my local environment, the android toolchain is not in the PATH either

Extremely sneaky but stupid idea: do you have a PATH variable set in your environment (like, at all)?

Yes.

Does it work with PATH entirely unset?

I've not checked, but the nightly build script does set PATH.

@NiLuJe
Copy link
Member

NiLuJe commented Jul 11, 2023

Possibly related (or not, I can never grok how the fuck these assignments differ in practice), but MACHINE uses =, while most everything else uses := (because that one is less awful, in my experience ;D).

@NiLuJe
Copy link
Member

NiLuJe commented Jul 11, 2023

I've not checked, but the nightly build script does set PATH.

I don't recall if the front CI does, though.

@benoit-pierre
Copy link
Contributor Author

From TARGET_MARCHINE. :P

@NiLuJe
Copy link
Member

NiLuJe commented Jul 11, 2023

But we already do set PATH before (around line 147) the call to set TARGET_MACHINE (around line 559).

Which makefile are we talking about here? ^^

base/Makefile.defs.

Oh, true, but I have an inkling it might the front one failing: https://github.com/koreader/koreader/blob/3ac8a67c6d39ce09f0cdbdfface63498857a6f22/Makefile#L34

(And I'm not sure if it isn't actually assigned before the base includes (with its proper PATH export) gets processed, because make is weird or something).

@benoit-pierre
Copy link
Contributor Author

But we already do set PATH before (around line 147) the call to set TARGET_MACHINE (around line 559).

Which makefile are we talking about here? ^^

base/Makefile.defs.

Oh, true, but I have an inkling it might the front one failing: https://github.com/koreader/koreader/blob/3ac8a67c6d39ce09f0cdbdfface63498857a6f22/Makefile#L34

Why are we duplicating those variables?

It's still done after including base/Makefile.defs, so after setting PATH.

@NiLuJe
Copy link
Member

NiLuJe commented Jul 11, 2023

Why are we duplicating those variables?

It's still done after including base/Makefile.defs, so after setting PATH.

Yeah, see my edits above, that's what I'm not sure on because of the seven billion ways there are to assign variables in make, I'm not sure the sensible thing is actually what's happening here...

@benoit-pierre
Copy link
Contributor Author

Since it's set with =, it's only going to be expanded on use, so even later, so is something messing with PATH / CC before that?

@NiLuJe
Copy link
Member

NiLuJe commented Jul 11, 2023

We can't guarantee that base will be checked out yet at the time the fetchthirdparty target is called, so we don't necessarily have those defines yet?

That would both explain the weird duplication, and the silently-failing include (-include).

@NiLuJe
Copy link
Member

NiLuJe commented Jul 11, 2023

(I may have lost the plot a little, it's 2AM, sorry if I'm making less and less sense ;p)

@benoit-pierre
Copy link
Contributor Author

It's definitively an issue with older make versions:

▸ env PATH=/bin:/usr/bin make41 -f - <<\EOF
export PATH=/pouet:/bin:/usr/bin
$(error $(shell echo "$$PATH"))
EOF
/tmp/Gm4xFbl8:2: *** /bin:/usr/bin.  Stop.
▸ env PATH=/bin:/usr/bin make43 -f - <<\EOF
export PATH=/pouet:/bin:/usr/bin
$(error $(shell echo "$$PATH"))
EOF
/tmp/Gm3Vvgp6:2: *** /bin:/usr/bin.  Stop.
▸ env PATH=/bin:/usr/bin make44 -f - <<\EOF
export PATH=/pouet:/bin:/usr/bin
$(error $(shell echo "$$PATH"))
EOF
/tmp/GmGMUP9D:2: *** /pouet:/bin:/usr/bin.  Stop.

@benoit-pierre
Copy link
Contributor Author

Let me amend the code / commit message to mention that.

Ensure our possibly updated `PATH` variable is picked up by
`$(shell …)` invocations when using older (<4.4) make versions.
@benoit-pierre
Copy link
Contributor Author

OK, I think this can be merged. And then bump base again, and… wait for the next nightly?

@NiLuJe
Copy link
Member

NiLuJe commented Jul 11, 2023

I can't find any mention of the behavior change in the NEWS file, FWIW, yaaay -_-".

@NiLuJe
Copy link
Member

NiLuJe commented Jul 11, 2023

I can't find any mention of the behavior change in the NEWS file, FWIW, yaaay -_-".

Actually, I can, it sure helps if I look at the right version xD.

* WARNING: Backward-incompatibility!
  Previously makefile variables marked as export were not exported to commands
  started by the $(shell ...) function.  Now, all exported variables are
  exported to $(shell ...).  If this leads to recursion during expansion, then
  for backward-compatibility the value from the original environment is used.
  To detect this change search for 'shell-export' in the .FEATURES variable.

(In 4.4)

@NiLuJe NiLuJe merged commit 2c09cd2 into koreader:master Jul 11, 2023
2 checks passed
@benoit-pierre benoit-pierre deleted the pr/fix_possible_PATH_issue branch July 11, 2023 01:08
benoit-pierre added a commit to benoit-pierre/koreader that referenced this pull request Jul 11, 2023
benoit-pierre added a commit to benoit-pierre/koreader that referenced this pull request Jul 11, 2023
NiLuJe pushed a commit to koreader/koreader that referenced this pull request Jul 11, 2023
@Frenzie
Copy link
Member

Frenzie commented Jul 11, 2023

And when compiling with my local environment, the android toolchain is not in the PATH either, but it works fine, maybe, again, because the make version is newer.

I can and afaik only 4.4 is newer.

$ make --version
GNU Make 4.3
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Edit: sorry, commented too fast. I see you figured that out too.

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

3 participants