Skip to content

Commit

Permalink
Fix using semantic options for global_options
Browse files Browse the repository at this point in the history
  • Loading branch information
jimporter committed Jul 6, 2019
1 parent 6d44680 commit 7e6d007
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
15 changes: 9 additions & 6 deletions bfg9000/builtins/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from ..path import Path, Root
from ..shell import posix as pshell

build_input('compile_flags')(lambda build_inputs, env: defaultdict(list))
build_input('compile_options')(lambda build_inputs, env: defaultdict(list))


class ObjectFiles(list):
Expand Down Expand Up @@ -176,18 +176,21 @@ def precompiled_header(builtins, build, env, name=None, file=None, **kwargs):
@builtin.function('build_inputs')
def global_options(build, options, lang):
for i in iterate(lang):
build['compile_flags'][i].extend(pshell.listify(options))
build['compile_options'][i].extend(pshell.listify(
options, type=opts.option_list
))


def _get_flags(backend, rule, build_inputs, buildfile):
variables = {}
cmd_kwargs = {}

if hasattr(rule.compiler, 'flags_var'):
compiler = rule.compiler
if hasattr(compiler, 'flags_var'):
global_cflags, cflags = backend.flags_vars(
rule.compiler.flags_var,
( rule.compiler.global_flags +
build_inputs['compile_flags'][rule.compiler.lang] ),
compiler.flags_var,
( compiler.global_flags +
compiler.flags(build_inputs['compile_options'][compiler.lang]) ),
buildfile
)
cmd_kwargs['flags'] = cflags
Expand Down
23 changes: 13 additions & 10 deletions bfg9000/builtins/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
merge_into_dict, slice_dict, uniques)
from ..shell import posix as pshell

build_input('link_flags')(lambda build_inputs, env: {
build_input('link_options')(lambda build_inputs, env: {
'dynamic': defaultdict(list), 'static': defaultdict(list)
})

Expand Down Expand Up @@ -359,18 +359,20 @@ def whole_archive(builtins, name, *args, **kwargs):
@builtin.function('build_inputs')
def global_link_options(build, options, family='native', mode='dynamic'):
for i in iterate(family):
build['link_flags'][mode][i].extend(pshell.listify(options))
build['link_options'][mode][i].extend(pshell.listify(options))


def _get_flags(backend, rule, build_inputs, buildfile):
variables = {}
cmd_kwargs = {}

if hasattr(rule.linker, 'flags_var'):
linker = rule.linker
if hasattr(linker, 'flags_var'):
global_ldflags, ldflags = backend.flags_vars(
rule.linker.flags_var,
(rule.linker.global_flags +
build_inputs['link_flags'][rule.base_mode][rule.linker.family]),
linker.flags_var,
(linker.global_flags +
linker.flags(build_inputs['link_options'][rule.base_mode]
[linker.family])),
buildfile
)
cmd_kwargs['flags'] = ldflags
Expand Down Expand Up @@ -478,13 +480,13 @@ def ninja_link(rule, build_inputs, buildfile, env):
from .compile import CompileHeader
from ..backends.msbuild import writer as msbuild

def _parse_compiler_cflags(compilers, global_cflags):
def _parse_compiler_cflags(compilers, global_options):
per_compiler_cflags = {}
for c in compilers:
key = c.command_var
if key not in per_compiler_cflags:
per_compiler_cflags[key] = c.parse_flags(msbuild.textify_each(
c.global_flags + global_cflags[c.lang]
c.global_flags + c.flags(global_options[c.lang])
))
return per_compiler_cflags

Expand Down Expand Up @@ -514,7 +516,7 @@ def msbuild_link(rule, build_inputs, solution, env):
compilers = uniques(i.compiler for i in obj_creators)

per_compiler_options = _parse_compiler_cflags(
compilers, build_inputs['compile_flags']
compilers, build_inputs['compile_options']
)
if len(per_compiler_options) == 1:
common_compile_options = per_compiler_options.popitem()[1]
Expand All @@ -524,7 +526,8 @@ def msbuild_link(rule, build_inputs, solution, env):
# Parse linking flags.
ldflags = [
rule.linker.global_flags +
build_inputs['link_flags'][rule.base_mode][rule.linker.family] +
rule.linker.flags(build_inputs['link_options'][rule.base_mode]
[rule.linker.family]) +
rule.flags
]
if hasattr(rule.linker, 'libs_var'):
Expand Down
2 changes: 1 addition & 1 deletion examples/10_custom_args/build.bfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
# Once these options are defined, you can fetch their results from the built-in
# argv global in your `build.bfg` file:

global_options(['-DNAME="{}"'.format(argv.name)], lang='c++')
global_options([opts.define('NAME', '"' + argv.name + '"')], lang='c++')

executable('simple', files=['simple.cpp'])

0 comments on commit 7e6d007

Please sign in to comment.