Commit 5a3c7f85 authored by Craig Silverstein's avatar Craig Silverstein

Tue Apr 14 12:35:25 2009 Google Inc. <opensource@google.com>

	* google-gflags: version 1.1
	* Add both foo and nofoo for boolean flags, with --undefok (andychu)
	* Better document how validators work (wojtekm)
	* Improve binary-detection for bash-completion (mtamsky)
	* Python: Add a concept of "key flags", used with --help (salcianu)
	* Python: Robustify flag_values (salcianu)
	* Python: Add a new DEFINE_bool alias (keir, andrewliu)
	* Python: Do module introspection based on module name (dsturtevant)
	* Fix autoconf a bit better, especially on windows and solaris (ajenjo)
	* BUG FIX: gflags_nothreads was linking against the wrong lib (ajenjo)
	* BUG FIX: threads-detection failed on FreeBSD; replace it (ajenjo)
	* PORTABILITY: Quiet an internal compiler error with SUSE 10 (csilvers)
	* PORTABILITY: Update deb.sh for more recenty debuilds (csilvers)
	* PORTABILITY: #include more headers to satify new gcc's (csilvers)
	* INSTALL: Updated to autoconf 2.61 and libtool 1.5.26 (csilvers)


git-svn-id: https://gflags.googlecode.com/svn/trunk@29 6586e3c6-dcc4-952a-343f-ff74eb82781d
parent e0b71e57
Tue Apr 14 12:35:25 2009 Google Inc. <opensource@google.com>
* google-gflags: version 1.1
* Add both foo and nofoo for boolean flags, with --undefok (andychu)
* Better document how validators work (wojtekm)
* Improve binary-detection for bash-completion (mtamsky)
* Python: Add a concept of "key flags", used with --help (salcianu)
* Python: Robustify flag_values (salcianu)
* Python: Add a new DEFINE_bool alias (keir, andrewliu)
* Python: Do module introspection based on module name (dsturtevant)
* Fix autoconf a bit better, especially on windows and solaris (ajenjo)
* BUG FIX: gflags_nothreads was linking against the wrong lib (ajenjo)
* BUG FIX: threads-detection failed on FreeBSD; replace it (ajenjo)
* PORTABILITY: Quiet an internal compiler error with SUSE 10 (csilvers)
* PORTABILITY: Update deb.sh for more recenty debuilds (csilvers)
* PORTABILITY: #include more headers to satify new gcc's (csilvers)
* INSTALL: Updated to autoconf 2.61 and libtool 1.5.26 (csilvers)
Fri Oct 3 15:16:46 2008 Google Inc. <opensource@google.com>
* google-gflags: version 1.0
* Add a missing newline to an error string (bcmills)
* (otherwise exactly the same as gflags 1.0rc2)
Thu Sep 18 12:58:05 2008 Google Inc. <opensource@google.com>
* google-gflags: version 1.0rc2
......
Copyright 1994, 1995, 1996, 1999, 2000, 2001, 2002 Free Software
Foundation, Inc.
Installation Instructions
*************************
This file is free documentation; the Free Software Foundation gives
unlimited permission to copy, distribute and modify it.
Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005 Free
Software Foundation, Inc.
This file is free documentation; the Free Software Foundation gives
unlimited permission to copy, distribute and modify it.
Basic Installation
==================
These are generic installation instructions.
These are generic installation instructions.
The `configure' shell script attempts to guess correct values for
various system-dependent variables used during compilation. It uses
......@@ -68,9 +70,9 @@ The simplest way to compile this package is:
Compilers and Options
=====================
Some systems require unusual options for compilation or linking that
the `configure' script does not know about. Run `./configure --help'
for details on some of the pertinent environment variables.
Some systems require unusual options for compilation or linking that the
`configure' script does not know about. Run `./configure --help' for
details on some of the pertinent environment variables.
You can give `configure' initial values for configuration parameters
by setting variables in the command line or in the environment. Here
......@@ -83,7 +85,7 @@ is an example:
Compiling For Multiple Architectures
====================================
You can compile the package for more than one kind of computer at the
You can compile the package for more than one kind of computer at the
same time, by placing the object files for each architecture in their
own directory. To do this, you must use a version of `make' that
supports the `VPATH' variable, such as GNU `make'. `cd' to the
......@@ -100,19 +102,19 @@ for another architecture.
Installation Names
==================
By default, `make install' will install the package's files in
`/usr/local/bin', `/usr/local/man', etc. You can specify an
installation prefix other than `/usr/local' by giving `configure' the
option `--prefix=PATH'.
By default, `make install' installs the package's commands under
`/usr/local/bin', include files under `/usr/local/include', etc. You
can specify an installation prefix other than `/usr/local' by giving
`configure' the option `--prefix=PREFIX'.
You can specify separate installation prefixes for
architecture-specific files and architecture-independent files. If you
give `configure' the option `--exec-prefix=PATH', the package will use
PATH as the prefix for installing programs and libraries.
Documentation and other data files will still use the regular prefix.
pass the option `--exec-prefix=PREFIX' to `configure', the package uses
PREFIX as the prefix for installing programs and libraries.
Documentation and other data files still use the regular prefix.
In addition, if you use an unusual directory layout you can give
options like `--bindir=PATH' to specify different values for particular
options like `--bindir=DIR' to specify different values for particular
kinds of files. Run `configure --help' for a list of the directories
you can set and what kinds of files go in them.
......@@ -123,7 +125,7 @@ option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
Optional Features
=================
Some packages pay attention to `--enable-FEATURE' options to
Some packages pay attention to `--enable-FEATURE' options to
`configure', where FEATURE indicates an optional part of the package.
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
is something like `gnu-as' or `x' (for the X Window System). The
......@@ -138,11 +140,11 @@ you can use the `configure' options `--x-includes=DIR' and
Specifying the System Type
==========================
There may be some features `configure' cannot figure out
automatically, but needs to determine by the type of machine the package
will run on. Usually, assuming the package is built to be run on the
_same_ architectures, `configure' can figure that out, but if it prints
a message saying it cannot guess the machine type, give it the
There may be some features `configure' cannot figure out automatically,
but needs to determine by the type of machine the package will run on.
Usually, assuming the package is built to be run on the _same_
architectures, `configure' can figure that out, but if it prints a
message saying it cannot guess the machine type, give it the
`--build=TYPE' option. TYPE can either be a short name for the system
type, such as `sun4', or a canonical name which has the form:
......@@ -157,7 +159,7 @@ where SYSTEM can have one of these forms:
need to know the machine type.
If you are _building_ compiler tools for cross-compiling, you should
use the `--target=TYPE' option to select the type of system they will
use the option `--target=TYPE' to select the type of system they will
produce code for.
If you want to _use_ a cross compiler, that generates code for a
......@@ -168,9 +170,9 @@ eventually be run) with `--host=TYPE'.
Sharing Defaults
================
If you want to set default values for `configure' scripts to share,
you can create a site shell script called `config.site' that gives
default values for variables like `CC', `cache_file', and `prefix'.
If you want to set default values for `configure' scripts to share, you
can create a site shell script called `config.site' that gives default
values for variables like `CC', `cache_file', and `prefix'.
`configure' looks for `PREFIX/share/config.site' if it exists, then
`PREFIX/etc/config.site' if it exists. Or, you can set the
`CONFIG_SITE' environment variable to the location of the site script.
......@@ -179,7 +181,7 @@ A warning: not all `configure' scripts look for a site script.
Defining Variables
==================
Variables not defined in a site shell script can be set in the
Variables not defined in a site shell script can be set in the
environment passed to `configure'. However, some packages may run
configure again during the build, and the customized values of these
variables may be lost. In order to avoid this problem, you should set
......@@ -187,14 +189,18 @@ them in the `configure' command line, using `VAR=value'. For example:
./configure CC=/usr/local2/bin/gcc
will cause the specified gcc to be used as the C compiler (unless it is
overridden in the site shell script).
causes the specified `gcc' to be used as the C compiler (unless it is
overridden in the site shell script). Here is a another example:
/bin/bash ./configure CONFIG_SHELL=/bin/bash
Here the `CONFIG_SHELL=/bin/bash' operand causes subsequent
configuration-related scripts to be executed by `/bin/bash'.
`configure' Invocation
======================
`configure' recognizes the following options to control how it
operates.
`configure' recognizes the following options to control how it operates.
`--help'
`-h'
......
......@@ -14,6 +14,10 @@ if GCC
AM_CXXFLAGS += -Wall -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare
endif
# The -no-undefined flag allows libtool to generate shared libraries for
# Cygwin and MinGW. LIBSTDCXX_LA_LINKER_FLAG is used to fix a Solaris bug.
AM_LDFLAGS = -no-undefined $(LIBSTDCXX_LA_LINKER_FLAG)
gflagsincludedir = $(includedir)/gflags
## The .h files you want to install (that is, .h files that people
## who install this package can include in their own applications.)
......@@ -49,25 +53,31 @@ CLEANFILES =
## vvvv RULES TO MAKE THE LIBRARIES, BINARIES, AND UNITTESTS
GFLAGS_SOURCES = $(gflagsinclude_HEADERS) src/config.h src/mutex.h \
src/gflags.cc src/gflags_reporting.cc \
src/gflags_completions.cc
lib_LTLIBRARIES += libgflags.la
libgflags_la_SOURCES = $(gflagsinclude_HEADERS) src/config.h \
src/gflags.cc src/gflags_reporting.cc \
src/gflags_completions.cc
libgflags_la_SOURCES = $(GFLAGS_SOURCES)
libgflags_la_CXXFLAGS = $(PTHREAD_CFLAGS) -DNDEBUG
libgflags_la_LDFLAGS = $(PTHREAD_CFLAGS)
libgflags_la_LIBADD = $(PTHREAD_LIBS)
lib_LTLIBRARIES += libgflags_nothreads.la
libgflags_nothreads_la_SOURCES = $(GFLAGS_SOURCES)
libgflags_nothreads_la_CXXFLAGS = -DNDEBUG -DNO_THREADS
TESTS += gflags_unittest$(EXEEXT)
gflags_unittest_SOURCES = $(gflagsinclude_HEADERS) src/config.h \
src/gflags_unittest.cc
gflags_unittest_CXXFLAGS = $(PTHREAD_CFLAGS)
gflags_unittest_LDFLAGS = $(PTHREAD_CFLAGS)
gflags_unittest_LDADD = libgflags.la $(PTHREAD_LIBS)
gflags_unittest_LDADD = libgflags.la
# Also make sure this works when we don't link in pthreads
TESTS += gflags_nothreads_unittest$(EXEEXT)
gflags_nothreads_unittest_SOURCES = $(gflags_unittest_SOURCES)
gflags_nothreads_unittest_LDADD = libgflags.la
gflags_nothreads_unittest_LDADD = libgflags_nothreads.la
# We also want to test that things work properly when the file that
# holds main() has a name ending with -main or _main. To keep the
......@@ -75,7 +85,7 @@ gflags_nothreads_unittest_LDADD = libgflags.la
TESTS += gflags_unittest2$(EXEEXT)
gflags_unittest2_SOURCES = $(gflagsinclude_HEADERS) src/config.h \
src/gflags_unittest-main.cc
gflags_unittest2_LDADD = libgflags.la
gflags_unittest2_LDADD = libgflags_nothreads.la
src/gflags_unittest-main.cc: src/gflags_unittest.cc
rm -f src/gflags_unittest-main.cc
cp -p src/gflags_unittest.cc src/gflags_unittest-main.cc
......@@ -84,7 +94,7 @@ CLEANFILES += src/gflags_unittest-main.cc
TESTS += gflags_unittest3$(EXEEXT)
gflags_unittest3_SOURCES = $(gflagsinclude_HEADERS) src/config.h \
src/gflags_unittest_main.cc
gflags_unittest3_LDADD = libgflags.la
gflags_unittest3_LDADD = libgflags_nothreads.la
src/gflags_unittest_main.cc: src/gflags_unittest.cc
rm -f src/gflags_unittest_main.cc
cp -p src/gflags_unittest.cc src/gflags_unittest_main.cc
......@@ -107,7 +117,9 @@ gflags_unittest_sh: gflags_unittest$(EXEEXT) \
PYTHON = python/setup.py \
python/gflags.py \
python/gflags2man.py \
python/gflags_unittest.py
python/gflags_unittest.py \
python/test_module_foo.py \
python/test_module_bar.py
## ^^^^ END OF RULES TO MAKE THE LIBRARIES, BINARIES, AND UNITTESTS
......@@ -126,4 +138,5 @@ deb: dist-gzip packages/deb.sh packages/deb/*
libtool: $(LIBTOOL_DEPS)
$(SHELL) ./config.status --recheck
EXTRA_DIST = packages/rpm.sh packages/rpm/rpm.spec packages/deb.sh packages/deb \
libtool $(SCRIPTS) $(PYTHON)
libtool $(SCRIPTS) $(PYTHON) \
src/solaris/libstdc++.la
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -4,7 +4,7 @@
# make sure we're interpreted by some minimal autoconf
AC_PREREQ(2.57)
AC_INIT(gflags, 1.0rc2, opensource@google.com)
AC_INIT(gflags, 1.1, opensource@google.com)
# The argument here is just something that should be in the current directory
# (for sanity checking)
AC_CONFIG_SRCDIR(README)
......@@ -16,6 +16,22 @@ AC_PROG_CC
AC_PROG_CPP
AC_PROG_CXX
AM_CONDITIONAL(GCC, test "$GCC" = yes) # let the Makefile know if we're gcc
AC_CANONICAL_HOST
# Populate $host_cpu, $host_os, etc.
AC_CANONICAL_HOST
case $host_os in
*mingw*)
# Disabling fast install keeps libtool from creating wrapper scripts
# around the executables it builds. Such scripts have caused failures on
# MinGW. Using this option means an extra link step is executed during
# "make install".
AC_DISABLE_FAST_INSTALL
;;
*)
AC_ENABLE_FAST_INSTALL
;;
esac
# Uncomment this if you'll be exporting libraries (.so's)
AC_PROG_LIBTOOL
......@@ -28,7 +44,7 @@ AC_HEADER_STDC
AC_CHECK_HEADER(stdint.h, ac_cv_have_stdint_h=1, ac_cv_have_stdint_h=0)
AC_CHECK_HEADER(sys/types.h, ac_cv_have_systypes_h=1, ac_cv_have_systypes_h=0)
AC_CHECK_HEADER(inttypes.h, ac_cv_have_inttypes_h=1, ac_cv_have_inttypes_h=0)
AC_CHECK_HEADERS([fnmatch.h windows.h])
AC_CHECK_HEADERS([fnmatch.h])
# These are the types I need. We look for them in either stdint.h,
# sys/types.h, or inttypes.h, all of which are part of the default-includes.
......@@ -36,8 +52,6 @@ AC_CHECK_TYPE(uint16_t, ac_cv_have_uint16_t=1, ac_cv_have_uint16_t=0)
AC_CHECK_TYPE(u_int16_t, ac_cv_have_u_int16_t=1, ac_cv_have_u_int16_t=0)
AC_CHECK_TYPE(__int16, ac_cv_have___int16=1, ac_cv_have___int16=0)
AC_CHECK_FUNCS([InitializeCriticalSection])
AC_CHECK_FUNCS([InterlockedCompareExchange])
AC_CHECK_FUNCS([strtoll strtoq])
AX_C___ATTRIBUTE__
......@@ -55,6 +69,15 @@ ACX_PTHREAD
AC_CXX_STL_NAMESPACE
AC_DEFINE_GOOGLE_NAMESPACE(google)
# Solaris 10 6/06 has a bug where /usr/sfw/lib/libstdc++.la is empty.
# If so, we replace it with our own version.
LIBSTDCXX_LA_LINKER_FLAG=
if test -f /usr/sfw/lib/libstdc++.la && ! test -s /usr/sfw/lib/libstdc++.la
then
LIBSTDCXX_LA_LINKER_FLAG='-L$(top_srcdir)/src/solaris'
fi
AC_SUBST(LIBSTDCXX_LA_LINKER_FLAG)
# These are what's needed by gflags.h.in
AC_SUBST(ac_google_start_namespace)
AC_SUBST(ac_google_end_namespace)
......
......@@ -197,7 +197,10 @@ function with the flag. If you do this, after the flag is parsed from
the commandline, and whenever its value is changes via a call to
<code>SetCommandLineOption()</code>, the validator function is called
with the new value as an argument. The validator function should
return 'true' if the flag value is valid, and false otherwise.
return 'true' if the flag value is valid, and false otherwise.
If the function returns false for the new setting of the
flag, the flag will retain its current value. If it returns false for the
default value, InitGoogle will die.
<p>Here is an example use of this functionality:</p>
<pre>
......
......@@ -12,6 +12,7 @@ LIB=
#LIB=lib
PACKAGE="$1"
VERSION="$2"
# We can only build Debian packages, if the Debian build tools are installed
if [ \! -x /usr/bin/debuild ]; then
......@@ -30,7 +31,8 @@ fi
topdir="${PWD%/*}"
# Find the tar archive built by "make dist"
archive="$(basename "$(ls -1 ${topdir}/$PACKAGE*.tar.gz | tail -n 1)" .tar.gz)"
archive="${PACKAGE}-${VERSION}"
archive_with_underscore="${PACKAGE}_${VERSION}"
if [ -z "${archive}" ]; then
echo "Cannot find ../$PACKAGE*.tar.gz. Run \"make dist\" first." 1>&2
exit 0
......@@ -48,11 +50,13 @@ cd tmp
# packages to the parent of the source directory. We accommodate these
# requirements by building directly from the tar file.
ln -s "${topdir}/${archive}.tar.gz" "${LIB}${archive}.orig.tar.gz"
# Some version of debuilder want foo.orig.tar.gz with _ between versions.
ln -s "${topdir}/${archive}.tar.gz" "${LIB}${archive_with_underscore}.orig.tar.gz"
tar zfx "${LIB}${archive}.orig.tar.gz"
[ -n "${LIB}" ] && mv "${archive}" "${LIB}${archive}"
cd "${LIB}${archive}"
# This is one of those 'specific requirements': where the deb control files live
ln -s "packages/deb" "debian"
cp -a "packages/deb" "debian"
# Now, we can call Debian's standard build tool
debuild -uc -us
......
gflags (1.1-1) unstable; urgency=low
* New upstream release.
* Renamed package to gflags, from google-gflags, to match the package
and library names used in the .rpm file, and in the tarball.
-- Google Inc. <opensource@google.com> Tue, 14 Apr 2009 12:35:25 -0700
google-gflags (1.0-1) unstable; urgency=low
* New upstream release.
-- Google Inc. <opensource@google.com> Fri, 03 Oct 2008 15:16:46 -0700
google-gflags (1.0rc2-1) unstable; urgency=low
* New upstream release.
......
Source: google-gflags
Source: gflags
Priority: optional
Maintainer: Google Inc. <opensource@google.com>
Build-Depends: debhelper (>= 4.0.0), binutils
Standards-Version: 3.6.1
Package: libgoogle-gflags-dev
Package: libgflags-dev
Section: libdevel
Architecture: any
Depends: libgoogle-gflags0 (= ${Source-Version})
Depends: libgflags0 (= ${Source-Version})
Description: a library that implements commandline flags
processing. As such it's a replacement for getopt(). It has increased
flexibility, including built-in support for C++ types like string, and
the ability to define flags in the source file in which they're used.
The devel package contains static and debug libraries and header files
for developing applications that use the google-gflags package.
for developing applications that use the gflags package.
Package: libgoogle-gflags0
Package: libgflags0
Section: libs
Architecture: any
Depends: ${shlibs:Depends}
Description: a library that implements commandline flags
processing. As such it's a replacement for getopt(). It has increased
flexibility, including built-in support for C++ types like string, and
the ability to define flags in the source file in which they're used.
\ No newline at end of file
the ability to define flags in the source file in which they're used.
......@@ -62,6 +62,8 @@ rm -rf $RPM_BUILD_ROOT
%{prefix}/lib/libgflags.so.0
%{prefix}/lib/libgflags.so.0.0.0
%{prefix}/lib/libgflags_nothreads.so.0
%{prefix}/lib/libgflags_nothreads.so.0.0.0
%{prefix}/bin/gflags_completions.sh
%files devel
......@@ -72,3 +74,6 @@ rm -rf $RPM_BUILD_ROOT
%{prefix}/lib/libgflags.a
%{prefix}/lib/libgflags.la
%{prefix}/lib/libgflags.so
%{prefix}/lib/libgflags_nothreads.a
%{prefix}/lib/libgflags_nothreads.la
%{prefix}/lib/libgflags_nothreads.so
This diff is collapsed.
This diff is collapsed.
#!/usr/bin/env python
# Copyright (c) 2009, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Auxiliary module for testing flags.py.
The purpose of this module is to define a few flags. We want to make
sure the unit tests for flags.py involve more than one module.
"""
__author__ = 'Alex Salcianu'
__pychecker__ = "no-local" # for unittest
# We use the name 'flags' internally in this test, for historical reasons.
# Don't do this yourself! :-) Just do 'import gflags; FLAGS=gflags.FLAGS; etc'
import gflags as flags
FLAGS = flags.FLAGS
def DefineFlags(flag_values=FLAGS):
"""Defines some flags.
Args:
flag_values: The FlagValues object we want to register the flags
with.
"""
# The 'tmod_bar_' prefix (short for 'test_module_bar') ensures there
# is no name clash with the existing flags.
flags.DEFINE_boolean('tmod_bar_x', True, 'Boolean flag.',
flag_values=flag_values)
flags.DEFINE_string('tmod_bar_y', 'default', 'String flag.',
flag_values=flag_values)
flags.DEFINE_boolean('tmod_bar_z', False,
'Another boolean flag from module bar.',
flag_values=flag_values)
flags.DEFINE_integer('tmod_bar_t', 4, 'Sample int flag.',
flag_values=flag_values)
flags.DEFINE_integer('tmod_bar_u', 5, 'Sample int flag.',
flag_values=flag_values)
flags.DEFINE_integer('tmod_bar_v', 6, 'Sample int flag.',
flag_values=flag_values)
def RemoveOneFlag(flag_name, flag_values=FLAGS):
"""Removes the definition of one flag from flags.FLAGS.
Note: if the flag is not defined in flags.FLAGS, this function does
not do anything (in particular, it does not raise any exception).
Motivation: We use this function for cleanup *after* a test: if
there was a failure during a test and not all flags were declared,
we do not want the cleanup code to crash.
Args:
flag_name: A string, the name of the flag to delete.
flag_values: The FlagValues object we remove the flag from.
"""
if flag_name in flag_values.FlagDict():
flag_values.__delattr__(flag_name)
def NamesOfDefinedFlags():
"""Returns: List of names of the flags declared in this module."""
return ['tmod_bar_x',
'tmod_bar_y',
'tmod_bar_z',
'tmod_bar_t',
'tmod_bar_u',
'tmod_bar_v']
def RemoveFlags(flag_values=FLAGS):
"""Deletes the flag definitions done by the above DefineFlags().
Args:
flag_values: The FlagValues object we remove the flags from.
"""
for flag_name in NamesOfDefinedFlags():
RemoveOneFlag(flag_name, flag_values=flag_values)
def GetModuleName():
"""Uses flags._GetCallingModule() to return the name of this module.
For checking that _GetCallingModule works as expected.
Returns:
A string, the name of this module.
"""
# Calling the protected _GetCallingModule generates a lint warning,
# but we do not have any other alternative to test that function.
return flags._GetCallingModule()
def ExecuteCode(code, global_dict):
"""Executes some code in a given global environment.
For testing of _GetCallingModule.
Args:
code: A string, the code to be executed.
global_dict: A dictionary, the global environment that code should
be executed in.
"""
# Indeed, using exec generates a lint warning. But some user code
# actually uses exec, and we have to test for it ...
exec code in global_dict
#!/usr/bin/env python
# Copyright (c) 2009, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Auxiliary module for testing flags.py.
The purpose of this module is to define a few flags, and declare some
other flags as being important. We want to make sure the unit tests
for flags.py involve more than one module.
"""
__author__ = 'Alex Salcianu'
__pychecker__ = "no-local" # for unittest
# We use the name 'flags' internally in this test, for historical reasons.
# Don't do this yourself! :-) Just do 'import gflags; FLAGS=gflags.FLAGS; etc'
import gflags as flags
FLAGS = flags.FLAGS
# For historical reasons we use the name module_bar instead of test_module_bar.
import test_module_bar as module_bar
DECLARED_KEY_FLAGS = ['tmod_bar_x', 'tmod_bar_z', 'tmod_bar_t']
def DefineFlags():
"""Defines a few flags."""
module_bar.DefineFlags()
# The 'tmod_foo_' prefix (short for 'test_module_foo') ensures that we
# have no name clash with existing flags.
flags.DEFINE_boolean('tmod_foo_bool', True, 'Boolean flag from module foo.')
flags.DEFINE_string('tmod_foo_str', 'default', 'String flag.')
flags.DEFINE_integer('tmod_foo_int', 3, 'Sample int flag.')
def DeclareKeyFlags():
"""Declares a few key flags."""
for flag_name in DECLARED_KEY_FLAGS:
flags.DECLARE_key_flag(flag_name)
def DeclareExtraKeyFlags():
"""Declares some extra key flags."""
flags.ADOPT_module_key_flags(module_bar)
def NamesOfDefinedFlags():
"""Returns: list of names of flags defined by this module."""
return ['tmod_foo_bool', 'tmod_foo_str', 'tmod_foo_int']
def NamesOfDeclaredKeyFlags():
"""Returns: list of names of key flags for this module."""
return NamesOfDefinedFlags() + DECLARED_KEY_FLAGS
def NamesOfDeclaredExtraKeyFlags():
"""Returns the list of names of additional key flags for this module.
These are the flags that became key for this module only as a result
of a call to DeclareExtraKeyFlags() above. I.e., the flags declared
by module_bar, that were not already declared as key for this
module.
Returns:
The list of names of additional key flags for this module.
"""
names_of_extra_key_flags = list(module_bar.NamesOfDefinedFlags())
for flag_name in NamesOfDeclaredKeyFlags():
while flag_name in names_of_extra_key_flags:
names_of_extra_key_flags.remove(flag_name)
return names_of_extra_key_flags
def RemoveFlags():
"""Deletes the flag definitions done by the above DefineFlags()."""
for flag_name in NamesOfDefinedFlags():
module_bar.RemoveOneFlag(flag_name)
module_bar.RemoveFlags()
def GetModuleName():
"""Uses flags._GetCallingModule() to return the name of this module.
For checking that _GetCallingModule works as expected.
Returns:
A string, the name of this module.
"""
# Calling the protected _GetCallingModule generates a lint warning,
# but we do not have any other alternative to test that function.
return flags._GetCallingModule()
......@@ -9,12 +9,6 @@
/* Define to 1 if you have the <fnmatch.h> header file. */
#undef HAVE_FNMATCH_H
/* Define to 1 if you have the `InitializeCriticalSection' function. */
#undef HAVE_INITIALIZECRITICALSECTION
/* Define to 1 if you have the `InterlockedCompareExchange' function. */
#undef HAVE_INTERLOCKEDCOMPAREEXCHANGE
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
......@@ -54,9 +48,6 @@
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to 1 if you have the <windows.h> header file. */
#undef HAVE_WINDOWS_H
/* define if your compiler has __attribute__ */
#undef HAVE___ATTRIBUTE__
......
This diff is collapsed.
......@@ -117,9 +117,12 @@ typedef unsigned __int64 uint64;
// DEFINE_string, etc. at the bottom of this file. You may also find
// it useful to register a validator with the flag. This ensures that
// when the flag is parsed from the commandline, or is later set via
// SetCommandLineOption, we call the validation function. The
// validation function should return true if the flag value is valid,
// and false otherwise.
// SetCommandLineOption, we call the validation function.
//
// The validation function should return true if the flag value is valid, and
// false otherwise. If the function returns false for the new setting of the
// flag, the flag will retain its current value. If it returns false for the
// default value, InitGoogle will die.
//
// This function is safe to call at global construct time (as in the
// example below).
......@@ -501,6 +504,9 @@ extern bool FlagsTypeWarn(const char *name);
// --string and --nostring. And we need a temporary place to put val
// so we don't have to evaluate it twice. Two great needs that go
// great together!
// The weird 'using' + 'extern' inside the fLS namespace is to work around
// an unknown compiler bug/issue with the gcc 4.2.1 on SUSE 10. See
// http://code.google.com/p/google-gflags/issues/detail?id=20
#define DEFINE_string(name, val, txt) \
namespace fLS { \
static union { void* align; char s[sizeof(std::string)]; } s_##name[2]; \
......@@ -508,6 +514,8 @@ extern bool FlagsTypeWarn(const char *name);
static @ac_google_namespace@::FlagRegisterer o_##name( \
#name, "string", MAYBE_STRIPPED_HELP(txt), __FILE__, \
s_##name[0].s, new (s_##name[1].s) std::string(*FLAGS_no##name)); \
extern std::string& FLAGS_##name; \
using fLS::FLAGS_##name; \
std::string& FLAGS_##name = *(reinterpret_cast<std::string*>(s_##name[0].s)); \
} \
using fLS::FLAGS_##name
......
......@@ -49,7 +49,9 @@
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h> // for strlen
#include <set>
#include <string>
......@@ -463,6 +465,13 @@ static void CategorizeAllMatchingFlags(
}
}
static void PushNameWithSuffix(vector<string>* suffixes, const char* suffix) {
string s("/");
s += ProgramInvocationShortName();
s += suffix;
suffixes->push_back(s);
}
static void TryFindModuleAndPackageDir(
const vector<CommandLineFlagInfo> all_flags,
string *module,
......@@ -475,15 +484,14 @@ static void TryFindModuleAndPackageDir(
// could share the same trailing folder and file structure (and even worse,
// same file names), causing us to be unsure as to which of the two is the
// actual package for this binary. In this case, we'll arbitrarily choose.
string progname(ProgramInvocationShortName());
suffixes.push_back("/" + progname + ".");
suffixes.push_back("/" + progname + "-main.");
suffixes.push_back("/" + progname + "_main.");
PushNameWithSuffix(&suffixes, ".");
PushNameWithSuffix(&suffixes, "-main.");
PushNameWithSuffix(&suffixes, "_main.");
// These four are new but probably merited?
suffixes.push_back("/" + progname + "_test.");
suffixes.push_back("/" + progname + "-test.");
suffixes.push_back("/" + progname + "_unittest.");
suffixes.push_back("/" + progname + "-unittest.");
PushNameWithSuffix(&suffixes, "-test.");
PushNameWithSuffix(&suffixes, "_test.");
PushNameWithSuffix(&suffixes, "-unittest.");
PushNameWithSuffix(&suffixes, "_unittest.");
for (vector<CommandLineFlagInfo>::const_iterator it = all_flags.begin();
it != all_flags.end();
......@@ -504,16 +512,16 @@ static void TryFindModuleAndPackageDir(
// Can't specialize template type on a locally defined type. Silly C++...
struct DisplayInfoGroup {
string header;
string footer;
const char* header;
const char* footer;
set<const CommandLineFlagInfo *> *group;
int SizeInLines() const {
int size_in_lines = static_cast<int>(group->size()) + 1;
if (!header.empty()) {
if (strlen(header) > 0) {
size_in_lines++;
}
if (!footer.empty()) {
if (strlen(footer) > 0) {
size_in_lines++;
}
return size_in_lines;
......@@ -545,7 +553,7 @@ static void FinalizeCompletionOutput(
!notable_flags->perfect_match_flag.empty()) {
perfect_match_found = true;
DisplayInfoGroup group =
{ string(),
{ "",
"==========",
&notable_flags->perfect_match_flag };
lines_so_far += group.SizeInLines();
......@@ -594,7 +602,7 @@ static void FinalizeCompletionOutput(
if (!obscure_flags.empty()) {
DisplayInfoGroup group = {
"-* Other flags *-",
string(),
"",
&obscure_flags };
lines_so_far += group.SizeInLines();
output_groups.push_back(group);
......@@ -613,8 +621,8 @@ static void FinalizeCompletionOutput(
OutputSingleGroupWithLimit(
*it->group, // group
string(indent, ' '), // line indentation
it->header, // header
it->footer, // footer
string(it->header), // header
string(it->footer), // footer
perfect_match_found, // long format
&remaining_lines, // line limit - reduces this by number printed
&completions_output, // completions (not lines) added
......@@ -650,7 +658,7 @@ static void RetrieveUnusedFlags(
}
}
// 5) Output matches (and helpfer methods)
// 5) Output matches (and helper methods)
static void OutputSingleGroupWithLimit(
const set<const CommandLineFlagInfo *> &group,
......
......@@ -111,7 +111,9 @@ params="$params --tab_completion_word \"$completion_word\""
# If we think we have a reasonable command to execute, then execute it
# and hope for the best.
if [ -f "$binary" ] && [ -x "$binary" ]; then
candidate=$(type -p "$binary")
if [ ! -z "$candidate" ]; then
eval "$candidate 2>/dev/null $params"
elif [ -f "$binary" ] && [ -x "$binary" ]; then
eval "$binary 2>/dev/null $params"
fi
......@@ -192,18 +192,29 @@ static string XMLText(const string& txt) {
return ans;
}
static void AddXMLTag(string* r, const char* tag, const string& txt) {
*r += ('<');
*r += (tag);
*r += ('>');
*r += (XMLText(txt));
*r += ("</");
*r += (tag);
*r += ('>');
}
static string DescribeOneFlagInXML(const CommandLineFlagInfo& flag) {
// The file and flagname could have been attributes, but default
// and meaning need to avoid attribute normalization. This way it
// can be parsed by simple programs, in addition to xml parsers.
return (string("<flag>") +
"<file>" + XMLText(flag.filename) + "</file>" +
"<name>" + XMLText(flag.name) + "</name>" +
"<meaning>" + XMLText(flag.description) + "</meaning>" +
"<default>" + XMLText(flag.default_value) + "</default>" +
"<current>" + XMLText(flag.current_value) + "</current>" +
"<type>" + XMLText(flag.type) + "</type>" +
string("</flag>"));
string r("<flag>");
AddXMLTag(&r, "file", flag.filename);
AddXMLTag(&r, "name", flag.name);
AddXMLTag(&r, "meaning", flag.description);
AddXMLTag(&r, "default", flag.default_value);
AddXMLTag(&r, "current", flag.current_value);
AddXMLTag(&r, "type", flag.type);
r += "</flag>";
return r;
}
// --------------------------------------------------------------------
......@@ -342,6 +353,15 @@ static void ShowVersion() {
# endif
}
static void AppendPrognameStrings(vector<string>* substrings,
const char* progname) {
string r("/");
r += progname;
substrings->push_back(r + ".");
substrings->push_back(r + "-main.");
substrings->push_back(r + "_main.");
}
// --------------------------------------------------------------------
// HandleCommandLineHelpFlags()
// Checks all the 'reporting' commandline flags to see if any
......@@ -356,13 +376,12 @@ void HandleCommandLineHelpFlags() {
HandleCommandLineCompletions();
vector<string> substrings;
AppendPrognameStrings(&substrings, progname);
if (FLAGS_helpshort) {
// show only flags related to this binary:
// E.g. for fileutil.cc, want flags containing ... "/fileutil." cc
vector<string> substrings;
substrings.push_back(string("/") + progname + ".");
substrings.push_back(string("/") + progname + "-main.");
substrings.push_back(string("/") + progname + "_main.");
ShowUsageWithFlagsMatching(progname, substrings);
commandlineflags_exitfunc(1); // almost certainly exit()
......@@ -388,10 +407,6 @@ void HandleCommandLineHelpFlags() {
// filename like "/progname.cc", and take the dirname of that.
vector<CommandLineFlagInfo> flags;
GetAllFlags(&flags);
vector<string> substrings;
substrings.push_back(string("/") + progname + ".");
substrings.push_back(string("/") + progname + "-main.");
substrings.push_back(string("/") + progname + "_main.");
string last_package;
for (vector<CommandLineFlagInfo>::const_iterator flag = flags.begin();
flag != flags.end();
......
......@@ -181,6 +181,8 @@ Expect $LINENO 0 "gflags_unittest" "gflags_unittest.cc" --version
# --undefok is a fun flag...
Expect $LINENO 1 "unknown command line flag 'foo'" "" --undefok= --foo --unused_bool
Expect $LINENO 0 "PASS" "" --undefok=foo --foo --unused_bool
# If you say foo is ok to be undefined, we'll accept --nofoo as well
Expect $LINENO 0 "PASS" "" --undefok=foo --nofoo --unused_bool
# It's ok if the foo is in the middle
Expect $LINENO 0 "PASS" "" --undefok=fee,fi,foo,fum --foo --unused_bool
# But the spelling has to be just right...
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment