How to specify a path to Meson custom_target() command? - meson-build

I did a simple custom target in Meson:
my_build = custom_target('my_build', command: ['../my_script.sh', '-arg1'], build_always_stale: true, output: 'fake')
This works OK..., but when I try to use this as subproject from other Meson projects, I get a message that ../my_script.sh cannot be found.
How do I specify the path to my_script.sh, so that the script is always found, no matter called directly in this subproject, or from a root project?

You need to specify the path to your script and you can do that like this:
scirpt_path = join_paths(meson.current_source_dir(), 'my_script.sh')
and your custom target will look like this:
my_build = custom_target('my_build', command: [script_path, '-arg1'], build_always_stale: true, output: 'fake')
The reason it works for you when you don't have a subproject is because you have a structure that your build directory is in the root of your project, so it is possible to find your script with ../my_script.sh

Related

Set meson variable using Current Directory /Project Directory

I have a meson project on the path /home/$user/foo/bar/project. I want to set a variable sys_root in a cross_compile.txt file. I don't want to hard code the path in case my project moves to another directory.
I don't want sys_root = /home/$user/foo/bar/project/prefix. I want i
sys_root = project-dir/foo/bar/prefix
What is the variable for the current directory with the cross_compile.txt in case it is in the same directory with the meson.build file?
The closest thing that currently exists is the [constants] section of the machine files, you can write something like:
[constants]
root_dir = "/home/$user"
and
[properties]
sys_root = root_dir + "/project_dir/..."
And layer them together with meson setup builddir --cross-file contants.ini --cross-file main.ini

Singularity definition file with paths relative to it

Question
When building Singularity images using definition files, is there a way to specify the path to a file on the host system relative to the definition file (i.e. independent of where the build command is called)?
Example to Illustrate the Problem
I have the following files in the same directory (e.g. a git repository):
foobar.def
some_file.txt
foobar.def looks as follows:
Bootstrap: library
From: ubuntu:20.04
Stage: build
%files
# Add some_file.txt at the root of the image
some_file.txt /some_file.txt
This works fine when I build with the following command in the directory which contains the files:
singularity build --fakeroot foobar.sif foobar.def
However, it fails if I call the build command from anywhere else (e.g. from a dedicated "build" directory) because it searches some_file.txt relative to the current working directory of the build command, not relative to the definition file.
Is there a way to implement the definition file such that the build works independently of where the command is called? I know that I could use absolute paths but this is not a viable solution in my case.
To make it even more complicated: My actual definition file is bootstrapping from another local image, which is located in the build directory. So ideally I would need a solution where some files are found relative the working directory while others are found relative to the location of the definition file.
Short answer: Not really
Longer answer: Not really, but there's a reason why and it shouldn't really matter for most use cases. While Docker went the route of letting you specify what your directory context is, Singularity decided to base all of its commands off the current directory where it is being executed. This also follows with $PWD being auto-mounted into the container, so it makes sense for it to be consistent.
That said, is there a reason you can't run singularity build --fakeroot $build_dir/foobar.sif foobar.def from the repo directory? There isn't any other output written besides the final image and it makes more sense for the directory with the data being used to be the context to work from.

How to use package.json scripts to copy files with specific file extension

