Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Custom Ebuild - Help Me With the Install Portion!
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
NTibbitts
n00b
n00b


Joined: 04 Mar 2022
Posts: 16

PostPosted: Sun Sep 10, 2023 8:59 pm    Post subject: Custom Ebuild - Help Me With the Install Portion! Reply with quote

Hi all, you may have seen me around, asking about how to fix ebuilds. Well, I've graduated to trying to write my own. There's a service I need for work called Cloudfoundry, yet there aren't any ebuilds. Surprising, since it's open source software. Unsurprising, since basically no one uses it.

Here is my ebuild, with any identifying information left out. So far, what works is building from source. What DOESN'T work is patching the make file, and then running the custom install command.

I do not intend to distribute my custom Ebuild Repo, just fyi.

I don't have much experience with makefiles, but the install should do the following:

Code:

echo "copying binaries"
cp -r /path/to/binaries /usr/bin
echo "Done! Have a nice day"


There are literally no libraries to worry about, all that's needed is the cf-cli binaries.

Here is the ebuild, it's pretty short.

Code:
# Ebuild System Copyright 1999-2023 Gentoo Authors
#This Ebuild Copyright N Tibbitts.
# Distributed under the terms of the GNU General Public License v2
EAPI=7
DESCRIPTION="The Cloudfoundry PAAS CLI Tool"
HOMEPAGE="https://github.com/cloudfoundry/cli/"
SRC_URI="https://github.com/cloudfoundry/cli/archive/refs/tags/v${PV}.tar.gz"
export S=${WORKDIR}/cli-${PV}
LICENSE="GPL-2"
SLOT="0"
KEYWORDS="amd64"
IUSE=""
DEPEND=""
RDEPEND="${DEPEND}"
BDEPEND="dev-lang/go"
PATCHES="/var/db/repos/tibbitts/app-containers/cloudfoundry-cli/make.patch"
src_unpack(){
  unpack "v${PV}.tar.gz"
}
src_compile(){
  make build
}
src_install() {
  echo ${FILESDIR}
  emake DESTDIR="${D}" install
}


The patch, made with Diff:

Code:

> install:
> @cp --recursive out/cf /usr/bin
> @ln -s /usr/bin/cf /usr/bin/cf8
>


Finally, the error:

Code:

gpatch: **** Only garbage was found in the patch input.                                                                               [ !! ]


I am curious what is wrong with the patch, syntax wise. Everything leads back to that.

I have built LFS and used Gentoo as my main system for quite a while, but this is a conundrum.

Solved. Simple solution was to look closer at the diff/patch documentation. I forgot to add -Run to it.

Patch is NOW
Code:

--- /var/tmp/portage/app-containers/cloudfoundry-cli-8.7.2/work/cli-8.7.2/Makefile  2023-09-10 15:07:56.496730795 -0000
+++ /var/tmp/portage/app-containers/cloudfoundry-cli-8.7.2/work/cli-8.7.2/Makefile 2023-09-10 15:07:49.463397382 -0000

