Skip to content

Commit

Permalink
maint: sync luke with upstream.
Browse files Browse the repository at this point in the history
* build-aux/luke: Sync with upstream for bug fixes.
* NEWS.md: Update.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
  • Loading branch information
gvvaughan committed May 30, 2017
1 parent e252015 commit aae1889
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 30 deletions.
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# lyaml NEWS - User visible changes

## Noteworthy changes in release 6.1.3 (2017-05-29) [stable]

### Bug fixes

- `luke` no longer bombs out with a nil concat error.


## Noteworthy changes in release 6.1.2 (2017-04-30) [stable]

### Bug fixes
Expand Down
70 changes: 40 additions & 30 deletions build-aux/luke
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env lua
--[[ minified code follows, see --help text for source location! ]]
package.searchers=package.searchers or package.loaders
for i=2,#package.searchers do
package.searchers[i]=nil
Expand All @@ -10,7 +11,7 @@ stderr:write('luke: fatal: '..msg..'\n')exit(1)end}
end
package.preload['luke.cli']=function()
local _ENV=require'std.normalize'{'luke._base','luke.lukefile','luke.platforms','std.functional',}local function version()print[[
luke (Luke) 0.1
luke (Luke) 0.1.1
Written by Gary V. Vaughan <gary@gnu.org>, 2014
Copyright (C) 2017, Gary V. Vaughan
Expand Down Expand Up @@ -44,12 +45,12 @@ stderr:write('luke: error: '..msg..'\n')stderr:write("luke: try '"..arg[0].." --
local function display(...)return stdout:write(concat{...})end
local function dump(...)return stderr:write(' DEBUG: "'..concat(map(list(...),str))..'"\n')end
local function interpolate_to_substitute(s)return(gsub(s,'%$([%w_]+)','@%1@'))end
return{parse_arguments=function(args)local clidefs,fname,targets,install={},'lukefile',{},{}local verbose,write,debug=nop,display,nop
map(args,function(opt)case(opt,{['--debug']=function()debug=dump
return{parse_arguments=function(args)local clidefs,fname,targets,install={},'lukefile',{},{}local verbose,write,log=nop,display,nop
map(args,function(opt)case(opt,{['--debug']=function()log=dump
end,['--file=(.+)']=function(optarg)fname=optarg
end,['--quiet']=function()write=nop
end,['--verbose']=function()verbose=display
end,['--help']=help,['--version']=version,['(.+)=(.+)']=function(name,value)clidefs[name]=value
end,['--help']=help,['--version']=version,['([^=]+)=(.+)']=function(name,value)clidefs[name]=value
end,function(opt)if match(opt,'^-')~=nil then
opterr(format("unrecognized option '%s'",opt))end
append(targets,opt)end,})end)local luke,err=loadluke(fname)if luke==nil then
Expand All @@ -69,7 +70,7 @@ luke.modules=build
if isempty(luke.modules)then
luke.external_dependencies=nil
end
luke.substitute=merge(luke.substitute or{},{package=interpolate_to_substitute(luke.package),version=interpolate_to_substitute(luke.version),})luke.variables=merge(luke.variables or{},collect_variables(luke),{LUA_DIR='/usr',LUA_BINDIR='$LUA_DIR/bin',LUA_INCDIR='$LUA_DIR/include/lua$LUAVERSION',LUA_LIBDIR='$LUA_DIR/lib',objdir=platforms[1],package=luke.package,version=luke.version,})return{clidefs=clidefs,install=install,debug=debug,luke=luke,verbose=verbose,write=write,}end,}
luke.substitute=merge(luke.substitute or{},{package=interpolate_to_substitute(luke.package),version=interpolate_to_substitute(luke.version),})luke.variables=merge(luke.variables or{},collect_variables(luke),{LUA_DIR='/usr',LUA_BINDIR='$LUA_DIR/bin',LUA_INCDIR='$LUA_DIR/include/lua$LUAVERSION',LUA_LIBDIR='$LUA_DIR/lib',objdir=platforms[1],package=luke.package,version=luke.version,})return{clidefs=clidefs,install=install,log=log,luke=luke,verbose=verbose,write=write,}end,}
end
package.preload['luke.compile']=function()
local _ENV=require'std.normalize'{'luke._base','luke.environment','std.functional','type.context-manager',SHELLMETACHARS='[%s%$"]',}local function spawn(env,...)local command=interpolate(env,concat({...},' '))return with(TmpFile(),TmpFile(),function(out,err)local pipe=concat{command,' >',out.filename,' 2>',err.filename,'; printf $?'}return int(slurp(Pipe(pipe))),slurp(File(err.filename)),slurp(File(out.filename))end)end
Expand Down Expand Up @@ -102,27 +103,29 @@ return status
end)end,libdirs=libdirs,run_command=run,spawn=spawn,}
end
package.preload['luke.configure']=function()
local _ENV=require'std.normalize'{'luke._base','luke.compile','luke.environment','std.functional','type.context-manager','type.dict',CCPROGS={'cc','gcc','clang'},}local function checking(L,...)L.verbose('checking ',concat({...},' '),'... ')end
local _ENV=require'std.normalize'{'luke._base','luke.compile','luke.environment','std.functional','type.context-manager','type.dict',CCPROGS={'cc','gcc','clang'},}local function logspawn(L,env,...)local status,err=spawn(env,...)if status~=0 and err~=''then
L.log(err)end
return status
end
local function checking(L,...)L.verbose('checking ',concat({...},' '),'... ')end
local function found_library(L,x)if x==nil or x==''then
L.verbose'none required'else
L.verbose'none required'elseif isempty(x)then
L.verbose'not supported'else
L.verbose(x)end
L.verbose'\n'return x
end
local function found_prog(L,x)L.verbose(x and'yes\n'or'no\n')return x
end
local function found_result(L,x)L.verbose(x==1 and'yes\n'or'no\n')return x
local function found_result(L,x)L.verbose(x==0 and'yes\n'or'no\n')return x~=0 and 0 or 1
end
local function bindirs(...)return map(flatten(...),function(v)return v..':'end)end
local function compile_command(L,env,config,filename)local command=flatten('$CC','-c','$CFLAGS',incdirs(config.incdir),'$CPPFLAGS',filename)L.debug(interpolate(env,concat(command,' ')))return unpack(command)end
local function link_command(L,env,config,a_out,source,lib)local command=flatten('$CC','$CFLAGS',incdirs(config.incdir),'$CPPFLAGS','-o',a_out,source,libdirs(config.libdir),'$LDFLAGS','$libs',CONFIGENV.libs,lib)L.debug(interpolate(env,concat(command,' ')))return unpack(command)end
local function compile_command(L,env,config,filename)local command=flatten('$CC','-c','$CFLAGS',incdirs(config.incdir),'$CPPFLAGS',filename)L.log(interpolate(env,concat(command,' ')))return unpack(command)end
local function link_command(L,env,config,a_out,source,lib)local command=flatten('$CC','$CFLAGS',incdirs(config.incdir),'$CPPFLAGS','-o',a_out,source,libdirs(config.libdir),'$LDFLAGS','$libs',CONFIGENV.libs,lib)L.log(interpolate(env,concat(command,' ')))return unpack(command)end
local function check_executable_in_path(L,env,config,prog)local PATH=concat(bindirs(config.bindir))..getenv('PATH')local found=dropuntil(gmatch(PATH,'[^:]+'),function(path)local progpath=path..'/'..prog
return with(File(progpath,'r'),function(h)return isfile(h.context)and progpath or nil
end)end)L.debug('found '..found)return found~=nil
end)end)L.log(found and'found '..found or prog..' not found')return found~=nil
end
local function check_header_compile(L,env,config,header,extra_hdrs)return with(CTest(),function(conftest)conftest:write(format('%s\n#include "%s"\n',extra_hdrs,header))local status,err=spawn(env,compile_command(L,env,config,conftest.filename))if status~=0 and err~=''then
L.debug(err)end
return 0==status and 1 or 0
end)end
local function check_header_compile(L,env,config,header,extra_hdrs)return with(CTest(),function(conftest)conftest:write(format('%s\n#include "%s"\n',extra_hdrs,header))return logspawn(L,env,compile_command(L,env,config,conftest.filename))end)end
local function try_link(L,env,config,lib,symbol)return with(CTest(),TmpFile(),function(conftest,a_out)conftest:write(format([[
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
Expand All @@ -131,10 +134,18 @@ char %s ();
int main () {
return %s ();
}
]],symbol,symbol))local status,err=spawn(env,link_command(L,env,config,a_out.filename,conftest.filename,lib))if status~=0 and err~=''then
L.debug(err)end
return status
end)end
]],symbol,symbol))return logspawn(L,env,link_command(L,env,config,a_out.filename,conftest.filename,lib))end)end
local function try_compile(L,env,config,headers)return with(CTest(),TmpFile(),function(conftest,a_out)conftest:write(format([[
%s
#if !defined %s || %s == -1
choke me
#endif
int
main()
{
return 0;
}
]],headers,config.ifdef,config.ifdef))return logspawn(L,env,link_command(L,env,config,a_out.filename,conftest.filename))end)end
local function check_func_decl(L,env,config,fname,extra_hdrs)return with(CTest(),function(conftest)conftest:write(format([[
%s
int
Expand All @@ -145,10 +156,7 @@ main()
#endif
return 0;
}
]],extra_hdrs,fname,fname))local status,err=spawn(env,compile_command(L,env,config,conftest.filename))if status~=0 and err~=''then
L.debug(err)end
return 0==status and 1 or 0
end)end
]],extra_hdrs,fname,fname))return logspawn(L,env,compile_command(L,env,config,conftest.filename))end)end
local function check_func_link(L,env,config,fname)return with(CTest(),TmpFile(),function(conftest,a_out)conftest:write(format([[
/* Define to an innocous variant, in case <limits.h> declares it.
For example, HP-UX 11i <limits,h> declares gettimeofday. */
Expand Down Expand Up @@ -182,10 +190,7 @@ choke me
int main () {
return %s ();
}
]],fname,fname,fname,fname,fname,fname,fname))local status,err=spawn(env,link_command(L,env,config,a_out.filename,conftest.filename))if status~=0 and err~=''then
L.debug(err)end
return 0==status and 1 or 0
end)end
]],fname,fname,fname,fname,fname,fname,fname))return logspawn(L,env,link_command(L,env,config,a_out.filename,conftest.filename))end)end
local function add_external_deps(env,config,prefix)if prefix~=nil then
for k,v in next,{bindir='$%s_BINDIR',incdir='$%s_INCDIR',libdir='$%s_LIBDIR'}do
local envvar=interpolate(env,format(v,prefix))if envvar~=''then
Expand All @@ -194,10 +199,15 @@ end
end
end
end
local function format_includes(includes)return map(includes or{},function(include)return format('#include "%s"',include)end)end
local configure=setmetatable(OrderedDict({checkprog=function(L,env,config)return dropuntil(config.progs,function(prog)checking(L,'for',prog)if found_prog(L,check_executable_in_path(L,env,config,prog))then
return prog
end
end)or fatal('cannot find '..config.checkprog)end},{checkheader=function(L,env,config)checking(L,'for',config.checkheader)local extra_hdrs=map(config.includes or{},function(include)return format('#include "%s"',include)end)return found_result(L,check_header_compile(L,env,config,config.checkheader,concat(extra_hdrs,'\n')))end},{checkdecl=function(L,env,config)checking(L,'whether',config.checkdecl,'is declared')local extra_hdrs=map(config.includes or{},function(include)return format('#include "%s"',include)end)return found_result(L,check_func_decl(L,env,config,config.checkdecl,concat(extra_hdrs,'\n')))end},{checksymbol=function(L,env,config)checking(L,'for library containing',config.checksymbol)local libraries,symbol=config.libraries,config.checksymbol
end)or fatal('cannot find '..config.checkprog)end},{checkheader=function(L,env,config)checking(L,'for',config.checkheader)local extra_hdrs=concat(format_includes(config.includes),'\n')return found_result(L,check_header_compile(L,env,config,config.checkheader,extra_hdrs))end},{checkdecl=function(L,env,config)checking(L,'whether',config.checkdecl,'is declared')local extra_hdrs=concat(format_includes(config.includes),'\n')return found_result(L,check_func_decl(L,env,config,config.checkdecl,extra_hdrs))end},{checksymbol=function(L,env,config)checking(L,'for library containing',config.checksymbol)if config.ifdef~=nil then
local headers=concat(format_includes(config.includes),'\n')if try_compile(L,env,config,headers)~=0 then
return found_library(L,{})end
end
local libraries,symbol=config.libraries,config.checksymbol
local trylibs=reduce(libraries,{''},function(r,lib)append(r,'-l'..lib)end)local lib=dropuntil(trylibs,function(lib)if try_link(L,env,config,lib,symbol)==0 then
if lib~=''then
if CONFIGENV.libs~=''then
Expand All @@ -208,7 +218,7 @@ end
return found_library(L,lib)end
end)or call(function()L.verbose'\n'fatal("required symbol '%s' not found in any of libc, lib%s",symbol,concat(libraries,', lib'))end)return{library=gsub(lib,'^-l','')}end},{checkfunc=function(L,env,config)checking(L,'for',config.checkfunc)return found_result(L,check_func_link(L,env,config,config.checkfunc))end}),{__call=function(self,L,env,config,prefix)return case(type(config),{['number']=function()return str(config)end,['string']=function()return config
end,['table']=function()return dropuntil(self,function(fname)if config[fname]~=nil then
add_external_deps(env,config,prefix)return apply(self[fname],{L,env,config})end
add_external_deps(env,config,prefix)return apply(self[fname],list(L,env,config))end
end)or fatal("unable to configure with keys '%s'",concat(keys(config),"', '"))end,function(type)fatal("unsupported configure type '%s'",type)end,})end,})return{config_compiler=function(L,env)local CC=env.CC
if CC==nil then
CC=configure(L,env,{checkprog='C compiler',progs=CCPROGS})env=makeenv(env,{CC=CC})end
Expand Down Expand Up @@ -302,7 +312,7 @@ return v
end
return unwind_external_dependencies(v)end)if istable(r.external_dependencies)then
for prefix,config in next,r.external_dependencies do
if config.library~=''then
if next(config)and config.library~=''then
r.incdirs=append(r.incdirs or{},format('$%s_INCDIR',prefix))r.libdirs=append(r.libdirs or{},format('$%s_LIBDIR',prefix))r.libraries=append(r.libraries or{},'-l'..config.library)end
end
r.external_dependencies=nil
Expand Down

0 comments on commit aae1889

Please sign in to comment.