Started target out dir refactoring with some clarifying renamings.

pull/255/head
Jussi Pakkanen 9 years ago
parent b057b061c3
commit 363bc42c5c
  1. 11
      backends.py
  2. 54
      ninjabackend.py
  3. 8
      vs2010backend.py

@ -74,7 +74,10 @@ class Backend():
return dirname return dirname
def get_target_private_dir(self, target): def get_target_private_dir(self, target):
dirname = os.path.join(self.get_target_dir(target), target.get_basename() + target.type_suffix()) return os.path.join(self.get_target_dir(target), target.get_basename() + target.type_suffix())
def get_target_private_dir_abs(self, target):
dirname = self.get_target_private_dir(target)
os.makedirs(os.path.join(self.environment.get_build_dir(), dirname), exist_ok=True) os.makedirs(os.path.join(self.environment.get_build_dir(), dirname), exist_ok=True)
return dirname return dirname
@ -87,7 +90,7 @@ class Backend():
language = comp.get_language() language = comp.get_language()
suffix = '.' + comp.get_default_suffix() suffix = '.' + comp.get_default_suffix()
if language not in langlist: if language not in langlist:
outfilename = os.path.join(self.get_target_private_dir(target), target.name + '-unity' + suffix) outfilename = os.path.join(self.get_target_private_dir_abs(target), target.name + '-unity' + suffix)
outfileabs = os.path.join(self.environment.get_build_dir(), outfilename) outfileabs = os.path.join(self.environment.get_build_dir(), outfilename)
outfileabs_tmp = outfileabs + '.tmp' outfileabs_tmp = outfileabs + '.tmp'
abs_files.append(outfileabs) abs_files.append(outfileabs)
@ -167,7 +170,7 @@ class Backend():
def determine_ext_objs(self, extobj, proj_dir_to_build_root=''): def determine_ext_objs(self, extobj, proj_dir_to_build_root=''):
result = [] result = []
targetdir = self.get_target_private_dir(extobj.target) targetdir = self.get_target_private_dir_abs(extobj.target)
suffix = '.' + self.environment.get_object_suffix() suffix = '.' + self.environment.get_object_suffix()
for osrc in extobj.srclist: for osrc in extobj.srclist:
osrc_base = osrc.fname osrc_base = osrc.fname
@ -187,7 +190,7 @@ class Backend():
def get_pch_include_args(self, compiler, target): def get_pch_include_args(self, compiler, target):
args = [] args = []
pchpath = self.get_target_private_dir(target) pchpath = self.get_target_private_dir_abs(target)
includeargs = compiler.get_include_args(pchpath) includeargs = compiler.get_include_args(pchpath)
for lang in ['c', 'cpp']: for lang in ['c', 'cpp']:
p = target.get_pch(lang) p = target.get_pch(lang)

