Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 130655 - best_version problems
Summary: best_version problems
Status: RESOLVED FIXED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Core - Ebuild Support (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Portage team
URL:
Whiteboard:
Keywords: InVCS
Depends on:
Blocks: 115839
  Show dependency tree
 
Reported: 2006-04-20 13:41 UTC by Alexandru Toma
Modified: 2006-05-13 15:24 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
bad.sh (bad.sh,93 bytes, text/plain)
2006-04-20 13:42 UTC, Alexandru Toma
Details
good.sh (good.sh,99 bytes, text/plain)
2006-04-20 13:43 UTC, Alexandru Toma
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alexandru Toma 2006-04-20 13:41:21 UTC
I am trying to write an ebuild and best_version is driving me nuts :(

I am trying to write something like this:
best_version blah/blah && a="foo" || a="moo"
but it always returned a="foo" regardless of whether blah/blah was installed or not

Then I tried this:
if best_version lah/blah ; then
   a="foo"
else
   a="moo"
fi

which had the same result.

After that I hit Bugzilla and found bug #34814 in which it is clearly mentioned that the correct syntax is "if best_version blah/blah ; then". Not only that, but I also remember being told by a developer the same thing (it was for use though, not best_version). And lastly, the same syntax is used in man 5 ebuild, for "use" again.

After all of this I tried using the wrong (deprecated) syntax... and it worked!
So, after wasting a few hours trying to figure this out, I would like a developer to make light in this situation:

What is the correct syntax?
Why is the syntax not consistent?
Comment 1 Alexandru Toma 2006-04-20 13:42:43 UTC
Created attachment 85064 [details]
bad.sh

Script showing the correct (recommended) syntax which, unfortunately, doesn't work
Comment 2 Alexandru Toma 2006-04-20 13:43:25 UTC
Created attachment 85065 [details]
good.sh

Script showing the old (deprecated) syntax which works
Comment 3 Tuan Van (RETIRED) gentoo-dev 2006-04-20 17:08:41 UTC
tvan@mars ~ $ portageq --help
...
   has_version <root> <category/package>
      Return code 0 if it's available, 1 otherwise.
...
   best_version <root> <category/package>
      Returns category/package-version (without .ebuild).
...

tvan@mars ~ $ portageq best_version / 'sys-apps/portage'
sys-apps/portage-2.1_pre7-r5
tvan@mars ~ $ echo $?
0
tvan@mars ~ $ portageq best_version / 'sys-apps/foo'

tvan@mars ~ $ echo $?
0
tvan@mars ~ $ portageq has_version / 'sys-apps/portage'
tvan@mars ~ $ echo $?
0
tvan@mars ~ $ portageq has_version / 'sys-apps/foo'
tvan@mars ~ $ echo $?
1

for what you want to do, has_version is the one to use.

tvan@mars ~ $ if portageq has_version / 'sys-apps/portage'; then echo "yes" ;else echo "no"; fi
yes
tvan@mars ~ $ if portageq has_version / 'sys-apps/foo'; then echo "yes"; else echo "no"; fi
no
Comment 4 Alexandru Toma 2006-04-20 17:19:51 UTC
> for what you want to do, has_version is the one to use.
I didn't realize that you could use has_version with just the package name, without any version number. man 5 ebuild would make you think that a version is required


> tvan@mars ~ $ portageq best_version / 'sys-apps/portage'
> sys-apps/portage-2.1_pre7-r5
> tvan@mars ~ $ echo $?
> 0
> tvan@mars ~ $ portageq best_version / 'sys-apps/foo'
>
> tvan@mars ~ $ echo $?
> 0

There must be something wrong somewhere since man 5 ebuild says:
"The function returns 0  if there  is  a  package that matches package name. Otherwise, the function will return 1."

Please nothe the last sentence... When does best_version return 1 since in your example it always returns 0 regardless of whether the package is installed or not? Maybe I'm missing something here.

Thnak you.
Comment 5 Simon Stelling (RETIRED) gentoo-dev 2006-05-02 11:55:21 UTC
the behaviour demonstrated in comment 3 is correct, this is a documentation bug.

or rather, it was one in revisions < 3310 *g*
Comment 6 Zac Medico gentoo-dev 2006-05-13 15:24:30 UTC
This has been released in 2.1_rc1.