Set meson variable using Current Directory /Project Directory - variables

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

Related

How to specify a path to Meson custom_target() command?

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

Use Conan package manager to copy files to project

I use Conan to manage the dependencies within my (c++) project.
Now I need some relatively large files in the project, which should not be checked in to GIT. I have these files on a http server and want to download them via a Conan recipe and make them available within my project (the files are needed by the finished binary and have nothing to do with the build process itself).
But I can't get conan to copy the files to the right place, here is my attempt:
from conan's import ConanFile, tools
class MyPackage(ConanFile):
name = "package"
version = "11.28"
author = "Whatever"
keep_imports = True
exports = "*"
def source(self):
tools.get("http://just/a/file.zip")
def imports(self):
self.copy("*", dst="content")
def package(self):
self.copy("*")
def package_id(self):
self.info.header_only()
For example, if my project is located under C:\dev\project and the files A.dat, B/C.dat are located in the "file.zip", I would like to have them under c:\dev\project\ \A.dat or c:\dev\project\ \B\C.dat
The problem is that when I run the recipe, the files are under <CONAN_HOME>\package\11.28\ (...) \package\A.dat or
<CONAN_HOME>\package\11.28\ (...) \package\B\C.dat (Additionally also under <CONAN_HOME>\package\11.28\ ... \source, but that is not important)
and not under c:\dev\project...
You are calling
conan create .
when you run the recipe I suppose. Actually you can't modify you local folder running conan create, but there is one exception to this rule:
if you define a
set_version(self):
self.version = "11.28"
# do whatever you want in your local folder
# e.g. tools.get("http://just/a/file.zip")
# and unpack your files into A.dat and B/C.dat
inside your recipe. All you do inside this function is executed within your current working directory, so you could download your zipfile here and copy the files in it in their locations.
Additionally, you have to pick these files with the exports_sources attribute if you want them to become part of your final package:
exports_sources = "A.dat","B/C.dat"
This is a hack and should be avoided, however.
Try instead to package your files "A.dat" and "C.dat" in a own package say MyDats/1.0, using the following recipe:
class MyPackage(ConanFile):
name = "MyDats"
version = "1.0"
def source(self):
tools.get("http://just/a/file.zip")
# unpack files into A.dat and C.dat herein..
def package(self):
self.copy("*", dest = "include", keep_path = False)
def package_id(self):
self.info.header_only()
By the way: you don't need to specify exports = "*" normally, the only things that should be exported are files that are necessary to run the recipe itself (not source code or your files A.dat, C.dat).
When you call
conan create .
on this it will package your files and install them locally in your cache.
Then place a conanfile.txt in your folder C:\dev\project\import\ of your local project containing:
[requires]
MyDats/1.0
[imports]
include, A.dat -> ..\
include, C.dat -> ..\B
You can obviously put your conanfile.txt in another location than project\import, the main point is to non have two recipes in the same location.
If these file are needed in your finished binary, you should include them into your package of your project however, which is what you did already inadvertently as far as I understood.

Apache server cannot find local file [duplicate]

I'm working on a Flask extension from which I want to create a directory in the project's root path on the file system.
Suppose we have this directory structure
/project
/app
/tests
/my_folder
manage.py
my_folder should be created dynamically by the extension, which is a test utility and wraps the application under test in the /tests directory. However, I'm struggling to determine the project's root path within my extension.
For now, I am trying to guess the path from the run file:
def root_path(self):
# Infer the root path from the run file in the project root (e.g. manage.py)
fn = getattr(sys.modules['__main__'], '__file__')
root_path = os.path.abspath(os.path.dirname(fn))
return root_path
This obviously breaks as soon as the tests are run from within the IDE instead of the manage.py. I could simply infer the project's root relative to the app or tests directory, but I don't want to make any assumptions regarding the name or structure of these directories (since multiple apps might be hosted as subpackages in a single package).
I was wondering if there is a best practice for this type of problem or an undocumented method which the Flask object provides (such as get_root_path).
app.root_path contains the root path for the application. This is determined based on the name passed to Flask. Typically, you should use the instance path (app.instance_path) not the root path, as the instance path will not be within the package code.
filename = os.path.join(app.instance_path, 'my_folder', 'my_file.txt')
app.root_path is the absolute path to the root directory containing your app code.
app.instance_path is the absolute path to the instance folder. os.path.dirname(app.instance_path) is the directory above the instance folder. During development, this is next to or the same as the root path, depending on your project layout.

Remove Structure from Copy

I have a Task on my TFS build to Copy files to the staging folder:
Currently, this builds the staging folder with all the subfolder structure, e.g. \MyProject\bin\release\
Is there a way to set this so that it dumps to just \MyProject\, without the bin\release portions?
You can try change the output path :
Configure the build configuration output path, eg set ".\" as
out path (In solution right click the project > properties > Build > Output > Output path).
Specify the output path in MSBuild Arguments such as
/p:OutputPath=$(Build.BinariesDirectory) then copy from $(Build.BinariesDirectory) directly. Reference screenshot below.
Besides, you can also try to copy the contents to stage folder first. then add another Copy Files step to copy the \MyProject\bin\release\** to \MyProject

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.