Project specific root path environment variable? - linux

In a mixed languages project I have often to refer to configuration files, header files or even Makefiles. I usually use relative paths from the current file. It can be confusing in the case of a YAML configuration file parsed with an external Python script. Should I use the relative path from the configuration file or from the tool used to parse the configuration file? Also if I decide to move my files I have to adjust all the relative paths as well.
To solve this issue I am thinking to use relative paths to the project's absolute root path.
Is there any convention to define a project's path such as:
other_file: "$PROJECT_ROOT/src/foo/bar.xml"
One possible other solution is to always refer to Git, or define an environment variable for that:
other_file: "$(git rev-parse --show-toplevel)/src/foo/bar.xml"
$ export PROJECT_ROOT=`git rev-parse --show-toplevel`

Related

How to set RubyMine's default working directory to the executing .rb program's subdirectory?

In RubyMine, I have a project with many subfolders, each of which contains:
One or more standalone single-file executable Ruby programs (.rb files);
An input text file.
In older versions of RubyMine, when running one of the standalone executable programs (via Cmd+Shift+R on my Mac), the default folder in which RubyMine would look for the input file would be the same directory as the .rb file currently being executed -- which worked great.
The code used to read the file is something like:
data = File.readlines('input.txt')
However, after recently updating RubyMine to v2022.3.1, the behavior has changed, such that RubyMines now seems to be looking in the project's root directory for the file, instead of the same subdirectory as the .rb file currently being run. This produces the error:
in `readlines': No such file or directory # rb_sysopen - input.txt (Errno::ENOENT)
To correct this, I've been going into Run (menu) > Edit Configurations; and in the Edit Configurations dialog, in the configuration that RubyMine auto-created for the current executable file, changing the Working Directory value from the default of the project's root directory, to the subfolder of the current .rb file.
However, this above workaround is annoying, since I need to do it once each for every individual one of the many individual .rb executable files in my project.
My question: How can I configure my project and/or RubyMine itself to go back to the older behavior of defaulting a given .rb file to use its own directory as the default Working Directory, instead of the project's root directory?
(This question and/or its solution might also apply to other JetBrains IDEs such as IntelliJ, since they all seem to work similarly.)
The previous behaviour has been changed with https://youtrack.jetbrains.com/issue/RUBY-29236. So now yes, the logic is the following:
in case of no Ruby module, project's root will be used
in case of Rails, its home folder
otherwise the module's root
There is no option to change it in RubyMine but you can configure the configuration template using some variable there as Working directory.

Relative paths allowed in libtool archive (.la) files?

I am working on a (mostly C/C++) build environment that should be relocatable to a different folder location and system.
This actually already works, but when using libtool archive (.la) files there are warnings about those files being relocated. Basically this error can be ignored and everything builds fine.
So I was wondering if it's possible to have a relative path in .la files (for at least the libdir setting), or if there is some kind of built-in variable that can be used to refer to the path containing the .la file (similar to ${pcfiledir} in pkg-config's .pc files).

Can I include a folder relative to the current directory in PATH in Powershell?

I run a lot of node projects and often have binaries located in:
.\node_modules\.bin
...relative to the projects folder. I'd like to be able to have PATH always include these directories, if they exist. I don't want to include other directories, just the one relative to the current directory. I'm familiar with
Add-PathVariable from PSCX and other Powershell basics, but how do I include a folder relative to the current dir in PATH?
Edit: as mentioned in the question, already, I expect the path to stay updated as the directory changes. This is not simply asking about how to use pwd.
You can use a relative path in Env:PATH and the binaries found will update dynamically:
Eg:
$env:PATH += ';.\node_modules\.bin'
Or with the PowerShell Community Extensions (PSCX):
Add-PathVariable '.\node_modules\.bin'
Unlike using $(pwd) the . is not immediately resolved to an absolute path, so PATH is always relative to the current working directory.
Testing this:
$ which uuid
C:\Users\username\Documents\myapp\node_modules\.bin\uuid.cmd
Then changing directory, uuid now refers to a program in a different dir:
$ cd ..\blog\
$ which uuid
C:\Users\username\Documents\blog\node_modules\.bin\uuid.cmd
It's also possible to persistently change PATH in the user or system environment:
[Environment]::SetEnvironmentVariable(($env:PATH + ';.'), 'User')
or
[Environment]::SetEnvironmentVariable(($env:PATH + ';.'), 'Machine')
Security note: when entering a command Windows will automatically search all directories in $env:PATH for files with one of the extensions listed in $env:PATHEXT and execute the first match it finds. Depending on where exactly in the search path you placed . that may even supersede system executables.
You may want to take a look at how to use package installed locally in node_modules for alternative approaches.

SoapUI and absolute path

I managed to execute a bat file via Groovy in SoapUI with Runtime.runtime.exec("cmd /c C:\temp\test.bat") But I would like to have the bat file in a folder called scripts where my soapui-project file is.
Example:
Soapui-project file.xml
-- Scripts
--- test.bat
Runtime.runtime.exec("cmd /c Scripts/test.bat") doesn't work. I really need help here.
In a team, we share the project artifacts with different members and each may use different directory to copy them. So, in such situations absolute path in groovy scripts, like you mentioned, may not work if the directory gets changes.
To hand this, prefix of the path should be variable. And the rest of the path can fixed as the whole artifacts are still unchanged.
To handle that, use below which makes use of project directory as root and it gets that dynamically.
import com.eviware.soapui.support.GroovyUtils
def path = new GroovyUtils(context).projectPath
log.info "Project directory : ${path}"
Runtime.runtime.exec("cmd /c ${path}/Scripts/test.bat")

hubot script load yml file, dont work with relative path

I am building a hubot script and I want to load a yml file in it.
I am using the yamljs npm package to read the YAML file.
The problem is that it allways says "No such file or directory" error.
If i put the absolute path it works.
What I am missing?
I am loading the file like this:
feeds = YAML.load('../feeds.yml');
Here is my directory structure:
Where are you executing the script from? In node, path files in fs are relative to process.cwd().
Relative path to filename can be used, remember however that this path
will be relative to process.cwd().
Sources: http://nodejs.org/api/fs.html, https://stackoverflow.com/a/16730379/1007263
Therefore, if your script is in the same directory as feeds.yml, you should probably:
feeds = YAML.load('./feeds.yml');
Otherwise, there might be a bug in YAML. In this case, you can simply use path to deliver the absolute path directly.
path.resolve('../feeds.yml')
Source: http://nodejs.org/api/path.html#path_path_resolve_from_to

Resources