@@ -232,4 +232,5 @@
 help:
        @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-34s\033[0m %s\n", $$1, $$2}'
+- install:
+ @cp --recursive out/cf /usr/bin
+ @ln -s /usr/bin/cf /usr/bin/cf8


_________________
~NTibbitts


Last edited by NTibbitts on Mon Sep 11, 2023 2:25 am; edited 2 times in total
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 21918

PostPosted: Sun Sep 10, 2023 9:20 pm    Post subject: Reply with quote

That patch looks ill-formed. Where does it set what file to patch? Where is the line number information? How exactly did you generate it? Normally, you should use diff -u from one directory above the files.
Back to top
View user's profile Send private message
NTibbitts
n00b
n00b


Joined: 04 Mar 2022
Posts: 16

PostPosted: Sun Sep 10, 2023 9:28 pm    Post subject: Reply with quote

Hu wrote:
That patch looks ill-formed. Where does it set what file to patch? Where is the line number information? How exactly did you generate it? Normally, you should use diff -u from one directory above the files.


Thank you, I realized that moments before you posted this help

I have updated it, with slightly more success this time.

Now it successfully finds the patch, and even knows which files to apply it to, but it does not apply successfully.

The error is
Code:

gpatch: **** malformed patch at line 8: + @cp --recursive out/cf /usr/bin


_________________
~NTibbitts
Back to top
View user's profile Send private message
sam_
Developer
Developer


Joined: 14 Aug 2020
Posts: 1721

PostPosted: Sun Sep 10, 2023 9:30 pm    Post subject: Reply with quote

Keep in mind that patches are whitespace sensitive (so copy/pasting may mangle it) and that crafting them manually if you have done is not a good idea. Make sure to generate with diff or git diff and just pipe to a file in /etc/portage/patches or the repository in question.
Back to top
View user's profile Send private message
NTibbitts
n00b
n00b


Joined: 04 Mar 2022
Posts: 16

PostPosted: Sun Sep 10, 2023 9:50 pm    Post subject: Reply with quote

sam_ wrote:
Keep in mind that patches are whitespace sensitive (so copy/pasting may mangle it) and that crafting them manually if you have done is not a good idea. Make sure to generate with diff or git diff and just pipe to a file in /etc/portage/patches or the repository in question.


I figured out the original problem that required a patch to the makefile in the first place. It was my misunderstanding of Portage...

Hopefully this Ebuild works...

Code:

# Copyright 1999-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=7
DESCRIPTION="The Cloudfoundry PAAS CLI Tool"
HOMEPAGE="https://github.com/cloudfoundry/cli/"
SRC_URI="https://github.com/cloudfoundry/cli/archive/refs/tags/v${PV}.tar.gz"
export S=${WORKDIR}/cli-${PV}
LICENSE="GPL-2"
SLOT="0"
KEYWORDS="amd64"
IUSE=""
DEPEND=""
RDEPEND="${DEPEND}"
BDEPEND="dev-lang/go"
src_prepare(){
}
src_unpack(){
  unpack "v${PV}.tar.gz"
}
src_compile(){
  make build
}
src_install() {
  echo ${FILESDIR}
  cp "${WORKDIR}/out/cf" "/usr/bin"
  ln -sf "/usr/bin/cf8" "/usr/bin/cf"
}



Edit: DRAT. Everything goes well besides the symlink and copy commands. It throws a permission denied error.

Edit 2: This error is by design apparently. Oh well, I can copy the binaries to ~/bin, that should work if it's in my path.
_________________
~NTibbitts
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 21918

PostPosted: Sun Sep 10, 2023 10:20 pm    Post subject: Reply with quote

The revised patch as posted is wrong, because it tries to write to the live filesystem. That is not allowed, and has not been good practice for decades. Per the ebuild documentation, you need to install the files under $D, and let Portage manage them from there.

Incidentally, it looks like your src_unpack could be removed as redundant. Also, I would use the SRC_URI arrow operator to assign a more meaningful local filename to the downloaded archive.
Back to top
View user's profile Send private message
NTibbitts
n00b
n00b


Joined: 04 Mar 2022
Posts: 16

PostPosted: Mon Sep 11, 2023 2:27 am    Post subject: Custom Ebuild - Help Me With the Install Portion! [Solved] Reply with quote

Hu wrote:
The revised patch as posted is wrong, because it tries to write to the live filesystem. That is not allowed, and has not been good practice for decades. Per the ebuild documentation, you need to install the files under $D, and let Portage manage them from there.

Incidentally, it looks like your src_unpack could be removed as redundant. Also, I would use the SRC_URI arrow operator to assign a more meaningful local filename to the downloaded archive.


I have rewritten the ebuild. A few points:

vendor.tar.gz is under localhost because of an issue with retrieving local files.

It doesn't extract properly because the first file overwrites the second. Is there a way to prevent this?

Code:

# Distributed under the terms of the GNU General Public License v2

EAPI=7

inherit go-module

KEYWORDS="amd64"
DESCRIPTION="Service orchestration and management tool"
HOMEPAGE="https://github.com/cloudfoundry/cli"
SRC_URI="https://github.com/cloudfoundry/cli/archive/refs/tags/v8.7.2.tar.gz -> $P.tar.gz \
http://localhost/vendor.tar.gz"
SLOT="0"
LICENSE="GNU GPL2"
IUSE=""
BDEPEND=""
RDEPEND=""
S=/var/tmp/portage/app-containers/cloudfoundry-cli-8.7.2/work
src_prepare() {
   default
   
}
src_unpack(){
   unpack $P.tar.gz
   mkdir cli-8.7.2/vendor && cd cli-8.7.2/vendor/
   unpack "/var/cache/distfiles/vendor.tar.gz"
   
}

src_compile() {
   echo $PWD
   cd cli-8.7.2
   mkdir -p "${S}/cli-8.7.2/out/cf"
   go build -o "${S}/cli-8.7.2/out/cf"
   ls "${S}/cli-8.7.2/out"
}

src_install() {
   cp -R "${S}/" "${D}/" || die "Install failed!"
}




Done. Solved, I guess.

Edit: Still not solved. I did find a workaround in writing an ebuild for a binary package:

Code:

# Copyright 1999-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
 
EAPI=8
export S=/var/tmp/portage/app-containers/cloudfoundry-cli-bin-8.7.2/work/
DESCRIPTION="The Cloudfoundry PAAS CLI Tool"
HOMEPAGE="https://github.com/cloudfoundry/cli/"
SRC_URI="https://s3-us-west-1.amazonaws.com/v8-cf-cli-releases/releases/v8.7.2/cf8-cli_8.7.2_linux_x86-64.tgz"
LICENSE="GPL-2"
SLOT="0"
KEYWORDS="amd64"
IUSE=""
DEPEND=""
RDEPEND="${DEPEND}"
BDEPEND="dev-lang/go"
 
src_install(){
        mkdir -p "${D}/usr/bin"
        cp -R "${S}/cf" "${D}/usr/bin"
        cp -R "${S}/cf8" "${D}/usr/bin"
}


_________________
~NTibbitts
Back to top
View user's profile Send private message
Genone
Retired Dev
Retired Dev


Joined: 14 Mar 2003
Posts: 9559
Location: beyond the rim

PostPosted: Mon Sep 11, 2023 6:44 am    Post subject: Reply with quote

You shouldn't use cp/ln/mkdir directly in ebuilds, but rather the provided wrappers like dobin (see https://dev.gentoo.org/~zmedico/portage/doc/man/ebuild.5.html ). Also you want to variables like ${PV} instead of hardcoding version numbers in your functions. And esp. you do not want to use hardcoded absolute paths anywhere.
Back to top
View user's profile Send private message
logrusx
Veteran
Veteran


Joined: 22 Feb 2018
Posts: 1751

PostPosted: Mon Sep 11, 2023 7:32 am    Post subject: Reply with quote

To add to Genone's input, here's a list of variables available in any ebuild (there could be other variables depending on the eclasses used) with their description.

When not sure what to do, you can browse other ebuilds for inspiration too.

Best Regards,
Georgi
Back to top
View user's profile Send private message
logrusx
Veteran
Veteran


Joined: 22 Feb 2018
Posts: 1751

PostPosted: Mon Sep 11, 2023 8:43 am    Post subject: Reply with quote

BTW patching makefiles is not a good practice. And since this project doesn't have an install on its own, there are some functions like insinto, doins and similar that can be used instead.

Best Regards,
Georgi
Back to top
View user's profile Send private message
NTibbitts
n00b
n00b


Joined: 04 Mar 2022
Posts: 16

PostPosted: Mon Sep 11, 2023 3:10 pm    Post subject: Reply with quote

logrusx wrote:
BTW patching makefiles is not a good practice. And since this project doesn't have an install on its own, there are some functions like insinto, doins and similar that can be used instead.

Best Regards,
Georgi


Thanks for the advice, and thanks to Genone for best practices information
Genone wrote:
You shouldn't use cp/ln/mkdir directly in ebuilds, but rather the provided wrappers like dobin (see https://dev.gentoo.org/~zmedico/portage/doc/man/ebuild.5.html ). Also you want to variables like ${PV} instead of hardcoding version numbers in your functions. And esp. you do not want to use hardcoded absolute paths anywhere.


I have rewritten the ebuild, and all seems to go well:

Code:
# Copyright 1999-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
 
EAPI=8
export S=$WORKDIR
DESCRIPTION="The Cloudfoundry PAAS CLI Tool"
HOMEPAGE="https://github.com/cloudfoundry/cli/"
SRC_URI="https://s3-us-west-1.amazonaws.com/v8-cf-cli-releases/releases/v${PV}/cf8-cli_${PV}_linux_x86-64.tgz"
LICENSE="GPL-2"
SLOT="0"
KEYWORDS="amd64"
IUSE=""
DEPEND=""
RDEPEND="${DEPEND}"
BDEPEND="dev-lang/go"
 
src_install(){
   dobin $WORKDIR/cf $WORKDIR/cf8
}

_________________
~NTibbitts
Back to top
View user's profile Send private message
logrusx
Veteran
Veteran


Joined: 22 Feb 2018
Posts: 1751

PostPosted: Mon Sep 11, 2023 3:59 pm    Post subject: Reply with quote

Maybe you need to modify the licence, just for any case. I don't know how accepting licences works in ebuilds, but this is not GPL and if you intend to share the ebuild, that matter is better taken care of. At least modify it in the description so that eventual users are aware there are terms and conditions to using this.

One more thing, you're downloading a binary package, the name of the package should be cloudfoundry-cli-bin

Best Regards,
Georgi
Back to top
View user's profile Send private message
salahx
Guru
Guru


Joined: 12 Mar 2005
Posts: 534

PostPosted: Mon Sep 11, 2023 4:17 pm    Post subject: Reply with quote

ITS relatively easy to create a packages the traditional way that compiles the source and installs the binaries by folowing:this guide.

This worked for me: (as cloudfoundry-cli-8.7.2.ebuild)
Code:
# Copyright 1999-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

inherit go-module

DESCRIPTION="The Cloudfoundry PAAS CLI Tool"
HOMEPAGE="https://github.com/cloudfoundry/cli/"
SRC_URI="https://github.com/cloudfoundry/cli/archive/refs/tags/v${PV}.tar.gz -> ${P}.tar.gz"
SRC_URI+=" http://localhost:8000/${P}-deps.tar.xz"
LICENSE="Apache-2.0"

SLOT="0"
KEYWORDS="~amd64"
S="${WORKDIR}/cli-${PV}"

src_compile() {
   emake build
}

src_install() {
   dobin out/cf
}


The only tricky part is creating ${P}-deps.tar.xz .You'll need to comment out the 2nd URL_SRC line, then "ebuild cloudfoundry-cli-8.7.2.ebuild unpack". You'll get an error about "go mod verify", but that's ok, it'll still unpack the source for you in /var/tmp/portage . I had to use the "Dependency tarball" as the "Vendor tarball" did nto pull in all the dependencies. The liICENSE shoudl be adjusted too, as it statically links other modules with different licenses.
Back to top
View user's profile Send private message
NTibbitts
n00b
n00b


Joined: 04 Mar 2022
Posts: 16

PostPosted: Mon Sep 11, 2023 6:01 pm    Post subject: Reply with quote

logrusx wrote:
Maybe you need to modify the licence, just for any case. I don't know how accepting licences works in ebuilds, but this is not GPL and if you intend to share the ebuild, that matter is better taken care of. At least modify it in the description so that eventual users are aware there are terms and conditions to using this.

One more thing, you're downloading a binary package, the name of the package should be cloudfoundry-cli-bin

Best Regards,
Georgi


Georgi, the name of the package IS cloudfoundry-cli-bin.

Also, the source code of the package is freely available under the GPL-2 license, how is that different for a binary package? I'm just wondering so I can change it.
_________________
~NTibbitts
Back to top
View user's profile Send private message
logrusx
Veteran
Veteran


Joined: 22 Feb 2018
Posts: 1751

PostPosted: Tue Sep 12, 2023 4:04 am    Post subject: Reply with quote

NTibbitts wrote:
logrusx wrote:
Maybe you need to modify the licence, just for any case. I don't know how accepting licences works in ebuilds, but this is not GPL and if you intend to share the ebuild, that matter is better taken care of. At least modify it in the description so that eventual users are aware there are terms and conditions to using this.

One more thing, you're downloading a binary package, the name of the package should be cloudfoundry-cli-bin

Best Regards,
Georgi


Georgi, the name of the package IS cloudfoundry-cli-bin.

Also, the source code of the package is freely available under the GPL-2 license, how is that different for a binary package? I'm just wondering so I can change it.


I have mistakenly thought of another licence I didn't pay attention what it was. It was Contributor Licence Agreement for those who want to contribute.

Otherwise it's not GPL but Apache. Also binaries can be distributed by a different license. Your assumption that if the source has that license, the binaries must have the same is wrong.

Best Regards,
Georgi
Back to top
View user's profile Send private message
sam_
Developer
Developer


Joined: 14 Aug 2020
Posts: 1721

PostPosted: Tue Sep 12, 2023 4:21 am    Post subject: Reply with quote

logrusx wrote:
BTW patching makefiles is not a good practice. And since this project doesn't have an install on its own, there are some functions like insinto, doins and similar that can be used instead.

Best Regards,
Georgi


Not sure I agree with this bit. It's perfectly fine to patch Makefiles. What isn't okay is to patch generated Makefiles from autotools and such, where you should be patching Makefile.in or Makefile.am.
Back to top
View user's profile Send private message
logrusx
Veteran
Veteran


Joined: 22 Feb 2018
Posts: 1751

PostPosted: Tue Sep 12, 2023 10:17 am    Post subject: Reply with quote

sam_ wrote:
logrusx wrote:
BTW patching makefiles is not a good practice. And since this project doesn't have an install on its own, there are some functions like insinto, doins and similar that can be used instead.

Best Regards,
Georgi


Not sure I agree with this bit. It's perfectly fine to patch Makefiles. What isn't okay is to patch generated Makefiles from autotools and such, where you should be patching Makefile.in or Makefile.am.


Thank you for that clarification, it makes sense. I believe back when I read it somewhere in the devmanual or other information resources on the wiki surrounding that matter, I didn't have a good understanding an maybe I generalized it to mean all makefiles rather than generated only.

Best Regards,
Georgi
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum