Shortened name placeholder for project.getfilename
This commit is contained in:
parent
53e5f42b0a
commit
2806554e59
@ -19,20 +19,20 @@
|
||||
},
|
||||
|
||||
onsolution = function(sln)
|
||||
premake.generate(sln, "{name}.workspace", premake.codeblocks_workspace)
|
||||
premake.generate(sln, "%%.workspace", premake.codeblocks_workspace)
|
||||
end,
|
||||
|
||||
onproject = function(prj)
|
||||
premake.generate(prj, "{name}.cbp", premake.codeblocks_cbp)
|
||||
premake.generate(prj, "%%.cbp", premake.codeblocks_cbp)
|
||||
end,
|
||||
|
||||
oncleansolution = function(sln)
|
||||
premake.clean.file(sln, "{name}.workspace")
|
||||
premake.clean.file(sln, "%%.workspace")
|
||||
end,
|
||||
|
||||
oncleanproject = function(prj)
|
||||
premake.clean.file(prj, "{name}.cbp")
|
||||
premake.clean.file(prj, "{name}.depend")
|
||||
premake.clean.file(prj, "{name}.layout")
|
||||
premake.clean.file(prj, "%%.cbp")
|
||||
premake.clean.file(prj, "%%.depend")
|
||||
premake.clean.file(prj, "%%.layout")
|
||||
end
|
||||
}
|
||||
|
@ -18,23 +18,23 @@
|
||||
},
|
||||
|
||||
onsolution = function(sln)
|
||||
premake.generate(sln, "{name}.workspace", premake.codelite_workspace)
|
||||
premake.generate(sln, "%%.workspace", premake.codelite_workspace)
|
||||
end,
|
||||
|
||||
onproject = function(prj)
|
||||
premake.generate(prj, "{name}.project", premake.codelite_project)
|
||||
premake.generate(prj, "%%.project", premake.codelite_project)
|
||||
end,
|
||||
|
||||
oncleansolution = function(sln)
|
||||
premake.clean.file(sln, "{name}.workspace")
|
||||
premake.clean.file(sln, "{name}_wsp.mk")
|
||||
premake.clean.file(sln, "{name}.tags")
|
||||
premake.clean.file(sln, "%%.workspace")
|
||||
premake.clean.file(sln, "%%_wsp.mk")
|
||||
premake.clean.file(sln, "%%.tags")
|
||||
end,
|
||||
|
||||
oncleanproject = function(prj)
|
||||
premake.clean.file(prj, "{name}.project")
|
||||
premake.clean.file(prj, "{name}.mk")
|
||||
premake.clean.file(prj, "{name}.list")
|
||||
premake.clean.file(prj, "{name}.out")
|
||||
premake.clean.file(prj, "%%.project")
|
||||
premake.clean.file(prj, "%%.mk")
|
||||
premake.clean.file(prj, "%%.list")
|
||||
premake.clean.file(prj, "%%.out")
|
||||
end
|
||||
}
|
||||
|
@ -144,12 +144,12 @@
|
||||
--
|
||||
|
||||
function premake.vstudio.cleansolution(sln)
|
||||
premake.clean.file(sln, "{name}.sln")
|
||||
premake.clean.file(sln, "{name}.suo")
|
||||
premake.clean.file(sln, "{name}.ncb")
|
||||
premake.clean.file(sln, "%%.sln")
|
||||
premake.clean.file(sln, "%%.suo")
|
||||
premake.clean.file(sln, "%%.ncb")
|
||||
-- MonoDevelop files
|
||||
premake.clean.file(sln, "{name}.userprefs")
|
||||
premake.clean.file(sln, "{name}.usertasks")
|
||||
premake.clean.file(sln, "%%.userprefs")
|
||||
premake.clean.file(sln, "%%.usertasks")
|
||||
end
|
||||
|
||||
function premake.vstudio.cleanproject(prj)
|
||||
@ -160,7 +160,7 @@
|
||||
fext = ".vcproj"
|
||||
end
|
||||
|
||||
local fname = premake.project.getfilename(prj, "{name}" .. fext)
|
||||
local fname = premake.project.getfilename(prj, "%%" .. fext)
|
||||
os.remove(fname)
|
||||
os.remove(fname .. ".user")
|
||||
|
||||
@ -322,15 +322,15 @@
|
||||
},
|
||||
|
||||
onsolution = function(sln)
|
||||
premake.generate(sln, "{name}.sln", premake.vs2002_solution)
|
||||
premake.generate(sln, "%%.sln", premake.vs2002_solution)
|
||||
end,
|
||||
|
||||
onproject = function(prj)
|
||||
if premake.isdotnetproject(prj) then
|
||||
premake.generate(prj, "{name}.csproj", premake.vs2002_csproj)
|
||||
premake.generate(prj, "{name}.csproj.user", premake.vs2002_csproj_user)
|
||||
premake.generate(prj, "%%.csproj", premake.vs2002_csproj)
|
||||
premake.generate(prj, "%%.csproj.user", premake.vs2002_csproj_user)
|
||||
else
|
||||
premake.generate(prj, "{name}.vcproj", premake.vs200x_vcproj)
|
||||
premake.generate(prj, "%%.vcproj", premake.vs200x_vcproj)
|
||||
end
|
||||
end,
|
||||
|
||||
@ -355,15 +355,15 @@
|
||||
},
|
||||
|
||||
onsolution = function(sln)
|
||||
premake.generate(sln, "{name}.sln", premake.vs2003_solution)
|
||||
premake.generate(sln, "%%.sln", premake.vs2003_solution)
|
||||
end,
|
||||
|
||||
onproject = function(prj)
|
||||
if premake.isdotnetproject(prj) then
|
||||
premake.generate(prj, "{name}.csproj", premake.vs2002_csproj)
|
||||
premake.generate(prj, "{name}.csproj.user", premake.vs2002_csproj_user)
|
||||
premake.generate(prj, "%%.csproj", premake.vs2002_csproj)
|
||||
premake.generate(prj, "%%.csproj.user", premake.vs2002_csproj_user)
|
||||
else
|
||||
premake.generate(prj, "{name}.vcproj", premake.vs200x_vcproj)
|
||||
premake.generate(prj, "%%.vcproj", premake.vs200x_vcproj)
|
||||
end
|
||||
end,
|
||||
|
||||
@ -388,15 +388,15 @@
|
||||
},
|
||||
|
||||
onsolution = function(sln)
|
||||
premake.generate(sln, "{name}.sln", premake.vs2005_solution)
|
||||
premake.generate(sln, "%%.sln", premake.vs2005_solution)
|
||||
end,
|
||||
|
||||
onproject = function(prj)
|
||||
if premake.isdotnetproject(prj) then
|
||||
premake.generate(prj, "{name}.csproj", premake.vs2005_csproj)
|
||||
premake.generate(prj, "{name}.csproj.user", premake.vs2005_csproj_user)
|
||||
premake.generate(prj, "%%.csproj", premake.vs2005_csproj)
|
||||
premake.generate(prj, "%%.csproj.user", premake.vs2005_csproj_user)
|
||||
else
|
||||
premake.generate(prj, "{name}.vcproj", premake.vs200x_vcproj)
|
||||
premake.generate(prj, "%%.vcproj", premake.vs200x_vcproj)
|
||||
end
|
||||
end,
|
||||
|
||||
@ -421,15 +421,15 @@
|
||||
},
|
||||
|
||||
onsolution = function(sln)
|
||||
premake.generate(sln, "{name}.sln", premake.vs2005_solution)
|
||||
premake.generate(sln, "%%.sln", premake.vs2005_solution)
|
||||
end,
|
||||
|
||||
onproject = function(prj)
|
||||
if premake.isdotnetproject(prj) then
|
||||
premake.generate(prj, "{name}.csproj", premake.vs2005_csproj)
|
||||
premake.generate(prj, "{name}.csproj.user", premake.vs2005_csproj_user)
|
||||
premake.generate(prj, "%%.csproj", premake.vs2005_csproj)
|
||||
premake.generate(prj, "%%.csproj.user", premake.vs2005_csproj_user)
|
||||
else
|
||||
premake.generate(prj, "{name}.vcproj", premake.vs200x_vcproj)
|
||||
premake.generate(prj, "%%.vcproj", premake.vs200x_vcproj)
|
||||
end
|
||||
end,
|
||||
|
||||
|
@ -76,47 +76,19 @@
|
||||
|
||||
function premake.action.call(name)
|
||||
local a = premake.action.list[name]
|
||||
|
||||
-- walk the session objects and pass to the action for handling
|
||||
local function generatefiles(this, templates)
|
||||
if (not templates) then return end
|
||||
for _,tmpl in ipairs(templates) do
|
||||
local output = true
|
||||
if (tmpl[3]) then
|
||||
output = tmpl[3](this)
|
||||
end
|
||||
if (output) then
|
||||
local fname = path.getrelative(os.getcwd(), premake.getoutputname(this, tmpl[1]))
|
||||
printf("Generating %s...", fname)
|
||||
local f, err = io.open(fname, "wb")
|
||||
if (not f) then
|
||||
error(err, 0)
|
||||
end
|
||||
io.output(f)
|
||||
|
||||
-- call the template function to generate the output
|
||||
tmpl[2](this)
|
||||
|
||||
io.output():close()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for _,sln in ipairs(_SOLUTIONS) do
|
||||
if type(a.onsolution) == "function" then
|
||||
if a.onsolution then
|
||||
a.onsolution(sln)
|
||||
end
|
||||
generatefiles(sln, a.solutiontemplates)
|
||||
for prj in premake.eachproject(sln) do
|
||||
if type(a.onproject) == "function" then
|
||||
if a.onproject then
|
||||
a.onproject(prj)
|
||||
end
|
||||
generatefiles(prj, a.projecttemplates)
|
||||
end
|
||||
end
|
||||
|
||||
-- call execute() to perform general processing
|
||||
if type(a.execute) == "function" then
|
||||
if a.execute then
|
||||
a.execute()
|
||||
end
|
||||
end
|
||||
|
@ -20,17 +20,15 @@
|
||||
--
|
||||
|
||||
function premake.generate(obj, filename, callback)
|
||||
-- open the file for output and handle any errors
|
||||
filename = premake.project.getfilename(obj, filename)
|
||||
printf("Generating %s...", filename)
|
||||
|
||||
local f, err = io.open(filename, "wb")
|
||||
if (not f) then
|
||||
error(err, 0)
|
||||
end
|
||||
io.output(f)
|
||||
|
||||
-- generate the file
|
||||
io.output(f)
|
||||
callback(obj)
|
||||
|
||||
-- clean up
|
||||
f:close()
|
||||
end
|
||||
|
@ -248,15 +248,15 @@
|
||||
-- @param prj
|
||||
-- A project or solution object with the file naming information.
|
||||
-- @param pattern
|
||||
-- A naming pattern, which may include these placeholders:
|
||||
-- {path} - the project's location, set by the location property
|
||||
-- {file} - the project's name, set by the name property
|
||||
-- A naming pattern. The sequence "%%" will be replaced by the
|
||||
-- project name.
|
||||
-- @returns
|
||||
-- A filename matching the specified pattern.
|
||||
-- A filename matching the specified pattern, with a relative path
|
||||
-- from the current directory to the project location.
|
||||
--
|
||||
|
||||
function premake.project.getfilename(prj, pattern)
|
||||
local fname = pattern:gsub("{name}", prj.name)
|
||||
local fname = pattern:gsub("%%%%", prj.name)
|
||||
fname = path.join(prj.location, fname)
|
||||
return path.getrelative(os.getcwd(), fname)
|
||||
end
|
||||
@ -278,7 +278,7 @@
|
||||
-- object - return the project object of the dependency
|
||||
--
|
||||
|
||||
function premake.getlinks(cfg, kind, part)
|
||||
function premake.getlinks(cfg, kind, part)
|
||||
-- if I'm building a list of link directories, include libdirs
|
||||
local result = iif (part == "directory" and kind == "all", cfg.libdirs, {})
|
||||
|
||||
@ -376,24 +376,6 @@
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Converts a project object and a template filespec (the first value in an
|
||||
-- action's template reference) into a filename for that template's output.
|
||||
-- The filespec may be either a file extension, or a function.
|
||||
--
|
||||
|
||||
function premake.getoutputname(this, namespec)
|
||||
local fname
|
||||
if (type(namespec) == "function") then
|
||||
fname = namespec(this)
|
||||
else
|
||||
fname = this.name .. namespec
|
||||
end
|
||||
return path.join(this.location, fname)
|
||||
end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Gets the path style for a configuration, indicating what kind of path separator
|
||||
-- should be used in target file names.
|
||||
|
File diff suppressed because one or more lines are too long
@ -36,12 +36,12 @@
|
||||
|
||||
function T.premake.generate_OpensCorrectFile()
|
||||
prj = { name = "MyProject", location = "MyLocation" }
|
||||
premake.generate(prj, "{name}.prj", function () end)
|
||||
premake.generate(prj, "%%.prj", function () end)
|
||||
test.openedfile("MyLocation/MyProject.prj")
|
||||
end
|
||||
|
||||
function T.premake.generate_ClosesFile()
|
||||
prj = { name = "MyProject", location = "MyLocation" }
|
||||
premake.generate(prj, "{path}/{name}.prj", function () end)
|
||||
premake.generate(prj, "%%.prj", function () end)
|
||||
test.closedfile(true)
|
||||
end
|
||||
|
@ -34,7 +34,7 @@
|
||||
|
||||
function T.project.getfilename_PerformsSubstitutions()
|
||||
local prj = { name = "project", location = "location" }
|
||||
local r = _project.getfilename(prj, "{name}.prj")
|
||||
local r = _project.getfilename(prj, "%%.prj")
|
||||
test.isequal("location/project.prj", r)
|
||||
end
|
||||
|
||||
|
@ -148,6 +148,8 @@
|
||||
local function stub_io_output(f)
|
||||
end
|
||||
|
||||
local function stub_print(s)
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
@ -169,6 +171,10 @@
|
||||
_OPTIONS = { }
|
||||
_SOLUTIONS = { }
|
||||
|
||||
-- capture any printed output
|
||||
test.print = print
|
||||
print = stub_print
|
||||
|
||||
test.value_openedfilename = nil
|
||||
test.value_openedfilemode = nil
|
||||
test.value_closedfile = false
|
||||
@ -187,6 +193,8 @@
|
||||
|
||||
|
||||
local function test_teardown(suite, fn)
|
||||
print = test.print
|
||||
|
||||
if suite.teardown then
|
||||
return pcall(suite.teardown)
|
||||
else
|
||||
|
Reference in New Issue
Block a user