@ -215,13 +215,13 @@ class NinjaBackend(backends.Backend):
else: else:
for src in gensource.get_outfilelist(): for src in gensource.get_outfilelist():
if self.environment.is_object(src): if self.environment.is_object(src):
obj_list.append(os.path.join(self.get_target_private_dir(target), src)) obj_list.append(os.path.join(self.get_target_private_dir_abs(target), src))
elif not self.environment.is_header(src): elif not self.environment.is_header(src):
if is_unity: if is_unity:
if '/' in src: if '/' in src:
rel_src = src rel_src = src
else: else:
rel_src = os.path.join(self.get_target_private_dir(target), src) rel_src = os.path.join(self.get_target_private_dir_abs(target), src)
unity_deps.append(rel_src) unity_deps.append(rel_src)
abs_src = os.path.join(self.environment.get_build_dir(), rel_src) abs_src = os.path.join(self.environment.get_build_dir(), rel_src)
unity_src.append(abs_src) unity_src.append(abs_src)
@ -576,10 +576,10 @@ class NinjaBackend(backends.Backend):
if e != '': if e != '':
commands.append(main_class) commands.append(main_class)
commands.append(self.get_target_filename(target)) commands.append(self.get_target_filename(target))
commands += ['-C', self.get_target_private_dir(target)] commands += ['-C', self.get_target_private_dir_abs(target)]
commands += class_list commands += class_list
elem = NinjaBuildElement(outname_rel, jar_rule, []) elem = NinjaBuildElement(outname_rel, jar_rule, [])
elem.add_dep([os.path.join(self.get_target_private_dir(target), i) for i in class_list]) elem.add_dep([os.path.join(self.get_target_private_dir_abs(target), i) for i in class_list])
elem.add_item('ARGS', commands) elem.add_item('ARGS', commands)
elem.write(outfile) elem.write(outfile)
@ -592,7 +592,7 @@ class NinjaBackend(backends.Backend):
a = '-resource:' + rel_sourcefile a = '-resource:' + rel_sourcefile
elif r.endswith('.txt') or r.endswith('.resx'): elif r.endswith('.txt') or r.endswith('.resx'):
ofilebase = os.path.splitext(os.path.basename(r))[0] + '.resources' ofilebase = os.path.splitext(os.path.basename(r))[0] + '.resources'
ofilename = os.path.join(self.get_target_private_dir(target), ofilebase) ofilename = os.path.join(self.get_target_private_dir_abs(target), ofilebase)
elem = NinjaBuildElement(ofilename, "CUSTOM_COMMAND", rel_sourcefile) elem = NinjaBuildElement(ofilename, "CUSTOM_COMMAND", rel_sourcefile)
elem.add_item('COMMAND', ['resgen', rel_sourcefile, ofilename]) elem.add_item('COMMAND', ['resgen', rel_sourcefile, ofilename])
elem.add_item('DESC', 'Compiling resource %s.' % rel_sourcefile) elem.add_item('DESC', 'Compiling resource %s.' % rel_sourcefile)
@ -641,10 +641,10 @@ class NinjaBackend(backends.Backend):
def generate_single_java_compile(self, subdir, src, target, compiler, outfile): def generate_single_java_compile(self, subdir, src, target, compiler, outfile):
args = [] args = []
args += compiler.get_buildtype_args(self.environment.coredata.buildtype) args += compiler.get_buildtype_args(self.environment.coredata.buildtype)
args += compiler.get_output_args(self.get_target_private_dir(target)) args += compiler.get_output_args(self.get_target_private_dir_abs(target))
rel_src = src.rel_to_builddir(self.build_to_src) rel_src = src.rel_to_builddir(self.build_to_src)
plain_class_path = src.fname[:-4] + 'class' plain_class_path = src.fname[:-4] + 'class'
rel_obj = os.path.join(self.get_target_private_dir(target), plain_class_path) rel_obj = os.path.join(self.get_target_private_dir_abs(target), plain_class_path)
element = NinjaBuildElement(rel_obj, compiler.get_language() + '_COMPILER', rel_src) element = NinjaBuildElement(rel_obj, compiler.get_language() + '_COMPILER', rel_src)
element.add_item('ARGS', args) element.add_item('ARGS', args)
element.write(outfile) element.write(outfile)
@ -665,7 +665,7 @@ class NinjaBackend(backends.Backend):
if not s.endswith('.vala'): if not s.endswith('.vala'):
continue continue
vapibase = os.path.basename(s.fname)[:-4] + 'vapi' vapibase = os.path.basename(s.fname)[:-4] + 'vapi'
rel_vapi = os.path.join(self.get_target_private_dir(target), vapibase) rel_vapi = os.path.join(self.get_target_private_dir_abs(target), vapibase)
args = ['--fast-vapi=' + rel_vapi] args = ['--fast-vapi=' + rel_vapi]
rel_s = s.rel_to_builddir(self.build_to_src) rel_s = s.rel_to_builddir(self.build_to_src)
element = NinjaBuildElement(rel_vapi, valac.get_language() + '_COMPILER', rel_s) element = NinjaBuildElement(rel_vapi, valac.get_language() + '_COMPILER', rel_s)
@ -695,7 +695,7 @@ class NinjaBackend(backends.Backend):
for s in src: for s in src:
if not s.endswith('.vala'): if not s.endswith('.vala'):
continue continue
args = ['-d', self.get_target_private_dir(target)] args = ['-d', self.get_target_private_dir_abs(target)]
sc = os.path.basename(s.fname)[:-4] + 'c' sc = os.path.basename(s.fname)[:-4] + 'c'
args += ['-C'] args += ['-C']
vapi_order_deps = [] vapi_order_deps = []
@ -705,7 +705,7 @@ class NinjaBackend(backends.Backend):
(vapibase, rel_vapi) = vapi_info (vapibase, rel_vapi) = vapi_info
args += ['--use-fast-vapi=' + rel_vapi] args += ['--use-fast-vapi=' + rel_vapi]
vapi_order_deps.append(rel_vapi) vapi_order_deps.append(rel_vapi)
relsc = os.path.join(self.get_target_private_dir(target), sc) relsc = os.path.join(self.get_target_private_dir_abs(target), sc)
rel_s = s.rel_to_builddir(self.build_to_src) rel_s = s.rel_to_builddir(self.build_to_src)
args += ['--deps', relsc + '.d'] args += ['--deps', relsc + '.d']
if self.environment.coredata.werror: if self.environment.coredata.werror:
@ -1046,16 +1046,16 @@ rule FORTRAN_DEP_HACK
extra_dependencies = [os.path.join(self.build_to_src, i) for i in genlist.extra_depends] extra_dependencies = [os.path.join(self.build_to_src, i) for i in genlist.extra_depends]
for i in range(len(infilelist)): for i in range(len(infilelist)):
if len(generator.outputs) == 1: if len(generator.outputs) == 1:
sole_output = os.path.join(self.get_target_private_dir(target), outfilelist[i]) sole_output = os.path.join(self.get_target_private_dir_abs(target), outfilelist[i])
else: else:
sole_output = '' sole_output = ''
curfile = infilelist[i] curfile = infilelist[i]
infilename = os.path.join(self.build_to_src, curfile) infilename = os.path.join(self.build_to_src, curfile)
outfiles = genlist.get_outputs_for(curfile) outfiles = genlist.get_outputs_for(curfile)
outfiles = [os.path.join(self.get_target_private_dir(target), of) for of in outfiles] outfiles = [os.path.join(self.get_target_private_dir_abs(target), of) for of in outfiles]
args = [x.replace("@INPUT@", infilename).replace('@OUTPUT@', sole_output)\ args = [x.replace("@INPUT@", infilename).replace('@OUTPUT@', sole_output)\
for x in base_args] for x in base_args]
args = self.replace_outputs(args, self.get_target_private_dir(target), outfilelist) args = self.replace_outputs(args, self.get_target_private_dir_abs(target), outfilelist)
relout = os.path.join(target.subdir, target.get_basename() + target.type_suffix()) relout = os.path.join(target.subdir, target.get_basename() + target.type_suffix())
args = [x.replace("@SOURCE_DIR@", self.build_to_src).replace("@BUILD_DIR@", relout) args = [x.replace("@SOURCE_DIR@", self.build_to_src).replace("@BUILD_DIR@", relout)
for x in args] for x in args]
@ -1100,7 +1100,7 @@ rule FORTRAN_DEP_HACK
def get_fortran_deps(self, compiler, src, target): def get_fortran_deps(self, compiler, src, target):
mod_files = [] mod_files = []
usere = re.compile(r"\s*use\s+(\w+)", re.IGNORECASE) usere = re.compile(r"\s*use\s+(\w+)", re.IGNORECASE)
dirname = self.get_target_private_dir(target) dirname = self.get_target_private_dir_abs(target)
tdeps= self.fortran_deps[target.get_basename()] tdeps= self.fortran_deps[target.get_basename()]
for line in open(src): for line in open(src):
usematch = usere.match(line) usematch = usere.match(line)
@ -1133,7 +1133,7 @@ rule FORTRAN_DEP_HACK
extra_orderdeps = [] extra_orderdeps = []
compiler = self.get_compiler_for_source(src) compiler = self.get_compiler_for_source(src)
commands = self.generate_basic_compiler_args(target, compiler) commands = self.generate_basic_compiler_args(target, compiler)
commands += compiler.get_include_args(self.get_target_private_dir(target)) commands += compiler.get_include_args(self.get_target_private_dir_abs(target))
curdir = target.get_subdir() curdir = target.get_subdir()
tmppath = os.path.normpath(os.path.join(self.build_to_src, curdir)) tmppath = os.path.normpath(os.path.join(self.build_to_src, curdir))
commands += compiler.get_include_args(tmppath) commands += compiler.get_include_args(tmppath)
@ -1150,7 +1150,7 @@ rule FORTRAN_DEP_HACK
if '/' in src: if '/' in src:
rel_src = src rel_src = src
else: else:
rel_src = os.path.join(self.get_target_private_dir(target), src) rel_src = os.path.join(self.get_target_private_dir_abs(target), src)
abs_src = os.path.join(self.environment.get_source_dir(), rel_src) abs_src = os.path.join(self.environment.get_source_dir(), rel_src)
else: else:
if isinstance(src, File): if isinstance(src, File):
@ -1167,7 +1167,7 @@ rule FORTRAN_DEP_HACK
else: else:
src_filename = src src_filename = src
obj_basename = src_filename.replace('/', '_').replace('\\', '_') obj_basename = src_filename.replace('/', '_').replace('\\', '_')
rel_obj = os.path.join(self.get_target_private_dir(target), obj_basename) rel_obj = os.path.join(self.get_target_private_dir_abs(target), obj_basename)
rel_obj += '.' + self.environment.get_object_suffix() rel_obj += '.' + self.environment.get_object_suffix()
dep_file = rel_obj + '.' + compiler.get_depfile_suffix() dep_file = rel_obj + '.' + compiler.get_depfile_suffix()
if self.environment.coredata.use_pch: if self.environment.coredata.use_pch:
@ -1178,7 +1178,7 @@ rule FORTRAN_DEP_HACK
pch_dep = [] pch_dep = []
else: else:
arr = [] arr = []
i = os.path.join(self.get_target_private_dir(target), compiler.get_pch_name(pchlist[0])) i = os.path.join(self.get_target_private_dir_abs(target), compiler.get_pch_name(pchlist[0]))
arr.append(i) arr.append(i)
pch_dep = arr pch_dep = arr
for i in target.get_include_dirs(): for i in target.get_include_dirs():
@ -1202,19 +1202,19 @@ rule FORTRAN_DEP_HACK
# Dependency hack. Remove once multiple outputs in Ninja is fixed: # Dependency hack. Remove once multiple outputs in Ninja is fixed:
# https://groups.google.com/forum/#!topic/ninja-build/j-2RfBIOd_8 # https://groups.google.com/forum/#!topic/ninja-build/j-2RfBIOd_8
for modname, srcfile in self.fortran_deps[target.get_basename()].items(): for modname, srcfile in self.fortran_deps[target.get_basename()].items():
modfile = os.path.join(self.get_target_private_dir(target), modfile = os.path.join(self.get_target_private_dir_abs(target),
compiler.module_name_to_filename(modname)) compiler.module_name_to_filename(modname))
if srcfile == src: if srcfile == src:
depelem = NinjaBuildElement(modfile, 'FORTRAN_DEP_HACK', rel_obj) depelem = NinjaBuildElement(modfile, 'FORTRAN_DEP_HACK', rel_obj)
depelem.write(outfile) depelem.write(outfile)
commands += compiler.get_module_outdir_args(self.get_target_private_dir(target)) commands += compiler.get_module_outdir_args(self.get_target_private_dir_abs(target))
element = NinjaBuildElement(rel_obj, compiler_name, rel_src) element = NinjaBuildElement(rel_obj, compiler_name, rel_src)
for d in header_deps: for d in header_deps:
if isinstance(d, RawFilename): if isinstance(d, RawFilename):
d = d.fname d = d.fname
elif not '/' in d: elif not '/' in d:
d = os.path.join(self.get_target_private_dir(target), d) d = os.path.join(self.get_target_private_dir_abs(target), d)
element.add_dep(d) element.add_dep(d)
for d in extra_deps: for d in extra_deps:
element.add_dep(d) element.add_dep(d)
@ -1222,7 +1222,7 @@ rule FORTRAN_DEP_HACK
if isinstance(d, RawFilename): if isinstance(d, RawFilename):
d = d.fname d = d.fname
elif not '/' in d : elif not '/' in d :
d = os.path.join(self.get_target_private_dir(target), d) d = os.path.join(self.get_target_private_dir_abs(target), d)
element.add_orderdep(d) element.add_orderdep(d)
element.add_orderdep(pch_dep) element.add_orderdep(pch_dep)
element.add_orderdep(extra_orderdeps) element.add_orderdep(extra_orderdeps)
@ -1250,7 +1250,7 @@ rule FORTRAN_DEP_HACK
header = pch[0] header = pch[0]
source = pch[1] source = pch[1]
pchname = compiler.get_pch_name(header) pchname = compiler.get_pch_name(header)
dst = os.path.join(self.get_target_private_dir(target), pchname) dst = os.path.join(self.get_target_private_dir_abs(target), pchname)
commands = [] commands = []
commands += self.generate_basic_compiler_args(target, compiler) commands += self.generate_basic_compiler_args(target, compiler)
@ -1263,7 +1263,7 @@ rule FORTRAN_DEP_HACK
def generate_gcc_pch_command(self, target, compiler, pch): def generate_gcc_pch_command(self, target, compiler, pch):
commands = [] commands = []
commands += self.generate_basic_compiler_args(target, compiler) commands += self.generate_basic_compiler_args(target, compiler)
dst = os.path.join(self.get_target_private_dir(target), dst = os.path.join(self.get_target_private_dir_abs(target),
os.path.split(pch)[-1] + '.' + compiler.get_pch_suffix()) os.path.split(pch)[-1] + '.' + compiler.get_pch_suffix())
dep = dst + '.' + compiler.get_depfile_suffix() dep = dst + '.' + compiler.get_depfile_suffix()
return (commands, dep, dst, []) # Gcc does not create an object file during pch generation. return (commands, dep, dst, []) # Gcc does not create an object file during pch generation.
@ -1300,7 +1300,7 @@ rule FORTRAN_DEP_HACK
def generate_shsym(self, outfile, target): def generate_shsym(self, outfile, target):
target_name = self.get_target_filename(target) target_name = self.get_target_filename(target)
targetdir = self.get_target_private_dir(target) targetdir = self.get_target_private_dir_abs(target)
symname = os.path.join(targetdir, target_name + '.symbols') symname = os.path.join(targetdir, target_name + '.symbols')
elem = NinjaBuildElement(symname, 'SHSYM', target_name) elem = NinjaBuildElement(symname, 'SHSYM', target_name)
if self.environment.is_cross_build() and self.environment.cross_info.need_cross_compiler(): if self.environment.is_cross_build() and self.environment.cross_info.need_cross_compiler():
@ -1373,7 +1373,7 @@ rule FORTRAN_DEP_HACK
def get_dependency_filename(self, t): def get_dependency_filename(self, t):
if isinstance(t, build.SharedLibrary): if isinstance(t, build.SharedLibrary):
return os.path.join(self.get_target_private_dir(t), self.get_target_filename(t) + '.symbols') return os.path.join(self.get_target_private_dir_abs(t), self.get_target_filename(t) + '.symbols')
return self.get_target_filename(t) return self.get_target_filename(t)
def generate_shlib_aliases(self, target, outdir, outfile, elem): def generate_shlib_aliases(self, target, outdir, outfile, elem):
@ -1425,7 +1425,7 @@ rule FORTRAN_DEP_HACK
plainname = os.path.split(src)[1] plainname = os.path.split(src)[1]
basename = plainname.split('.')[0] basename = plainname.split('.')[0]
outname = rule.name_templ.replace('@BASENAME@', basename).replace('@PLAINNAME@', plainname) outname = rule.name_templ.replace('@BASENAME@', basename).replace('@PLAINNAME@', plainname)
outfilename = os.path.join(self.get_target_private_dir(target), outname) outfilename = os.path.join(self.get_target_private_dir_abs(target), outname)
infilename = os.path.join(self.build_to_src, target.get_source_subdir(), src) infilename = os.path.join(self.build_to_src, target.get_source_subdir(), src)
elem = NinjaBuildElement(outfilename, rule.name, infilename) elem = NinjaBuildElement(outfilename, rule.name, infilename)
elem.write(outfile) elem.write(outfile)

