# Package marked as broken, install from Github source?



## freejetz888 (Oct 15, 2021)

I have a package that fails to build in my Poudriere repository, databases/postgresql-plv8js, due to it being marked as broken. Unfortunately this is a required package for the piece of ERP software the PostgreSQL database is built for. I have found the Github source for plv8 and I'm trying to figure out if it is possible to build from there into my Poudriere repository to distribute to my servers that need it. If not possible would I be able to install directly onto the servers bypassing Poudriere.

I have done some searching and found a couple sources that makes me think this is possible but wonder if I am wasting my time. If anyone could point me in the right direction or manuals it would be greatly appreciated. Thanks!


----------



## dd_ff_bb (Oct 15, 2021)

I guess you have 2 options:

1) try to fix the port version. its marked broken with error on 01 Jan 2021 20:58:57 you can see error details from below link:





						FreshPorts -- databases/postgresql-plv8js: PL/v8js procedural language for PostgreSQL database
					

PLV8 is a trusted JavaScript language extension for PostgreSQL, using Google V8 Engine.  It can be used for stored procedures, triggers, etc.  PLV8 works with most versions of Postgres, but works best with 9.1 and above, including 10.0 and 10.1.




					www.freshports.org
				




2) you can download github version and port it to freebsd.

If you can 1st option seems easier


----------



## SirDice (Oct 18, 2021)

The port uses the same source as that Github page. So I suggest to try and fix the port.


----------



## zirias@ (Oct 18, 2021)

Might be all this port needs would be `compiler:c++14-lang` in its `USES`.


----------



## SirDice (Oct 18, 2021)

Looking at the error it may just need a simple patch. I would definitely try to change that `std::remove_cv_t` to `std::remove_cv` and see if that works. 






						[ports] Revision 559872
					






					svnweb.freebsd.org
				




