You are not logged in.

#1 2013-01-16 15:52:53

Gyroplast
Member
From: Germany
Registered: 2002-09-03
Posts: 166
Website

Sample eclipse PKGBUILD on wiki broken?

Greetings!

While packaging several eclipse plugins, I dutifully followed the appropriate package guidelines. However, the sample PKGBUILD listed in the wiki strikes me a subtly incorrect. I would like your opinion before I "fix" such a central piece of information.
Please consider this code excerpt:

  # Features
  find features -type f | while read _feature ; do
    if [[ ${_feature} =~ (.*\.jar$) ]] ; then
      install -dm755 ${_dest}/${_feature%*.jar}
      cd ${_dest}/${_feature/.jar}
      jar xf ${srcdir}/${_feature} || return 1
    else
      install -Dm644 ${_feature} ${_dest}/${_feature}
    fi
  done

Take note of the "cd" in there. It changes into a target directory to unpack a feature jar, but never changes back to the srcdir. It never broke for me, until now, and I'm rather sure this is due to the fact that my package (eclipse-subversive) contains *.jar.pack.gz files in it's features/ sources, i.e. anything NOT matching .*\.jar$, and thus entering the else-branch in that code, which simply never happened to me, yet!

The fix seems simple: Add a 'cd -' when done, right before the 'else' to go back to the last working directory after jar did it's dirty deeds:

  # Features
  find features -type f | while read _feature ; do
    if [[ ${_feature} =~ (.*\.jar$) ]] ; then
      install -dm755 ${_dest}/${_feature%*.jar}
      cd ${_dest}/${_feature/.jar}
      jar xf ${srcdir}/${_feature} || return 1
      cd - >/dev/null
    else
      install -Dm644 ${_feature} ${_dest}/${_feature}
    fi
  done

Apart from that, I'm only noticing a lack of quoting. I have a habit of sprinkling quotes around these variables in my builds, just in case someone makes the package in a strange path.

Therefore I'd propose to adopt this as a standard example build() function in the Wiki, as I have made good experiences with it so far for a dozen or more builds:

build() {
  _dest="${pkgdir}/usr/share/eclipse/dropins/${pkgname/eclipse-}/eclipse"

  cd "${srcdir}"

  # Features
  find features -type f | while read _feature ; do
    if [[ "${_feature}" =~ (.*\.jar$) ]] ; then
      install -dm755 "${_dest}/${_feature%*.jar}"
      # change into target dir, since "jar xf" only extracts to current working directory
      cd "${_dest}/${_feature/.jar}"
      jar xf "${srcdir}/${_feature}" || return 1
      # go back to last working directory silently
      cd - >/dev/null
    else
      install -Dm644 "${_feature}" "${_dest}/${_feature}"
    fi
  done

  # Plugins
  find plugins -type f | while read _plugin ; do
    install -Dm644 "${_plugin}" "${_dest}/${_plugin}"
  done
}

Am I overlooking something? Any comments or objections?

Last edited by Gyroplast (2013-01-16 15:56:08)


"That's the problem with good advice. Nobody wants to hear it."
-- Dogbert

Offline

#2 2013-01-16 17:01:23

tdy
Member
From: Sacremende
Registered: 2008-12-14
Posts: 438

Re: Sample eclipse PKGBUILD on wiki broken?

Gyroplast wrote:

Take note of the "cd" in there. It changes into a target directory to unpack a feature jar, but never changes back to the srcdir. It never broke for me, until now, and I'm rather sure this is due to the fact that my package (eclipse-subversive) contains *.jar.pack.gz files in it's features/ sources, i.e. anything NOT matching .*\.jar$, and thus entering the else-branch in that code, which simply never happened to me, yet!

The fix seems simple: Add a 'cd -' when done, right before the 'else' to go back to the last working directory after jar did it's dirty deeds:

You can use a subshell to handle the chdir. You'll automatically jump back to the previous dir after you leave the parentheses.

(cd $_dest/${_feature/.jar} && jar xf $srcdir/$_feature)

(another example seen in /usr/share/pacman/PKGBUILD-svn.proto)

Offline

#3 2013-01-16 17:12:54

Gyroplast
Member
From: Germany
Registered: 2002-09-03
Posts: 166
Website

Re: Sample eclipse PKGBUILD on wiki broken?

tdy wrote:

You can use a subshell to handle the chdir. You'll automatically jump back to the previous dir after you leave the parentheses.

(cd $_dest/${_feature/.jar} && jar xf $srcdir/$_feature)

(another example seen in /usr/share/pacman/PKGBUILD-svn.proto)

Duh. Right, that's much cleaner. Thanks!
I'm not being totally daft here, and this change fixes an actual, existing problem, right?


"That's the problem with good advice. Nobody wants to hear it."
-- Dogbert

Offline

#4 2013-01-16 17:22:42

tdy
Member
From: Sacremende
Registered: 2008-12-14
Posts: 438

Re: Sample eclipse PKGBUILD on wiki broken?

Gyroplast wrote:

I'm not being totally daft here, and this change fixes an actual, existing problem, right?

Looks to me like a needed change (aside from my missing quotes - I was typing quickly and not paying attention). It's possible that I'm also missing something though.

Last edited by tdy (2013-01-16 17:43:23)

Offline

Board footer

Powered by FluxBB