[Qbs] Using ConanfileProbe with yocto cross compiling toolchain
Kai Dohmen
psykai1993 at googlemail.com
Mon May 18 09:20:22 CEST 2020
Hello.
I archived my goal with the following code:
Yocto_Conan_Qbs.qbs:
import qbs
import qbs.File
import qbs.FileInfo
import qbs.Probes
import qbs.Process
import qbs.TextFile
import qbs.Utilities
Project {
references: conanFileProbe.generatedFilesPath + "/conanbuildinfo.qbs"
Probe {
id: yoctoEnvProbe
/* in */
property path environmentSetupScriptPath:
"/home/psy-kai/Develop/Yocto_SDKs/armv7hf_reference/environment-setup-armv7vet2hf-neon-poky-linux-gnueabi"
/* out */
property var environmentVariables
/* private */
readonly property path _projectBuildDirectory:
project.buildDirectory
readonly property path _envExportScript:
FileInfo.cleanPath(FileInfo.joinPaths(project.sourceDirectory,
"env_export.sh"))
configure: {
var extractEnvironmentVariables = function(textFile){
var extractVariable = function(line){
var eqPos = line.indexOf("=");
var name = line.substr(0, eqPos);
var value = line.substr(eqPos+1);
if (!name)
throw "Invalid line in "+textFile.filePath();
return {"name": name, "value": value};
}
var envVars = [];
while (!textFile.atEof())
envVars.push(extractVariable(textFile.readLine()));
textFile.close();
return envVars;
}
var outputEnvFiles = FileInfo.cleanPath(
FileInfo.joinPaths(_projectBuildDirectory,
"yoctoenv",
Utilities.getHash(environmentSetupScriptPath)));
File.makePath(outputEnvFiles);
var emptyEnvFilePath = FileInfo.joinPaths(outputEnvFiles,
"emptyEnv");
var yoctoEnvFilePath = FileInfo.joinPaths(outputEnvFiles,
"yoctoEnv");
var process = new Process();
try {
process.exec("env",
["-", _envExportScript,
environmentSetupScriptPath, emptyEnvFilePath,
yoctoEnvFilePath],
true);
} finally {
process.close();
}
var emptyEnvVars = extractEnvironmentVariables(new
TextFile(emptyEnvFilePath));
var yoctoEnvVars = extractEnvironmentVariables(new
TextFile(yoctoEnvFilePath));
environmentVariables =
yoctoEnvVars.filter(function(yoctoEnvVar){
for (var i in emptyEnvVars) {
if (emptyEnvVars[i].name === yoctoEnvVar.name)
return false;
}
return true;
});
found = true;
}
}
Probes.ConanfileProbe {
id: conanFileProbe
conanfilePath: project.sourceDirectory+"/conanfile.txt"
additionalArguments: {
var args = ["-pr:b=imx6", "-b=missing"];
for (var i in yoctoEnvProbe.environmentVariables) {
var envVar = yoctoEnvProbe.environmentVariables[i];
args.push("-e:b="+envVar.name+"="+envVar.value);
}
return args
}
generators: "qbs"
}
}
env_export.sh:
#!/bin/sh
env > $2
source $1
env > $3
But this code has some restrictions (like using bash or zsh but not fish).
Thus I don't think that it should be made into the official Qbs codebase.
Maybe this code could be used in some How-To section or something.
If you really want me to contribute this as a "YoctoEnvironmentProbe",
despite the restrictions, I will do some cleanup an contribute it.
Kai
Am Fr., 15. Mai 2020 um 13:50 Uhr schrieb Richard Weickelt <
richard at weickelt.de>:
>
> > Sorry. I meant how to extract the environment variables from the yocto
> script.
> > My idea was to source the script in a process
> > with https://doc.qt.io/qbs/jsextension-process.html
> > and then just query all the process environment variables with
> > https://doc.qt.io/qbs/jsextension-environment.html#currentenv.
> > This way I would not need to parse the yocto script myself in the
> > "YoctoEnvProbe".
>
> Maybe you can write another script that
> 1. prints the environment variables
> 2. then sources the yocto script
> 3. then prints the environment variables again
>
> Run this script in a Probe (with an appropriate shell) and parse the output
> somehow. You may also omit step 1 and just use all environment variables
> printed by script.
>
> Richard
> _______________________________________________
> Qbs mailing list
> Qbs at qt-project.org
> https://lists.qt-project.org/listinfo/qbs
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qbs/attachments/20200518/fcd1f7fe/attachment.html>
More information about the Qbs
mailing list