Path Issue in Matlab 2014b MCR Deployments with Added Folders - matlab

The compile command mcc -m app.m -a file.ext -a ./dir creates a directory /app containing app.m and file.ext and a directory /dir on the same level as /app containing all the files in /dir. What is the solution to add /dir in the /app directory, not on the same directory level (i.e. /app/dir)?
(Here is why I want to do this: In directory /dir are stored the images that are used by app.m, such as splash screen, button icons, default images, etc. app.m is accessing them using imread('./dir/img.jpg'). Since the compiler is adding the /dir directory one level below where it appears in the Matlab structure at development time, the images are no longer accessible when the standalone software is deployed. Hence I need to use a isdeployed switch to specify the correct path to the images for the development and deployment cases. I would rather avoid this, probably on code aesthetic grounds of an inconsistency of treating added files differently according to whether they are or not on the same directory level as the compiled application [file file.ext is put in /app while the image files from /dir are moved on the same level as /app].)

Instead of adding the path with the compile command, you may be able to use mkdir at run time.
Your command would look like this:
status=mkdir('dir');
The advantage to this is that the dir path is now below your app path, i.e. /app/dir.
The disadvantage is that the user of your program will need the privileges to create that directory.
If you need to compile the directory with the app, you could still use mkdir and then movefile to move all of your files to the new directory from the packaged one.

A possible solution is to use two paths depending on whether the application is deployed or not. Code example:
% path to images directory 'pix'
apppath = mfilename('fullpath');
idx = strfind(apppath,filesep);
if isdeployed
pixdir = [apppath(1:idx(end-1)),'pix',filesep];
else
pixdir = [apppath(1:idx(end)),'pix',filesep];
end
% read image
img = imread(fullfile(pixdir,'logo.jpg'));

Related

Stale file is located outside of the allowed root path when using Cuckoo

I wanted to mock some of my files, so I used Cuckoo framework. I am using Swift Package Manager, so I did every step that is shown in README of framework.
I tried to use this script
# Define output file. Change "${PROJECT_DIR}/${PROJECT_NAME}Tests" to your test's
root source folder, if it's not the default name.
OUTPUT_FILE="${PROJECT_DIR}/${PROJECT_NAME}Tests/GeneratedMocks.swift"
echo "Generated Mocks File = ${OUTPUT_FILE}"
# Define input directory. Change "${PROJECT_DIR}/${PROJECT_NAME}" to your project's root source folder, if it's not the default name.
INPUT_DIR="${PROJECT_DIR}/${PROJECT_NAME}"
echo "Mocks Input Directory = ${INPUT_DIR}"
# Generate mock files, include as many input files as you'd like to create mocks for.
"${PROJECT_DIR}/run" --download generate --testable "${PROJECT_NAME}" \
--output "${OUTPUT_FILE}" \
"${INPUT_DIR}/Common/Repository/LatestNewsRepository/LatestNewsRepositoryImpl.swift" \
# ... and so forth, the last line should never end with a backslash
# After running once, locate `GeneratedMocks.swift` and drag it into your Xcode test target group.
I also downloaded the latest run script and I had to check For install builds only.
When app is launched I am getting this error -
Stale file '.../LibraryTests/GeneratedMocks.swift' is located outside of the allowed root paths.
Things I tried -
Clean Xcode derived data
Clean build folder
Reset Xcode
Reset Packages Cache
and I am still not getting output file. Is there anything else I should try?

Why does Yocto use absolute paths in TMPDIR?

Changing the path of a Yocto environment is not a good idea, as I found out. This also explains why e.g. bitbake can be run regardless the current working directory. Absolute paths are stored in many places during the build process, even subdirectory structures are created into the tmp directory tree. I ended up in rebuilding from scratch - which takes a long time.
A documentation of how I tried to modify all paths:
find . -name *.conf -exec sed -i 's/media\/rob\/3210bcd4-49ef-473e-97a6-e4b7a2c1973e/home/g' {} +
This step replaces absolute paths, within many dynamic conf files (from xx/xx/linux to /home/linux - where linux was chosen for historical reasons. I could mount the partition also as /home/yocto or whatever name).
Next was deletion of subdirectory structures with the old path in the hope that the build process would recognize these deletions, and still rebuild quickly:
find . -name *3210bcd4-49ef-473e-97a6-e4b7a2c1973e* -exec fakeroot rm -r {} +
It was not recognized. Then I gave up.
From a user new to Yocto, familiar with former/classic crossbuild environments based on make menuconfig etc.
My question is:
Why are absolute paths generated & used throughout tmp instead of treating everything as relative?
Or, asked differently:
Why not use something like ${TOPDIR}/tmp throughout the build configuration, instead of hardcoding the absolute path to tmp?

