Use Conan package manager to copy files to project - conan

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.

Related

handle in meson several git wrap files

I'm working in a project that use meson as build system and has several libs dependency in different repositories
mainProject
---subProj1
---subproj2
---subproj3
.....
in order to clone and get the dependency from each of them I could use the wrap file
e.g.
subProj1.wrap
[subProj1-git]
directory = subProj1
url = https://...../bitbucket/..../subProj1
revision = 0.0.1
depth = 1
but this means that I need one wrap file for each of them, is there a smart way to collect all the wrap files needed in a single file? or is there some other way to handle all the repository that I need to clone

Xcode Build path and copying additional files

I'm writing a plugin for Elgato Stream Deck. https://developer.elgato.com/documentation/stream-deck/sdk/overview/
Basically it is a binary command line tool written in C++/OBJ-C/Swift combined with a JSON manifest and optionally some HTML and JS files as well as different assets (.png, ...). All files have to be included in a folder (com.companyname.pluginname.sdPlugin) which lives in Library/Application Support/com.elgato.StreamDeck/Plugins/
At the moment, I'm building the binary to the default build path (derived data, ...) and manually copy it to the above folder. But I need to build and run that binary with an executable (Stream Deck app) defined in the scheme for debugging under Xcode. The JSON manifest and assets also lives in my xcode project folder and have to be copied manually.
So Before:
After:
So my question: how can I automate that under Xcode? I assume I can do some sort of post build scripting, but I have no knowledge about all that stuff.
Thanks
Solution:
go to target -> build settings
Deployment Location = YES
Installation Build Products Location = / (empty this one!)
Installation Directory = path to folder (= $INSTALL_PATH)
this will copy your binary to the defined installation path
go to target -> build phases
new phase -> run script
cp -r "$SRCROOT"/<FILE OR FOLDER NAME> "$INSTALL_PATH"/<FILE OR FOLDER NAME>
repeat this for all files and folders you need to be copied to the installation path. be careful with empty spaces in the folder/file names, they won't be recognized correctly and you have to use quotation marks

How to set up a Kotlin/Native project so that it places resources alongside the executables?

My Kotlin/Native project's target is a windows exe file.
I would like to ship a text file (let's call it resource.txt) together with the exe file, the goal being that in the build dir, I would have a directory with the built exe file plus the resource files ( so that all I'd need to do is copy that directory to e.g. C:\Program Files\MySoftware).
On Android, I would place these types of files in the assets dir and they would get bundled in the APK.
Is there something equivalent for Kotlin/Native?
Basically I would like to place the text file alongside Kotlin code ( e.g. in commonMain/resources)
and then I would like to end up with a build output directory that contains the built exe file as well as the text file.
Is there a standardized way to do this? Or do I need to create my own gradle scripts to bundle my exe + other files?
It's tracked to be supported (either Gradle task, or maybe compiler) but not available yet, so a custom Gradle task it has to be
youtrack
As answered by #Dmitri, it's not implemented yet ( see on youtrack , or an issue on github )
I've solved this with a set of gradle tasks:
package: copies the release binary into a new dir package
packageToZip : makes a zip from the package dir, for convenience.
runPackaged : executes the binary in the package dir, where the required resource files are present.
tasks {
val thePackageTask = register("package", Copy::class) {
group = "package"
description = "Copies the release exe and resources into one directory"
from("$buildDir/processedResources/myprojectname/main") {
include("**/*")
}
from("$buildDir/bin/myprojectname/releaseExecutable") {
include("**/*")
}
into("$buildDir/packaged")
includeEmptyDirs = false
dependsOn("myprojectnameProcessResources")
dependsOn("assemble")
}
val zipTask = register<Zip>("packageToZip") {
group = "package"
description = "Copies the release exe and resources into one ZIP file."
archiveFileName.set("packaged.zip")
destinationDirectory.set(file("$buildDir/packagedZip"))
from("$buildDir/packaged")
dependsOn(thePackageTask)
}
named("build").get().dependsOn(zipTask.get())
val runPackaged = register<Exec>("runPackaged") {
group = "package"
description = "Run the exe file in the \"packaged\" directory."
workingDir = File("$buildDir/packaged")
dependsOn(thePackageTask)
}
}
This could probably be improved so that one doesn't have to hardcode the build directory names, and the project names, but this worked for me ;-)

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.

How to mark package as a resource folder?

I have a dir structure for Intellij 12:
...
...test
- java
- com.mycompany.myproject
- package1 (contains code, etc,.)
- resourcePackage (want to contain .json files but can't mark as a resource)
- myOtherJunk.json
- o o o
- resources
- aResource.json
The thing is if I right click on my package name (com.mycompany.myproject) I can only add packages and not directories (like that of an existing resource folder).
However, I don't want to use that existing resource folder for the .json files that I'm going to read into per my test class.
So, I need something to support:
// this already works for the resources directory per the .json file but doesn't for the
// myOtherJunk.json per the resourcePackage.
InputStream is = MyClassTest.class.getResourceAsStream("aResource.json");
This can be solved in several ways. An example of a good approach would be the following folder structure:
src
main
java
resources
test
java
resources
When this is done, you put all you java classes under src/main/java/com.mycompany package and any resources under /src/main/resources/com/mycompany folder.
To link them together, go to the project properties, and find the Path tab. Mark the src/main/java and src/main/resources as source folders. (see the screen-shot attached)
If you link them together, you'll be able to use getResourceAsStream() method.
If you wonder why you should use the following folder structure - this is standard maven way of keeping things clean and tidy.
Directories Creation
Intellij creates directories when you ask her to create package. It is not an error.
If you create package "com", it will create the dir "com", and if you create a source file there, it will think that the file is in the package "com".
If you create package "com.next.pack", it will create three nested dirs "com", then "next", then "pack", and if you create a source file there, it will think that the file is in the package "com.next.pack".
Directories Structures
Only the path under the source root is taken as a package. Any directory(ies) can be set as a source root(s).
Resources roots
Make practically any structure of directories. Somewhere in it there is the root dir of resources. Right-click it and Mark Directory As ... Resources Root.
Notice, the same method can be used for the directories structures for tests, test classes, and test resources. Look here.
Please use #ContextConfiguration annotation to load the resource files. Please see below example.
#ContextConfiguration( { "/app-config.xml", "/test-data-access-config.xml",application-test.yml })