You can also try just updating it, the port builds version 1.4.8 but on the github page there are many newer versions available (https://github.com/plv8/plv8/tags). So the issue may already have been resolved in the code.


----------



## zirias@ (Oct 18, 2021)

I found somewhere on the internet  (so, well, not sure it can be trusted) that `std::remove_cv_t` was introduced with C++14. If that's true, a `USES=    compiler:c++14-lang` would probably be the better fix.


----------



## SirDice (Oct 18, 2021)

Zirias said:


> I found somewhere on the internet


I think we read the same thing, was it on some page about NodeJS? 



Zirias said:


> If that's true, a `USES= compiler:c++14-lang` would probably be the better fix.


Agreed. But I would also recommend checking out a newer version of the code, this issue may already have been fixed, 1.4.8 is pretty old (released in April 2016). Current version appears to be v3.0.0.









						Release v1.4.8 · plv8/plv8
					

v1.4.8 release




					github.com
				











						Release v3.0.0 · plv8/plv8
					

version 3.0.0




					github.com


----------



## freejetz888 (Oct 18, 2021)

Thank you for the replies. I have done some testing this morning, though I am not exactly sure if I am testing it correctly.

So far I've gone in and modified the Makefile located at /usr/local/poudriere/ports/TEST/databases/postgresql-plv8js to comment out the 'Broken' tag and to modify the compiler to:

```
USES=    compiler:c++14-lang
```
This results in the same error so I'm not sure if this was the correct place to make this change. I have also changed in the make file the version from 1.4.8 to 3.0.0 which fails to fetch.


```
=> plv8-plv8-v3.0.0_GH0.tar.gz is not in /usr/ports/databases/postgresql-plv8js/distinfo.
=> Either /usr/ports/databases/postgresql-plv8js/distinfo is out of date, or
=> plv8-plv8-v3.0.0_GH0.tar.gz is spelled incorrectly.
*** Error code 1
```

I've never really done maintenance of ports like this so I could be off the mark here. I uploaded the plv8-3.0.0 that SirDice linked to my Poudriere server but I'm not sure how to tell Poudriere to use that as the source to build the package.

Below is the log output of the failure using the 1.4.8 version with the compiler:c++14-lang:


```
===========================================================================
=======================<phase: configure      >============================
===>  Configuring for postgresql10-plv8js-1.4.8_6
===========================================================================
=======================<phase: build          >============================
===>  Building for postgresql10-plv8js-1.4.8_6
gmake[1]: Entering directory '/wrkdirs/usr/ports/databases/postgresql-plv8js/work/plv8-1.4.8'
sed -e 's/^#undef PLV8_VERSION/#define PLV8_VERSION "1.4.8"/' plv8_config.h.in > plv8_config.h
c++ -Wall -O2 -std=c++11 -fno-rtti  -I. -I./ -I/usr/local/include/postgresql/server -I/usr/local/include/postgresql/internal  -I/usr/local/include -I/usr/local/include -I/usr/local/include -fPIC -c -o plv8.o plv8.cc
In file included from plv8.cc:8:
In file included from ./plv8.h:12:
In file included from /usr/local/include/v8.h:30:
/usr/local/include/v8-internal.h:506:38: error: no template named 'remove_cv_t' in namespace 'std'; did you mean 'remove_cv'?
            !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
                                ~~~~~^~~~~~~~~~~
                                     remove_cv
/usr/include/c++/v1/type_traits:697:50: note: 'remove_cv' declared here
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_cv
                                                 ^
In file included from plv8.cc:8:
./plv8.h:86:6: error: no type named 'ExternalArrayType' in namespace 'v8'
        v8::ExternalArrayType ext_array;
        ~~~~^
./plv8.h:174:41: error: no member named 'NewSymbol' in 'v8::String'
                                        context->Global()->Get(v8::String::NewSymbol("plv8")));
                                                               ~~~~~~~~~~~~^
./plv8.h:180:30: error: too few arguments to function call, expected 2, have 1
                                        v8::External::New(fcinfo));
                                        ~~~~~~~~~~~~~~~~~       ^
/usr/local/include/v8.h:6062:3: note: 'New' declared here
  static Local<External> New(Isolate* isolate, void* value);
  ^
In file included from plv8.cc:8:
./plv8.h:211:40: error: no member named 'NewSymbol' in 'v8::String'
                                context->Global()->Get(v8::String::NewSymbol("plv8")));
                                                       ~~~~~~~~~~~~^
./plv8.h:217:32: error: too few arguments to function call, expected 2, have 1
                                                                        v8::External::New(conv));
                                                                        ~~~~~~~~~~~~~~~~~     ^
/usr/local/include/v8.h:6062:3: note: 'New' declared here
  static Local<External> New(Isolate* isolate, void* value);
  ^
In file included from plv8.cc:8:
./plv8.h:219:36: error: too few arguments to function call, expected 2, have 1
                                                                        v8::External::New(tupstore));
                                                                        ~~~~~~~~~~~~~~~~~         ^
/usr/local/include/v8.h:6062:3: note: 'New' declared here
  static Local<External> New(Isolate* isolate, void* value);
  ^
In file included from plv8.cc:8:
./plv8.h:247:55: error: no type named 'Arguments' in namespace 'v8'
extern v8::Handle<v8::Value> Subtransaction(const v8::Arguments& args) throw();
                                                  ~~~~^
In file included from plv8.cc:19:
In file included from /usr/local/include/postgresql/server/commands/trigger.h:17:
In file included from /usr/local/include/postgresql/server/nodes/execnodes.h:17:
In file included from /usr/local/include/postgresql/server/access/genam.h:19:
In file included from /usr/local/include/postgresql/server/nodes/tidbitmap.h:26:
In file included from /usr/local/include/postgresql/server/utils/dsa.h:17:
In file included from /usr/local/include/postgresql/server/port/atomics.h:70:
/usr/local/include/postgresql/server/port/atomics/arch-x86.h:143:2: warning: 'register' storage class specifier is deprecated and incompatible with C++17 [-Wdeprecated-register]
        register char _res = 1;
        ^~~~~~~~~
In file included from plv8.cc:19:
In file included from /usr/local/include/postgresql/server/commands/trigger.h:17:
In file included from /usr/local/include/postgresql/server/nodes/execnodes.h:31:
In file included from /usr/local/include/postgresql/server/storage/condition_variable.h:25:
/usr/local/include/postgresql/server/storage/s_lock.h:226:2: warning: 'register' storage class specifier is deprecated and incompatible with C++17 [-Wdeprecated-register]
        register slock_t _res = 1;
        ^~~~~~~~~
plv8.cc:229:14: error: no member named 'Dispose' in 'v8::Persistent<v8::Object, v8::NonCopyablePersistentTraits<v8::Object> >'
                        env->recv.Dispose();
                        ~~~~~~~~~ ^
plv8.cc:230:14: error: no member named 'Clear' in 'v8::Persistent<v8::Object, v8::NonCopyablePersistentTraits<v8::Object> >'
                        env->recv.Clear();
                        ~~~~~~~~~ ^
plv8.cc:270:15: error: calling a protected constructor of class 'v8::HandleScope'
                HandleScope     handle_scope;
                                ^
/usr/local/include/v8.h:1233:13: note: declared protected here
  V8_INLINE HandleScope() = default;
            ^
plv8.cc:276:17: error: no matching function for call to 'CreateExecEnv'
                        proc->xenv = CreateExecEnv(proc->cache->function);
                                     ^~~~~~~~~~~~~
plv8.cc:132:23: note: candidate function not viable: no known conversion from 'Persistent<v8::Function>' to 'Handle<v8::Function>' (aka 'Local<v8::Function>') for 1st argument
static plv8_exec_env *CreateExecEnv(Handle<Function> script);
                      ^
plv8.cc:329:17: error: calling a protected constructor of class 'v8::HandleScope'
                HandleScope                     handle_scope;
                                                ^
/usr/local/include/v8.h:1233:13: note: declared protected here
  V8_INLINE HandleScope() = default;
            ^
plv8.cc:332:19: error: no viable conversion from 'Persistent<v8::Context>' to 'Handle<v8::Context>' (aka 'Local<v8::Context>')
                Handle<Context> global_context = GetGlobalContext();
                                ^                ~~~~~~~~~~~~~~~~~~
/usr/local/include/v8.h:201:7: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'Persistent<v8::Context>' to 'const v8::Local<v8::Context> &' for 1st argument
class Local {
      ^
/usr/local/include/v8.h:201:7: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'Persistent<v8::Context>' to 'v8::Local<v8::Context> &&' for 1st argument
/usr/local/include/v8.h:205:13: note: candidate template ignored: could not match 'Local' against 'Persistent'
  V8_INLINE Local(Local<S> that)
            ^
/usr/local/include/v8.h:349:22: note: explicit constructor is not a candidate
  explicit V8_INLINE Local(T* that) : val_(that) {}
                     ^
plv8.cc:373:12: error: no matching constructor for initialization of 'v8::TryCatch'
        TryCatch                try_catch;
                                ^
/usr/local/include/v8.h:10249:12: note: candidate constructor not viable: requires single argument 'isolate', but no arguments were provided
  explicit TryCatch(Isolate* isolate);
           ^
/usr/local/include/v8.h:10371:3: note: candidate constructor not viable: requires 1 argument, but 0 were provided
  TryCatch(const TryCatch&) = delete;
  ^
plv8.cc:377:58: error: too few arguments to function call, expected 4, have 3
        Local<v8::Value> result = fn->Call(receiver, nargs, args);
                                  ~~~~~~~~                      ^
/usr/local/include/v8.h:4779:3: note: 'Call' declared here
  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Call(Local<Context> context,
  ^
/usr/local/include/v8config.h:502:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
#define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
                              ^
plv8.cc:393:19: error: no viable conversion from 'Persistent<v8::Context>' to 'Handle<v8::Context>' (aka 'Local<v8::Context>')
        Handle<Context>         context = xenv->context;
                                ^         ~~~~~~~~~~~~~
/usr/local/include/v8.h:201:7: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'Persistent<v8::Context>' to 'const v8::Local<v8::Context> &' for 1st argument
class Local {
      ^
/usr/local/include/v8.h:201:7: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'Persistent<v8::Context>' to 'v8::Local<v8::Context> &&' for 1st argument
/usr/local/include/v8.h:205:13: note: candidate template ignored: could not match 'Local' against 'Persistent'
  V8_INLINE Local(Local<S> that)
            ^
/usr/local/include/v8.h:349:22: note: explicit constructor is not a candidate
  explicit V8_INLINE Local(T* that) : val_(that) {}
                     ^
plv8.cc:421:35: error: member reference type 'Persistent<v8::Object>' is not a pointer; did you mean to use '.'?
                Local<Function>::Cast(xenv->recv->GetInternalField(0));
                                      ~~~~~~~~~~^~
                                                .
plv8.cc:421:37: error: no member named 'GetInternalField' in 'v8::Persistent<v8::Object, v8::NonCopyablePersistentTraits<v8::Object> >'
                Local<Function>::Cast(xenv->recv->GetInternalField(0));
                                      ~~~~~~~~~~  ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
2 warnings and 20 errors generated.
gmake[1]: *** [Makefile:68: plv8.o] Error 1
gmake[1]: Leaving directory '/wrkdirs/usr/ports/databases/postgresql-plv8js/work/plv8-1.4.8'
*** Error code 1

Stop.
make: stopped in /usr/ports/databases/postgresql-plv8js
=>> Cleaning up wrkdir
===>  Cleaning for postgresql10-plv8js-1.4.8_6
build of databases/postgresql-plv8js | postgresql10-plv8js-1.4.8_6 ended at Mon Oct 18 09:41:51 CDT 2021
build time: 00:01:11
!!! build failure encountered !!!
```


----------



## zirias@ (Oct 18, 2021)

I'll have a look as soon as
a) my package builder is done building my `i386` repo and
b) I find some time

