carbonblack / intellij-rpmspec

An IntelliJ plugin for RPM SPEC file support
Apache License 2.0
11 stars 4 forks source link

RPM macros are only found when application is started from the command line on macOS #4

Closed recck closed 3 years ago

recck commented 3 years ago

We package a handful of PHP applications using spec files, so heavy use of PHPStorm. RPM/rpmbuild installed on macOS drops the macros in /usr/local/opt/rpm/lib/rpm/macros.

PHPStorm only recognizes the macros if you launch PHPStorm from the command line (pstorm) on macOS.

tlusk commented 3 years ago

@recck could you possibly paste me the output from the top of the rpm --showrc command?

everything until it starts showing the actual macros (which is separated by a line of equal signs), example:

build arch            : x86_64
compatible build archs: x86_64 noarch
build os              : Linux
compatible build os's : Linux
install arch          : x86_64
install os            : Linux
compatible archs      : x86_64 amd64 em64t athlon noarch i686 i586 i486 i386 fat
compatible os's       : Linux

RPMRC VALUES:
archcolor             : 2
optflags              : -O2 -g -m64 -fmessage-length=0 -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables

Features supported by rpmlib:
    rpmlib(BuiltinLuaScripts) = 4.2.2-1
    rpmlib(CompressedFileNames) = 3.0.4-1
    rpmlib(ConcurrentAccess) = 4.1-1
    rpmlib(ExplicitPackageProvide) = 4.0-1
    rpmlib(FileCaps) = 4.6.1-1
    rpmlib(FileDigests) = 4.6.0-1
    rpmlib(HeaderLoadSortsTags) = 4.0.1-1
    rpmlib(LargeFiles) = 4.12.0-1
    rpmlib(PartialHardlinkSets) = 4.0.4-1
    rpmlib(PayloadFilesHavePrefix) = 4.0-1
    rpmlib(PayloadIsBzip2) = 3.0.5-1
    rpmlib(PayloadIsLzma) = 4.4.2-1
    rpmlib(PayloadIsXz) = 5.2-1
    rpmlib(PayloadIsZstd) = 5.4.18-1
    rpmlib(RichDependencies) = 4.12.0-1
    rpmlib(ScriptletExpansion) = 4.9.0-1
    rpmlib(ScriptletInterpreterArgs) = 4.0.3-1
    rpmlib(TildeInVersions) = 4.10.0-1
    rpmlib(VersionedDependencies) = 3.0.3-1