I am trying out npm as a build tool.
One stumbling block I have encountered is that I need to copy javascript files from one folder to another. The source folder contains typescript files, javascript files and map files, but in the target folder I am only interested in javascript files.
I do not want to make a copy-statement for each file, but would like to copy all .js files. Also, my source folder contains subfolders that also contains javascript files. These need to be copied as well, and maintain the subfolder structure.
What I have tried is using NCP with a filter, but I cannot get the filter to work. I have tested the regex used in the filter and it appears to work fine. The test was done at Regex Tester with regular expression .*\.js$ and test-strings like main.ts, main.js main.js.map etc, and only the .js strings were matched.
My package json contains the following (abbreviated):
{
"scripts": {
"copy": "ncp scripts wwwroot/scripts --filter=\".*(\\\\.js$)\""
},
"devDependencies": {
"ncp": "2.0.0.0"
}
}
Since my regex is in a string in a string I have double-escaped it. I have also tried other variations, for example:
--filter=/.*\.js$/g - compilation error
--filter=/.*\\.js$/g - no files copied
--filter=\".*\\.js$\" - no files copied
--filter=\"/.*\\.js$/g\" - no files copied
(no filter) - all files copied
I am in no way married to NCP. If something else works better then I will use that.
So: How do I, inside package.json's scripts section copy only files with a speific extension to another folder? I am pretty sure I have overlooked something blindingly obvious...
Warning! The cpx package appears to be abandoned. cpy-cli, copyfiles, and other solutions are listed in comments here or answers, below.
cpx might be a good substitution.
It has a CLI, allows you to use globs instead of regex, can preserve the directory tree, and is relatively up-to-date as I write this....
There's also npm module called copyfiles
https://github.com/calvinmetcalf/copyfiles
E.g. to copy all *.css files from the ./src folder to the ./styles folder:
copyfiles --flat src/*.css styles
Quick compatibility build script (also works on Windows):
"build": "react-scripts build && mv build docs || move build docs",
#powershell copy \"D:/Path/untitled.txt\" destionation-file.txt"
Windows users:
// Copy file
xcopy c:\workfile d:\test
// Copy folders incl. sub folders
xcopy <source> <destination> /e
// If folder name has space in name use double quotes
xcopy c:\workfile “d:\test new”
More info here
You can use gulp.js for this.
Write a gulp task to isolate only the js files (/path/to/files/*.js) and move it to destination of your choice.
It will require only a few lines of code.
Include that in the script section of package.json if necessary.
The link to gulp.js : https://gulpjs.com/
var gulp = require('gulp');
gulp.task('jscopy', function(){
return gulp.src('client/templates/*.js')
.pipe(gulp.dest('build/js'))
});
ncp copies recursively, therefore before copying files it will check whether directory matches filter or not, e.g.:
d:\path\to\app\src\server
d:\path\to\app\src\server\middleware
d:\path\to\app\src\server\middleware\cool-middleware.js
d:\path\to\app\src\server\middleware\cool-middleware.js.map
So your regex must matches all these paths and your file also
I am able to just use cp in my script command:
"build": "npx babel src --out-dir dist && cp ./src/*.css ./dist",
This will work if you have your distribution package already inside the /dist folder. You can also add another command to copy that over, then even run the publish command.
I use this in Git bash in windows which has the cp command available. The comments are correct that you will need this in your underlying shell/command prompt. It should be able to be modeled and updated for your OS.
#KostovV answer but adapted for json string and relative path
"build": "nest build && xcopy \".\\myFolder0\" \".\\myFolde1\\sub\"",

How to pass bundle id of extension as environment variable

I need to build an Xcode project within a Today Extension by 'xcodebuild'. The bundle is of the main target is com.myapp, while the bundle id of the extension is com.myapp.todayextension.
I'd like to pass both the bundle id's as parameters of xcodebuild: I tried to replace the bundle id's in the xcode project by custom environment variables (e.g. ${MAIN_TARGET_BUNDLEID} and ${EXTENSION_BUNDLEID}) but the xcodebuild fails. Could you please help me with the correct syntax of xcodebuild command ? Thanks.
That's called PRODUCT_BUNDLE_IDENTIFIER, as per the documentation.
Better too late than never; We can't directly use an environment variable in General tab, you will need to go into Build Settings tab, then set Product Bundle Identifier to your environment-variable, for example $(PRODUCT_NAME).
See below for another approach.
How to load prefix set by parent project?
Create an .xcconfig file (with content like example).
Set up the .xcconfig file in project settings's Info tab (not target's Info tab).
In target's Build Settings tab, ensure PRODUCT_BUNDLE_IDENTIFIER is not bold (click it and press delete).
But Podfile users should see also: How to make Xcode use multiple xcconfig files?
Example
My extension.xcconfig file (which is in MyApp/MyLib/MyExtension directory), looks something like:
// Below loads `MyApp/config/mylib.xcconfig` file.
#include "../../config/mylib.xcconfig"
PRODUCT_BUNDLE_IDENTIFIER = $(MYLIB_BUNDLE_PREFIX).$(PRODUCT_NAME)
Note that:
You want to use some environment as prefix, but above I use PRODUCT_NAME as suffix (simply edit as you wish).
The mylib.xcconfig file sets MYLIB_BUNDLE_PREFIX, and is outside of my MyLib.xcodeproj file's directory (so is in parent project's config directory, I describe in MyLib's README.md that users should create it there).
So, beside showing my #include approache, I try to introduce use of environment-variable.

Get the closest path that have a config.rb file in file watcher plugin

I recently installed the file watchers plugin, and I must configure it to use compass to compile my sass files.
My current config is:
Program: compass
Arguments: compile
Working dir:
Env vars:
output:
How can I target the closest path to(upward folder tree) config.rb file within scss`s parents folders?
I need it to put in "Working dir:" field
My paths are
scss:
projects/<gitrepo>/<project>/<module-name>/static/<same-module-name>/scss/common/main.scss
css:
projects/<gitrepo>/<project>/<module-name>/static/<same-module-name>/css/common/main.css
config.rb are in:
projects/<gitrepo>/<project>/<module-name>
Module name and folders under scss may vary.
Thanks
I'm using the following solution:
Create a compass project in your Idea project folder by this command in your idea project folder:
compass create --css-dir <your css dir here> --sass-dir <your SASS dir here>
this will create a config.rb in the root of your idea project (this is important). You can learn more about possible options calling compass create --help.
Set up the following setting for SASS/SCSS file watcher
Scope: project files
Program: compass.bat
Arguments: compile $FilePathRelativeToProjectRoot$
Working directory: $ProjectFileDir$
Environment variables: --empty--
Output paths to refresh: --empty--
Please note that ruby bin folder is in my PATH environment variable.