@ -40,17 +40,17 @@ class Vs2010Backend(backends.Backend):
base_args = generator.get_arglist() base_args = generator.get_arglist()
for i in range(len(infilelist)): for i in range(len(infilelist)):
if len(infilelist) == len(outfilelist): if len(infilelist) == len(outfilelist):
sole_output = os.path.join(self.get_target_private_dir(target), outfilelist[i]) sole_output = os.path.join(self.get_target_private_dir_abs(target), outfilelist[i])
else: else:
sole_output = '' sole_output = ''
curfile = infilelist[i] curfile = infilelist[i]
infilename = os.path.join(self.environment.get_source_dir(), curfile) infilename = os.path.join(self.environment.get_source_dir(), curfile)
outfiles = genlist.get_outputs_for(curfile) outfiles = genlist.get_outputs_for(curfile)
outfiles = [os.path.join(self.get_target_private_dir(target), of) for of in outfiles] outfiles = [os.path.join(self.get_target_private_dir_abs(target), of) for of in outfiles]
all_output_files += outfiles all_output_files += outfiles
args = [x.replace("@INPUT@", infilename).replace('@OUTPUT@', sole_output)\ args = [x.replace("@INPUT@", infilename).replace('@OUTPUT@', sole_output)\
for x in base_args] for x in base_args]
args = [x.replace("@SOURCE_DIR@", self.environment.get_source_dir()).replace("@BUILD_DIR@", self.get_target_private_dir(target)) args = [x.replace("@SOURCE_DIR@", self.environment.get_source_dir()).replace("@BUILD_DIR@", self.get_target_private_dir_abs(target))
for x in args] for x in args]
fullcmd = [exe_file] + args fullcmd = [exe_file] + args
cbs = ET.SubElement(idgroup, 'CustomBuildStep') cbs = ET.SubElement(idgroup, 'CustomBuildStep')
@ -221,7 +221,7 @@ class Vs2010Backend(backends.Backend):
clconf = ET.SubElement(compiles, 'ClCompile') clconf = ET.SubElement(compiles, 'ClCompile')
opt = ET.SubElement(clconf, 'Optimization') opt = ET.SubElement(clconf, 'Optimization')
opt.text = 'disabled' opt.text = 'disabled'
inc_dirs = [proj_to_src_dir, self.get_target_private_dir(target)] inc_dirs = [proj_to_src_dir, self.get_target_private_dir_abs(target)]
cur_dir = target.subdir cur_dir = target.subdir
if cur_dir == '': if cur_dir == '':
cur_dir= '.' cur_dir= '.'

Loading…
Cancel
Save