Allow for ninja files to regenerate themselves
This commit is contained in:
@@ -49,7 +49,19 @@ def get_sources(path):
|
|||||||
|
|
||||||
|
|
||||||
def get_git_version():
|
def get_git_version():
|
||||||
return version(0,5,0,'aaaaaa')
|
from subprocess import run
|
||||||
|
cp = run(['git', 'describe', '--always'],
|
||||||
|
check=True, capture_output=True)
|
||||||
|
full_version = cp.stdout.decode('utf-8').strip()
|
||||||
|
|
||||||
|
parts1 = full_version.split('-')
|
||||||
|
parts2 = parts1[0].split('.')
|
||||||
|
|
||||||
|
return version(
|
||||||
|
parts2[0],
|
||||||
|
parts2[1],
|
||||||
|
parts2[2],
|
||||||
|
parts1[-1])
|
||||||
|
|
||||||
|
|
||||||
def main(buildroot):
|
def main(buildroot):
|
||||||
@@ -62,11 +74,15 @@ def main(buildroot):
|
|||||||
os.mkdir(buildroot)
|
os.mkdir(buildroot)
|
||||||
|
|
||||||
git_version = get_git_version()
|
git_version = get_git_version()
|
||||||
|
print("Generating build files for Popcorn {}.{}.{}-{}...".format(
|
||||||
|
git_version.major, git_version.minor, git_version.patch, git_version.sha))
|
||||||
|
|
||||||
from jinja2 import Environment, FileSystemLoader
|
from jinja2 import Environment, FileSystemLoader
|
||||||
env = Environment(loader=FileSystemLoader("scripts/templates"))
|
env = Environment(loader=FileSystemLoader(join(srcroot, "scripts", "templates")))
|
||||||
|
|
||||||
targets = {}
|
targets = {}
|
||||||
|
templates = set()
|
||||||
|
buildfiles = []
|
||||||
for name, mod in MODULES.items():
|
for name, mod in MODULES.items():
|
||||||
if isinstance(mod, program):
|
if isinstance(mod, program):
|
||||||
for target in mod.targets:
|
for target in mod.targets:
|
||||||
@@ -80,14 +96,18 @@ def main(buildroot):
|
|||||||
open_list.extend(dep.deps)
|
open_list.extend(dep.deps)
|
||||||
targets[target].add(depname)
|
targets[target].add(depname)
|
||||||
|
|
||||||
sources = get_sources(mod.path)
|
sources = get_sources(join(srcroot, mod.path))
|
||||||
with open(join(buildroot, name + ".ninja"), 'w') as out:
|
buildfile = join(buildroot, name + ".ninja")
|
||||||
print("Generating module", name)
|
buildfiles.append(buildfile)
|
||||||
|
with open(buildfile, 'w') as out:
|
||||||
|
#print("Generating module", name)
|
||||||
template = get_template(env, type(mod).__name__, name)
|
template = get_template(env, type(mod).__name__, name)
|
||||||
|
templates.add(template.filename)
|
||||||
out.write(template.render(
|
out.write(template.render(
|
||||||
name=name,
|
name=name,
|
||||||
module=mod,
|
module=mod,
|
||||||
sources=sources,
|
sources=sources,
|
||||||
|
buildfile=buildfile,
|
||||||
version=git_version))
|
version=git_version))
|
||||||
|
|
||||||
for target, mods in targets.items():
|
for target, mods in targets.items():
|
||||||
@@ -95,21 +115,33 @@ def main(buildroot):
|
|||||||
if not isdir(root):
|
if not isdir(root):
|
||||||
os.mkdir(root)
|
os.mkdir(root)
|
||||||
|
|
||||||
with open(join(root, "target.ninja"), 'w') as out:
|
buildfile = join(root, "target.ninja")
|
||||||
print("Generating target", target)
|
buildfiles.append(buildfile)
|
||||||
|
with open(buildfile, 'w') as out:
|
||||||
|
#print("Generating target", target)
|
||||||
template = get_template(env, "target", target)
|
template = get_template(env, "target", target)
|
||||||
|
templates.add(template.filename)
|
||||||
out.write(template.render(
|
out.write(template.render(
|
||||||
target=target,
|
target=target,
|
||||||
modules=mods,
|
modules=mods,
|
||||||
|
buildfile=buildfile,
|
||||||
version=git_version))
|
version=git_version))
|
||||||
|
|
||||||
with open(join(buildroot, 'build.ninja'), 'w') as out:
|
buildfile = join(buildroot, "build.ninja")
|
||||||
print("Generating main build.ninja")
|
buildfiles.append(buildfile)
|
||||||
|
with open(buildfile, 'w') as out:
|
||||||
|
#print("Generating main build.ninja")
|
||||||
template = env.get_template('build.ninja.j2')
|
template = env.get_template('build.ninja.j2')
|
||||||
|
templates.add(template.filename)
|
||||||
|
|
||||||
out.write(template.render(
|
out.write(template.render(
|
||||||
targets=targets,
|
targets=targets,
|
||||||
buildroot=buildroot,
|
buildroot=buildroot,
|
||||||
srcroot=srcroot,
|
srcroot=srcroot,
|
||||||
|
buildfile=buildfile,
|
||||||
|
buildfiles=buildfiles,
|
||||||
|
templates=[abspath(f) for f in templates],
|
||||||
|
generator=abspath(__file__),
|
||||||
version=git_version))
|
version=git_version))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
ninja_required_version = 1.3
|
||||||
builddir = {{ buildroot }}
|
builddir = {{ buildroot }}
|
||||||
srcroot = {{ srcroot }}
|
srcroot = {{ srcroot }}
|
||||||
|
|
||||||
@@ -46,9 +47,24 @@ rule lib
|
|||||||
description = Archiving $name
|
description = Archiving $name
|
||||||
command = $ar qcs $out $in
|
command = $ar qcs $out $in
|
||||||
|
|
||||||
|
rule regen
|
||||||
|
generator = true
|
||||||
|
description = Regenrating build files
|
||||||
|
command = {{ generator }} ${builddir}
|
||||||
|
|
||||||
{% for target in targets %}
|
{% for target in targets %}
|
||||||
subninja {{ target }}/target.ninja
|
subninja {{ target }}/target.ninja
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
build $
|
||||||
|
{%- for buildfile in buildfiles %}
|
||||||
|
{{ buildfile }} $
|
||||||
|
{%- endfor %}
|
||||||
|
: regen | $
|
||||||
|
{%- for template in templates %}
|
||||||
|
{{ template }} $
|
||||||
|
{%- endfor %}
|
||||||
|
{{ generator }}
|
||||||
|
|
||||||
# vim: et ts=4 sts=4 sw=4
|
# vim: et ts=4 sts=4 sw=4
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ ccflags = $ccflags $
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% for source in sources %}
|
{% for source in sources %}
|
||||||
build ${moddir}/{{ source.output }} : {{ source.action }} {{ source.input }}
|
build ${moddir}/{{ source.output }} : {{ source.action }} {{ source.input }} || {{ buildfile }}
|
||||||
name = {{ source.name }}
|
name = {{ source.name }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user