Always happy to fix something in ports, I'm pretty sure it _can_ be fixed, but no guarantees I can do it ;-)


----------



## SirDice (Oct 18, 2021)

freejetz888 said:


> So far I've gone in and modified the Makefile


Modify the PORTVERSION to 3.0.0 and remove PORTREVISION so it actually fetches the latest source code. Leave the compiler settings as is. Then see what happens. As this is a new version you probably need to run `make makesum` first, the port's distinfo needs to be updated for the new version. Then run `make patch`, this will apply the patches that are in the files/ directory. They're likely going to fail to apply (due to the changed sources), figure out which ones are still needed, remove those that don't apply anymore.


----------



## zirias@ (Oct 18, 2021)

`s:probably:certainly:`

Doing that right now ;-)

(edit: I decided to start looking while my builder is still busy, so testing is pretty slow. Some day, I need a "super computer", hehe)


----------



## zirias@ (Oct 18, 2021)

Yeah, one dependency is lang/v8. This might take a while


----------



## freejetz888 (Oct 18, 2021)

Zirias said:


> Yeah, one dependency is lang/v8. This might take a while


Yes, 3 hours to build on my machine. I do really appreciate your and SirDice's help.

On that, I've modified the Makefile to PORTVERSION=    3.0.0 and PORTREVISION=   1. I ran `make makesum` which finished successfully. I then ran `make patch` and removed all files that were failing, which was all of them. I then get the following error on build:



