diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2019-09-26 23:58:44 +0300 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2019-09-26 23:58:44 +0300 |
commit | 3fcca74e340e23b88444748efd792df91a81da63 (patch) | |
tree | ee2418a09f9a745fa4f633041f7b2f72a4209991 /mesonbuild | |
parent | 534e94ffc35dae3a0b2cc9f1e60e7e452872c512 (diff) | |
download | meson-vsmodtest.zip meson-vsmodtest.tar.gz meson-vsmodtest.tar.bz2 |
Q&D experiment to scan and build C++ modules with VS.vsmodtest
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/backend/ninjabackend.py | 12 | ||||
-rw-r--r-- | mesonbuild/compilers/compilers.py | 2 | ||||
-rw-r--r-- | mesonbuild/scripts/fakeall.py | 71 |
3 files changed, 83 insertions, 2 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 417f6d9..6323830 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -328,11 +328,14 @@ int dummy; self.write_rules(outfile) self.write_builds(outfile) - default = 'default all\n\n' + + default = 'default fakeall\n\n' outfile.write(default) # Only overwrite the old build file after the new one has been # fully created. os.replace(tempfilename, outfilename) + import shutil + shutil.copy(outfilename, outfilename + '.hackbak') self.generate_compdb() # http://clang.llvm.org/docs/JSONCompilationDatabase.html @@ -2685,6 +2688,13 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485''')) self.add_build(elem) # Alias that runs the target defined above self.create_target_alias('meson-uninstall') + cmd = self.environment.get_build_command() + ['--internal', 'scanhack'] + elem = NinjaBuildElement(self.all_outputs, 'meson-fakeall', 'CUSTOM_COMMAND', 'PHONY') + elem.add_item('COMMAND', cmd) + elem.add_item('pool', 'console') + self.add_build(elem) + # Alias that runs the target defined above + self.create_target_alias('meson-fakeall') def generate_ending(self): targetlist = [] diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index bb698fc..63aea8d 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -44,7 +44,7 @@ lib_suffixes = ('a', 'lib', 'dll', 'dylib', 'so') # This means we can't include .h headers here since they could be C, C++, ObjC, etc. lang_suffixes = { 'c': ('c',), - 'cpp': ('cpp', 'cc', 'cxx', 'c++', 'hh', 'hpp', 'ipp', 'hxx'), + 'cpp': ('cpp', 'cc', 'cxx', 'c++', 'hh', 'hpp', 'ipp', 'hxx', 'ixx'), 'cuda': ('cu',), # f90, f95, f03, f08 are for free-form fortran ('f90' recommended) # f, for, ftn, fpp are for fixed-form fortran ('f' or 'for' recommended) diff --git a/mesonbuild/scripts/fakeall.py b/mesonbuild/scripts/fakeall.py new file mode 100644 index 0000000..1630c10 --- /dev/null +++ b/mesonbuild/scripts/fakeall.py @@ -0,0 +1,71 @@ +# Copyright 2019 The Meson development team + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import json, os, sys, subprocess + +def scan_file(src): + moddeps = [] + for line in open(src): + if line.startswith('import '): + line = line.strip() + modnum = line.split('M')[-1][:-1] + d = 'src{}.ixx'.format(modnum) + if d not in moddeps: + moddeps.append(d) + return moddeps + +def scan_deps(): + compdb = json.load(open('compile_commands.json')) + src2obj = {} + name2path = {} + mmap = {} + obj_deps = {} # AWFUL HACK! Should put the dep on the generated ifc file instead but can't because of Ninja limitation of one output per rule if you need dep files as well. + for o in compdb: + full_srcname = o['file'] + srcname = os.path.split(full_srcname)[1] + objname = o['output'] + assert(srcname.endswith('.ixx') or srcname.endswith('.cpp')) + src2obj[srcname] = objname + name2path[srcname] = full_srcname + for o in compdb: + full_srcname = o['file'] + objname = o['output'] + srcname = os.path.split(full_srcname)[1] + mod_deps = scan_file(full_srcname) + obj_deps[objname] = [src2obj[x] for x in mod_deps] + #for k, v in obj_deps.items(): + # print(k, '=>', v) + return obj_deps + +def rewrite_ninja(obj_deps): + ifilename = 'build.ninja.hackbak' + ofilename = 'build.ninja' + ofile = open(ofilename, 'w') + for line in open(ifilename): + if line.startswith('build '): + line = line.strip() + out, deps = line.split(':', 1) + out_obj = out.split(' ', 1)[1] + dep_objs = obj_deps.get(out_obj, []) + if len(dep_objs) > 0: + deps += ' | ' + ' '.join(dep_objs) + line = out + ':' + deps + '\n' + ofile.write(line) + +def run(args): + print('Scanning and rewriting Ninja file.') + obj_deps = scan_deps() + rewrite_ninja(obj_deps) + sys.exit(subprocess.run(['ninja', 'all']).returncode) + |