I want to run a check like
if user is root then
directorypath = /set/path/to/this/dir
else
directorypath = /set/path/to/that/dir/instead
In my Makefile.am but I am unsure on what syntax to use to achieve this and whether or not I need to do something in configure.ac to make the conditional work. Can anybody point me in the right direction?
Figured it out.
In configure.ac:
AM_CONDITIONAL(USER, test `whoami` = "root")
In Makefile.am:
if USER
directorypath = /set/path/to/this/dir
else
directorypath = /set/path/to/that/dir/instead
endif
Simples.
Related
I am currently using bazel for my GoLang app.
container_image(
name = "my-golang-app",
base = "#ubuntu_base//image",
cmd = ["/bin/my-golang-app"],
directory = "/bin/",
files = [":my-golang-app"],
tags = [
"manual",
VERSION,
],
visibility = ["//visibility:public"],
)
Except my-golang-app folder I need to copy, while building this image, another folder named my-new-folder and everything in it.
How does one do that with bazel? I can't seem to find the solution in the bazel docs.
dockerfile {
run 'mkdir -p /usr/local/bin'
// add the lines below
add {
from 'docker/my-new-folder/'
into '/'
}
Use pkg_tar like the container_image docs reference. Something like this:
pkg_tar(
name = "my-files",
srcs = glob(["my-new-folder/**"]),
strip_prefix = ".",
)
container_image(
name = "my-golang-app",
files = [":my-golang-app"],
<everything else you already have>,
tars = [":my-files"],
)
pkg_tar has various options to control where your files end up, if you want something beyond just taking an entire directory. For more complicated arrangements, I find multiple pkg_tar rules for various directories linked together via deps a helpful pattern.
I have a program that uses forms. The forms are pointing to files in c:\filepath1 as set forth in main.prg (set defa, set path). I make a test copy of the files, change the path in main.prg, the forms are still referencing the files in the old path. I don't want to have to recreate all the data environments in all the forms. How can I avoid doing so? Any help on this would be kindly appreciated.
Missy.
When Dataenvironment is used AND the path recorded in DataEnvironment tables exist, then that path is used no matter what the current path is. If you don't want to touch Dataenvironment at all (even programmatically) then you must remove that path (rename for example).
As a side note: I have:
UpdateDE(this)
in my DataEnvironment.BeforeOpenTables method. In UpdateDE.prg I have code that loops all the cursors in DE and set their path to the one that I want to use as "current".
EDIT: Here is a sample UpdateDE.prg:
Lparameters toDE
Do setups && prg keeping common "set" entries
Local Array aDEMembers[1]
Local lnMembers,ix,lcMembers
If !(Type('oApp')='O' And !Isnull(m.oApp))
Public oApp
oApp = Createobject('myApp')
Endif
lnMembers = Amembers(aDEMembers,m.toDE,2)
For ix=1 To m.lnMembers
With Evaluate('toDe.'+aDEMembers[m.ix])
If Lower(.BaseClass) == 'cursor'
If Atc(oApp.cAppDBC,.Database) > 0
.Database = Addbs(oApp.cAppDataPath)+oApp.cAppDBC
Else
.CursorSource = Addbs(oApp.cAppDataPath)+Justfname(.CursorSource)
Endif
Endif
Endwith
Endfor
Define Class myApp As Custom
cAppDBC = 'myDatabase.dbc'
cAppDataPath=Fullpath('data')
cCurPath = ''
Procedure Init
This.cCurPath = Set('path')
If File('dbparam.dbf') && a small dbf that holds path to current data folder
Select dataLoc From dbparam Where locType == 'DATABASE' Into Array arrDataLoc
If _Tally > 0
This.cAppDataPath = arrDataLoc
Set Path To (arrDataLoc[1]+';'+This.cCurPath)
Endif
Use In 'dbparam'
Endif
Endproc
Procedure Destroy
Set Path To (This.cCurPath)
Endproc
Enddefine
I ended up renaming the default path then going through all the screens in the program then recompiling. Thank you for your help. I did understand it and is probably another good solution.
I would like to use a specific version of g++ installedvat /opt/blabla/bin/g++.
How do I force premake to add initialization of CXX variable in makefile, such that it will point to the specific location?
I do realize that once makefile is generated, I can to 'make CXX=...' but I would like to have CXX set inside auto-generated makefile.
Using premake5, targeting gmake.
Thanks in advance
=============
Update:
By poking examples and browsing the code, I figured out I can do it by adding this code into premake5.lua:
local GCC_BIN_PATH = "/opt/blala/bin"
-- start: setting gcc version
-- todo: consider moving this instrumentation into a side lua script
local gcc = premake.tools.gcc
gcc.tools = {
cc = GCC_BIN_PATH.."/gcc",
cxx = GCC_BIN_PATH.."/g++",
ar = GCC_BIN_PATH.."/ar"
}
function gcc.gettoolname(cfg, tool)
return gcc.tools[tool]
end
-- finish: setting gcc version
Is there a better way to achieve the same? In particular, does it make sense to redefine gettoolname function?
Same answer as above but more generic. This file can be named "add_new_gcc_toolset.lua":
local function add_new_gcc_toolset (name, prefix)
local gcc = premake.tools.gcc
local new_toolset = {}
new_toolset.getcflags = gcc.getcflags
new_toolset.getcxxflags = gcc.getcxxflags
new_toolset.getforceincludes = gcc.getforceincludes
new_toolset.getldflags = gcc.getldflags
new_toolset.getcppflags = gcc.getcppflags
new_toolset.getdefines = gcc.getdefines
new_toolset.getincludedirs = gcc.getincludedirs
new_toolset.getLibraryDirectories = gcc.getLibraryDirectories
new_toolset.getlinks = gcc.getlinks
new_toolset.getmakesettings = gcc.getmakesettings
new_toolset.toolset_prefix = prefix
function new_toolset.gettoolname (cfg, tool)
if tool == "cc" then
name = new_toolset.toolset_prefix .. "gcc"
elseif tool == "cxx" then
name = new_toolset.toolset_prefix .. "g++"
elseif tool == "ar" then
name = new_toolset.toolset_prefix .. "ar"
end
return name
end
premake.tools[name] = new_toolset
end
return add_new_gcc_toolset
I think that official way is to create your own toolset.
The example below creates a toolset with the "arm_gcc" name:
premake.tools.arm_gcc = {}
local arm_gcc = premake.tools.arm_gcc
local gcc = premake.tools.gcc
arm_gcc.getcflags = gcc.getcflags
arm_gcc.getcxxflags = gcc.getcxxflags
arm_gcc.getforceincludes = gcc.getforceincludes
arm_gcc.getldflags = gcc.getldflags
arm_gcc.getcppflags = gcc.getcppflags
arm_gcc.getdefines = gcc.getdefines
arm_gcc.getincludedirs = gcc.getincludedirs
arm_gcc.getLibraryDirectories = gcc.getLibraryDirectories
arm_gcc.getlinks = gcc.getlinks
arm_gcc.getmakesettings = gcc.getmakesettings
function arm_gcc.gettoolname (cfg, tool)
local prefix = path.getabsolute ("../../arm_env")
prefix = prefix .. "/arm_toolchain/bin/arm-linux-gnueabihf-"
if tool == "cc" then
name = prefix .. "gcc"
elseif tool == "cxx" then
name = prefix .. "g++"
elseif tool == "ar" then
name = prefix .. "ar"
else
name = nil
end
return name
end
Then you can use:
toolset "arm_gcc"
Inside your projects, filters, etc.
This method has the advantage that you aren't overwriting the regular gcc toolset. Both can coexist if necessary.
In my case I actually find cleaner to add each compiler in its own lua file and then include it from the main (premake5.lua) script.
as a workaround, I found this method:
makesettings [[
CC = gcc
]]
https://github.com/premake/premake-core/wiki/makesettings
See this snippet of code:
exclude = ["BURSAR", "SHOP"]
for name in exclude:
if name in machineName: # machineName is defined further up in the script.
inputText.insert("end", machineName + " has been excluded.\n")
else:
command = subprocess.Popen( commands here...)
It's job is to exclude any machine which includes certain words within it's name.
Currently, if I pass two machines to the script, one of which is called 'BURSAR3' (for example), it will register the fact that it should be excluded, and runs the inputText to show that fact. Unfortunately it also continues to pass the name to the command below, when it shouldn't. I can even replace the 'else:' with 'if name not in exclude:' and it will still fail in the same way!
What have I done wrong here? It looks like it should be so simple...
Thanks,
Chris.
p.s. apologies if the title is rubbish - I couldn't think how to define it better...
Use the optional else after a for:
exclude = ["BURSAR", "SHOP"]
for name in exclude:
if name in machineName: # machineName is defined further up in the script.
inputText.insert("end", machineName + " has been excluded.\n")
break
else:
command = subprocess.Popen( commands here...)
The else is executed ONLY if the for loop completed naturally, without encountering the break. Thus, if none of the blacklisted words appear in the machine name, the else block is executed.
Of course, there's an easier way to do this:
exclude = ["BURSAR", "SHOP"]
if any((name in machineName for name in exclude)): # machineName is defined further up in the script.
inputText.insert("end", machineName + " has been excluded.\n")
else:
command = subprocess.Popen( commands here...)
I am having a problem in matlab and the problem is described as follows:
When i try to read an image ( I have several images) and write them to a specific folder, the matlab triggers an error saying
Error using ==> imwrite at 394
Can't open file "\Temp\\inim735282.4716703009300000.jpg" for writing.
You may not have write permission.
May I know why this is happening?
this is the code where the problem occurs
mkdir('.\Temp');
temp_name = sprintf('%.16f',now);
corner_file = ['\Temp\corners', temp_name,'.in'];
image_file = ['\Temp\inim', temp_name,'.jpg'];
out_file = ['\Temp\out', temp_name,'.desc'];
out_imname = ['\Temp\out', temp_name,'.desc.jpg'];
I tried to change it by omitting
mkdir('.\Temp');
moreoever, i direct the path in the folder to the folder by doing this
binary_path = 'C:\Users\cool\Documents\MATLAB\Experment\experiments\bag_of_words\Temp';
to read and and write in and out of the folder.
Can someone please help me figure out this problem?
Thank you guys
Open MatLAB with admin privileges.
A few suggestions:
To generate a temporary output name use the command tempname.
temp_name = tempname();
To concatenate paths and file names use fullfile.
conrner_file = fullfile( '\', 'Temp', 'corners', [temp_name, '.in'] );
You should be careful not to mix '\Temp' and '.\Temp': as the first is an absolute path, while the second is a relative path to cwd.
EDIT:
How about:
temp_name = tempname(); % temp name + folder name in TEMP
corner_file = [ temp_name,'.in'];
image_file = [ temp_name,'.jpg'];
out_file = [temp_name,'.desc'];
out_imname = [temp_name,'.desc.jpg'];
Is it working now?