> ===>  Building for postgresql10-plv8js-3.0.0_1
> gmake[1]: Entering directory '/wrkdirs/usr/ports/databases/postgresql-plv8js/work/plv8-3.0.0'
> mkdir -p build
> cd build; git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
> ...



I installed git on this machine, reboot, and run again but receive the same error.

ETA: I can run `git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git` just fine on its own.


----------



## zirias@ (Oct 18, 2021)

The build tries to do a `git clone`? Oh my, this will be "fun" to fix. I WILL have a look, I can't promise anything, but in any case, don't expect a result too soon, it will probably take a few days…


freejetz888 said:


> I installed git on this machine, reboot, and run again but receive the same error.


Well, I guess you use poudriere? (and, you should!) -- then installing something locally on the machine won't have any effect. poudriere creates a jail for building that has nothing but what is actually listed as a dependency in the port itself  – but a git clone during build is a no-go anyways, once the build starts, there should be no more "fetching". I guess this might be a PITA to port


----------



## SirDice (Oct 18, 2021)

freejetz888 said:


> PORTREVISION= 1


Should be 0 or removed. It's the first revision of the port with the 'new' version, so it starts counting at 0. Should you make a change to the port, without affection the version, then you should increase the PORTREVISION.


----------



## astyle (Oct 18, 2021)

There's a port that's been marked as "Broken" that I did manage to successfully compile: audio/lash. Relevant part to this thread - I told the Makefile to ignore the 'Broken' flag. After that, compiling went fine (The reason for the 'Broken' tag was a py27 dep, anyway). But fighting past source code errors (incorrectly specified APIs / variables) is a bit more than I have the patience for at this point. 

Sometimes, I just look at what else is available in ports to solve my problem... But in this case, it looks like the problem is getting some attention from people who actually know what it takes to go from a simple compile error to getting the ports system to play nice with the software.


----------



## zirias@ (Oct 18, 2021)

SirDice said:


> Should be 0 or removed.


Actually, removed. Explicitly setting it to 0 is frowned upon. This is only an option with complex stuff like e.g. master-slave-ports.


SirDice said:


> Should you make a change to the port, without affection the version, then you should increase the PORTREVISION.


Just for completeness: Only if the built result will differ. So e.g. for a simple build fix, you don't bump PORTREVISION.


astyle said:


> But in this case, it looks like the problem is getting some attention from people who actually know what it takes to go from a simple compile error to getting the ports system to play nice with the software.


Well, I hope I know, at least I have _some_ experience . It will take time until I can really start. Right now, my builder machine has a load of 61 (with 4 cores with hyperthreading). Uhm, yeah


----------



## zirias@ (Oct 19, 2021)

Here you go: PR 259262.

Not sure everything is correct (I can't test whether it works), but it's now building and packaging fine for me.

For testing, if you use git, just download the patch and apply it with `git am`. Otherwise, I assume the following should work: Make sure you have no local changes to the port, then go to the root of your ports tree and apply the patch with
`fetch -o- "https://bz-attachments.freebsd.org/attachment.cgi?id=228826&action=diff&format=raw&headers=1" | patch -Np1`



Zirias said:


> The build tries to do a `git clone`? Oh my, this will be "fun" to fix.


Luckily, this was only a minor problem. Upstream added a new Makefile that attempts to fetch and build all dependencies and links them statically  – nothing you'd *ever* want for a port or package. But the original Makefile doing just the build is still there, only renamed, so all it took to get out of this madness was a line `MAKEFILE=    Makefile.shared`


----------



## zirias@ (Oct 19, 2021)

Amazing, it's already committed to latest and MFH'd to quarterly 

So, freejetz888 just update your ports tree!


----------



## zirias@ (Oct 19, 2021)

Ah damn, pointy-hat to me. I just discovered 3.0.0 seems to build fine with _any_ postgresql version, so no need any more to restrict it to 9.6 .

Added another patch to the PR, let's see 

freejetz888 if you use the default postgres version (currently 12) and want to use this port with it, as long as my additional fix isn't committed, try this little change to the port's Makefile after updating your ports tree:

```
-USES=        compiler:c++14-lang gmake perl5 pgsql:9.6-10
+USES=        compiler:c++14-lang gmake perl5 pgsql
```


----------



## freejetz888 (Oct 19, 2021)

Amazing! Really appreciate your efforts Zirias! I just updated the ports tree and the package built successfully. I am still stuck using Postgres 10 due to the ERP application restrictions but I will keep the last trick in mind once I'm able to move past PG10. Also, looking at your PR 259262 it looks like someone also stepped up to be a maintainer. I will definitely look into getting better at this side of things and help maintain as well.

Again, thank you!


----------



## SirDice (Oct 19, 2021)

freejetz888 said:


> I am still stuck using Postgres 10


Set `DEFAULT_VERSIONS+= pgsql=10` in /etc/make.conf. Then everything you build from ports will be build against PostgreSQL 10. You can change the defaults when you build from ports. See /usr/ports/Mk/bsd.default-versions.mk.


----------



## zirias@ (Oct 19, 2021)

freejetz888 said:


> Also, looking at your PR 259262 it looks like someone also stepped up to be a maintainer.


Yep, I was surprised to see that  I'm maintaining a few ports myself, but I refused here because I think it's difficult to maintain something you don't use yourself…


freejetz888 said:


> I will definitely look into getting better at this side of things and help maintain as well.


That's great! One thing I really like about FreeBSD is that every user is _welcome_ to contribute and make things better. Of course, it's a learning curve. But the existing ports framework is pretty nice and many things are easy to do (once you learned how, of course)


----------



## zirias@ (Oct 19, 2021)

SirDice said:


> Set `DEFAULT_VERSIONS+= pgsql=10` in /etc/make.conf.


When using poudriere, add it for example to /usr/local/etc/poudriere.d/make.conf instead.


----------



## freejetz888 (Oct 19, 2021)

Yep, I have the default versions set for the Poudriere jails using the make.conf files. I've been using it for a few years so I'm pretty comfortable with this side of things. I would love to stay on the cutting edge but the applications we use seem to move at a snails pace when it comes to that.

Zirias, any advice or resources you can point me to that helped you become better at port/package maintenance? I know about the Porters Handbook, but I'm curious if any other resources are out there.


----------



## zirias@ (Oct 19, 2021)

freejetz888 anything you find in Mk/ inside the ports tree. Especially Mk/bsd.port.mk has extensive documentation in the comments on top of the file. But the first thing to consider is indeed the handbook. Only if you miss some info there, it helps to look directly into the ports' make framework


----------



## astyle (Oct 19, 2021)

SirDice said:


> Set `DEFAULT_VERSIONS+= pgsql=10` in /etc/make.conf. Then everything you build from ports will be build against PostgreSQL 10. You can change the defaults when you build from ports. See /usr/ports/Mk/bsd.default-versions.mk.


I would disagree with that, I'd rather modify the port's makefile to tell it to require pgsql v.10... Messing with make.conf can have unintended consequences down the road, especially when a given version reaches EOL.


----------



## SirDice (Oct 19, 2021)

astyle said:


> Messing with make.conf can have unintended consequences down the road, especially when a given version reaches EOL.


And a dozen or so custom edits to various ports won't? Really, I much rather have this done in one place that's specifically meant for this exact purpose. Sure you have to keep track of what versions are actually available but you have to do that anyway.


----------



## zirias@ (Oct 19, 2021)

Indeed, there's no question about it: `DEFAULT_VERSIONS` is the mechanism _explicitly meant_ to be used for that. The consequence when using a version that's removed will be that your builds will fail (which I wouldn't call unintended...) and if you use `DEFAULT_VERSIONS`, there's only one single place where you have to edit something.

freejetz888 when you're finished with your installs (or upgrades?), could you give feedback whether the package is actually operational correctly? thanks 

*edit:* after fixing some "obvious" (side note, C++ stinks *fg*) runtime issues over in the PR (thanks for taking it there directly) and I'm still waiting for my fixes to be committed – I'd still be interested to learn whether the package now works as expected in actual use  Maybe the new maintainer is reluctant to commit without knowing for sure everything is sorted out now


----------



## zirias@ (Nov 1, 2021)

The fully fixed port finally made it into `main`. freejetz888 if you're still around, it would still be nice to know whether it actually _works_ correctly – so far I only know it _loads_ correctly…


----------

