Dynamically loading erlang header files - erlang

I know that you can dynamically load erlang beam files in an erlang node using "l(module_name).". My question is is it possible to load ".hrl" files the same way or some such similar without having to restart an erlang node

I am not sure this is possible, but just based on understanding, when you try to define an macro in url and you want to modify it, the compiler replaces the macro during the compilation of the erlang file by replacing the the macros that are defined in header.
Logically you should rebuilding you code and deploy it again. I don't understand a reason why you need hrl files to be loaded dynamically if you have an option for replacing the entire code dynamically. IMHO all you need to do is rebuild and upgrade and this also can be done without restarting erlang node.

".hrl" files - used only by compiler on compile sources. It is not is runtime files.
You can use popular auto-reloader by Mochi team
https://github.com/mochi/mochiweb/blob/master/src/reloader.erl
put them in your src/ folder and add to your exec erl -s reloader option

Related

Is there a way to add native rules to Bazel?

I would like a set of rules from my_package.bzl to be accessible to all BUILD files of a workspace without having to load my_package.bzl in the BUILD files. Basically I want the rules in the package to look like native rules. How can I achieve this?
I was thinking maybe there's a line I could add to one of the .bazelrcs or to the WORKSPACE file of the the project.
This can be achieved by adding a prelude_bazel file at //tools/build_rules:prelude_bazel (this must be a package, so tools/build_rules must contain a BUILD file).
This will be loaded and prepended to all BUILD files loaded by Bazel.
However, there are a few things to consider before going this route. It's currently undocumented, and while doing some searching to find any info on this feature, it's unclear if it will remain a part of Bazel.
It may also have performance / scaling problems. If the prelude were to change (or any of its dependencies), every BUILD file would have to be reloaded, and this may take some time depending on the size of the build graph.

How to reload all OTP code when developing an OTP application?

While I'm learning OTP I've been making a lot of changes to the .app and .erl files and re-running my application to see the effect of the changes.
I've tried the following sequence of commands to pick up all my new changes, but it doesn't seem to work:
Compile src files ...
erlc -o ebin src/*.erl
... followed by this is the erlang shell:
application:stop(my_app).
application:unload(my_app).
application:load(my_app).
application:start(my_app).
However, this doesn't seem to work. The only way I have found to work is to exit the erlang shell, recompile the app and then run application:start(my_app)..
Is there an easier way of picking up my changes?
Calling application:load(App) (after stopping and unloading) will reload the .app file but not the modules. As the documentation says: "Note that the function does not load the actual Erlang object code."
If you were to do an upgrade using releases, you would ship an .appup file that specified which modules to reload on upgrade to the new version (no need to reload all of them if only one or two have changed), but if you're just developing and don't want to stop and restart everything, you'll have to set up your own help functions for reloading code.
Edit: Since OTP 20 (2017), the interactive Erlang shell now has the lm() function for loading all modules whose .beam files have changed, so there is no need to roll your own utility function for this anymore. See https://erlang.org/doc/man/c.html#lm-0

How do I know which modules to include when packaging with py2app?

I'm trying to package the Mac version of an open source application that I didn't write (I'm not much of a coder). I'm using py2app 0.6.4. The application builds on my system properly, but I'm unsure of what to list for the includes in the setup.py file.
The dependencies include qt4, PyQt, matplotlib, cherrypy, and sip.
When I looked at this article on handling PyQt applications, I noticed the dependencies were not listed simply as PyQt but rather *PyQt4._qt* etc. How can I determine what to insert in the includes statement from the code of the application?
When py2app runs, it's going to look at each of your scripts, automatically grabbing any modules or packages imported by your scripts. In many cases, this will suffice and you won't need to list anything in the includes variable. Some packages have extra files such as data files that aren't used by the import statement, but must be present for the package to run correctly. Then you need to explicitly include it so py2app will grab it as well. Try to use your app; if you get an error that some module or file isn't found then worry about putting it in the includes variable.

QMake and a .pro file

I've downloaded a package and am trying to build/install it. The project's wiki page has a command that looks like
qmake VAR=/path/to/something/ project.pro
It says that this command should tell qmake to generate a make file. Instead, I'm getting
qmake: Nothing to be done for `project.pro'.
Why is qmake not generating the make file like it's supposed to?
Without knowing the project in questions or the contents of the project (.pro) file, it is difficult to diagnose. One possibility is that qmake was already run, or that the files it is to generate are included with your download. In these circumstances, there really is nothing to be done for said project.
As a side note, may I recommend downloading "Qt Creator" and opening the project file in there? Qt Creator tends to make Qt development and project building a lot easier.
I just answered my own question... apparently there is more than one qmake. On my system, we're using a qmake: distributed parallel make, scheduling by Grid Engine. I found /etc/alternatives/qmake which is the QT qmake...

How do I change the file extension for dependencies

I'm building a program that uses Delphi Packages (BPLs) as plugins, but I'd like to use a custom extension to show that the files have a specific purpose instead of just being BPLs. That works well enough until I end up with one package having a dependency on another. Then the compiler automatically creates the binary with the extension BPL built in.
This wouldn't be too hard to fix with a hex editor, but that's sort of an extreme solution. Is there any way I could make the compiler generate the packages with the right dependency names in the first place?
EDIT: The answers so far seem to have not understood the question.
I know exactly how to create the packages with my custom TEP extension instead of a BPL extension. But if I have package1.TEP and package2.TEP, and package2 depends on package1, and then I try to load package2, it gives an error because it can't find "package1.BPL". What I want is to find some simpler way to make package2 look for the correct filename, "package1.TEP," that doesn't involve editing the binary after it's been created. Is there any way to do that?
Use the {$E} directive.
The simplest solution would be to use a post build event to rename your destination file from *.BPL to whatever specific extension you are requiring.
EDIT:
You could write a separate patch program to search for and patch the offending binaries and run it as part of the post build process. If a patch is made to the compiler, then you can remove your step easily.

Resources