Is it possible to use relative paths in sphinx.conf?

I'm using Sphinx on a Linux production server as well as a Windows dev machine running WampServer.
The index configurations in sphinx.conf each require a path setting for the output file name. Because the filesystems on the production server and dev machine are different, I have to have two lines and then comment one out depending on which server I'm using.
#path = /path/to/folder/name #LIVE
path = C:\wamp\www\site\path\to\folder\name #LOCALHOST
Since I have lots of indexes, it gets really old having to constantly comment and uncomment dozens of lines every time I need to update the file.
Using relative paths would be the ideal solution, but when I tried that I received the following error when running the indexer:
FATAL: failed to open ../folder/name.tmp.spl: Invalid argument, will not index. Try --rotate option.
Is it possible to use relative paths in sphinx.conf?
You can use relative paths, but its kind of tricky because you the various utilities will have different working directories.
eg On windows the searchd service, will start IIRC with a working directory of $WINDIR$\System32
on linux, via crontab, I think it has working directory left over from previously, so would have to change the folder in the actual command line
... ie its not relative to the config file, its relative to the current working directory.
Personally I use a version control system (SVN actually) to manage it. The version from Dev, is always the one commited to the repository, the 'working copy' on the LIVE server, has had the paths edited to the right location. So when 'update' to the latest file, only changes are merged leaving the local filepaths in tact.
Other people use a dynamic config file. The config file can be a script (php/python/perl etc) - but this only works on linux so wont help you.
Or can just have a 'publish' script. Basically, you edit a 'master' config file, and one that can be freely copied to all servers. Then a 'publish' script, that writes the apprirate local path. It could do it with some pretty simple search replace.
<?php
if (trim(`hostname`) == 'live') {
$path = '/path/to/folder/';
} else {
$path = 'C:\wamp\www\site\path\to\folder\`;
}
$contents = file_get_contents('sphinx.conf.master');
$contents = str_replace('$path',$path,$contents);
file_put_contents('sphinx.conf',$contents);
Then have path = $path\name in the master config file, which will get replaced to the proper path, when run the script on the local machine

Is it possible to set output directory for triangle program from triangle package?

I see no way to set destination directory or file here: http://www.cs.cmu.edu/~quake/triangle.switch.html
Actually, the program places result file in the same directory, even if current directory is different.
Why? Is ti possible to change?
The output files for the program are generated from the input file names. You can see this from the source code on line 3586
strcpy(b->outnodefilename, b->innodefilename);
...
strcat(b->outnodefilename, ".node");
strcat(b->outelefilename, ".ele");
...
Because of that I don't think there is a way to set the output directory as an option. It seems you will need to manually copy the output files to a different directory
cp output.node your/output/dir/output.node && rm output.node

Problem with the system command in MATLAB

I am using the system command in MATLAB as follows (with the current directory being 'scripts'):
[status, result] = system('cd ..\\TxtInOut')
However, invoking the system command does not seem to work. It returns status = 0 and result = ''.
Any suggestions?
If you want to change directories, you should use the CD command. The argument can be either a full path or relative path:
cd('c:\matlab\toolbox'); %# Full path to a directory
cd('scripts'); %# Move to a subdirectory "scripts"
cd('..\TxtInOut'); %# Move up one level, then to directory "TxtInOut"
If you want information about a directory, you should use the DIR command. DIR will return an m-by-1 structure of information for a directory, where m is the number of files and folders in the directory. Again, the argument can be either a full path or relative path:
data = dir('c:\matlab\toolbox'); %# Data for a full path to a directory
data = dir('scripts'); %# Data for a subdirectory "scripts"
NOTE: When working on different platforms (i.e. Windows or UNIX), you will have to pay attention to whether you use the file separator \ or /. You can get the file separator for your platform using the function FILESEP. You can also build your file paths using the function FULLFILE.
Any command executed by "system" is external to MATLAB. A command shell is generated, executes your request, and then returns the result. The 0 result indicates successful completion: the command shell changed its current directory as requested and then returned. (Command shells use non-zero to indicate an error, because there are usually many more ways that a program can fail than succeed.) Unfortunately that only affects the command shell's current directory - see gnovice's answer for how to actually change the directory.
you can use cd, dir, ls, etc directly in matlab without call system functions.
You can also use the underlying operating system commands by preceding them by an exclamation sign.
For instance:
!dir will show you the current directory contents in Windows
!pwd will show you the current directory in Linux/Mac
But calling cd does not change the current directory!