Skip to content

build: avoid passing empty strings to build flags #1789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,8 @@ def configure_library(lib, output):
if default_libpath:
default_libpath = '-L' + default_libpath
(pkg_libs, pkg_cflags, pkg_libpath) = pkg_config(lib)
cflags = pkg_cflags.split('-I') if pkg_cflags else default_cflags
# Remove empty strings from the list of include_dirs
cflags = filter(None, pkg_cflags.split('-I')) if pkg_cflags else default_cflags
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long line.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside, the filter step removes empty lines but not blank lines. Would that matter?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't come across that just yet. I'll improve the filter; guess it couldn't hurt. Just want to avoid making parsing too complex.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bnoordhuis filter(False, foo) would do, right (captures '' or None)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think filter() accepts False. What about this?

cflags = default_cflags
if pkg_cflags:
  cflags = filter(False, map(str.strip, pkg_cflags.split('-I')))
  # Maybe easier to read:
  cflags = map(str.strip, pkg_cflags.split('-I'))
  cflags = [s for s in cflags if s]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adapted a similar strategy.

libs = pkg_libs if pkg_libs else default_lib
libpath = pkg_libpath if pkg_libpath else default_libpath

Expand Down Expand Up @@ -846,10 +847,12 @@ def configure_intl(o):
sys.exit(1)
(libs, cflags, libpath) = pkgicu
# libpath provides linker path which may contain spaces
o['libraries'] += [libpath]
if libpath:
o['libraries'] += [libpath]
# safe to split, cannot contain spaces
o['libraries'] += libs.split()
o['cflags'] += cflags.split()
if cflags:
o['cflags'] += filter(None, cflags.split('-I'))
# use the "system" .gyp
o['variables']['icu_gyp_path'] = 'tools/icu/icu-system.gyp'
return
Expand Down