Follow

How 'bout we just... 

...don't ever write things in .

I mean, whenever I try to install something written in Ruby, I run into problems I don't get with any other language.

The problem doesn't seem to be so much with the language itself as with the packaging system(s) that apparently everyone uses -- but the error messages are really unhelpful and leave me with no idea where to start.

The problem this time is some kind of undeclared function -- but searching the web for the function (so I could figure out what I need to install) just leads to other people trying to solve the same problem and never really getting to an understanding of what was causing it.

It also kind of feels like the people who do understand these things are almost proud of how tricky such problems are to fix and/or how little understanding they have of what the basic concepts are that one needs to understand in order to properly deal with such problems in the future.

· · Web · 4 · 0 · 2

To be fair, the last commenter in that thread did explain at least some of the problem.

In my case, it seems to be that I have ruby-mysql2 version 0.5.2 and for some reason it wants version 0.5.3. I don't know if that's what is causing the missing identifier, or if something is just barfing because it can't find the exact version it wants, or if I could just ignore that problem and move on now...

The Gemfile seems to think anything 0.5.x should be fine.

Just....why.

Show thread

I got past one error by editing one of the system libraries, which is probably a Bad Solution, but... geez, guys, ever hear of graceful fallback?

I changed

path.split(...)

to

path&.split(...)

in /usr/lib/ruby/2.7.0/mkmf.rb, for the record.

On to gewgling the next syntax error...

Show thread

I seem to have gotten it to install by making the same change in about 4 places in 2 different files.

So now, whenever something automatically upgrades those libraries, everything will break again... and I'm not quite sure what installed them...

Can I submit a pull request? (Redmine uses subversion, but what does Ruby use?)

Show thread

Also, the install documentation is out of date:

$ bundle install --without development test rmagick
[DEPRECATED] The --without flag is deprecated because it relies on being remembered across bundler invocations, which bundler will no longer do in future versions. Instead please use bundle config set --local without 'development test rmagick', and stop using this flag

(...followed by the usual reminder not to run bundler as root even though it will probably need root privs at some point.)

Show thread

@woozle Sometimes I wonder if prior to ever release, we should take away the developers' machines and make them start over with fresh ones.

Just how many previously-unnoticed environmental assumptions would come to light?

@woozle bugs.ruby-lang.org/projects/ru looks like they prefer you to open a redmine ticket, which will forward it to the mailing list.

@FiXato It looks like submitting a pull-request would be appropriate for these very small fixes -- but I feel like I should actually get my instance working first, just to establish that they're not breaking something further down in the process.

So far so good with the testing process...

@woozle where did you change this btw? in the find_executable0 method, or the find_library one?

A safer way might be to override the method in the installer, and either fail early or ensure the path is a valid value.

justinweiss.com/articles/3-way

@FiXato

I ended up editing two different files:

  • /usr/lib/ruby/2.7.0/mkmf.rb
  • /usr/lib/x86_64-linux-gnu/ruby/2.7.0/rbconfig.rb

[insert and then delete a lot of rambling about trying to figure out where I made the changes]

Kate edit-history to the rescue!

  • mkmf.rb
    • 535 end % x&.quote
    • 1050 paths = paths.collect {|path| path&.split(File::PATH_SEPARATOR)}.flatten
  • rbconfig.rb
    • 288 newval = val&.gsub(/\$\$|\$(([]+))|\${([{}]+)}/) {

The monkey-patching advice seems good, but I have no idea how to do it just from his instructions.

(
As far as submitting patches:

I found mkmf.rb, but still no idea where rbconfig.rb is.

If I could find both of them, I could clone the repo, make the change in my clone, and do a diff to get which lines were changed (and possibly do a PR for the changes).
)

@woozle with the paths.collect one I am guessing that one of the paths is nil somehow, in which case it might also be worth removing it from the array with .compact, so paths.compact.collect, though I'm curious what would cause the path to be nil.

As far as rbconfig.rb goes, I believe that's created by mkconfig.rb:

# This script, which is run when ruby is built, generates rbconfig.rb by
4 # parsing information from config.status. rbconfig.rb contains build
5 # information for ruby (compiler flags, paths, etc.) and is used e.g. by
6 # mkmf to build compatible native extensions.

@FiXato So where would one patch mkconfig.rb so that the code it generates has that patch in it?

As yet, I have zero experience coding in Ruby, so this looks way above my spoons-level.

@woozle I would guess svn.ruby-lang.org/cgi-bin/view, though I also see svn.ruby-lang.org/cgi-bin/view

Though I have to admit that this is a bit beyond my comfort zone too :) I have no experience with native extensions in Ruby apart from making use of them. ;)

re: How 'bout we just... 

@woozle I've done development in Ruby for years, but the past year and a half or so I grab for Python instead since it's just less of a hassle to port something to a different system or version.

re: How 'bout we just... 

@FiXato ommean, I'm just trying to install Redmine.

That's all. No dev work on it; just get it running.

[muffled screaming in ASM86]

re: How 'bout we just... 

@woozle yeah, I've never found a satisfying solution to package a Ruby programme into an executable... probably for similar reasons :)

re: How 'bout we just... 

@woozle Ruby pro-tip: Don't.

>_>

re: How 'bout we just... 

@SetecAstronomy
Can we ride Ruby out of town on some Rails?

re: How 'bout we just... 

@woozle We tried, but there were a bunch of cryptic error messages and everyone gave up.

@SetecAstronomy
Oh, yeah, here's the problem:

Using roadie-rails 2.2.0
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

Can't run anything out on rails if you can't build the rails.

Dang natives and their extensions, interfering with my linguistic colonization...

(Actually, this is a bad metaphor; it feels more like Ruby is trying to assimilate me, part of which involves learned helplessness when it comes to fixing anything.)

How 'bout we just... 

@woozle

I love Ruby but yeah, dependency management is awful.

Actually, it's *really good* for a language-level dependency manager but that means people tend to use it instead of making self-contained standalone packages, so getting a program written in Ruby to work on a new machine is often a crapshot.

And yeah, a lot of Ruby users mistake proficiency with the packaging system for architecture skill.

How 'bout we just... 

@woozle

(I once heard the author of $MAJOR_RUBY_TOOL describe the community as a bunch of 14-year-olds.)

Also: there *are* tools available for shipping stuff. E.g. warbler will package your jruby app into a single jar file, for example.

re: How 'bout we just... 

@suetanvil Indeed, the language itself seems fine, from the little bits I've been able to understand.

It's just that there seems to be this culture of depencency-reliance -- every significant Ruby project requires, like, 37 other packages to be installed, and the corresponding library headers to handle them... which supposedly Bundler or something will handle for you, but it always seems to get it wrong somehow.

(When that happens with PHP, I know I just need to go to Synaptic and search for "php" and [name of library]; usually it'll be just "php-[name of thing]".)

Maybe most Ruby programmers target Windows, and don't test their deployments on Linux?

...yeah, I'm grasping at straws, here... there's just this discrepancy between the number of times I run into problems with Ruby project deployment and how much trouble Ruby developers seem to have with them, and I don't know how else to explain it.

re: How 'bout we just... 

@woozle

AFAICT, the workflow is:

1. Use rbenv or rvm to install a compatible Ruby.
2. Install gem and bundler for it.
3. Checkout the source tree.
4. Run bundler to get your dependencies.

If your program was correctly packaged, Gemfile.lock will ensure bundle retrieves the correct versions of all of the dependencies.

You'll still need the relevant *-dev packages on your LInux host though if you're using something with native components. gem is pretty bad at warning you.

re: How 'bout we just... 

@woozle

(Note: my Ruby fondness doesn't extend to Rails; I ragequit a couple of hours into my first post-tutorial project once I realized I was grepping the Rails source tree to tr to find *reference documentation* for the form validator.

Sinatra is my preferred Ruby web framework; someday, I may actually used it for something.)

re: How 'bout we just... 

@suetanvil Okay, so now I am even more tempted to try rewriting my homebrew web framework in Ruby...

re: How 'bout we just... 

@woozle

Ruby's a really fun language to play with, especially once you get into what you can do with blocks (i.e. lambdas) and the object system's plumbing.

I once wrote an HTML/XML generator for giggles that mostly replicated the structure of the document as Ruby source code. It's 237 lines of code.

re: How 'bout we just... 

@woozle

(Note: not valid html because I used bogus tag attributes ('speed' and 'color'). This is from the unit tests.)

re: How 'bout we just... 

@suetanvil That seems like it would be doable in PHP as well -- you're basically creating an array-structure and then passing it to the generator, is what it looks like?

re: How 'bout we just... 

@woozle

Oh no, it's *much* nuttier than that.

The `html(...) { ... }` is a function call; the bit in the braces is a block (i.e. an anonymous function that's closure) that gets tacked onto the argument list.

`html` does some setup and then evaluates the block, which is just more such function calls; each of these appends its corresponding open tag, evaluates the body and then appends the close tag; the body appends the contents between the tag.

Oh, but it's nuttier than that.

re: How 'bout we just... 

@woozle

You see, the named-after-tags functions don't exist.

In Ruby, a method call on self:

self.foo()

can be shortened to

foo()

(I.e. the 'self' is implied.)

And there are no actual functions in Ruby; just methods. The (apparent) global functions are methods of the lobby object that acts as the default evaluation context.

(ctd)

re: How 'bout we just... 

@woozle

Next piece: there are a couple of methods in the base class that will take a block and evaluate it as though it were part of that object. That is, it points the block's 'self' at itself and then evaluates it. So now method calls in the block are evaluated by the outer object instead of the 'self' that was there when the block was defined.

(ctd)

re: How 'bout we just... 

@woozle

Final piece: if you call an undefined method of a Ruby object, it will first attempt to call the method 'method_missing' (if defined) with the name and arguments of the call.

(ctd)

re: How 'bout we just... 

@woozle

So:

1. `html` creates an object of class HtmlBuilder and evaluates the block inside it.
2. HtmlBuilder's `method_missing` catches the tag-named functions. It writes the open tag, evaluates the block, writes the close tag and returns.

re: How 'bout we just... 

@woozle

Hmmm. Actually, that's a bit wrong. This strategy would work but on review, what I'm actually doing is looping through a list of supported tags and adding each one to HtmlBuilder.

This is done using a method that takes a block and turns it into a method. The code is always the same but it captures the current tag's name from the context in which the block is defined.

Anyway, fun language.

re: How 'bout we just... 

@suetanvil I'll have to read through this again when it's quieter, to see if I can string enough braincells together to wrap around it...

re: How 'bout we just... 

@woozle

Feel free to ping me if it doesn't make sense. I like talking about programming languages.

Sign in to participate in the conversation
Toot.Cat

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!