Macro path: /usr/lib/rpm/macros:/usr/lib/rpm/macros.d/macros.*:/usr/lib/rpm/platform/%{_target}/macros:/usr/lib/rpm/fileattrs/*.attr:/usr/lib/rpm/suse/macros:/etc/rpm/macros.*:/etc/rpm/macros:/etc/rpm/%{_target}/macros:~/.rpmmacros

========================

Also rpm --version might help too.

recck commented 3 years ago

Output from rpm --showrc:

 ~  rpm --showrc
ARCHITECTURE AND OS:
build arch            : x86_64
compatible build archs: x86_64 noarch
build os              : darwin
compatible build os's : Darwin
install arch          : x86_64
install os            : Darwin
compatible archs      : x86_64 amd64 em64t athlon noarch i686 i586 i486 i386 fat
compatible os's       : Darwin MacOSX

RPMRC VALUES:
archcolor             : 2
optflags              : -O2 -g

Features supported by rpmlib:
    rpmlib(BuiltinLuaScripts) = 4.2.2-1
    rpmlib(CaretInVersions) = 4.15.0-1
    rpmlib(CompressedFileNames) = 3.0.4-1
    rpmlib(ConcurrentAccess) = 4.1-1
    rpmlib(DynamicBuildRequires) = 4.15.0-1
    rpmlib(ExplicitPackageProvide) = 4.0-1
    rpmlib(FileDigests) = 4.6.0-1
    rpmlib(HeaderLoadSortsTags) = 4.0.1-1
    rpmlib(LargeFiles) = 4.12.0-1
    rpmlib(PartialHardlinkSets) = 4.0.4-1
    rpmlib(PayloadFilesHavePrefix) = 4.0-1
    rpmlib(PayloadIsBzip2) = 3.0.5-1
    rpmlib(PayloadIsLzma) = 4.4.2-1
    rpmlib(PayloadIsXz) = 5.2-1
    rpmlib(PayloadIsZstd) = 5.4.18-1
    rpmlib(RichDependencies) = 4.12.0-1
    rpmlib(ScriptletExpansion) = 4.9.0-1
    rpmlib(ScriptletInterpreterArgs) = 4.0.3-1
    rpmlib(TildeInVersions) = 4.10.0-1
    rpmlib(VersionedDependencies) = 3.0.3-1

Macro path: /usr/local/Cellar/rpm/4.16.1.2/lib/rpm/macros:/usr/local/Cellar/rpm/4.16.1.2/lib/rpm/macros.d/macros.*:/usr/local/Cellar/rpm/4.16.1.2/lib/rpm/platform/%{_target}/macros:/usr/local/Cellar/rpm/4.16.1.2/lib/rpm/fileattrs/*.attr:/usr/local/Cellar/rpm/4.16.1.2/lib/rpm/homebrew/macros:/usr/local/etc/rpm/macros.*:/usr/local/etc/rpm/macros:/usr/local/etc/rpm/%{_target}/macros:~/.rpmmacros

Using RPM version 4.16.1.2

tlusk commented 3 years ago

I'm not seeing that path you mentioned above /usr/local/opt/rpm/lib/rpm/macros in the Macro path... :thinking:

The way it determines where to search for macros is by parsing the Macro path from that command and indexes all the folders listed there.

recck commented 3 years ago

Yep, just realized the path I posted in the issue is a symlink:

$ ls -l /usr/local/opt/rpm
lrwxr-xr-x  1 recck  admin  22 Jan  8 09:27 /usr/local/opt/rpm -> ../Cellar/rpm/4.16.1.2

the target is in the macro path.

tlusk commented 3 years ago

~Could you run a find inside /usr/local/opt/Cellar/rpm/4.16.1.2/ so I can see all the structure/files under that?~

Actually just an ls inside /usr/local/Cellar/rpm/4.16.1.2/lib/rpm/platform/ will do if you don't want to paste the entire find.

I'm wondering if ${_target} in the path is not being resolved to the correct value

tlusk commented 3 years ago

One thing you mentioned is that the macros work if you launch it via command line? Actually could this be an issue where the rpm command isn't on the PATH if it's launched one way vs the other?

recck commented 3 years ago
 ~  ls /usr/local/Cellar/rpm/4.16.1.2/lib/rpm/platform
aarch64-darwin      amd64-darwin        armv6hl-darwin      athlon-darwin       ia64-darwin         mipsel-darwin       ppc32dy4-darwin     ppc8560-darwin      sh3-darwin          sparcv9-darwin
alpha-darwin        armv3l-darwin       armv6l-darwin       geode-darwin        m68k-darwin         mipsr6-darwin       ppc64-darwin        ppciseries-darwin   sh4-darwin          sparcv9v-darwin
alphaev5-darwin     armv4b-darwin       armv7hl-darwin      i386-darwin         mips-darwin         mipsr6el-darwin     ppc64iseries-darwin ppcpseries-darwin   sh4a-darwin         x86_64-darwin
alphaev56-darwin    armv4l-darwin       armv7hnl-darwin     i486-darwin         mips64-darwin       noarch-darwin       ppc64le-darwin      riscv64-darwin      sparc-darwin
alphaev6-darwin     armv5tejl-darwin    armv7l-darwin       i586-darwin         mips64el-darwin     pentium3-darwin     ppc64p7-darwin      s390-darwin         sparc64-darwin
alphaev67-darwin    armv5tel-darwin     armv8hl-darwin      i686-darwin         mips64r6-darwin     pentium4-darwin     ppc64pseries-darwin s390x-darwin        sparc64v-darwin
alphapca56-darwin   armv5tl-darwin      armv8l-darwin       ia32e-darwin        mips64r6el-darwin   ppc-darwin          ppc8260-darwin      sh-darwin           sparcv8-darwin

It must be related to how the application opens. If I open via terminal I see the following in idea.log:

2021-01-11 15:56:07,349 [     27]   INFO - .intellij.util.EnvironmentUtil - loading shell env is skipped: IDE has been launched from a terminal (SHLVL=1)

And when I open it from the Applications folder:

2021-01-11 15:57:34,223 [     28]   INFO - .intellij.util.EnvironmentUtil - loading shell env: /bin/zsh -l -i -c '/Applications/PhpStorm.app/Contents/bin/printenv.py' '/var/folders/gv/nrlkj26x0ln_npjpx3_yz27r0000gq/T/intellij-shell-env.4169145817345157938.tmp'
tlusk commented 3 years ago

Ok I think there are two issues going on.

  1. rpm needs to be on the PATH and depending on how you're opening it it's possibly not on the path
  2. the %{_target} macro is being resolved to x86_64-linux and not x86_64-darwin. This is hard coded currently because I only tested this on CentOS and openSUSE. That means even when the macros are working they're still missing some of the definitions for you. This is a bug and I'll look into fixing this.

The first might be fixable by allowing the rpm command to be specified via absolute path in a config menu but depending on how difficult that is I might not get to that for a while. You might want to check if there's something environment-wise you can change to get it on the PATH.

I can increase logging around the detection of the macros though, that might help uncover something and/or make it easier to debug this in the future for others.

recck commented 3 years ago

Yea, I've tried a variety of ways to get my PATH to run with PhpStorm's environment. None of them seem to do the trick, even system level environment variables. I've exhausted all the ideas I can think of.

I appreciate the help and for your time spent creating this plugin, great tool to have so I don't have to constantly reference some website! Thanks!

tlusk commented 3 years ago

@recck I've made changes to allow manually specifying the rpm executable in the IDE settings. Note that after changing the path and saving you need to restart the IDE for the changes to take effect.

Screenshot_20210121_125914

I've currently published this build as a beta so you'll need to manually install it from here: https://plugins.jetbrains.com/plugin/12552-rpm-spec-file/versions/beta/108336

I'll promote the plugin to Stable after I use it for a little bit and/or I hear back from you that it is resolving the issues you've had.

Thanks!

recck commented 3 years ago

Awesome. Was able to change the path to /usr/local/bin/rpm, restarted IDE, and voila...

Screen Shot 2021-01-22 at 8 04 28 AM

The macros load properly in spec files now without needing to open via command line!

As a note, the default value for "Path to rpm executable" was just rpm, not sure if that makes a difference for your own knowledge.

From one RIT Alum to another, thanks for responding so quickly and providing a great plugin!

tlusk commented 3 years ago

Great! Glad this has resolved the issue for you.

The default value for the executable being rpm is expected in your case, basically now if my code to try to find the absolute path of the executable comes up short it defaults to rpm hoping that maybe in some last ditch effort it might be successful trying just the executable name (which is all it was using before these changes).

And thanks for the kudos, it's great to see other people getting use out of this plugin that I originally wrote just to make my own life easier editing SPEC files :smiley: