pax_global_header 0000666 0000000 0000000 00000000064 13613276011 0014512 g ustar 00root root 0000000 0000000 52 comment=4d3b72d86d3ec47b52c5d4c03e0d9f17b7f4c8ca
Bear-2.4.3/ 0000775 0000000 0000000 00000000000 13613276011 0012371 5 ustar 00root root 0000000 0000000 Bear-2.4.3/.github/ 0000775 0000000 0000000 00000000000 13613276011 0013731 5 ustar 00root root 0000000 0000000 Bear-2.4.3/.github/CONTRIBUTING.md 0000664 0000000 0000000 00000002527 13613276011 0016170 0 ustar 00root root 0000000 0000000 # How to contribute
Thank you for taking the time to contribute!
## Reporting bug
- Please read the documentation, maybe it's a limitation, a known issue of that release. This might also help to clear false expectation from the tool itself, or help you to classify you request not as a bug, but maybe an enhancement.
- Ensure that the bug was not already reported by searching on GitHub under Issues.
- If you have not found an open issue addressing the problem, open a new one. Be sure to include a title and clear description, with as much relevant information as possible. You might also attach the output of the tool, this case try to run it with verbose flags.
- For more detailed information on submitting a bug report and creating an issue, visit our reporting guidelines.
## Suggesting enhancements
- Enhancement suggestions are tracked as GitHub issues.
- Use a clear and descriptive title for the issue to identify the suggestion.
- Describe the current behavior and explain which behavior you expected to see instead and why.
## Pull Requests
- Open a new GitHub pull request with the patch.
- Ensure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable.
- Think about testability. Please write test(s) for the problem you have fixed. Make sure that existing test are not get broken.
Bear-2.4.3/.github/FUNDING.yml 0000664 0000000 0000000 00000000023 13613276011 0015541 0 ustar 00root root 0000000 0000000 github: [rizsotto]
Bear-2.4.3/.github/ISSUE_TEMPLATE/ 0000775 0000000 0000000 00000000000 13613276011 0016114 5 ustar 00root root 0000000 0000000 Bear-2.4.3/.github/ISSUE_TEMPLATE/bug_report.md 0000664 0000000 0000000 00000002370 13613276011 0020610 0 ustar 00root root 0000000 0000000 ---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''
---
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
**Expected behavior**
A clear and concise description of what you expected to happen.
**Environment:**
- OS name: [e.g. linux] run `uname -s`
- OS version: [e.g. CentOS 7.6]
- OS architecture: [e.g. x86_64] run `uname -m`
- Bear version: [e.g. 2.4.0]
- Bear install method: [e.g. from package]
**Additional context**
- Can you give us a reference to the project that you are running against this tool? [e.g. No if it's a close source project, but in case of an open source project a link to the sources could be nice.]
- What build tools this project is using? [e.g. GNU make]
- What architecture you are trying to compile for? [e.g. cross compiling]
- Could you attach build logs? If you can re-run the command which failed (e.g. `bear make`) with extra verbose log switches (e.g. `bear -vvvv make`) and send the output of it, that would help a lot.
**Before you send...**
- Have you read the `README.md` file or `man bear`?
- Have you looked what other open issues Bear has?
- Are you sure that the build works without Bear?
Bear-2.4.3/.gitignore 0000664 0000000 0000000 00000000072 13613276011 0014360 0 ustar 00root root 0000000 0000000 .idea/
cmake-build*/
Output/
Cargo.lock
target/
.DS_Store
Bear-2.4.3/.travis.yml 0000664 0000000 0000000 00000002211 13613276011 0014476 0 ustar 00root root 0000000 0000000 language: python
matrix:
include:
- os: linux
sudo: false
dist: xenial
python: "pypy"
- os: linux
sudo: required
dist: xenial
python: 2.7
- os: linux
sudo: false
dist: xenial
python: 3.6
- os: linux
sudo: false
dist: xenial
python: 3.7
- os: osx
osx_image: xcode7.3
language: generic
- os: osx
osx_image: xcode8
language: generic
addons:
apt:
packages:
- cmake
- scons
- gfortran
- qt4-qmake
- nvidia-cuda-toolkit
before_install:
- uname
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
csrutil status || true;
brew update;
brew install scons;
fi
install:
- pip --version
- pip install --upgrade pip
- pip install lit pycodestyle
script:
- mkdir "$HOME/build"; cd "$HOME/build"
- cmake "$TRAVIS_BUILD_DIR" -DCPACK_GENERATOR="TGZ"
- VERBOSE=1 make all
- VERBOSE=1 make check
- VERBOSE=1 make package
- if [ "$TRAVIS_SUDO" == "true" ]; then
sudo make install;
(cd "$TRAVIS_BUILD_DIR"; git clean -fdx;);
lit -v "$TRAVIS_BUILD_DIR/test";
fi
Bear-2.4.3/CMakeLists.txt 0000664 0000000 0000000 00000003454 13613276011 0015137 0 ustar 00root root 0000000 0000000 cmake_minimum_required(VERSION 2.8)
project(bear C)
set(BEAR_VERSION "2.4.3")
include(GNUInstallDirs)
install(FILES COPYING README.md ChangeLog.md
DESTINATION ${CMAKE_INSTALL_DOCDIR})
include(CheckCCompilerFlag)
check_c_compiler_flag("-std=c99" C99_SUPPORTED)
if (C99_SUPPORTED)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
endif()
add_definitions(-D_GNU_SOURCE)
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
set(CMAKE_OSX_ARCHITECTURES "i386;x86_64" CACHE STRING "Rogue")
set(EAR_LIB_FILE ${CMAKE_SHARED_LIBRARY_PREFIX}ear${CMAKE_SHARED_LIBRARY_SUFFIX})
set(EAR_LIB_PATH "${CMAKE_INSTALL_LIBDIR}/bear")
set(DEFAULT_PRELOAD_FILE ${CMAKE_INSTALL_PREFIX}/${EAR_LIB_PATH}/${EAR_LIB_FILE} CACHE STRING "Default path to libear.")
add_subdirectory(libear)
add_subdirectory(bear)
add_subdirectory(test)
add_subdirectory(man)
add_subdirectory(shell-completion)
set(CPACK_PACKAGE_NAME "bear")
set(CPACK_PACKAGE_CONTACT "László Nagy")
set(CPACK_PACKAGE_VENDOR ${CPACK_PACKAGE_CONTACT})
set(CPACK_PACKAGE_VERSION ${BEAR_VERSION})
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "BuildEAR")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
set(CPACK_RPM_PACKAGE_RELEASE "1%{?dist}")
set(CPACK_RPM_PACKAGE_LICENSE "GPLv3")
set(CPACK_RPM_PACKAGE_GROUP "Development/Tools")
set(CPACK_RPM_PACKAGE_URL "http://github.com/rizsotto/Bear")
set(CPACK_RPM_PACKAGE_DESCRIPTION "Bear is a tool to generate compilation database for clang tooling.")
set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION
"${CMAKE_INSTALL_MANDIR}"
"${CMAKE_INSTALL_MANDIR}/man1")
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
include(CPack)
Bear-2.4.3/COPYING 0000664 0000000 0000000 00000104513 13613276011 0013430 0 ustar 00root root 0000000 0000000 GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Copyright (C)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
.
Bear-2.4.3/ChangeLog.md 0000664 0000000 0000000 00000021262 13613276011 0014545 0 ustar 00root root 0000000 0000000 ## 2.4.3 (2020-01-26)
Features:
- Support CUDA compilations (@nweston, #275, #277, #278)
- Better duplicate entry detection (#278)
## 2.4.2 (2019.08.29)
Features:
- Support `output` field in the output. (#254, @bofeng17)
- Support Fortran compiler (#201, #241, #253, @rubyzhou2014, @chunhualiao)
- Support filter options (#261, #252, @liugang)
Bugfixes:
- Fix Cpack problem to create RPM. (#191, @antmak, @reverendhomer)
## 2.4.1 (2019.07.30)
Features:
- Add bash completion (#231, @1ace)
Bugfixes:
- Fix limitation section in readme (#256, @Manouchehri)
- Fix preprocessor flags (#239, @bdemick)
## 2.4.0 (2019.05.12)
Features:
- `libear.so` write binary file instead of JSON.
Bugfixes:
- Fix `newlocale` problem (#182, #190, @timblaktu, @3v1n0, @caohaiming, @rbresalier)
- Fix long command line problem (#246, @jmodares)
- Fix help text for parameter `--use-only` (#245, @koutheir)
## 2.3.13 (2018.08.30)
Bugfixes:
- Fix bug introduced in 2.3.12 to fix #211 (#221, @markuspohjoismaki)
## 2.3.12 (2018.08.06)
Bugfixes:
- Accept compiler name version without hyphen separator (#216, @Jehops)
- Keep original compiler name (#211, @TomMD)
- Readme file updates on known issues (#208, @matanster)
- Filter extra compilation if requested (#218, @jkbbwr)
## 2.3.11 (2018.01.04)
Bugfixes:
- Fix CPack RPM problems on CentOS7 (@antmak, #191, #192)
- Change `libear.so` location to `$LIBDIR/bear` to avoid direct linking. (@morxa, #189)
## 2.3.10 (2017.12.07)
Bugfixes:
- Fix MPI wrapper problem (@ffevotte, #193)
- Not crash on invalid execution trace file (@dengste, #195)
## 2.3.9 (2017.10.25)
Bugfixes:
- Fix newlocale problem (@bartlibert, #182)
## 2.3.8 (2017.10.16)
Bugfixes:
- Fix compilation issue against libc 2.26 (@ffuugoo, #176)
## 2.3.7 (2017.10.07)
Features:
- Support OpenMPI compiler wrapper
Bugfixes:
- Fix multithreading build tools problem. (@TTimo, #173)
## 2.3.6 (2017.07.02)
Bugfixes:
- Fix assert when `--append` mode the file is missing for that entry.
## 2.3.5 (2017.05.31)
Bugfixes:
- Fix 0 length argument bug (@jaelsasser, @nickdesaulniers, #160, #161, #163, #164)
## 2.3.4 (2017.04.25)
Bugfixes:
- Include assembly language file extensions (@RichardsonAlex, @bstaletic, #146)
## 2.3.3 (2017.04.25)
Bugfixes:
- Fix crashes caused by unicode command execution (@cgull, #141, @knowack1, #154)
## 2.3.2 (2017.04.24)
Bugfixes:
- Make Bear work with 32-bit and 64-bit toolchains (@deb0ch, @andrey-desman, @nolange, #134)
## 2.3.1 (2017.04.22)
Bugfixes:
- Fix problem with `make install` (@ilovezfs, #153)
## 2.3.0 (2017.04.20)
Features:
- Rewrite functional test on LLVM `lit`.
- Write intermediate execution report in JSON format.
- Write compilation database with "arguments" instead of "command".
- Write compilation database with relative paths.
Bugfixes:
- Compiler name can be specified as argument (@JakeFederico, #142)
- Update documentation about OSX SIP workaround (@isotes, #152)
## 2.2.1 (2016.10.15)
Bugfixes:
- Fix spelling mistakes in man page (@sebastinas, #128)
- Fix support multiple compilers (@handrake0724, #136)
Features:
- Finish writing output when the build was interupted by user.
- Travis-CI runs build against OSX machines
## 2.2.0 (2016.06.05)
Bugfixes:
- Fix spelling mistakes in README file (@sebastinas, #116)
- Fix shell escaping to work with arguments which has space (@timangus, #124)
## 2.1.5 (2016.02.16)
Bugfixes:
- Stop filtering out `-m` options (@joshtriplett, #115)
- Updated man page bugs section (#114)
## 2.1.4 (2016.02.14)
Bugfixes:
- Make paths to sources and include files absolute. (@svenpanne, #111)
- Extend known issues section of documentation (#112, #108, #105, #102)
## 2.1.3 (2016.01.13)
Bugfixes:
- warnings are not filtered from output (@velkyel, #106)
- support universal binaries (32 and 64) on x86 OS X (@DeanoC, #101)
## 2.1.2 (2015.10.01)
Bugfixes:
- Fix escaping quotes for shell too. (@zauguin, #88)
## 2.1.1 (2015.08.31)
Bugfixes:
- Fix iterator next method usage (@drvink, #97)
## 2.1.0 (2015.08.08)
Features:
- Ignore preprocessor flags for dependency generation (@jonthn, #74)
- Exclude irrelevant files names in command (@wweic, #94)
- Support MetaWare toolkit (@twpedersen, #95)
- Use docker build for travis-ci
Bugfixes:
- Get rid of cmake warnings on osx (@emlai, #90)
- Protect report generation in multithread build systems (@smoofra, #93)
## 2.0.4 (2015-06-16)
Bugfixes:
- Fix crash when `make -j` runs parallel (@minhyuk, #87)
## 2.0.3 (2015-04-04)
Bugfixes:
- Fix passing of arguments to `mkdtemp` (@kljohann, #75)
- Empty output when compiler used to link. (@QuaziRandom, #80)
- Bad escape of strings in compilation database. (@jumapico, #81)
## 2.0.2 (2015-02-08)
Bugfixes:
- Address Sanitizer error fixed.
- Fix some typos in man page (@sebastinas, #72)
## 2.0.1 (2015-01-23)
Bugfixes:
- Double free problem fixed when descrutor called multiple times.
## 2.0 (2015-01-20)
Features:
- Rewrite command `bear` from C to Python.
- Simplified build process with a single module for `libear`.
Bugfixes:
- Work with empty environment (#69, @YorkZ)
- Filter out redundant entries (#66, @HongxuChen)
- Append to existing compilation database (#63, @p0rnfl4k3s)
## 1.4.4 (2015-01-09)
Features:
- Improve escaping logic (#67, #68, @SpecLad)
- Reword README file to be more english (#64, @libnoon)
## 1.4.3 (2014-07-11)
Features:
- Automatically generate Debian package dependency list with cpack (#62, @bbannier)
## 1.4.2 (2014-05-19)
Features:
- cross compilers recognised by bear (@nolange)
## 1.4.1 (2014-05-09)
Bugfixes:
- fix output entries have c14n file path (#61, @nickhutchinson)
- fix error message on missing config file (#60, @viraptor)
- extend README file based on user feedbacks (#54, #55, #56, #59, @btorpey, @breser, @vguerra)
## 1.4 (2014-01-12)
Bugfixes:
- fix typo in the README.md (#48, @breser)
- fix typo in the man page (#49, @sebastinas)
- fix cmake file to honor given `CFLAGS` (#50, @sebastinas)
- fix execle causes segfault on 32 bit systems (#51, #52, @breser, @sebastinas)
## 1.3 (2013-12-18)
Features:
- set empty cancel parameter list as default (#39, #43)
- implement verbose filter message at the end of the run (#41)
Bugfixes:
- fix process stops when ctrl-z pressed (#40, @bbannier)
- fix non filtered output option renamed from debug (#44, @mikemccracken)
- fix broken build on OS X (#46, @breser)
- fix documentation (@mlq)
- fix `posix_spawn*` call not implemented (#43, @agentsim, @apoluektov)
## 1.2 (2013-10-01)
Features:
- dependency file generation compiler calls are _optionally_ filtered (#35, @lonico)
- use config file for compiler call filtering parameters (#38, @lonico, @peti)
Bugfixes:
- fix end-to-end test on OS X (#37, @smmckay)
- fix memory leaks detected by static analyser
## 1.1 (2013-08-01)
Features:
- dependency file generation compiler calls `-M` are filtered (#35, @chrta)
- smaller memory footprint (less allocation, code went for places when it is called)
- add version query to command line
Bugfixes:
- fix memory leaks detected by static analyser
## 1.0 (2013-06-27)
Features:
- change license to GPLv3
Bugfixes:
- fix process synchronization problem (#33, @blowback)
- fix `malloc`, `realloc` usage (#34, @mlq)
## 0.5 (2013-06-09)
Features:
- use temporary directory for default socket (#29, @sebastinas)
Bugfixes:
- fix bashism in test (#27, @sebastinas)
- fix temporary socket dir problem introduce by new code (#31, @lukedirtwalker)
- fix bug introduced by report filtering (#32, @lukedirtwalker)
## 0.4 (2013-04-26)
Features:
- man page generation is optional (#18, @Sarcasm)
- port to OS X (#24, @breser)
Bugfixes:
- fix JSON output on whitespaces (#19)
- fix socket reading problem (#20, @brucestephens)
- improved signal handling (#21)
- build system checks for available `exec` functions (#22)
## 0.3 (2013-01-09)
Features:
- query known compilers which are play roles in filtering (#10)
- query recognised source file extensions which are filtering (#11)
- man page added (#12)
- pacage generation target added to `cmake` (#15)
Bugfixes:
- fix child process termination problem
- test added: build result propagation check
## 0.2 (2013-01-01)
Features:
- add debug output
Bugfixes:
- test added: unit test, end-to-end test and full `exec` family coverage (#4)
- `scons` does pass empty environment to child processes (#9)
- fix `execle` overriding bug (#13)
- fix JSON output (#14)
## 0.1 (2012-11-17)
Features:
- first working version
- [Travis CI](https://travis-ci.org/rizsotto/Bear) hook set up
Bear-2.4.3/README.md 0000664 0000000 0000000 00000017111 13613276011 0013651 0 ustar 00root root 0000000 0000000 [](https://repology.org/project/bear/versions)
[](https://github.com/rizsotto/Bear/releases)
[](https://github.com/rizsotto/Bear/releases)
[](https://travis-ci.org/rizsotto/bear/branches)
[](https://github.com/rizsotto/Bear/graphs/contributors)
[](https://gitter.im/rizsotto/Bear)
Build EAR (BEAR)
================
Bear is a tool that generates a compilation database for clang tooling.
The [JSON compilation database][JSONCDB] is used in the clang project
to provide information on how a single compilation unit is processed.
With this, it is easy to re-run the compilation with alternate
programs.
One way to get a compilation database is to use `cmake` as the build
tool. Passing `-DCMAKE_EXPORT_COMPILE_COMMANDS=ON` to cmake generates
the `compile_commands.json` file into the current directory.
For non-cmake projects, Bear generates the JSON file during the build process.
The concept behind Bear is: to execute the original build command and
intercept the `exec` calls issued by the build tool. To achieve that,
Bear uses the `LD_PRELOAD` or `DYLD_INSERT_LIBRARIES` mechanisms provided
by the dynamic linker.
Bear has two components: the library and the binary. The library
redefines the `exec` methods to be used by all child processes. The
executable enables the use of the library for child processes and
writes the output file.
[JSONCDB]: http://clang.llvm.org/docs/JSONCompilationDatabase.html
How to install
--------------
Bear is packaged for many distributions. Check out your package manager.
Or build it from source.
How to build
------------
Bear should be quite portable on UNIX operating systems. It has been
tested on FreeBSD, GNU/Linux and OS X.
### Prerequisites
1. an ANSI **C compiler**, to compile the sources.
2. **cmake**, to configure the build process.
3. **make**, to run the build. The makefiles are generated by `cmake`.
4. **python** is a runtime dependency. The `bear` command is written in
Python. (version >= 2.7)
5. **lit** is an optional dependency to run the functional tests
### Build commands
Ideally, you should build Bear in a separate build directory.
cmake $BEAR_SOURCE_DIR
make all
make install # to install
make check # to run tests
make package # to make packages
You can configure the build process with passing arguments to cmake.
How to use
----------
After installation the usage is like this:
bear
The output file called `compile_commands.json` is saved in the current directory.
For more options you can check the man page or pass `--help` parameter.
Side note: Since `bear` is executing the build command only those commands
will be recorded which were actually executed. Which means if you have already
built your project and you re-run the build command with Bear you probably end
up to have an empty output. (Practically it means you need to run `make clean`
before you run `bear make`.)
Known issues
------------
### Environment overriding caused problems
Because Bear uses `LD_PRELOAD` or `DYLD_INSERT_LIBRARIES` environment variables,
it does not append to it, but overrides it. So builds which are using these
variables might not work. (I don't know any build tool which does that, but
please let me know if you do.)
### Build with multiple architecture support
Multilib is one of the solutions allowing users to run applications built
for various application binary interfaces (ABIs) of the same architecture.
The most common use of multilib is to run 32-bit applications on 64-bit
kernel.
For OSX this is not an issue. The build commands from previous section will
work, Bear will intercept compiler calls for 32-bit and 64-bit applications.
For Linux, a small tune is needed at build time. Need to compile `libear.so`
library for 32-bit and for 64-bit too. Then install these libraries to the OS
preferred multilib directories. And replace the `libear.so` path default
value with a single path, which matches both. (The match can be achieved by
the `$LIB` token expansion from the dynamic loader. See `man ld.so` for more.)
Debian derivatives are using `lib/i386-linux-gnu` and `lib/x86_64-linux-gnu`,
while many other distributions are simple `lib` and `lib64`. Here comes an
example build script to install a multilib capable Bear. It will install Bear
under `/opt/bear` on a non Debian system.
(cd ~/build32; cmake "$BEAR_SOURCE_DIR" -DCMAKE_C_COMPILER_ARG1="-m32"; VERBOSE=1 make all;)
(cd ~/build64; cmake "$BEAR_SOURCE_DIR" -DCMAKE_C_COMPILER_ARG1="-m64" -DDEFAULT_PRELOAD_FILE='/opt/bear/$LIB/libear.so'; VERBOSE=1 make all;)
sudo install -m 0644 ~/build32/libear/libear.so /opt/bear/lib/libear.so
sudo install -m 0644 ~/build64/libear/libear.so /opt/bear/lib64/libear.so
sudo install -m 0555 ~/build64/bear/bear" /opt/bear/bin/bear
To check you installation, install `lit` and run the test suite.
PATH=/opt/bear/bin:$PATH lit -v test
PATH=/opt/bear/bin:$PATH lit -v test -DMULTILIB=true
### Empty compilation database on OS X / macOS or Fedora
Security extension/modes on different operating systems might disable library
preloads. In this case Bear behaves normally, but the result compilation database
will be empty. (Please make sure it's not the case when reporting bugs.)
Notable examples for enabled security modes are: OS X 10.11 (check with
`csrutil status | grep 'System Integrity Protection'`), and Fedora, CentOS, RHEL
(check with `sestatus | grep 'SELinux status'`).
Workaround could be to disable the security feature while running Bear. (This
might involve reboot of your computer, so might be heavy workaround.) Another
option if the build tool is not installed under [certain][osx_sip] directories.
Or use tools which are using compiler wrappers. (It injects a fake compiler
which does record the compiler invocation and calls the real compiler too.)
An example for such tool might be [scan-build][scanbuild]. The build system
shall respect `CC` and `CXX` environment variables.
[osx_sip]: https://support.apple.com/en-us/HT204899
[scanbuild]: https://github.com/rizsotto/scan-build
### Bazel builds produce empty outputs
The two main constraints to intercept compiler execution from bazel builds are:
bazel runs a daemon which runs the compilations, and it creates an isolated
environment to run the compiler. These problems are not just hard to circumvent,
but the workaround would not be stable to support it by this tool.
The good news is: there are extensions for bazel to generate the compilation
database.
### Static build tool produce empty output
Currently Bear based on dynamic linker load mechanism, executions made by
statically linked binaries are not captured. It means, if the build tool is
statically linked binary, compiler calls won't be recorded by Bear.
Problem reports
---------------
If you find a bug in this documentation or elsewhere in the program or would
like to propose an improvement, please use the project's [github issue
tracker][ISSUES]. Please describing the bug and where you found it. If you
have a suggestion how to fix it, include that as well. Patches are also
welcome.
Please follow the [contribution guide][GUIDE] when you do this.
[ISSUES]: https://github.com/rizsotto/Bear/issues
[GUIDE]: https://github.com/rizsotto/Bear/blob/master/.github/CONTRIBUTING.md
Bear-2.4.3/bear/ 0000775 0000000 0000000 00000000000 13613276011 0013302 5 ustar 00root root 0000000 0000000 Bear-2.4.3/bear/CMakeLists.txt 0000664 0000000 0000000 00000000610 13613276011 0016037 0 ustar 00root root 0000000 0000000 include(FindPythonInterp)
if (PYTHONINTERP_FOUND)
set(BEAR_PYTHON_EXECUTABLE "python${PYTHON_VERSION_MAJOR}")
else()
message(FATAL_ERROR "Have not found python interpreter")
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/bear.py ${CMAKE_CURRENT_BINARY_DIR}/bear)
include(GNUInstallDirs)
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/bear
DESTINATION ${CMAKE_INSTALL_BINDIR})
Bear-2.4.3/bear/bear.py 0000664 0000000 0000000 00000077045 13613276011 0014602 0 ustar 00root root 0000000 0000000 #!/usr/bin/env @BEAR_PYTHON_EXECUTABLE@
# -*- coding: utf-8 -*-
# Copyright (C) 2012-2019 by László Nagy
# This file is part of Bear.
#
# Bear is a tool to generate compilation database for clang tooling.
#
# Bear is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Bear is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
""" This module is responsible to capture the compiler invocation of any
build process. The result of that should be a compilation database.
This implementation is using the LD_PRELOAD or DYLD_INSERT_LIBRARIES
mechanisms provided by the dynamic linker. The related library is implemented
in C language and can be found under 'libear' directory.
The 'libear' library is capturing all child process creation and logging the
relevant information about it into separate files in a specified directory.
The input of the library is therefore the output directory which is passed
as an environment variable.
This module implements the build command execution with the 'libear' library
and the post-processing of the output files, which will condensates into a
(might be empty) compilation database. """
import argparse
import collections
import subprocess
import json
import sys
import functools
import os
import os.path
import re
import shlex
import itertools
import tempfile
import shutil
import struct
import contextlib
import logging
# Map of ignored compiler option for the creation of a compilation database.
# This map is used in _split_command method, which classifies the parameters
# and ignores the selected ones. Please note that other parameters might be
# ignored as well.
#
# Option names are mapped to the number of following arguments which should
# be skipped.
IGNORED_FLAGS = {
# preprocessor macros, ignored because would cause duplicate entries in
# the output (the only difference would be these flags). this is actual
# finding from users, who suffered longer execution time caused by the
# duplicates.
'-MD': 0,
'-MMD': 0,
'-MG': 0,
'-MP': 0,
'-MF': 1,
'-MT': 1,
'-MQ': 1,
# linker options, ignored because for compilation database will contain
# compilation commands only. so, the compiler would ignore these flags
# anyway. the benefit to get rid of them is to make the output more
# readable.
'-static': 0,
'-shared': 0,
'-s': 0,
'-rdynamic': 0,
'-l': 1,
'-L': 1,
'-u': 1,
'-z': 1,
'-T': 1,
'-Xlinker': 1,
# clang-cl / msvc cl specific flags
# consider moving visual studio specific warning flags also
'-nologo': 0,
'-EHsc': 0,
'-EHa': 0
} # type: Dict[str, int]
# Known C/C++ compiler wrapper name patterns.
COMPILER_PATTERN_WRAPPER = re.compile(r'^(distcc|ccache)$')
# Known MPI compiler wrapper name patterns.
COMPILER_PATTERNS_MPI_WRAPPER = re.compile(
r'^mpi(cc|cxx|CC|c\+\+|fort|f77|f90)$')
# Known C compiler executable name patterns.
COMPILER_PATTERNS_CC = (
re.compile(r'^([^-]*-)*[mg]cc(-?\d+(\.\d+){0,2})?$'),
re.compile(r'^([^-]*-)*clang(-\d+(\.\d+){0,2})?$'),
re.compile(r'^(|i)cc$'),
re.compile(r'^(g|)xlc$'),
)
# Known C++ compiler executable name patterns.
COMPILER_PATTERNS_CXX = (
re.compile(r'^(c\+\+|cxx|CC)$'),
re.compile(r'^([^-]*-)*[mg]\+\+(-?\d+(\.\d+){0,2})?$'),
re.compile(r'^([^-]*-)*clang\+\+(-\d+(\.\d+){0,2})?$'),
re.compile(r'^icpc$'),
re.compile(r'^nvcc$'),
re.compile(r'^(g|)xl(C|c\+\+)$'),
)
# Known Fortran compiler executable name patterns
# Gfortran, Intel Fortran Compilers, PGI compilers
COMPILER_PATTERNS_FORTRAN = (
re.compile(r'^(f95)$'),
re.compile(r'^(gfortran)$'),
re.compile(r'^(ifort)$'),
re.compile(r'^(pg)(f77|f90|f95|fortran)$')
)
TRACE_FILE_PREFIX = 'execution.' # same as in ear.c
C_LANG, CPLUSPLUS_LANG, FORTRAN_LANG, OTHER = range(4)
Execution = collections.namedtuple('Execution', ['cwd', 'cmd'])
CompilationCommand = collections.namedtuple(
'CompilationCommand',
['compiler', 'language', 'phase', 'flags', 'files', 'output'])
class Tools:
def __init__(self, only_use, c_compilers, cxx_compilers,
fortran_compilers):
self.ignore = only_use
self.c_compilers = [os.path.basename(cc) for cc in c_compilers]
self.cxx_compilers = [os.path.basename(cc) for cc in cxx_compilers]
self.fortran_compilers = [
os.path.basename(cc) for cc in fortran_compilers]
@classmethod
def is_wrapper(cls, cmd):
# type: (Type[Tools], str) -> bool
return True if COMPILER_PATTERN_WRAPPER.match(cmd) else False
@classmethod
def is_mpi_wrapper(cls, cmd):
# type: (Type[Tools], str) -> bool
return True if COMPILER_PATTERNS_MPI_WRAPPER.match(cmd) else False
def is_c_compiler(self, cmd):
# type: (Tools, str) -> bool
use_match = Tools._is_sting_match(cmd, self.c_compilers)
pattern_match = Tools._is_pattern_match(cmd, COMPILER_PATTERNS_CC)
return use_match if self.ignore else (use_match or pattern_match)
def is_cxx_compiler(self, cmd):
# type: (Tools, str) -> bool
use_match = Tools._is_sting_match(cmd, self.cxx_compilers)
pattern_match = Tools._is_pattern_match(cmd, COMPILER_PATTERNS_CXX)
return use_match if self.ignore else (use_match or pattern_match)
def is_fortran_compiler(self, cmd):
# type: (Tools, str) -> bool
use_match = Tools._is_sting_match(cmd, self.fortran_compilers)
pattern_match = Tools._is_pattern_match(
cmd, COMPILER_PATTERNS_FORTRAN)
return use_match if self.ignore else (use_match or pattern_match)
@classmethod
def _is_sting_match(cls, candidate, compilers):
# type (Type[Tools], str, Iterable[str) -> bool
return any((candidate == compiler) for compiler in compilers)
@classmethod
def _is_pattern_match(cls, candidate, patterns):
return any(pattern.match(candidate) for pattern in patterns)
def shell_split(string):
# type: (str) -> List[str]
""" Takes a command string and returns as a list. """
def unescape(arg):
# type: (str) -> str
""" Gets rid of the escaping characters. """
if len(arg) >= 2 and arg[0] == arg[-1] and arg[0] == '"':
return re.sub(r'\\(["\\])', r'\1', arg[1:-1])
return re.sub(r'\\([\\ $%&\(\)\[\]\{\}\*|<>@?!])', r'\1', arg)
return [unescape(token) for token in shlex.split(string)]
def run_build(command, *args, **kwargs):
# type: (...) -> int
""" Run and report build command execution
:param command: list of tokens
:return: exit code of the process
"""
environment = kwargs.get('env', os.environ)
logging.debug('run build %s, in environment: %s', command, environment)
exit_code = subprocess.call(command, *args, **kwargs)
logging.debug('build finished with exit code: %d', exit_code)
return exit_code
def run_command(command, cwd=None):
# type: (List[str], str) -> List[str]
""" Run a given command and report the execution.
:param command: array of tokens
:param cwd: the working directory where the command will be executed
:return: output of the command
"""
def decode_when_needed(result):
# type: (Any) -> str
""" check_output returns bytes or string depend on python version """
if not isinstance(result, str):
return result.decode('utf-8')
return result
try:
directory = os.path.abspath(cwd) if cwd else os.getcwd()
logging.debug('exec command %s in %s', command, directory)
output = subprocess.check_output(command,
cwd=directory,
stderr=subprocess.STDOUT)
return decode_when_needed(output).splitlines()
except subprocess.CalledProcessError as ex:
ex.output = decode_when_needed(ex.output).splitlines()
raise ex
def reconfigure_logging(verbose_level):
""" Reconfigure logging level and format based on the verbose flag.
:param verbose_level: number of `-v` flags received by the command
:return: no return value
"""
# exit when nothing to do
if verbose_level == 0:
return
root = logging.getLogger()
# tune level
level = logging.WARNING - min(logging.WARNING, (10 * verbose_level))
root.setLevel(level)
# be verbose with messages
if verbose_level <= 3:
fmt_string = '%(name)s: %(levelname)s: %(message)s'
else:
fmt_string = '%(name)s: %(levelname)s: %(funcName)s: %(message)s'
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(logging.Formatter(fmt=fmt_string))
root.handlers = [handler]
def command_entry_point(function):
# type: (Callable[[], int]) -> Callable[[], int]
""" Decorator for command entry methods.
The decorator initialize/shutdown logging and guard on programming
errors (catch exceptions).
The decorated method can have arbitrary parameters, the return value will
be the exit code of the process. """
@functools.wraps(function)
def wrapper(*args, **kwargs):
""" Do housekeeping tasks and execute the wrapped method. """
try:
logging.basicConfig(format='%(name)s: %(message)s',
level=logging.WARNING,
stream=sys.stdout)
# this hack to get the executable name as %(name)
logging.getLogger().name = os.path.basename(sys.argv[0])
return function(*args, **kwargs)
except KeyboardInterrupt:
logging.warning('Keyboard interrupt')
return 130 # signal received exit code for bash
except (OSError, subprocess.CalledProcessError):
logging.exception('Internal error.')
if logging.getLogger().isEnabledFor(logging.DEBUG):
logging.error("Please report this bug and attach the output "
"to the bug report")
else:
logging.error("Please run this command again and turn on "
"verbose mode (add '-vvvv' as argument).")
return 64 # some non used exit code for internal errors
finally:
logging.shutdown()
return wrapper
@command_entry_point
def intercept_build():
# type: () -> int
""" Entry point for 'intercept-build' command. """
args = parse_args_for_intercept_build()
tools = Tools(args.use_only, args.use_cc,
args.use_cxx, args.use_fortran)
exit_code, current = capture(args, tools)
# To support incremental builds, it is desired to read elements from
# an existing compilation database from a previous run.
if args.append and os.path.isfile(args.cdb):
previous = CompilationDatabase.load(args.cdb, tools)
entries = iter(set(itertools.chain(previous, current)))
CompilationDatabase.save(entries, args.cdb, args.field_output)
else:
CompilationDatabase.save(current, args.cdb, args.field_output)
return exit_code
def capture(args, tools):
""" Implementation of compilation database generation.
:param args: the parsed and validated command line arguments
:param tools: helper object to detect compiler
:return: the exit status of build process. """
with temporary_directory(prefix='intercept-') as tmp_dir:
# run the build command
environment = setup_environment(args, tmp_dir)
exit_code = run_build(args.build, env=environment)
# read the intercepted exec calls
calls = (parse_exec_trace(file) for file in exec_trace_files(tmp_dir))
safe_calls = (x for x in calls if x is not None)
current = compilations(safe_calls, tools)
# filter out not desired entries
include_filter = include(args.include, args.exclude)
filtered = set(entry for entry in current if include_filter(entry))
return exit_code, iter(filtered)
def include(includes, excludes):
# type: (str, str) -> Callable[[Compilation], bool]
""" Create a predicate to filter out Compilation entries.
:param includes: list of directories to include.
:param excludes: list of directories to exclude.
:return: a predicate which returns true if the entry should be
in the final output based on the location of the source file. """
def make_absolute(directory):
# type: (str) -> str
""" Makes a path like object absolute (to the project root). """
if os.path.isabs(directory):
return directory
else:
return os.path.normpath(os.path.join(os.getcwd(), directory))
include_dirs = [make_absolute(directory) for directory in includes]
exclude_dirs = [make_absolute(directory) for directory in excludes]
def include_filter(candidate):
# type: (Compilation) -> bool
""" The predicate which returns true if the compilation should
be included in the final output. """
def contains(container, directory):
# type: (str, str) -> bool
""" Returns true if the container contains the directory. """
return os.path.commonprefix([container, directory]) == container
source = candidate.source
needed = True if len(include_dirs) == 0 else \
any(contains(directory, source) for directory in include_dirs)
rejected = False if len(exclude_dirs) == 0 else not \
all(not contains(directory, source) for directory in exclude_dirs)
return needed and not rejected
return include_filter
def compilations(exec_calls, tools):
# type: (Iterable[Execution], Tools) -> Iterable[Compilation]
""" Needs to filter out commands which are not compiler calls. And those
compiler calls shall be compilation (not pre-processing or linking) calls.
Plus needs to find the source file name from the arguments.
:param exec_calls: iterator of executions
:param tools: helper object to detect compiler
:return: stream of formatted compilation database entries """
for call in exec_calls:
for compilation in Compilation.iter_from_execution(call, tools):
yield compilation
def setup_environment(args, destination):
# type: (argparse.Namespace, str) -> Dict[str, str]
""" Sets up the environment for the build command.
In order to capture the sub-commands (executed by the build process),
it needs to prepare the environment. It's either the compiler wrappers
shall be announce as compiler or the intercepting library shall be
announced for the dynamic linker.
:param args: command line arguments
:param destination: directory path for the execution trace files
:return: a prepared set of environment variables. """
environment = dict(os.environ)
environment.update({'INTERCEPT_BUILD_TARGET_DIR': destination})
if sys.platform == 'darwin':
environment.update({
'DYLD_INSERT_LIBRARIES': args.libear,
'DYLD_FORCE_FLAT_NAMESPACE': '1'
})
else:
environment.update({'LD_PRELOAD': args.libear})
return environment
def parse_exec_trace(filename):
# type: (str) -> Optional[Execution]
""" Parse execution report file.
Given filename points to a file which contains the basic report
generated by the interception library or compiler wrapper.
:param filename: path to an execution trace file to read from,
:return: an Execution object. """
def byte_to_int(byte):
return struct.unpack_from("=I", byte)[0]
def parse_length(handler, expected_type):
type_bytes = handler.read(3)
if type_bytes != expected_type:
raise Exception("type not expected")
length_bytes = handler.read(4)
return byte_to_int(length_bytes)
def parse_string(handler):
length = parse_length(handler, b'str')
value_bytes = handler.read(length)
return value_bytes.decode("utf-8")
def parse_string_list(handler):
length = parse_length(handler, b'lst')
return [parse_string(handler) for _ in range(length)]
logging.debug('parse exec trace file: %s', filename)
with open(filename, 'rb', buffering=0) as handler:
try:
return Execution(cwd=parse_string(handler),
cmd=parse_string_list(handler))
except Exception as exception:
logging.warning('parse exec trace file: %s FAILED: %s',
filename, exception)
return None
def exec_trace_files(directory):
""" Generates exec trace file names.
:param directory: path to directory which contains the trace files.
:return: a generator of file names (absolute path). """
candidates = (os.path.join(directory, file)
for file in os.listdir(directory)
if file.startswith(TRACE_FILE_PREFIX))
return sorted((f for f in filter(os.path.isfile, candidates)),
key=os.path.getctime)
def parse_args_for_intercept_build():
""" Parse and validate command-line arguments for intercept-build. """
parser = create_intercept_parser()
args = parser.parse_args()
reconfigure_logging(args.verbose)
logging.debug('Raw arguments %s', sys.argv)
# short validation logic
if not args.build:
parser.error(message='missing build command')
logging.debug('Parsed arguments: %s', args)
return args
def create_intercept_parser():
""" Creates a parser for command-line arguments to 'intercept'. """
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument(
'--version',
action='version',
version='%(prog)s @BEAR_VERSION@')
parser.add_argument(
'--verbose', '-v',
action='count',
default=0,
help="""Enable verbose output from '%(prog)s'. A second, third and
fourth flags increases verbosity.""")
parser.add_argument(
'--cdb', '-o',
metavar='',
default="compile_commands.json",
help="""The JSON compilation database.""")
parser.add_argument(
'--field-output',
action='store_true',
help="""Puts output field to entries if it founds.""")
parser.add_argument(
'--use-cc',
metavar='',
dest='use_cc',
action='append',
default=[os.getenv('CC', 'cc')],
help="""Hint '%(prog)s' to classify the given program name as C
compiler.""")
parser.add_argument(
'--use-c++',
metavar='',
dest='use_cxx',
action='append',
default=[os.getenv('CXX', 'c++')],
help="""Hint '%(prog)s' to classify the given program name as C++
compiler.""")
parser.add_argument(
'--use-fortran',
metavar='',
dest='use_fortran',
action='append',
default=['f95'],
help="""Hint '%(prog)s' to classify the given program name as Fortan
compiler.""")
parser.add_argument(
'--use-only',
action='store_true',
help="""Only use compilers given to '--use-cc', '--use-c++' and
'--use-fortran'.""")
parser.add_argument(
'--include',
action='append',
default=[],
help="""Only include these directories or files to the output.
(Absolute or relative to current working directory.)
Use --exclude parameters to filter more entries out.""")
parser.add_argument(
'--exclude',
action='append',
default=[],
help="""Exclude these directories or files from the output.
(Absolute or relative to current working directory.)
The --include will not enable entries from these directories.""")
advanced = parser.add_argument_group('advanced options')
advanced.add_argument(
'--append', '-a',
action='store_true',
help="""Extend existing compilation database with new entries.
Duplicate entries are detected and not present in the final output.
The output is not continuously updated, it's done when the build
command finished. """)
advanced.add_argument(
'--libear', '-l',
dest='libear',
default="@DEFAULT_PRELOAD_FILE@",
action='store',
help="""specify libear file location.""")
parser.add_argument(
dest='build', nargs=argparse.REMAINDER, help="""Command to run.""")
return parser
class Compilation:
def __init__(self,
compiler, language, phase, flags, source, directory, output):
""" Constructor for a single compilation.
This method just normalize the paths and initialize values. """
self.compiler = compiler
self.language = language
self.phase = phase
self.flags = flags
self.directory = os.path.normpath(directory)
self.source = source if os.path.isabs(source) else \
os.path.normpath(os.path.join(self.directory, source))
self.output = output
def __hash__(self):
# type: (Compilation) -> int
return hash(str(self.as_dict()))
def __eq__(self, other):
# type: (Compilation, object) -> bool
return (
self.__class__ == other.__class__ and
self.as_dict() == other.as_dict()
)
def as_dict(self):
# type: (Compilation) -> Dict[str, str]
""" This method dumps the object attributes into a dictionary. """
candidate = vars(self).copy()
candidate.pop("compiler", None)
candidate.pop("output", None)
candidate.pop("language", None)
return candidate
def as_db_entry(self, field_output):
# type: (Compilation, bool) -> Dict[str, Any]
""" This method creates a compilation database entry. """
source = os.path.relpath(self.source, self.directory)
if self.output:
result = {
'file': source,
'arguments':
[self.compiler, self.phase] + self.flags +
['-o', self.output] + [source],
'directory': self.directory,
}
if field_output:
result.update({'output': self.output})
return result
else:
return {
'file': source,
'arguments':
[self.compiler, self.phase] + self.flags + [source],
'directory': self.directory
}
@classmethod
def from_db_entry(cls, entry, tools):
# type: (Type[Compilation], Dict[str, str]) -> Iterable[Compilation]
""" Parser method for compilation entry.
From compilation database entry it creates the compilation object.
:param entry: the compilation database entry
:param tools: helper object to detect compiler
:return: stream of CompilationDbEntry objects """
command = shell_split(entry['command']) if 'command' in entry else \
entry['arguments']
execution = Execution(cmd=command, cwd=entry['directory'])
return cls.iter_from_execution(execution, tools)
@classmethod
def iter_from_execution(cls, execution, tools):
""" Generator method for compilation entries.
From a single compiler call it can generate zero or more entries.
:param execution: executed command and working directory
:param tools: helper object to detect compiler
:return: stream of CompilationDbEntry objects """
candidate = cls._split_command(execution.cmd, tools)
for source in candidate.files if candidate else []:
output = candidate.output[0] if candidate.output else None
phase = candidate.phase[0] if candidate.phase else '-c'
result = Compilation(directory=execution.cwd,
source=source,
compiler=candidate.compiler,
language=candidate.language,
phase=phase,
flags=candidate.flags,
output=output)
if os.path.isfile(result.source):
yield result
@classmethod
def _split_compiler(cls, command, tools):
""" A predicate to decide whether the command is a compiler call.
:param command: the command to classify
:param tools: helper object to detect compiler
:return: None if the command is not a compilation, or a tuple
(compiler, language, rest of the command) otherwise """
if command: # not empty list will allow to index '0' and '1:'
executable = os.path.basename(command[0]) # type: str
parameters = command[1:] # type: List[str]
# 'wrapper' 'parameters' and
# 'wrapper' 'compiler' 'parameters' are valid.
# Additionally, a wrapper can wrap another wrapper.
if tools.is_wrapper(executable):
result = cls._split_compiler(parameters, tools)
# Compiler wrapper without compiler is a 'C' compiler.
return result if result else (command[0], C_LANG, parameters)
# MPI compiler wrappers add extra parameters
elif tools.is_mpi_wrapper(executable):
# Pass the executable with full path to avoid pick different
# executable from PATH.
mpi_call = get_mpi_call(command[0]) # type: List[str]
return cls._split_compiler(mpi_call + parameters, tools)
# and 'compiler' 'parameters' is valid.
elif tools.is_c_compiler(executable):
return command[0], C_LANG, parameters
elif tools.is_cxx_compiler(executable):
return command[0], CPLUSPLUS_LANG, parameters
elif tools.is_fortran_compiler(executable):
return command[0], FORTRAN_LANG, parameters
return None
@classmethod
def _split_command(cls, command, tools):
""" Returns a value when the command is a compilation, None otherwise.
:param command: the command to classify
:param tools: helper object to detect compiler
:return: stream of CompilationCommand objects """
logging.debug('input was: %s', command)
# quit right now, if the program was not a C/C++ compiler
compiler_and_arguments = cls._split_compiler(command, tools)
if compiler_and_arguments is None:
return None
# the result of this method
result = CompilationCommand(compiler=compiler_and_arguments[0],
language=compiler_and_arguments[1],
phase=[],
flags=[],
files=[],
output=[])
# iterate on the compile options
args = iter(compiler_and_arguments[2])
for arg in args:
# quit when compilation pass is not involved
if arg in {'-E', '-cc1', '-cc1as', '-M', '-MM', '-###'}:
return None
elif arg in {'-S', '-c'}:
result.phase.append(arg)
# ignore some flags
elif arg in IGNORED_FLAGS:
count = IGNORED_FLAGS[arg]
for _ in range(count):
next(args)
elif re.match(r'^-(l|L|Wl,).+', arg):
pass
# some parameters look like a filename, take those explicitly
elif arg in {'-D', '-U', '-I', '-include'}:
result.flags.extend([arg, next(args)])
# get the output file separately
elif arg == '-o':
result.output.append(next(args))
# parameter which looks source file is taken...
elif re.match(r'^[^-].+', arg) and classify_source(arg):
result.files.append(arg)
# and consider everything else as compile option.
else:
result.flags.append(arg)
logging.debug('output is: %s', result)
# do extra check on number of source files
return result if result.files else None
class CompilationDatabase:
""" Compilation Database persistence methods. """
@staticmethod
def save(iterator, filename, field_output):
# type: (Iterable[Compilation], str, bool) -> None
""" Saves compilations to given file.
:param filename: the destination file name
:param iterator: iterator of Compilation objects. """
entries = [entry.as_db_entry(field_output) for entry in iterator]
with open(filename, 'w') as handle:
json.dump(entries, handle, sort_keys=True, indent=4)
@staticmethod
def load(filename, tools):
# type: (str, Tools) -> Iterable[Compilation]
""" Load compilations from file.
:param filename: the file to read from
:param tools: helper object to detect compiler
:returns: iterator of Compilation objects. """
with open(filename, 'r') as handle:
for entry in json.load(handle):
for compilation in Compilation.from_db_entry(entry, tools):
yield compilation
def classify_source(filename, c_compiler=True):
# type: (str, bool) -> str
""" Classify source file names and returns the presumed language,
based on the file name extension.
:param filename: the source file name
:param c_compiler: indicate that the compiler is a C compiler,
:return: the language from file name extension. """
mapping = {
'.c': 'c' if c_compiler else 'c++',
'.i': 'c-cpp-output' if c_compiler else 'c++-cpp-output',
'.ii': 'c++-cpp-output',
'.m': 'objective-c',
'.mi': 'objective-c-cpp-output',
'.mm': 'objective-c++',
'.mii': 'objective-c++-cpp-output',
'.C': 'c++',
'.cc': 'c++',
'.CC': 'c++',
'.cp': 'c++',
'.cpp': 'c++',
'.cxx': 'c++',
'.c++': 'c++',
'.C++': 'c++',
'.txx': 'c++',
'.cu': 'c++',
'.s': 'assembly',
'.S': 'assembly',
'.sx': 'assembly',
'.asm': 'assembly',
'.f95': 'fortran',
'.F95': 'fortran',
'.f90': 'fortran',
'.F90': 'fortran',
'.f': 'fortran',
'.F': 'fortran',
'.FOR': 'fortran',
'.f77': 'fortran',
'.fc': 'fortran',
'.for': 'fortran',
'.ftn': 'fortran',
'.fpp': 'fortran'
}
__, extension = os.path.splitext(os.path.basename(filename))
return mapping.get(extension)
def get_mpi_call(wrapper):
# type: (str) -> List[str]
""" Provide information on how the underlying compiler would have been
invoked without the MPI compiler wrapper. """
for query_flags in [['-show'], ['--showme']]:
try:
output = run_command([wrapper] + query_flags)
if output:
return shell_split(output[0])
except Exception:
pass
# Fail loud
raise RuntimeError("Could not determinate MPI flags.")
@contextlib.contextmanager
def temporary_directory(**kwargs):
name = tempfile.mkdtemp(**kwargs)
try:
yield name
finally:
shutil.rmtree(name)
if __name__ == "__main__":
sys.exit(intercept_build())
Bear-2.4.3/libear/ 0000775 0000000 0000000 00000000000 13613276011 0013627 5 ustar 00root root 0000000 0000000 Bear-2.4.3/libear/CMakeLists.txt 0000664 0000000 0000000 00000002505 13613276011 0016371 0 ustar 00root root 0000000 0000000 include(CheckFunctionExists)
include(CheckSymbolExists)
include(CheckIncludeFile)
check_function_exists(execve HAVE_EXECVE)
check_function_exists(execv HAVE_EXECV)
check_function_exists(execvpe HAVE_EXECVPE)
check_function_exists(execvp HAVE_EXECVP)
check_function_exists(execvP HAVE_EXECVP2)
check_function_exists(exect HAVE_EXECT)
check_function_exists(execl HAVE_EXECL)
check_function_exists(execlp HAVE_EXECLP)
check_function_exists(execle HAVE_EXECLE)
check_function_exists(posix_spawn HAVE_POSIX_SPAWN)
check_function_exists(posix_spawnp HAVE_POSIX_SPAWNP)
check_symbol_exists(_NSGetEnviron crt_externs.h HAVE_NSGETENVIRON)
find_package(Threads REQUIRED)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_library(ear SHARED ear.c)
target_link_libraries(ear ${CMAKE_DL_LIBS})
if(THREADS_HAVE_PTHREAD_ARG)
set_property(TARGET ear PROPERTY COMPILE_OPTIONS "-pthread")
set_property(TARGET ear PROPERTY INTERFACE_COMPILE_OPTIONS "-pthread")
endif()
if(CMAKE_THREAD_LIBS_INIT)
target_link_libraries(ear "${CMAKE_THREAD_LIBS_INIT}")
endif()
if(APPLE)
set(CMAKE_MACOSX_RPATH 1)
set_target_properties(ear PROPERTIES INSTALL_RPATH "@loader_path/${EAR_LIB_PATH}")
endif()
install(TARGETS ear
LIBRARY DESTINATION ${EAR_LIB_PATH})
Bear-2.4.3/libear/config.h.in 0000664 0000000 0000000 00000000536 13613276011 0015656 0 ustar 00root root 0000000 0000000 #pragma once
#cmakedefine HAVE_EXECVE
#cmakedefine HAVE_EXECV
#cmakedefine HAVE_EXECVPE
#cmakedefine HAVE_EXECVP
#cmakedefine HAVE_EXECVP2
#cmakedefine HAVE_EXECT
#cmakedefine HAVE_EXECL
#cmakedefine HAVE_EXECLP
#cmakedefine HAVE_EXECLE
#cmakedefine HAVE_POSIX_SPAWN
#cmakedefine HAVE_POSIX_SPAWNP
#cmakedefine HAVE_NSGETENVIRON
#cmakedefine APPLE
Bear-2.4.3/libear/ear.c 0000664 0000000 0000000 00000047517 13613276011 0014560 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2012-2019 by László Nagy
This file is part of Bear.
Bear is a tool to generate compilation database for clang tooling.
Bear is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Bear is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
/**
* This file implements a shared library. This library can be pre-loaded by
* the dynamic linker of the Operating System (OS). It implements a few function
* related to process creation. By pre-load this library the executed process
* uses these functions instead of those from the standard library.
*
* The idea here is to inject a logic before call the real methods. The logic is
* to dump the call into a file. To call the real method this library is doing
* the job of the dynamic linker.
*
* The only input for the log writing is about the destination directory.
* This is passed as environment variable.
*/
#include "config.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#if defined HAVE_POSIX_SPAWN || defined HAVE_POSIX_SPAWNP
#include
#endif
#if defined HAVE_NSGETENVIRON
# include
static char **environ;
#else
extern char **environ;
#endif
#define ENV_OUTPUT "INTERCEPT_BUILD_TARGET_DIR"
#ifdef APPLE
# define ENV_FLAT "DYLD_FORCE_FLAT_NAMESPACE"
# define ENV_PRELOAD "DYLD_INSERT_LIBRARIES"
# define ENV_SIZE 3
#else
# define ENV_PRELOAD "LD_PRELOAD"
# define ENV_SIZE 2
#endif
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#define AT "libear: (" __FILE__ ":" TOSTRING(__LINE__) ") "
#define PERROR(msg) do { perror(AT msg); } while (0)
#define ERROR_AND_EXIT(msg) do { PERROR(msg); exit(EXIT_FAILURE); } while (0)
#define DLSYM(TYPE_, VAR_, SYMBOL_) \
union { \
void *from; \
TYPE_ to; \
} cast; \
if (0 == (cast.from = dlsym(RTLD_NEXT, SYMBOL_))) { \
PERROR("dlsym"); \
exit(EXIT_FAILURE); \
} \
TYPE_ const VAR_ = cast.to;
typedef char const * bear_env_t[ENV_SIZE];
static int capture_env_t(bear_env_t *env);
static void release_env_t(bear_env_t *env);
static char const **string_array_partial_update(char *const envp[], bear_env_t *env);
static char const **string_array_single_update(char const *envs[], char const *key, char const *value);
static void report_call(char const *const argv[]);
static int write_report(int fd, char const *const argv[]);
static char const **string_array_from_varargs(char const * arg, va_list *args);
static char const **string_array_copy(char const **in);
static size_t string_array_length(char const *const *in);
static void string_array_release(char const **);
static bear_env_t env_names =
{ ENV_OUTPUT
, ENV_PRELOAD
#ifdef ENV_FLAT
, ENV_FLAT
#endif
};
static bear_env_t initial_env =
{ 0
, 0
#ifdef ENV_FLAT
, 0
#endif
};
static int initialized = 0;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static void on_load(void) __attribute__((constructor));
static void on_unload(void) __attribute__((destructor));
static int mt_safe_on_load(void);
static void mt_safe_on_unload(void);
#ifdef HAVE_EXECVE
static int call_execve(const char *path, char *const argv[],
char *const envp[]);
#endif
#ifdef HAVE_EXECVP
static int call_execvp(const char *file, char *const argv[]);
#endif
#ifdef HAVE_EXECVPE
static int call_execvpe(const char *file, char *const argv[],
char *const envp[]);
#endif
#ifdef HAVE_EXECVP2
static int call_execvP(const char *file, const char *search_path,
char *const argv[]);
#endif
#ifdef HAVE_EXECT
static int call_exect(const char *path, char *const argv[],
char *const envp[]);
#endif
#ifdef HAVE_POSIX_SPAWN
static int call_posix_spawn(pid_t *restrict pid, const char *restrict path,
const posix_spawn_file_actions_t *file_actions,
const posix_spawnattr_t *restrict attrp,
char *const argv[restrict],
char *const envp[restrict]);
#endif
#ifdef HAVE_POSIX_SPAWNP
static int call_posix_spawnp(pid_t *restrict pid, const char *restrict file,
const posix_spawn_file_actions_t *file_actions,
const posix_spawnattr_t *restrict attrp,
char *const argv[restrict],
char *const envp[restrict]);
#endif
/* Initialization method to Captures the relevant environment variables.
*/
static void on_load(void) {
pthread_mutex_lock(&mutex);
if (0 == initialized)
initialized = mt_safe_on_load();
pthread_mutex_unlock(&mutex);
}
static void on_unload(void) {
pthread_mutex_lock(&mutex);
if (0 != initialized)
mt_safe_on_unload();
initialized = 0;
pthread_mutex_unlock(&mutex);
}
static int mt_safe_on_load(void) {
#ifdef HAVE_NSGETENVIRON
environ = *_NSGetEnviron();
if (0 == environ)
return 0;
#endif
// Capture current relevant environment variables
return capture_env_t(&initial_env);
}
static void mt_safe_on_unload(void) {
release_env_t(&initial_env);
}
/* These are the methods we are try to hijack.
*/
#ifdef HAVE_EXECVE
int execve(const char *path, char *const argv[], char *const envp[]) {
report_call((char const *const *)argv);
return call_execve(path, argv, envp);
}
#endif
#ifdef HAVE_EXECV
#ifndef HAVE_EXECVE
#error can not implement execv without execve
#endif
int execv(const char *path, char *const argv[]) {
report_call((char const *const *)argv);
return call_execve(path, argv, environ);
}
#endif
#ifdef HAVE_EXECVPE
int execvpe(const char *file, char *const argv[], char *const envp[]) {
report_call((char const *const *)argv);
return call_execvpe(file, argv, envp);
}
#endif
#ifdef HAVE_EXECVP
int execvp(const char *file, char *const argv[]) {
report_call((char const *const *)argv);
return call_execvp(file, argv);
}
#endif
#ifdef HAVE_EXECVP2
int execvP(const char *file, const char *search_path, char *const argv[]) {
report_call((char const *const *)argv);
return call_execvP(file, search_path, argv);
}
#endif
#ifdef HAVE_EXECT
int exect(const char *path, char *const argv[], char *const envp[]) {
report_call((char const *const *)argv);
return call_exect(path, argv, envp);
}
#endif
#ifdef HAVE_EXECL
# ifndef HAVE_EXECVE
# error can not implement execl without execve
# endif
int execl(const char *path, const char *arg, ...) {
va_list args;
va_start(args, arg);
char const **argv = string_array_from_varargs(arg, &args);
va_end(args);
report_call((char const *const *)argv);
int const result = call_execve(path, (char *const *)argv, environ);
string_array_release(argv);
return result;
}
#endif
#ifdef HAVE_EXECLP
# ifndef HAVE_EXECVP
# error can not implement execlp without execvp
# endif
int execlp(const char *file, const char *arg, ...) {
va_list args;
va_start(args, arg);
char const **argv = string_array_from_varargs(arg, &args);
va_end(args);
report_call((char const *const *)argv);
int const result = call_execvp(file, (char *const *)argv);
string_array_release(argv);
return result;
}
#endif
#ifdef HAVE_EXECLE
# ifndef HAVE_EXECVE
# error can not implement execle without execve
# endif
// int execle(const char *path, const char *arg, ..., char * const envp[]);
int execle(const char *path, const char *arg, ...) {
va_list args;
va_start(args, arg);
char const **argv = string_array_from_varargs(arg, &args);
char const **envp = va_arg(args, char const **);
va_end(args);
report_call((char const *const *)argv);
int const result =
call_execve(path, (char *const *)argv, (char *const *)envp);
string_array_release(argv);
return result;
}
#endif
#ifdef HAVE_POSIX_SPAWN
int posix_spawn(pid_t *restrict pid, const char *restrict path,
const posix_spawn_file_actions_t *file_actions,
const posix_spawnattr_t *restrict attrp,
char *const argv[restrict], char *const envp[restrict]) {
report_call((char const *const *)argv);
return call_posix_spawn(pid, path, file_actions, attrp, argv, envp);
}
#endif
#ifdef HAVE_POSIX_SPAWNP
int posix_spawnp(pid_t *restrict pid, const char *restrict file,
const posix_spawn_file_actions_t *file_actions,
const posix_spawnattr_t *restrict attrp,
char *const argv[restrict], char *const envp[restrict]) {
report_call((char const *const *)argv);
return call_posix_spawnp(pid, file, file_actions, attrp, argv, envp);
}
#endif
/* These are the methods which forward the call to the standard implementation.
*/
#ifdef HAVE_EXECVE
static int call_execve(const char *path, char *const argv[],
char *const envp[]) {
typedef int (*func)(const char *, char *const *, char *const *);
DLSYM(func, fp, "execve");
char const **const menvp = string_array_partial_update(envp, &initial_env);
int const result = (*fp)(path, argv, (char *const *)menvp);
string_array_release(menvp);
return result;
}
#endif
#ifdef HAVE_EXECVPE
static int call_execvpe(const char *file, char *const argv[],
char *const envp[]) {
typedef int (*func)(const char *, char *const *, char *const *);
DLSYM(func, fp, "execvpe");
char const **const menvp = string_array_partial_update(envp, &initial_env);
int const result = (*fp)(file, argv, (char *const *)menvp);
string_array_release(menvp);
return result;
}
#endif
#ifdef HAVE_EXECVP
static int call_execvp(const char *file, char *const argv[]) {
typedef int (*func)(const char *file, char *const argv[]);
DLSYM(func, fp, "execvp");
char **const original = environ;
char const **const modified = string_array_partial_update(original, &initial_env);
environ = (char **)modified;
int const result = (*fp)(file, argv);
environ = original;
string_array_release(modified);
return result;
}
#endif
#ifdef HAVE_EXECVP2
static int call_execvP(const char *file, const char *search_path,
char *const argv[]) {
typedef int (*func)(const char *, const char *, char *const *);
DLSYM(func, fp, "execvP");
char **const original = environ;
char const **const modified = string_array_partial_update(original, &initial_env);
environ = (char **)modified;
int const result = (*fp)(file, search_path, argv);
environ = original;
string_array_release(modified);
return result;
}
#endif
#ifdef HAVE_EXECT
static int call_exect(const char *path, char *const argv[],
char *const envp[]) {
typedef int (*func)(const char *, char *const *, char *const *);
DLSYM(func, fp, "exect");
char const **const menvp = string_array_partial_update(envp, &initial_env);
int const result = (*fp)(path, argv, (char *const *)menvp);
string_array_release(menvp);
return result;
}
#endif
#ifdef HAVE_POSIX_SPAWN
static int call_posix_spawn(pid_t *restrict pid, const char *restrict path,
const posix_spawn_file_actions_t *file_actions,
const posix_spawnattr_t *restrict attrp,
char *const argv[restrict],
char *const envp[restrict]) {
typedef int (*func)(pid_t *restrict, const char *restrict,
const posix_spawn_file_actions_t *,
const posix_spawnattr_t *restrict,
char *const *restrict, char *const *restrict);
DLSYM(func, fp, "posix_spawn");
char const **const menvp = string_array_partial_update(envp, &initial_env);
int const result =
(*fp)(pid, path, file_actions, attrp, argv, (char *const *restrict)menvp);
string_array_release(menvp);
return result;
}
#endif
#ifdef HAVE_POSIX_SPAWNP
static int call_posix_spawnp(pid_t *restrict pid, const char *restrict file,
const posix_spawn_file_actions_t *file_actions,
const posix_spawnattr_t *restrict attrp,
char *const argv[restrict],
char *const envp[restrict]) {
typedef int (*func)(pid_t *restrict, const char *restrict,
const posix_spawn_file_actions_t *,
const posix_spawnattr_t *restrict,
char *const *restrict, char *const *restrict);
DLSYM(func, fp, "posix_spawnp");
char const **const menvp = string_array_partial_update(envp, &initial_env);
int const result =
(*fp)(pid, file, file_actions, attrp, argv, (char *const *restrict)menvp);
string_array_release(menvp);
return result;
}
#endif
/* this method is to write log about the process creation. */
static void report_call(char const *const argv[]) {
if (!initialized)
return;
// Create report file name
char const * const out_dir = initial_env[0];
size_t const path_max_length = strlen(out_dir) + 32;
char filename[path_max_length];
if (-1 == snprintf(filename, path_max_length, "%s/execution.XXXXXX", out_dir))
ERROR_AND_EXIT("snprintf");
// Create report file
int fd = mkstemp((char *)&filename);
if (-1 == fd)
ERROR_AND_EXIT("mkstemp");
// Write report file
const int finished = write_report(fd, argv);
// Close report file
if (close(fd))
ERROR_AND_EXIT("close");
// Remove the file if it's not done
if ((-1 == finished) && (-1 == unlink(filename)))
ERROR_AND_EXIT("unlink");
}
static int write_binary_string(int fd, const char *const string) {
// write type
if (-1 == write(fd, "str", 3)) {
PERROR("write type");
return -1;
}
// write length
const uint32_t length = strlen(string);
if (-1 == write(fd, (void *) &length, sizeof(uint32_t))) {
PERROR("write length");
return -1;
}
// write value
if (-1 == write(fd, (void *) string, length)) {
PERROR("write value");
return -1;
}
return 0;
}
static int write_binary_string_list(int fd, const char *const *const strings) {
// write type
if (-1 == write(fd, "lst", 3)) {
PERROR("write type");
return -1;
}
// write length
const uint32_t length = string_array_length(strings);
if (-1 == write(fd, (void *) &length, sizeof(uint32_t))) {
PERROR("write length");
return -1;
}
// write value
for (uint32_t idx = 0; idx < length; ++idx) {
const char *string = strings[idx];
if (-1 == write_binary_string(fd, string)) {
PERROR("write value");
return -1;
}
}
return 0;
}
static int write_report(int fd, char const *const argv[]) {
const char *cwd = getcwd(NULL, 0);
if (0 == cwd) {
PERROR("getcwd");
return -1;
} else {
if (-1 == write_binary_string(fd, cwd)) {
PERROR("cwd writing failed");
return -1;
}
}
free((void *)cwd);
if (-1 == write_binary_string_list(fd, argv)) {
PERROR("cmd writing failed");
return -1;
}
return 0;
}
/* update environment assure that chilren processes will copy the desired
* behaviour */
static int capture_env_t(bear_env_t *env) {
for (size_t it = 0; it < ENV_SIZE; ++it) {
char const * const env_value = getenv(env_names[it]);
if (0 == env_value) {
PERROR("getenv");
return 0;
}
char const * const env_copy = strdup(env_value);
if (0 == env_copy) {
PERROR("strdup");
return 0;
}
(*env)[it] = env_copy;
}
return 1;
}
static void release_env_t(bear_env_t *env) {
for (size_t it = 0; it < ENV_SIZE; ++it) {
free((void *)(*env)[it]);
(*env)[it] = 0;
}
}
static char const **string_array_partial_update(char *const envp[], bear_env_t *env) {
char const **result = string_array_copy((char const **)envp);
for (size_t it = 0; it < ENV_SIZE && (*env)[it]; ++it)
result = string_array_single_update(result, env_names[it], (*env)[it]);
return result;
}
static char const **string_array_single_update(char const *envs[], char const *key, char const * const value) {
// find the key if it's there
size_t const key_length = strlen(key);
char const **it = envs;
for (; (it) && (*it); ++it) {
if ((0 == strncmp(*it, key, key_length)) &&
(strlen(*it) > key_length) && ('=' == (*it)[key_length]))
break;
}
// allocate a environment entry
size_t const value_length = strlen(value);
size_t const env_length = key_length + value_length + 2;
char *env = malloc(env_length);
if (0 == env)
ERROR_AND_EXIT("malloc");
if (-1 == snprintf(env, env_length, "%s=%s", key, value))
ERROR_AND_EXIT("snprintf");
// replace or append the environment entry
if (it && *it) {
free((void *)*it);
*it = env;
return envs;
} else {
size_t const size = string_array_length(envs);
char const **result = realloc(envs, (size + 2) * sizeof(char const *));
if (0 == result)
ERROR_AND_EXIT("realloc");
result[size] = env;
result[size + 1] = 0;
return result;
}
}
/* util methods to deal with string arrays. environment and process arguments
* are both represented as string arrays. */
static char const **string_array_from_varargs(char const *const arg, va_list *args) {
char const **result = 0;
size_t size = 0;
for (char const *it = arg; it; it = va_arg(*args, char const *)) {
result = realloc(result, (size + 1) * sizeof(char const *));
if (0 == result)
ERROR_AND_EXIT("realloc");
char const *copy = strdup(it);
if (0 == copy)
ERROR_AND_EXIT("strdup");
result[size++] = copy;
}
result = realloc(result, (size + 1) * sizeof(char const *));
if (0 == result)
ERROR_AND_EXIT("realloc");
result[size++] = 0;
return result;
}
static char const **string_array_copy(char const **const in) {
size_t const size = string_array_length(in);
char const **const result = malloc((size + 1) * sizeof(char const *));
if (0 == result)
ERROR_AND_EXIT("malloc");
char const **out_it = result;
for (char const *const *in_it = in; (in_it) && (*in_it);
++in_it, ++out_it) {
*out_it = strdup(*in_it);
if (0 == *out_it)
ERROR_AND_EXIT("strdup");
}
*out_it = 0;
return result;
}
static size_t string_array_length(char const *const *const in) {
size_t result = 0;
for (char const *const *it = in; (it) && (*it); ++it)
++result;
return result;
}
static void string_array_release(char const **in) {
for (char const *const *it = in; (it) && (*it); ++it) {
free((void *)*it);
}
free((void *)in);
}
Bear-2.4.3/man/ 0000775 0000000 0000000 00000000000 13613276011 0013144 5 ustar 00root root 0000000 0000000 Bear-2.4.3/man/CMakeLists.txt 0000664 0000000 0000000 00000000746 13613276011 0015713 0 ustar 00root root 0000000 0000000 # Markdown file is the source to the man file. Please modify that and generate
# the man file from it with pandoc.
#
# $ pandoc -s -t man bear.1.md -o bear.1
#
# This is not automated, because pandoc has big dependencies on different OS
# distributions and packaging would require to install those. Which might be
# too much effort to generate a single text file.
include(GNUInstallDirs)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/bear.1
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
Bear-2.4.3/man/bear.1 0000664 0000000 0000000 00000012324 13613276011 0014141 0 ustar 00root root 0000000 0000000 .\" Automatically generated by Pandoc 2.2.1
.\"
.TH "BEAR" "1" "May 10, 2019" "Bear User Manuals" ""
.hy
.SH NAME
.PP
Bear \- Build EAR
.SH SYNOPSIS
.PP
bear [\f[I]options\f[]] [\f[I]build command\f[]]
.SH DESCRIPTION
.PP
Bear is a tool to generate compilation database for clang tooling.
.PP
The JSON compilation database
is used in
Clang project to provide information how a single compilation unit was
processed.
When that is available then it is easy to re\-run the compilation with
different programs.
.PP
Bear executes the original build command and intercepts the subsequent
execution calls.
To achieve that Bear uses library preload mechanism provided by the
dynamic linker.
There is a library which defines the \f[I]exec\f[] methods and used in
every child processes of the build command.
The executable itself sets the environment up to child processes and
writes the output file.
.SH OPTIONS
.TP
.B \-\-version
Print out Bear version number.
.RS
.RE
.TP
.B \-v, \-\-verbose
Enable verbose output from Bear.
A second, third and fourth flags increases verbosity.
.RS
.RE
.TP
.B \-o \f[I]file\f[], \-\-cdb \f[I]file\f[]
Specify output file.
(Default value provided.) The output is not continuously updated, it's
done when the build command finished.
.RS
.RE
.TP
.B \[en]field\-output
Ask to emit the \f[C]output\f[] field for each entries in the output
file.
.RS
.RE
.TP
.B \-\-use\-cc \f[I]program\f[]
Hint Bear to classify the given program name as C compiler.
.RS
.RE
.TP
.B \-\-use\-c++ \f[I]program\f[]
Hint Bear to classify the given program name as C++ compiler.
.RS
.RE
.TP
.B \-\-use\-fortran \f[I]program\f[]
Hint Bear to classify the given program name as Fortran compiler.
.RS
.RE
.TP
.B \-\-use\-only
Force to use only the \f[C]\-\-use\-cc\f[] and \f[C]\-\-use\-c++\f[]
given compilers.
.RS
.RE
.TP
.B \-\-include \f[I]directory\f[]
Only include this directories or files to the output.
The flag can be used multiple times.
The directory is either absolute or relative to current working
directory.
Use \f[C]\-\-exclude\f[] to filter entries out from these directory.
.RS
.RE
.TP
.B \-\-exclude \f[I]directory\f[]
Exclude these directories or files from the output.
The flag can be used multiple times.
The directory is either absolute or relative to current working
directory.
The \f[C]\-\-include\f[] will not enable entries from these directories.
.RS
.RE
.TP
.B \-a, \-\-append
Use previously generated output file and append the new entries to it.
This way you can run Bear continuously during work, and it keeps the
compilation database up to date.
File deletion and addition are both considered.
But build process change (compiler flags change) might cause duplicate
entries.
.RS
.RE
.TP
.B \-l \f[I]path\f[], \-\-libear \f[I]path\f[]
Specify the preloaded library location.
(Default value provided.)
.RS
.RE
.SH OUTPUT
.PP
The JSON compilation database definition changed over time.
The current version of Bear generates entries where:
.TP
.B \f[C]directory\f[]
has absolute path.
.RS
.RE
.TP
.B \f[C]file\f[]
has relative path to the \f[C]directory\f[].
.RS
.RE
.TP
.B \f[C]arguments\f[]
used instead of \f[C]command\f[] to avoid shell escaping problems.
The source file in the compiler call match to the \f[C]file\f[]
attribute, therefore it is relative path to \f[C]directory\f[].
Other filesystem related references are not modified (those still can be
absolute or relative depending the original command).
.RS
.RE
.PP
Some non compilation related flags are filtered out from the final
output.
.SH EXIT STATUS
.PP
Bear exit status is the exit status of the build command.
Except when bear crashes, then it sets to non zero.
.SH ENVIRONMENT
.TP
.B \f[C]INTERCEPT_BUILD_TARGET_DIR\f[]
Temporary directory to collect the execution reports at one place.
Directory path is derived from \f[C]TMPDIR\f[], \f[C]TEMP\f[] or
\f[C]TMP\f[] environment variable.
.RS
.RE
.TP
.B \f[C]LD_PRELOAD\f[]
Used by the dynamic loader on Linux, FreeBSD and other UNIX OS.
Value set by Bear, overrides previous value for child processes.
.RS
.RE
.TP
.B \f[C]DYLD_INSERT_LIBRARIES\f[]
Used by the dynamic loader on OS X.
Value set by Bear, overrides previous value for child processes.
.RS
.RE
.TP
.B \f[C]DYLD_FORCE_FLAT_NAMESPACE\f[]
Used by the dynamic loader on OS X.
Value set by bear, overrides previous value for child processes.
.RS
.RE
.SH FILES
.TP
.B \f[C]libear.so\f[] or \f[C]libear.dylib\f[]
The preload library which implements the \f[I]exec\f[] methods.
.RS
.RE
.SH SEE ALSO
.PP
ld.so(8), exec(3)
.SH BUGS
.PP
Because Bear uses \f[C]LD_PRELOAD\f[] or \f[C]DYLD_INSERT_LIBRARIES\f[]
environment variables, it does not append to it, but overrides it.
So builds which are using these variables might not work.
(I don't know any build tool which does that, but please let me know if
you do.)
.PP
Security extension/modes on different operating systems might disable
library preloads.
This case Bear behaves normally, but the result compilation database
will be empty.
(Please make sure it's not the case when reporting bugs.) Notable
examples for enabled security modes are: SIP on OS X Captain and SELinux
on Fedora, CentOS, RHEL.
.SH COPYRIGHT
.PP
Copyright (C) 2012\-2019 by László Nagy
.SH AUTHORS
László Nagy.
Bear-2.4.3/man/bear.1.md 0000664 0000000 0000000 00000011175 13613276011 0014543 0 ustar 00root root 0000000 0000000 % BEAR(1) Bear User Manuals
% László Nagy
% May 10, 2019
# NAME
Bear - Build EAR
# SYNOPSIS
bear [*options*] [*build command*]
# DESCRIPTION
Bear is a tool to generate compilation database for clang tooling.
The JSON compilation database
is used in
Clang project to provide information how a single compilation unit
was processed. When that is available then it is easy to re-run the
compilation with different programs.
Bear executes the original build command and intercepts the subsequent
execution calls. To achieve that Bear uses library preload mechanism
provided by the dynamic linker.
There is a library which defines the *exec* methods and used in every
child processes of the build command.
The executable itself sets the environment up to child processes and
writes the output file.
# OPTIONS
\--version
: Print out Bear version number.
-v, \--verbose
: Enable verbose output from Bear. A second, third and fourth flags
increases verbosity.
-o *file*, \--cdb *file*
: Specify output file. (Default value provided.) The output is not
continuously updated, it's done when the build command finished.
--field-output
: Ask to emit the `output` field for each entries in the output file.
\--use-cc *program*
: Hint Bear to classify the given program name as C compiler.
\--use-c++ *program*
: Hint Bear to classify the given program name as C++ compiler.
\--use-fortran *program*
: Hint Bear to classify the given program name as Fortran compiler.
\--use-only
: Force to use only the `--use-cc` and `--use-c++` given compilers.
\--include *directory*
: Only include this directories or files to the output. The flag can
be used multiple times. The directory is either absolute or
relative to current working directory. Use `--exclude` to filter
entries out from these directory.
\--exclude *directory*
: Exclude these directories or files from the output. The flag can
be used multiple times. The directory is either absolute or
relative to current working directory. The `--include` will
not enable entries from these directories.
-a, \--append
: Use previously generated output file and append the new entries to it.
This way you can run Bear continuously during work, and it keeps the
compilation database up to date. File deletion and addition are both
considered. But build process change (compiler flags change) might
cause duplicate entries.
-l *path*, \--libear *path*
: Specify the preloaded library location. (Default value provided.)
# OUTPUT
The JSON compilation database definition changed over time. The current
version of Bear generates entries where:
`directory`
: has absolute path.
`file`
: has relative path to the `directory`.
`arguments`
: used instead of `command` to avoid shell escaping problems. The source
file in the compiler call match to the `file` attribute, therefore
it is relative path to `directory`. Other filesystem related references
are not modified (those still can be absolute or relative depending the
original command).
Some non compilation related flags are filtered out from the final output.
# EXIT STATUS
Bear exit status is the exit status of the build command.
Except when bear crashes, then it sets to non zero.
# ENVIRONMENT
`INTERCEPT_BUILD_TARGET_DIR`
: Temporary directory to collect the execution reports at one place.
Directory path is derived from `TMPDIR`, `TEMP` or `TMP` environment
variable.
`LD_PRELOAD`
: Used by the dynamic loader on Linux, FreeBSD and other UNIX OS.
Value set by Bear, overrides previous value for child processes.
`DYLD_INSERT_LIBRARIES`
: Used by the dynamic loader on OS X.
Value set by Bear, overrides previous value for child processes.
`DYLD_FORCE_FLAT_NAMESPACE`
: Used by the dynamic loader on OS X.
Value set by bear, overrides previous value for child processes.
# FILES
`libear.so` or `libear.dylib`
: The preload library which implements the *exec* methods.
# SEE ALSO
ld.so(8), exec(3)
# BUGS
Because Bear uses `LD_PRELOAD` or `DYLD_INSERT_LIBRARIES` environment variables,
it does not append to it, but overrides it. So builds which are using these
variables might not work. (I don't know any build tool which does that, but
please let me know if you do.)
Security extension/modes on different operating systems might disable library
preloads. This case Bear behaves normally, but the result compilation database
will be empty. (Please make sure it's not the case when reporting bugs.)
Notable examples for enabled security modes are: SIP on OS X Captain and
SELinux on Fedora, CentOS, RHEL.
# COPYRIGHT
Copyright (C) 2012-2019 by László Nagy
Bear-2.4.3/shell-completion/ 0000775 0000000 0000000 00000000000 13613276011 0015647 5 ustar 00root root 0000000 0000000 Bear-2.4.3/shell-completion/CMakeLists.txt 0000664 0000000 0000000 00000000027 13613276011 0020406 0 ustar 00root root 0000000 0000000 add_subdirectory(bash)
Bear-2.4.3/shell-completion/bash/ 0000775 0000000 0000000 00000000000 13613276011 0016564 5 ustar 00root root 0000000 0000000 Bear-2.4.3/shell-completion/bash/CMakeLists.txt 0000664 0000000 0000000 00000000474 13613276011 0021331 0 ustar 00root root 0000000 0000000 find_package(bash-completion)
if (NOT BASH_COMPLETION_FOUND)
# Fallback default dir
set(BASH_COMPLETION_COMPLETIONSDIR
"${CMAKE_INSTALL_DATADIR}/bash-completion/completions/")
endif()
install(
FILES "bear"
DESTINATION "${BASH_COMPLETION_COMPLETIONSDIR}"
COMPONENT shell-completion
)
Bear-2.4.3/shell-completion/bash/bear 0000664 0000000 0000000 00000002121 13613276011 0017414 0 ustar 00root root 0000000 0000000 _bear() {
for word in "${COMP_WORDS[@]:0:$COMP_CWORD}"
do
if [[ $word == -- ]]
then
_command_offset $COMP_CWORD
return
fi
done
local cur prev
if _get_comp_words_by_ref cur prev &>/dev/null; then
case $prev in
-o|--cdb)
_filedir
COMPREPLY+=($(compgen -W 'compile_commands.json' -- "$cur"))
return
;;
--use-cc|--use-c++)
_command_offset $COMP_CWORD
return
;;
esac
else
cur="${COMP_WORDS[COMP_CWORD]}"
fi
local shortopts=(
h
v
o
a
)
local longopts=(
help
version
verbose
cdb
use-cc
use-c++
use-only
)
if [[ "$cur" == "--"* ]]; then
COMPREPLY=($(compgen -P '--' -W '${longopts[*]}' -- "${cur:2}"))
elif [[ "$cur" == "-"* && ${#cur} -gt 1 ]]; then
COMPREPLY=($(compgen -P '-' -W '${shortopts[*]}' -- "${cur:1}"))
else
_command_offset $COMP_CWORD
COMPREPLY+=($(compgen -P '-' -W '${shortopts[*]}' -- "${cur:1}")
$(compgen -P '--' -W '${longopts[*]}' -- "${cur:2}"))
fi
} &&
complete -F _bear bear
Bear-2.4.3/test/ 0000775 0000000 0000000 00000000000 13613276011 0013350 5 ustar 00root root 0000000 0000000 Bear-2.4.3/test/CMakeLists.txt 0000664 0000000 0000000 00000001071 13613276011 0016107 0 ustar 00root root 0000000 0000000 enable_testing()
set(CMAKE_CTEST_COMMAND ctest -V)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
add_dependencies(check ear)
message(STATUS "Looking for lit")
find_program(LIT_EXECUTABLE
NAMES lit
PATHS ENV LIT_PATH)
if (LIT_EXECUTABLE)
set(LIT_FOUND 1)
message(STATUS "Looking for lit -- found")
endif()
if(LIT_FOUND)
set(EAR_EXE ${CMAKE_BINARY_DIR}/bear/bear)
set(EAR_LIB ${CMAKE_BINARY_DIR}/libear/${EAR_LIB_FILE})
add_test(NAME func_test
COMMAND lit -DEAR_EXE=${EAR_EXE} -DEAR_LIB=${EAR_LIB} -v ${CMAKE_CURRENT_SOURCE_DIR})
endif()
Bear-2.4.3/test/functional/ 0000775 0000000 0000000 00000000000 13613276011 0015512 5 ustar 00root root 0000000 0000000 Bear-2.4.3/test/functional/Input/ 0000775 0000000 0000000 00000000000 13613276011 0016611 5 ustar 00root root 0000000 0000000 Bear-2.4.3/test/functional/Input/compile_error.c 0000664 0000000 0000000 00000000016 13613276011 0021613 0 ustar 00root root 0000000 0000000 int test() { ; Bear-2.4.3/test/functional/Input/main.c 0000664 0000000 0000000 00000000031 13613276011 0017673 0 ustar 00root root 0000000 0000000 int main() { return 0; }
Bear-2.4.3/test/functional/cases/ 0000775 0000000 0000000 00000000000 13613276011 0016610 5 ustar 00root root 0000000 0000000 Bear-2.4.3/test/functional/cases/end-to-end/ 0000775 0000000 0000000 00000000000 13613276011 0020542 5 ustar 00root root 0000000 0000000 Bear-2.4.3/test/functional/cases/end-to-end/Input/ 0000775 0000000 0000000 00000000000 13613276011 0021641 5 ustar 00root root 0000000 0000000 Bear-2.4.3/test/functional/cases/end-to-end/Input/SConstruct 0000664 0000000 0000000 00000000730 13613276011 0023673 0 ustar 00root root 0000000 0000000 env = Environment()
env['CXX'] = 'c++'
env['CC'] = 'cc'
env.Append(CPPDEFINES={'RELEASE_BUILD' : 'First release \"quoted\"'})
some_lib = env.SharedLibrary(target="some_lib",
source=["lib/foo.cpp", "lib/bar.cc"])
some_app = env.Program(target="some_app",
source=["bin/far.cxx", "bin/boo.c++"],
CPPPATH=Split('#lib'),
LIBPATH=['.'],
LIBS=['some_lib'])
Bear-2.4.3/test/functional/cases/end-to-end/Input/bin/ 0000775 0000000 0000000 00000000000 13613276011 0022411 5 ustar 00root root 0000000 0000000 Bear-2.4.3/test/functional/cases/end-to-end/Input/bin/bin.pro 0000664 0000000 0000000 00000000217 13613276011 0023703 0 ustar 00root root 0000000 0000000 TEMPLATE = app
TARGET = some_app
INCLUDEPATH += ../lib
LIBS += -L../lib -lsome_lib
HEADERS += boo.h++
SOURCES += boo.c++
SOURCES += far.cxx
Bear-2.4.3/test/functional/cases/end-to-end/Input/bin/boo.c++ 0000664 0000000 0000000 00000000535 13613276011 0023465 0 ustar 00root root 0000000 0000000 #include "boo.h++"
#include
void t2(int i);
void t1()
{
for (int i = 0; i < 100; ++i)
{
if (98 == i)
{
t2(i);
break;
}
}
}
void t2(int i)
{
if (9 == i)
{
int k = i + 9;
++k;
return;
}
acme::t1();
}
int main()
{
t1();
return 0;
}
Bear-2.4.3/test/functional/cases/end-to-end/Input/bin/boo.h++ 0000664 0000000 0000000 00000000060 13613276011 0023463 0 ustar 00root root 0000000 0000000 #ifndef boo_h
#define boo_h
void t1();
#endif
Bear-2.4.3/test/functional/cases/end-to-end/Input/bin/far.cxx 0000664 0000000 0000000 00000000115 13613276011 0023702 0 ustar 00root root 0000000 0000000 #include
#include "boo.h++"
void b1()
{
t1();
acme::t1();
}
Bear-2.4.3/test/functional/cases/end-to-end/Input/lib/ 0000775 0000000 0000000 00000000000 13613276011 0022407 5 ustar 00root root 0000000 0000000 Bear-2.4.3/test/functional/cases/end-to-end/Input/lib/bar.cc 0000664 0000000 0000000 00000000077 13613276011 0023466 0 ustar 00root root 0000000 0000000 #include "foo.h"
namespace acme
{
void b1()
{
t1();
}
}
Bear-2.4.3/test/functional/cases/end-to-end/Input/lib/foo.cpp 0000664 0000000 0000000 00000000447 13613276011 0023703 0 ustar 00root root 0000000 0000000 #include "foo.h"
namespace acme
{
void t2(int i);
void t1()
{
for (int i = 0; i < 100; ++i)
{
if (98 == i)
{
t2(i);
break;
}
}
}
void t2(int i)
{
if (9 == i)
{
int k = i + 9;
--k;
return;
}
}
}
Bear-2.4.3/test/functional/cases/end-to-end/Input/lib/foo.h 0000664 0000000 0000000 00000000105 13613276011 0023337 0 ustar 00root root 0000000 0000000 #ifndef foo_h
#define foo_h
namespace acme
{
void t1();
}
#endif
Bear-2.4.3/test/functional/cases/end-to-end/Input/lib/lib.pro 0000664 0000000 0000000 00000000131 13613276011 0023672 0 ustar 00root root 0000000 0000000 TEMPLATE = lib
TARGET = some_lib
HEADERS += foo.h
SOURCES += foo.cpp
SOURCES += bar.cc
Bear-2.4.3/test/functional/cases/end-to-end/Input/qmake.pro 0000664 0000000 0000000 00000000100 13613276011 0023450 0 ustar 00root root 0000000 0000000 TEMPLATE = subdirs
CONFIG -= qt
SUBDIRS += lib
SUBDIRS += bin
Bear-2.4.3/test/functional/cases/end-to-end/check_files.py 0000664 0000000 0000000 00000001055 13613276011 0023354 0 ustar 00root root 0000000 0000000 #!/usr/bin/env python
import argparse
import json
import sys
import os.path
EXPECTED = frozenset(['far.cxx', 'bar.cc', 'foo.cpp', 'boo.c++'])
def main():
parser = argparse.ArgumentParser()
parser.add_argument('input', type=argparse.FileType('r'))
args = parser.parse_args()
# file is open, parse the json content
input = json.load(args.input)
# just get file names
result = set([os.path.basename(entry['file']) for entry in input])
return 0 if result == EXPECTED else 1
if __name__ == '__main__':
sys.exit(main())
Bear-2.4.3/test/functional/cases/end-to-end/qmake.ft 0000664 0000000 0000000 00000000372 13613276011 0022175 0 ustar 00root root 0000000 0000000 # REQUIRES: make,qmake,preload
# RUN: mkdir -p %T/qmake_build
# RUN: cd %T/qmake_build; %{qmake} ../../Input/qmake.pro
# RUN: cd %T/qmake_build; %{intercept-build} --cdb qmake.json %{make}
# RUN: %{python} %S/check_files.py %T/qmake_build/qmake.json
Bear-2.4.3/test/functional/cases/end-to-end/scons.ft 0000664 0000000 0000000 00000000311 13613276011 0022215 0 ustar 00root root 0000000 0000000 # REQUIRES: scons,preload
# RUN: mkdir -p %T/scons_build
# RUN: cd %T/scons_build; %{intercept-build} --cdb scons.json scons -Y ../../Input
# RUN: %{python} %S/check_files.py %T/scons_build/scons.json
Bear-2.4.3/test/functional/cases/exec_calls/ 0000775 0000000 0000000 00000000000 13613276011 0020712 5 ustar 00root root 0000000 0000000 Bear-2.4.3/test/functional/cases/exec_calls/CMakeLists.txt 0000664 0000000 0000000 00000001755 13613276011 0023462 0 ustar 00root root 0000000 0000000 project(exec C)
cmake_minimum_required(VERSION 2.8)
include(CheckCCompilerFlag)
check_c_compiler_flag("-std=c99" C99_SUPPORTED)
if (C99_SUPPORTED)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
endif()
include(CheckFunctionExists)
include(CheckSymbolExists)
add_definitions(-D_GNU_SOURCE)
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
check_function_exists(execve HAVE_EXECVE)
check_function_exists(execv HAVE_EXECV)
check_function_exists(execvpe HAVE_EXECVPE)
check_function_exists(execvp HAVE_EXECVP)
check_function_exists(execvP HAVE_EXECVP2)
check_function_exists(exect HAVE_EXECT)
check_function_exists(execl HAVE_EXECL)
check_function_exists(execlp HAVE_EXECLP)
check_function_exists(execle HAVE_EXECLE)
check_function_exists(posix_spawn HAVE_POSIX_SPAWN)
check_function_exists(posix_spawnp HAVE_POSIX_SPAWNP)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_executable(exec main.c)
Bear-2.4.3/test/functional/cases/exec_calls/config.h.in 0000664 0000000 0000000 00000000453 13613276011 0022737 0 ustar 00root root 0000000 0000000 #pragma once
#cmakedefine HAVE_EXECVE
#cmakedefine HAVE_EXECV
#cmakedefine HAVE_EXECVPE
#cmakedefine HAVE_EXECVP
#cmakedefine HAVE_EXECVP2
#cmakedefine HAVE_EXECT
#cmakedefine HAVE_EXECL
#cmakedefine HAVE_EXECLP
#cmakedefine HAVE_EXECLE
#cmakedefine HAVE_POSIX_SPAWN
#cmakedefine HAVE_POSIX_SPAWNP
Bear-2.4.3/test/functional/cases/exec_calls/main.c 0000664 0000000 0000000 00000022026 13613276011 0022004 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2012-2019 by László Nagy
This file is part of Bear.
Bear is a tool to generate compilation database for clang tooling.
Bear is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Bear is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include "config.h"
#include
#include
#include
#include
#include
#include
#if defined HAVE_POSIX_SPAWN || defined HAVE_POSIX_SPAWNP
#include
#endif
// ..:: environment access fixer - begin ::..
#ifdef HAVE_NSGETENVIRON
#include
#else
extern char **environ;
#endif
char **get_environ() {
#ifdef HAVE_NSGETENVIRON
return *_NSGetEnviron();
#else
return environ;
#endif
}
// ..:: environment access fixer - end ::..
// ..:: test fixtures - begin ::..
static char const *cwd = NULL;
static FILE *fd = NULL;
static int need_comma = 0;
void expected_out_open(const char *expected) {
cwd = getcwd(NULL, 0);
fd = fopen(expected, "w");
if (!fd) {
perror("fopen");
exit(EXIT_FAILURE);
}
fprintf(fd, "[\n");
need_comma = 0;
}
void expected_out_close() {
fprintf(fd, "]\n");
fclose(fd);
fd = NULL;
free((void *)cwd);
cwd = NULL;
}
void expected_out(const char * compiler, const char *file) {
if (need_comma)
fprintf(fd, ",\n");
else
need_comma = 1;
fprintf(fd, "{\n");
fprintf(fd, " \"directory\": \"%s\",\n", cwd);
fprintf(fd, " \"command\": \"%s -c %s\",\n", compiler, file);
fprintf(fd, " \"file\": \"%s\"\n", file);
fprintf(fd, "}\n");
}
void create_source(char *file) {
FILE *fd = fopen(file, "w");
if (!fd) {
perror("fopen");
exit(EXIT_FAILURE);
}
fprintf(fd, "typedef int score;\n");
fclose(fd);
}
typedef void (*exec_fun)();
void wait_for(pid_t child) {
int status;
if (-1 == waitpid(child, &status, 0)) {
perror("wait");
exit(EXIT_FAILURE);
}
if (WIFEXITED(status) ? WEXITSTATUS(status) : EXIT_FAILURE) {
fprintf(stderr, "children process has non zero exit code\n");
exit(EXIT_FAILURE);
}
}
#define FORK(FUNC) \
{ \
pid_t child = fork(); \
if (-1 == child) { \
perror("fork"); \
exit(EXIT_FAILURE); \
} else if (0 == child) { \
FUNC fprintf(stderr, "children process failed to exec\n"); \
exit(EXIT_FAILURE); \
} else { \
wait_for(child); \
} \
}
// ..:: test fixtures - end ::..
#ifdef HAVE_EXECV
void call_execv() {
fprintf(stderr, "%s\n", __PRETTY_FUNCTION__);
char *const file = "execv.c";
char *const compiler = "/usr/bin/cc";
char *const argv[] = {compiler, "-c", file, 0};
expected_out(compiler, file);
create_source(file);
FORK(execv(compiler, argv);)
}
#endif
#ifdef HAVE_EXECVE
void call_execve() {
fprintf(stderr, "%s\n", __PRETTY_FUNCTION__);
char *const file = "execve.c";
char *const compiler = "/usr/bin/cc";
char *const argv[] = {compiler, "-c", file, 0};
char *const envp[] = {"THIS=THAT", 0};
expected_out(compiler, file);
create_source(file);
FORK(execve(compiler, argv, envp);)
}
#endif
#ifdef HAVE_EXECVP
void call_execvp() {
fprintf(stderr, "%s\n", __PRETTY_FUNCTION__);
char *const file = "execvp.c";
char *const compiler = "cc";
char *const argv[] = {compiler, "-c", file, 0};
expected_out(compiler, file);
create_source(file);
FORK(execvp(compiler, argv);)
}
#endif
#ifdef HAVE_EXECVP2
void call_execvP() {
fprintf(stderr, "%s\n", __PRETTY_FUNCTION__);
char *const file = "execv_p.c";
char *const compiler = "cc";
char *const argv[] = {compiler, "-c", file, 0};
expected_out(compiler, file);
create_source(file);
FORK(execvP(compiler, _PATH_DEFPATH, argv);)
}
#endif
#ifdef HAVE_EXECVPE
void call_execvpe() {
fprintf(stderr, "%s\n", __PRETTY_FUNCTION__);
char *const file = "execvpe.c";
char *const compiler = "/usr/bin/cc";
char *const argv[] = {compiler, "-c", file, 0};
char *const envp[] = {"THIS=THAT", 0};
expected_out(compiler, file);
create_source(file);
FORK(execvpe(compiler, argv, envp);)
}
#endif
#ifdef HAVE_EXECT
void call_exect() {
fprintf(stderr, "%s\n", __PRETTY_FUNCTION__);
char *const file = "exect.c";
char *const compiler = "/usr/bin/cc";
char *const argv[] = {compiler, "-c", file, 0};
char *const envp[] = {"THIS=THAT", 0};
expected_out(compiler, file);
create_source(file);
FORK(exect(compiler, argv, envp);)
}
#endif
#ifdef HAVE_EXECL
void call_execl() {
fprintf(stderr, "%s\n", __PRETTY_FUNCTION__);
char *const file = "execl.c";
char *const compiler = "/usr/bin/cc";
expected_out("cc", file);
create_source(file);
FORK(execl(compiler, "cc", "-c", file, (char *)0);)
}
#endif
#ifdef HAVE_EXECLP
void call_execlp() {
fprintf(stderr, "%s\n", __PRETTY_FUNCTION__);
char *const file = "execlp.c";
char *const compiler = "cc";
expected_out(compiler, file);
create_source(file);
FORK(execlp(compiler, compiler, "-c", file, (char *)0);)
}
#endif
#ifdef HAVE_EXECLE
void call_execle() {
fprintf(stderr, "%s\n", __PRETTY_FUNCTION__);
char *const file = "execle.c";
char *const compiler = "/usr/bin/cc";
char *const envp[] = {"THIS=THAT", 0};
expected_out(compiler, file);
create_source(file);
FORK(execle(compiler, compiler, "-c", file, (char *)0, envp);)
}
#endif
#ifdef HAVE_POSIX_SPAWN
void call_posix_spawn() {
fprintf(stderr, "%s\n", __PRETTY_FUNCTION__);
char *const file = "posix_spawn.c";
char *const compiler = "cc";
char *const argv[] = {compiler, "-c", file, 0};
expected_out(compiler, file);
create_source(file);
pid_t child;
if (0 != posix_spawn(&child, "/usr/bin/cc", 0, 0, argv, get_environ())) {
perror("posix_spawn");
exit(EXIT_FAILURE);
}
wait_for(child);
}
#endif
#ifdef HAVE_POSIX_SPAWNP
void call_posix_spawnp() {
fprintf(stderr, "%s\n", __PRETTY_FUNCTION__);
char *const file = "posix_spawnp.c";
char *const compiler = "cc";
char *const argv[] = {compiler, "-c", file, 0};
expected_out(compiler, file);
create_source(file);
pid_t child;
if (0 != posix_spawnp(&child, "cc", 0, 0, argv, get_environ())) {
perror("posix_spawnp");
exit(EXIT_FAILURE);
}
wait_for(child);
}
#endif
int main(int argc, char *const argv[]) {
char *workdir = NULL;
char *output = NULL;
int c = 0;
opterr = 0;
while ((c = getopt (argc, argv, "C:o:")) != -1) {
switch (c) {
case 'C':
workdir = optarg;
break;
case 'o':
output = optarg;
break;
case '?':
if (optopt == 'C' || optopt == 'o')
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
else if (isprint (optopt))
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
else
fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt);
return 1;
default:
abort();
}
}
for (int index = optind; index < argc; ++index)
printf ("Non-option argument %s\n", argv[index]);
if (workdir != NULL) {
chdir(workdir);
}
expected_out_open(output);
#ifdef HAVE_EXECV
call_execv();
#endif
#ifdef HAVE_EXECVE
call_execve();
#endif
#ifdef HAVE_EXECVP
call_execvp();
#endif
#ifdef HAVE_EXECVP2
call_execvP();
#endif
#ifdef HAVE_EXECVPE
call_execvpe();
#endif
#ifdef HAVE_EXECT
call_exect();
#endif
#ifdef HAVE_EXECL
call_execl();
#endif
#ifdef HAVE_EXECLP
call_execlp();
#endif
#ifdef HAVE_EXECLE
call_execle();
#endif
#ifdef HAVE_POSIX_SPAWN
call_posix_spawn();
#endif
#ifdef HAVE_POSIX_SPAWNP
call_posix_spawnp();
#endif
expected_out_close();
return 0;
}
Bear-2.4.3/test/functional/cases/exec_calls/run_exec_test.ft 0000664 0000000 0000000 00000000276 13613276011 0024121 0 ustar 00root root 0000000 0000000 # REQUIRES: preload
# RUN: cmake -B%T -H%S
# RUN: make -C %T
# RUN: %{intercept-build} --cdb %T/result.json %T/exec -C %T -o expected.json
# RUN: %{cdb_diff} %T/result.json %T/expected.json
Bear-2.4.3/test/functional/cases/exit_code/ 0000775 0000000 0000000 00000000000 13613276011 0020553 5 ustar 00root root 0000000 0000000 Bear-2.4.3/test/functional/cases/exit_code/exit_code_for_empty.ft 0000664 0000000 0000000 00000000045 13613276011 0025134 0 ustar 00root root 0000000 0000000 # XFAIL: *
# RUN: %{intercept-build}
Bear-2.4.3/test/functional/cases/exit_code/exit_code_for_fail.ft 0000664 0000000 0000000 00000000153 13613276011 0024711 0 ustar 00root root 0000000 0000000 # XFAIL: *
# RUN: mkdir -p %T/exit_code_for_fail
# RUN: cd %T/exit_code_for_fail; %{intercept-build} false
Bear-2.4.3/test/functional/cases/exit_code/exit_code_for_help.ft 0000664 0000000 0000000 00000000041 13613276011 0024722 0 ustar 00root root 0000000 0000000 # RUN: %{intercept-build} --help
Bear-2.4.3/test/functional/cases/exit_code/exit_code_for_success.ft 0000664 0000000 0000000 00000000145 13613276011 0025447 0 ustar 00root root 0000000 0000000 # RUN: mkdir -p %T/exit_code_for_success
# RUN: cd %T/exit_code_for_success; %{intercept-build} true
Bear-2.4.3/test/functional/cases/fortran/ 0000775 0000000 0000000 00000000000 13613276011 0020263 5 ustar 00root root 0000000 0000000 Bear-2.4.3/test/functional/cases/fortran/compile_fortran.fts 0000664 0000000 0000000 00000001621 13613276011 0024164 0 ustar 00root root 0000000 0000000 #!/usr/bin/env bash
# REQUIRES: preload,make,fortran
# RUN: bash %s %T/fortran
# RUN: cd %T/fortran; %{intercept-build} --cdb preload.json make -C src
# RUN: cd %T/fortran; %{cdb_diff} preload.json expected.json
set -o errexit
set -o nounset
set -o xtrace
# the test creates a subdirectory inside output dir.
#
# ${root_dir}
# ├── expected.json
# └── src
# ├── Makefile
# └── main.c
root_dir=$1
mkdir -p "${root_dir}/src"
cat > "${root_dir}/src/ex.f95" << EOF
! Test Program
program first
print *,'This is my first program'
end program first
EOF
cat > ${root_dir}/src/Makefile << EOF
all:
gfortran ex.f95 -o ex
EOF
cat > "${root_dir}/expected.json" << EOF
[
{
"arguments": [
"gfortran",
"-c",
"-o",
"ex",
"ex.f95"
],
"directory": "${root_dir}/src",
"file": "ex.f95"
}
]
EOF
Bear-2.4.3/test/functional/cases/intercept/ 0000775 0000000 0000000 00000000000 13613276011 0020605 5 ustar 00root root 0000000 0000000 Bear-2.4.3/test/functional/cases/intercept/broken_build.fts 0000664 0000000 0000000 00000002334 13613276011 0023764 0 ustar 00root root 0000000 0000000 #!/usr/bin/env bash
# REQUIRES: preload
# RUN: bash %s %T/broken_build
# RUN: cd %T/broken_build; %{intercept-build} --cdb preload.json ./run.sh
# RUN: cd %T/broken_build; %{cdb_diff} preload.json expected.json
set -o errexit
set -o nounset
set -o xtrace
# the test creates a subdirectory inside output dir.
#
# ${root_dir}
# ├── run.sh
# ├── expected.json
# └── src
# └── broken.c
root_dir=$1
mkdir -p "${root_dir}/src"
cp "${test_input_dir}/compile_error.c" "${root_dir}/src/broken.c"
build_file="${root_dir}/run.sh"
cat > ${build_file} << EOF
#!/usr/bin/env bash
set -o nounset
set -o xtrace
\$CC -c -Dver=1 src/broken.c;
\$CXX -c -Dver=2 src/broken.c;
cd src
\$CC -c -Dver=3 broken.c;
\$CXX -c -Dver=4 broken.c;
true;
EOF
chmod +x ${build_file}
cat > "${root_dir}/expected.json" << EOF
[
{
"command": "cc -c -Dver=1 src/broken.c",
"directory": "${root_dir}",
"file": "src/broken.c"
}
,
{
"command": "c++ -c -Dver=2 src/broken.c",
"directory": "${root_dir}",
"file": "src/broken.c"
}
,
{
"command": "cc -c -Dver=3 broken.c",
"directory": "${root_dir}/src",
"file": "broken.c"
}
,
{
"command": "c++ -c -Dver=4 broken.c",
"directory": "${root_dir}/src",
"file": "broken.c"
}
]
EOF
Bear-2.4.3/test/functional/cases/intercept/clean_env_build.fts 0000664 0000000 0000000 00000002436 13613276011 0024441 0 ustar 00root root 0000000 0000000 #!/usr/bin/env bash
# REQUIRES: preload
# RUN: bash %s %T/clean_env_build
# RUN: cd %T/clean_env_build; %{intercept-build} --cdb result.json env - ./run.sh
# RUN: cd %T/clean_env_build; %{cdb_diff} result.json expected.json
set -o errexit
set -o nounset
set -o xtrace
# the test creates a subdirectory inside output dir.
#
# ${root_dir}
# ├── run.sh
# ├── expected.json
# └── src
# └── empty.c
clang=$(command -v ${CC})
clangpp=$(command -v ${CXX})
root_dir=$1
mkdir -p "${root_dir}/src"
touch "${root_dir}/src/empty.c"
build_file="${root_dir}/run.sh"
cat > ${build_file} << EOF
#!/usr/bin/env bash
set -o nounset
set -o xtrace
${clang} -c -Dver=1 src/empty.c;
${clangpp} -c -Dver=2 src/empty.c;
cd src
${clang} -c -Dver=3 empty.c;
${clangpp} -c -Dver=4 empty.c;
true;
EOF
chmod +x ${build_file}
cat > "${root_dir}/expected.json" << EOF
[
{
"command": "${clang} -c -Dver=1 src/empty.c",
"directory": "${root_dir}",
"file": "src/empty.c"
}
,
{
"command": "${clangpp} -c -Dver=2 src/empty.c",
"directory": "${root_dir}",
"file": "src/empty.c"
}
,
{
"command": "${clang} -c -Dver=3 empty.c",
"directory": "${root_dir}/src",
"file": "empty.c"
}
,
{
"command": "${clangpp} -c -Dver=4 empty.c",
"directory": "${root_dir}/src",
"file": "empty.c"
}
]
EOF
Bear-2.4.3/test/functional/cases/intercept/cuda/ 0000775 0000000 0000000 00000000000 13613276011 0021521 5 ustar 00root root 0000000 0000000 Bear-2.4.3/test/functional/cases/intercept/cuda/successful_build.fts 0000664 0000000 0000000 00000002033 13613276011 0025573 0 ustar 00root root 0000000 0000000 #!/usr/bin/env bash
# REQUIRES: preload,cuda
# RUN: bash %s %T/successful_build
# RUN: cd %T/successful_build; %{intercept-build} --cdb preload.json ./run.sh
# RUN: cd %T/successful_build; %{cdb_diff} --ignore-compiler preload.json expected.json
set -o errexit
set -o nounset
set -o xtrace
# the test creates a subdirectory inside output dir.
#
# ${root_dir}
# ├── run.sh
# ├── expected.json
# └── src
# └── empty.cu
root_dir=$1
mkdir -p "${root_dir}/src"
touch "${root_dir}/src/empty.cu"
build_file="${root_dir}/run.sh"
cat > ${build_file} << EOF
#!/usr/bin/env bash
set -o nounset
set -o xtrace
nvcc -c -Dver=1 src/empty.cu;
cd src
nvcc -c -Dver=2 empty.cu;
true;
EOF
chmod +x ${build_file}
cat > "${root_dir}/expected.json" << EOF
[
{
"arguments": [
"nvcc",
"-c",
"-Dver=1",
"src/empty.cu"
],
"directory": "${root_dir}",
"file": "src/empty.cu"
},
{
"arguments": [
"nvcc",
"-c",
"-Dver=2",
"empty.cu"
],
"directory": "${root_dir}/src",
"file": "empty.cu"
}
]
EOF
Bear-2.4.3/test/functional/cases/intercept/empty_argument.fts 0000664 0000000 0000000 00000001573 13613276011 0024371 0 ustar 00root root 0000000 0000000 #!/usr/bin/env bash
# REQUIRES: preload
# RUN: bash %s %T/empty_argument
# RUN: cd %T/empty_argument; %{intercept-build} --cdb preload.json ./run.sh
# RUN: cd %T/empty_argument; %{cdb_diff} preload.json expected.json
set -o errexit
set -o nounset
set -o xtrace
# the test creates a subdirectory inside output dir.
#
# ${root_dir}
# ├── run.sh
# ├── expected.json
# └── src
# └── empty.c
root_dir=$1
mkdir -p "${root_dir}/src"
touch "${root_dir}/src/empty.c"
build_file="${root_dir}/run.sh"
cat > ${build_file} << EOF
#!/usr/bin/env bash
set -o nounset
set -o xtrace
# empty argument for a command
true "" "";
# empty argument for a compiler
\$CC -c src/empty.c "";
true;
EOF
chmod +x ${build_file}
cat > "${root_dir}/expected.json" << EOF
[
{
"arguments": ["cc", "-c", "", "src/empty.c"],
"directory": "${root_dir}",
"file": "src/empty.c"
}
]
EOF
Bear-2.4.3/test/functional/cases/intercept/noisy_build.fts 0000664 0000000 0000000 00000002226 13613276011 0023645 0 ustar 00root root 0000000 0000000 #!/usr/bin/env bash
# REQUIRES: preload
# RUN: bash %s %T/noisy_build
# RUN: cd %T/noisy_build; %{intercept-build} --cdb preload.json ./run.sh
# RUN: cd %T/noisy_build; %{cdb_diff} preload.json expected.json
set -o errexit
set -o nounset
set -o xtrace
# the test creates a subdirectory inside output dir.
#
# ${root_dir}
# ├── run.sh
# ├── expected.json
# └── src
# └── empty.c
root_dir=$1
mkdir -p "${root_dir}/src"
touch "${root_dir}/src/empty.c"
build_file="${root_dir}/run.sh"
cat > ${build_file} << EOF
#!/usr/bin/env bash
set -o nounset
set -o xtrace
echo "hi there \"people\""
echo "hi again"
echo "מה שלומך?"
echo "Как дела?"
echo "[1mThis line might cause an exception in json load[0m"
\$CC -c -Dver=1 src/empty.c &
\$CXX -c -Dver=2 src/empty.c &
bash -c "\
mkdir -p ./this/that; \
touch ./this/that; \
rm -rf ./this;"
wait
true;
EOF
chmod +x ${build_file}
cat > "${root_dir}/expected.json" << EOF
[
{
"command": "cc -c -Dver=1 src/empty.c",
"directory": "${root_dir}",
"file": "src/empty.c"
}
,
{
"command": "c++ -c -Dver=2 src/empty.c",
"directory": "${root_dir}",
"file": "src/empty.c"
}
]
EOF
Bear-2.4.3/test/functional/cases/intercept/parallel_build.fts 0000664 0000000 0000000 00000002276 13613276011 0024305 0 ustar 00root root 0000000 0000000 #!/usr/bin/env bash
# REQUIRES: preload
# RUN: bash %s %T/parallel_build
# RUN: cd %T/parallel_build; %{intercept-build} --cdb preload.json ./run.sh
# RUN: cd %T/parallel_build; %{cdb_diff} preload.json expected.json
set -o errexit
set -o nounset
set -o xtrace
# the test creates a subdirectory inside output dir.
#
# ${root_dir}
# ├── run.sh
# ├── expected.json
# └── src
# └── empty.c
root_dir=$1
mkdir -p "${root_dir}/src"
touch "${root_dir}/src/empty.c"
build_file="${root_dir}/run.sh"
cat > ${build_file} << EOF
#!/usr/bin/env bash
set -o nounset
set -o xtrace
\$CC -c -Dver=1 src/empty.c &
\$CXX -c -Dver=2 src/empty.c &
cd src
\$CC -c -Dver=3 empty.c &
\$CXX -c -Dver=4 empty.c &
wait
true;
EOF
chmod +x ${build_file}
cat > "${root_dir}/expected.json" << EOF
[
{
"command": "cc -c -Dver=1 src/empty.c",
"directory": "${root_dir}",
"file": "src/empty.c"
}
,
{
"command": "c++ -c -Dver=2 src/empty.c",
"directory": "${root_dir}",
"file": "src/empty.c"
}
,
{
"command": "cc -c -Dver=3 empty.c",
"directory": "${root_dir}/src",
"file": "empty.c"
}
,
{
"command": "c++ -c -Dver=4 empty.c",
"directory": "${root_dir}/src",
"file": "empty.c"
}
]
EOF
Bear-2.4.3/test/functional/cases/intercept/successful_build.fts 0000664 0000000 0000000 00000002271 13613276011 0024663 0 ustar 00root root 0000000 0000000 #!/usr/bin/env bash
# REQUIRES: preload
# RUN: bash %s %T/successful_build
# RUN: cd %T/successful_build; %{intercept-build} --cdb preload.json ./run.sh
# RUN: cd %T/successful_build; %{cdb_diff} preload.json expected.json
set -o errexit
set -o nounset
set -o xtrace
# the test creates a subdirectory inside output dir.
#
# ${root_dir}
# ├── run.sh
# ├── expected.json
# └── src
# └── empty.c
root_dir=$1
mkdir -p "${root_dir}/src"
touch "${root_dir}/src/empty.c"
build_file="${root_dir}/run.sh"
cat > ${build_file} << EOF
#!/usr/bin/env bash
set -o nounset
set -o xtrace
\$CC -c -Dver=1 src/empty.c;
\$CXX -c -Dver=2 src/empty.c;
cd src
\$CC -c -Dver=3 empty.c;
\$CXX -c -Dver=4 empty.c;
true;
EOF
chmod +x ${build_file}
cat > "${root_dir}/expected.json" << EOF
[
{
"command": "cc -c -Dver=1 src/empty.c",
"directory": "${root_dir}",
"file": "src/empty.c"
}
,
{
"command": "c++ -c -Dver=2 src/empty.c",
"directory": "${root_dir}",
"file": "src/empty.c"
}
,
{
"command": "cc -c -Dver=3 empty.c",
"directory": "${root_dir}/src",
"file": "empty.c"
}
,
{
"command": "c++ -c -Dver=4 empty.c",
"directory": "${root_dir}/src",
"file": "empty.c"
}
]
EOF
Bear-2.4.3/test/functional/cases/intercept/unkown_compiler_recognised.fts 0000664 0000000 0000000 00000004404 13613276011 0026742 0 ustar 00root root 0000000 0000000 #!/usr/bin/env bash
# REQUIRES: preload
# RUN: bash %s %T/unkown_compiler_recognised
# RUN: cd %T/unkown_compiler_recognised; %{intercept-build} --use-cc=%T/unkown_compiler_recognised/wrapper --use-c++=%T/unkown_compiler_recognised/wrapper++ --cdb wrapper.json ./run.sh
# RUN: cd %T/unkown_compiler_recognised; %{cdb_diff} wrapper.json expected.json
# RUN: cd %T/unkown_compiler_recognised; %{intercept-build} --use-only --use-cc=%T/unkown_compiler_recognised/wrapper --use-c++=%T/unkown_compiler_recognised/wrapper++ --cdb wrapper_only.json ./run.sh
# RUN: cd %T/unkown_compiler_recognised; %{cdb_diff} wrapper_only.json expected_wrapper_only.json
set -o errexit
set -o nounset
set -o xtrace
# the test creates a subdirectory inside output dir.
#
# ${root_dir}
# ├── wrapper
# ├── wrapper++
# ├── run.sh
# ├── expected.json
# └── src
# └── empty.c
clang="clang"
clangpp="clang++"
root_dir=$1
mkdir -p "${root_dir}/src"
touch "${root_dir}/src/empty.c"
wrapper_file="${root_dir}/wrapper"
cat > ${wrapper_file} << EOF
#!/usr/bin/env bash
true
EOF
chmod +x ${wrapper_file}
wrapperxx_file="${root_dir}/wrapper++"
cat > ${wrapperxx_file} << EOF
#!/usr/bin/env bash
true
EOF
chmod +x ${wrapperxx_file}
build_file="${root_dir}/run.sh"
cat > ${build_file} << EOF
#!/usr/bin/env bash
set -o nounset
set -o xtrace
${clang} -c -Dver=1 src/empty.c;
${clangpp} -c -Dver=2 src/empty.c;
cd src
${wrapper_file} -c -Dver=3 empty.c;
${wrapperxx_file} -c -Dver=4 empty.c;
EOF
chmod +x ${build_file}
cat > "${root_dir}/expected.json" << EOF
[
{
"command": "${clang} -c -Dver=1 src/empty.c",
"directory": "${root_dir}",
"file": "src/empty.c"
}
,
{
"command": "${clangpp} -c -Dver=2 src/empty.c",
"directory": "${root_dir}",
"file": "src/empty.c"
}
,
{
"command": "${wrapper_file} -c -Dver=3 empty.c",
"directory": "${root_dir}/src",
"file": "empty.c"
}
,
{
"command": "${wrapperxx_file} -c -Dver=4 empty.c",
"directory": "${root_dir}/src",
"file": "empty.c"
}
]
EOF
cat > "${root_dir}/expected_wrapper_only.json" << EOF
[
{
"command": "${wrapper_file} -c -Dver=3 empty.c",
"directory": "${root_dir}/src",
"file": "empty.c"
}
,
{
"command": "${wrapperxx_file} -c -Dver=4 empty.c",
"directory": "${root_dir}/src",
"file": "empty.c"
}
]
EOF
Bear-2.4.3/test/functional/cases/result/ 0000775 0000000 0000000 00000000000 13613276011 0020126 5 ustar 00root root 0000000 0000000 Bear-2.4.3/test/functional/cases/result/assembly_sources.fts 0000664 0000000 0000000 00000002170 13613276011 0024226 0 ustar 00root root 0000000 0000000 #!/usr/bin/env bash
# REQUIRES: preload
# RUN: bash %s %T/assembly_sources
# RUN: cd %T/assembly_sources; %{intercept-build} --cdb preload.json make -C src
# RUN: cd %T/assembly_sources; %{cdb_diff} preload.json expected.json
set -o errexit
set -o nounset
set -o xtrace
# the test creates a subdirectory inside output dir.
#
# ${root_dir}
# ├── expected.json
# └── src
# ├── Makefile
# └── main.c
root_dir=$1
mkdir -p "${root_dir}/src"
cp "${test_input_dir}/main.c" "${root_dir}/src/main.c"
cat > ${root_dir}/src/Makefile << EOF
main: main.o
\$(CC) $< -o \$@
main.s: main.c
\$(CC) -S \$< -o \$@
main.o: main.s
\$(CC) -c \$< -o \$@
EOF
cat > "${root_dir}/expected.json" << EOF
[
{
"arguments": [
"cc",
"-c",
"-o",
"main.o",
"main.s"
],
"directory": "${root_dir}/src",
"file": "main.s"
},
{
"arguments": [
"cc",
"-S",
"-o",
"main.s",
"main.c"
],
"directory": "${root_dir}/src",
"file": "main.c"
}
]
EOF
Bear-2.4.3/test/functional/cases/result/define_with_escaped_quote.fts 0000664 0000000 0000000 00000002024 13613276011 0026030 0 ustar 00root root 0000000 0000000 #!/usr/bin/env bash
# REQUIRES: preload
# RUN: bash %s %T/define_with_escaped_quote
# RUN: cd %T/define_with_escaped_quote; %{intercept-build} --cdb result.json ./run.sh
# RUN: cd %T/define_with_escaped_quote; %{cdb_diff} result.json expected.json
set -o errexit
set -o nounset
set -o xtrace
# the test creates a subdirectory inside output dir.
#
# ${root_dir}
# ├── run.sh
# ├── expected.json
# └── src
# └── main.cpp
root_dir=$1
mkdir -p "${root_dir}/src"
cat > "${root_dir}/src/main.cpp" << EOF
#include
void foo(void) {
printf(MESSAGE);
}
int main() {
foo();
}
EOF
build_file="${root_dir}/run.sh"
cat > ${build_file} << EOF
#!/usr/bin/env bash
set -o nounset
set -o xtrace
\$CXX '-DMESSAGE="Hello World\\n"' -o hello src/main.cpp
EOF
chmod +x ${build_file}
cat > "${root_dir}/expected.json" << EOF
[
{
"arguments": ["c++", "-c", "-DMESSAGE=\\"Hello World\\\\n\\"", "-o", "hello", "src/main.cpp"],
"directory": "${root_dir}",
"file": "src/main.cpp"
}
]
EOF
Bear-2.4.3/test/functional/cases/result/define_with_nonutf_encode.fts 0000664 0000000 0000000 00000000751 13613276011 0026042 0 ustar 00root root 0000000 0000000 #!/usr/bin/env bash
# REQUIRES: preload
# RUN: bash %s %T/define_with_nonutf_encode
# RUN: cd %T/define_with_nonutf_encode; %{intercept-build} --cdb result.json ./run.sh
set -o errexit
set -o nounset
set -o xtrace
# the test creates a subdirectory inside output dir.
#
# ${root_dir}
# +-- run.sh
root_dir=$1
mkdir -p "${root_dir}"
build_file="${root_dir}/run.sh"
cat > ${build_file} << EOF
#!/usr/bin/env bash
set -o nounset
set -o xtrace
echo "©";
true;
EOF
chmod +x ${build_file}
Bear-2.4.3/test/functional/cases/result/define_with_quote.fts 0000664 0000000 0000000 00000001774 13613276011 0024357 0 ustar 00root root 0000000 0000000 #!/usr/bin/env bash
# REQUIRES: preload
# RUN: bash %s %T/define_with_quote
# RUN: cd %T/define_with_quote; %{intercept-build} --cdb result.json ./run.sh
# RUN: cd %T/define_with_quote; %{cdb_diff} result.json expected.json
set -o errexit
set -o nounset
set -o xtrace
# the test creates a subdirectory inside output dir.
#
# ${root_dir}
# ├── run.sh
# ├── expected.json
# └── src
# └── main.cpp
root_dir=$1
mkdir -p "${root_dir}/src"
cat > "${root_dir}/src/main.cpp" << EOF
#include
EXPORT void foo(void) {
printf("Hello world!\n");
}
int main() {
foo();
}
EOF
build_file="${root_dir}/run.sh"
cat > ${build_file} << EOF
#!/usr/bin/env bash
set -o nounset
set -o xtrace
\$CXX -DEXPORT="extern \"C\"" -o hello src/main.cpp
EOF
chmod +x ${build_file}
cat > "${root_dir}/expected.json" << EOF
[
{
"arguments": ["c++", "-c", "-DEXPORT=extern \"C\"", "-o", "hello", "src/main.cpp"],
"directory": "${root_dir}",
"file": "src/main.cpp"
}
]
EOF
Bear-2.4.3/test/functional/cases/result/define_with_unicode.fts 0000664 0000000 0000000 00000002467 13613276011 0024650 0 ustar 00root root 0000000 0000000 #!/usr/bin/env bash
# REQUIRES: preload
# RUN: bash %s %T/define_with_unicode
# RUN: cd %T/define_with_unicode; %{intercept-build} --cdb result.json ./run.sh
# RUN: cd %T/define_with_unicode; %{cdb_diff} result.json expected.json
set -o errexit
set -o nounset
set -o xtrace
# the test creates a subdirectory inside output dir.
#
# ${root_dir}
# ├── run.sh
# ├── expected.json
# └── src
# └── main.c
root_dir=$1
mkdir -p "${root_dir}/src"
cat > "${root_dir}/src/main.c" << EOF
#include
static char const * const message = "MESSAGE";
int main(void) {
printf("%s\n", message);
return 0;
}
EOF
build_file="${root_dir}/run.sh"
cat > ${build_file} << EOF
#!/usr/bin/env bash
set -o nounset
set -o xtrace
\$CC -DMESSAGE="מה שלומך?" -o hello src/main.c
\$CC -DMESSAGE="Как дела?" -o hello src/main.c
EOF
chmod +x ${build_file}
cat > "${root_dir}/expected.json" << EOF
[
{
"arguments": ["cc", "-c", "-DMESSAGE=\u041a\u0430\u043a \u0434\u0435\u043b\u0430?", "-o", "hello", "src/main.c"],
"directory": "${root_dir}",
"file": "src/main.c"
},
{
"arguments": ["cc", "-c", "-DMESSAGE=\u05de\u05d4 \u05e9\u05dc\u05d5\u05de\u05da?", "-o", "hello", "src/main.c"],
"directory": "${root_dir}",
"file": "src/main.c"
}
]
EOF
Bear-2.4.3/test/functional/cases/result/directory_path_absolute.fts 0000664 0000000 0000000 00000003505 13613276011 0025565 0 ustar 00root root 0000000 0000000 #!/usr/bin/env bash
# REQUIRES: preload
# RUN: bash %s %T/directory_path_absolute
# RUN: cd %T/directory_path_absolute; %{intercept-build} --cdb preload.json ./run.sh
# RUN: cd %T/directory_path_absolute; %{python} is_dir.py preload.json
# RUN: cd %T/directory_path_absolute; %{python} is_abs.py preload.json
set -o errexit
set -o nounset
set -o xtrace
# the test creates a subdirectory inside output dir.
#
# ${root_dir}
# ├── run.sh
# ├── is_dir.py
# ├── is_abs.py
# └── src
# └── empty.c
root_dir=$1
mkdir -p "${root_dir}/src"
touch "${root_dir}/src/empty.c"
build_file="${root_dir}/run.sh"
cat > ${build_file} << EOF
#!/usr/bin/env bash
set -o nounset
set -o xtrace
\$CC -c -Dver=1 src/empty.c;
\$CXX -c -Dver=2 src/empty.c;
cd src
\$CC -c -Dver=1 empty.c;
\$CXX -c -Dver=2 empty.c;
EOF
chmod +x ${build_file}
cat > "${root_dir}/is_dir.py" << EOF
#!/usr/bin/env python
import argparse
import json
import sys
import os.path
def main():
parser = argparse.ArgumentParser()
parser.add_argument('input', type=argparse.FileType('r'))
args = parser.parse_args()
# file is open, parse the json content
input = json.load(args.input)
# just get directory paths
return [os.path.isdir(entry['directory']) for entry in input].count(False)
if __name__ == '__main__':
sys.exit(main())
EOF
cat > "${root_dir}/is_abs.py" << EOF
#!/usr/bin/env python
import argparse
import json
import sys
import os.path
def main():
parser = argparse.ArgumentParser()
parser.add_argument('input', type=argparse.FileType('r'))
args = parser.parse_args()
# file is open, parse the json content
input = json.load(args.input)
# just get directory paths
return [os.path.isabs(entry['directory']) for entry in input].count(False)
if __name__ == '__main__':
sys.exit(main())
EOF
Bear-2.4.3/test/functional/cases/result/duplicate_entries.fts 0000664 0000000 0000000 00000001761 13613276011 0024354 0 ustar 00root root 0000000 0000000 #!/usr/bin/env bash
# REQUIRES: preload
# RUN: bash %s %T/duplicate_entries
# RUN: cd %T/duplicate_entries; %{intercept-build} --cdb preload.json ./run.sh
# RUN: cd %T/duplicate_entries; %{cdb_diff} preload.json expected.json
set -o errexit
set -o nounset
set -o xtrace
# the test creates a subdirectory inside output dir.
#
# ${root_dir}
# ├── run.sh
# ├── expected.json
# └── src
# └── empty.c
root_dir=$1
mkdir -p "${root_dir}/src"
touch "${root_dir}/src/empty.c"
build_file="${root_dir}/run.sh"
cat > ${build_file} << EOF
#!/usr/bin/env bash
set -o nounset
set -o xtrace
\$CC -c -Dver=1 src/empty.c;
\$CXX -c -Dver=2 src/empty.c;
\$CC -c -Dver=1 src/empty.c;
\$CXX -c -Dver=2 src/empty.c;
EOF
chmod +x ${build_file}
cat > "${root_dir}/expected.json" << EOF
[
{
"command": "cc -c -Dver=1 src/empty.c",
"directory": "${root_dir}",
"file": "src/empty.c"
}
,
{
"command": "c++ -c -Dver=2 src/empty.c",
"directory": "${root_dir}",
"file": "src/empty.c"
}
]
EOF
Bear-2.4.3/test/functional/cases/result/exclude.fts 0000664 0000000 0000000 00000002321 13613276011 0022273 0 ustar 00root root 0000000 0000000 #!/usr/bin/env bash
# REQUIRES: preload
# RUN: bash %s %T/exclude
# RUN: cd %T/exclude; %{intercept-build} --cdb preload.json --include src/target --exclude src/target/test ./run.sh
# RUN: cd %T/exclude; %{cdb_diff} preload.json expected.json
set -o errexit
set -o nounset
set -o xtrace
# the test creates a subdirectory inside output dir.
#
# ${root_dir}
# ├── run.sh
# ├── expected.json
# └── src
# ├── empty.c
# └── target
# ├── empty.c
# └── test
# └── empty.c
root_dir=$1
mkdir -p "${root_dir}/src"
touch "${root_dir}/src/empty.c"
mkdir -p "${root_dir}/src/target"
touch "${root_dir}/src/target/empty.c"
mkdir -p "${root_dir}/src/target/test"
touch "${root_dir}/src/target/test/empty.c"
build_file="${root_dir}/run.sh"
cat > ${build_file} << EOF
#!/usr/bin/env bash
set -o nounset
set -o xtrace
\$CC -c -o src/empty.o src/empty.c;
\$CC -c -o src/target/empty.o src/target/empty.c;
\$CC -c -o src/target/test/empty.o src/target/test/empty.c;
EOF
chmod +x ${build_file}
cat > "${root_dir}/expected.json" << EOF
[
{
"command": "cc -c -o src/target/empty.o src/target/empty.c",
"directory": "${root_dir}",
"file": "src/target/empty.c"
}
]
EOF
Bear-2.4.3/test/functional/cases/result/extend_build.fts 0000664 0000000 0000000 00000004200 13613276011 0023306 0 ustar 00root root 0000000 0000000 #!/usr/bin/env bash
# REQUIRES: preload
# RUN: bash %s %T/extend_build
# RUN: cd %T/extend_build; %{intercept-build} --cdb result.json ./run-one.sh
# RUN: cd %T/extend_build; %{cdb_diff} result.json one.json
# RUN: cd %T/extend_build; %{intercept-build} --cdb result.json ./run-two.sh
# RUN: cd %T/extend_build; %{cdb_diff} result.json two.json
# RUN: cd %T/extend_build; %{intercept-build} --cdb result.json --append ./run-one.sh
# RUN: cd %T/extend_build; %{cdb_diff} result.json sum.json
set -o errexit
set -o nounset
set -o xtrace
# the test creates a subdirectory inside output dir.
#
# ${root_dir}
# ├── run-one.sh
# ├── run-two.sh
# ├── one.json
# ├── two.json
# ├── sum.json
# └── src
# └── empty.c
root_dir=$1
mkdir -p "${root_dir}/src"
touch "${root_dir}/src/empty.c"
build_file="${root_dir}/run-one.sh"
cat > ${build_file} << EOF
#!/usr/bin/env bash
set -o nounset
set -o xtrace
\$CC -c -Dver=1 src/empty.c;
\$CXX -c -Dver=2 src/empty.c;
true;
EOF
chmod +x ${build_file}
build_file="${root_dir}/run-two.sh"
cat > ${build_file} << EOF
#!/usr/bin/env bash
set -o nounset
set -o xtrace
cd src
\$CC -c -Dver=3 empty.c;
\$CXX -c -Dver=4 empty.c;
true;
EOF
chmod +x ${build_file}
cat > "${root_dir}/one.json" << EOF
[
{
"command": "cc -c -Dver=1 src/empty.c",
"directory": "${root_dir}",
"file": "src/empty.c"
}
,
{
"command": "c++ -c -Dver=2 src/empty.c",
"directory": "${root_dir}",
"file": "src/empty.c"
}
]
EOF
cat > "${root_dir}/two.json" << EOF
[
{
"command": "cc -c -Dver=3 empty.c",
"directory": "${root_dir}/src",
"file": "empty.c"
}
,
{
"command": "c++ -c -Dver=4 empty.c",
"directory": "${root_dir}/src",
"file": "empty.c"
}
]
EOF
cat > "${root_dir}/sum.json" << EOF
[
{
"command": "cc -c -Dver=1 src/empty.c",
"directory": "${root_dir}",
"file": "src/empty.c"
}
,
{
"command": "c++ -c -Dver=2 src/empty.c",
"directory": "${root_dir}",
"file": "src/empty.c"
}
,
{
"command": "cc -c -Dver=3 empty.c",
"directory": "${root_dir}/src",
"file": "empty.c"
}
,
{
"command": "c++ -c -Dver=4 empty.c",
"directory": "${root_dir}/src",
"file": "empty.c"
}
]
EOF
Bear-2.4.3/test/functional/cases/result/extend_build_with_missing.fts 0000664 0000000 0000000 00000003307 13613276011 0026101 0 ustar 00root root 0000000 0000000 #!/usr/bin/env bash
# REQUIRES: preload
# RUN: bash %s %T/extend_build_with_missing
# RUN: cd %T/extend_build_with_missing; %{intercept-build} --cdb result.json ./run-one.sh
# RUN: cd %T/extend_build_with_missing; %{cdb_diff} result.json one.json
# RUN: cd %T/extend_build_with_missing; rm src/one.c
# RUN: cd %T/extend_build_with_missing; %{intercept-build} --cdb result.json --append ./run-two.sh
# RUN: cd %T/extend_build_with_missing; %{cdb_diff} result.json two.json
set -o errexit
set -o nounset
set -o xtrace
# the test creates a subdirectory inside output dir.
#
# ${root_dir}
# ├── run-one.sh
# ├── run-two.sh
# ├── one.json
# ├── two.json
# ├── sum.json
# └── src
# ├── one.c
# └── two.c
root_dir=$1
mkdir -p "${root_dir}/src"
touch "${root_dir}/src/one.c"
touch "${root_dir}/src/two.c"
build_file="${root_dir}/run-one.sh"
cat > ${build_file} << EOF
#!/usr/bin/env bash
set -o nounset
set -o xtrace
\$CC -c -Dver=1 src/one.c;
\$CXX -c -Dver=2 src/one.c;
true;
EOF
chmod +x ${build_file}
build_file="${root_dir}/run-two.sh"
cat > ${build_file} << EOF
#!/usr/bin/env bash
set -o nounset
set -o xtrace
cd src
\$CC -c -Dver=3 two.c;
\$CXX -c -Dver=4 two.c;
true;
EOF
chmod +x ${build_file}
cat > "${root_dir}/one.json" << EOF
[
{
"command": "cc -c -Dver=1 src/one.c",
"directory": "${root_dir}",
"file": "src/one.c"
}
,
{
"command": "c++ -c -Dver=2 src/one.c",
"directory": "${root_dir}",
"file": "src/one.c"
}
]
EOF
cat > "${root_dir}/two.json" << EOF
[
{
"command": "cc -c -Dver=3 two.c",
"directory": "${root_dir}/src",
"file": "two.c"
}
,
{
"command": "c++ -c -Dver=4 two.c",
"directory": "${root_dir}/src",
"file": "two.c"
}
]
EOF
Bear-2.4.3/test/functional/cases/result/field_output.fts 0000664 0000000 0000000 00000002117 13613276011 0023350 0 ustar 00root root 0000000 0000000 #!/usr/bin/env bash
# REQUIRES: preload
# RUN: bash %s %T/field_output
# RUN: cd %T/field_output; %{intercept-build} --cdb preload.json --field-output ./run.sh
# RUN: cd %T/field_output; %{cdb_diff} preload.json expected.json
set -o errexit
set -o nounset
set -o xtrace
# the test creates a subdirectory inside output dir.
#
# ${root_dir}
# ├── run.sh
# ├── expected.json
# └── src
# └── empty.c
root_dir=$1
mkdir -p "${root_dir}/src"
touch "${root_dir}/src/empty.c"
build_file="${root_dir}/run.sh"
cat > ${build_file} << EOF
#!/usr/bin/env bash
set -o nounset
set -o xtrace
\$CC -c -Dver=one -o src/one.o src/empty.c;
\$CC -c -Dver=two -o src/two.o src/empty.c;
\$CC -c -Dver=two -o src/three.o src/empty.c;
EOF
chmod +x ${build_file}
cat > "${root_dir}/expected.json" << EOF
[
{
"command": "cc -c -Dver=one -o src/one.o src/empty.c",
"directory": "${root_dir}",
"file": "src/empty.c",
"output": "src/one.o"
}
,
{
"command": "cc -c -Dver=two -o src/two.o src/empty.c",
"directory": "${root_dir}",
"file": "src/empty.c",
"output": "src/two.o"
}
]
EOF
Bear-2.4.3/test/functional/cases/result/file_path_relative.fts 0000664 0000000 0000000 00000003532 13613276011 0024475 0 ustar 00root root 0000000 0000000 #!/usr/bin/env bash
# REQUIRES: preload
# RUN: bash %s %T/file_path_relative
# RUN: cd %T/file_path_relative; %{intercept-build} --cdb preload.json ./run.sh
# RUN: cd %T/file_path_relative; %{python} is_file.py preload.json
# RUN: cd %T/file_path_relative; %{python} is_rel.py preload.json
set -o errexit
set -o nounset
set -o xtrace
# the test creates a subdirectory inside output dir.
#
# ${root_dir}
# ├── run.sh
# ├── is_file.py
# ├── is_rel.py
# └── src
# └── empty.c
root_dir=$1
mkdir -p "${root_dir}/src"
touch "${root_dir}/src/empty.c"
build_file="${root_dir}/run.sh"
cat > ${build_file} << EOF
#!/usr/bin/env bash
set -o nounset
set -o xtrace
\$CC -c -Dver=1 src/empty.c;
\$CXX -c -Dver=2 src/empty.c;
cd src
\$CC -c -Dver=1 empty.c;
\$CXX -c -Dver=2 empty.c;
EOF
chmod +x ${build_file}
cat > "${root_dir}/is_file.py" << EOF
#!/usr/bin/env python
import argparse
import json
import sys
import os.path
def main():
parser = argparse.ArgumentParser()
parser.add_argument('input', type=argparse.FileType('r'))
args = parser.parse_args()
# file is open, parse the json content
input = json.load(args.input)
# just get directory paths
return [os.path.isfile(os.path.join(entry['directory'], entry['file'])) \
for entry in input].count(False)
if __name__ == '__main__':
sys.exit(main())
EOF
cat > "${root_dir}/is_rel.py" << EOF
#!/usr/bin/env python
import argparse
import json
import sys
import os.path
def main():
parser = argparse.ArgumentParser()
parser.add_argument('input', type=argparse.FileType('r'))
args = parser.parse_args()
# file is open, parse the json content
input = json.load(args.input)
# just get directory paths
return [os.path.isabs(entry['file']) for entry in input].count(True)
if __name__ == '__main__':
sys.exit(main())
EOF
Bear-2.4.3/test/functional/cases/result/flags_filtered.fts 0000664 0000000 0000000 00000004247 13613276011 0023625 0 ustar 00root root 0000000 0000000 #!/usr/bin/env bash
# REQUIRES: preload
# RUN: bash %s %T/flags_filtered
# RUN: cd %T/flags_filtered; %{intercept-build} --cdb result.json ./run.sh
# RUN: cd %T/flags_filtered; %{cdb_diff} result.json expected.json
set -o errexit
set -o nounset
set -o xtrace
# the test creates a subdirectory inside output dir.
#
# ${root_dir}
# ├── run.sh
# ├── expected.json
# └── src
# ├── lib.c
# └── main.c
root_dir=$1
mkdir -p "${root_dir}/src"
cp "${test_input_dir}/main.c" "${root_dir}/src/main.c"
cat > "${root_dir}/src/lib.c" << EOF
int foo() { return 2; }
EOF
# set up platform specific linker options
PREFIX="fooflag"
if [ $(uname | grep -i "darwin") ]; then
LD_FLAGS="-o lib${PREFIX}.dylib -dynamiclib -install_name @rpath/${PREFIX}"
else
LD_FLAGS="-o lib${PREFIX}.so -shared -Wl,-soname,${PREFIX}"
fi
build_file="${root_dir}/run.sh"
cat > ${build_file} << EOF
#!/usr/bin/env bash
set -o nounset
set -o xtrace
# set up unique names for this test
cd src
# non compilation calls shall not be in the result
\$CC -### -c main.c 2> /dev/null
\$CC -E -o "\$\$.i" main.c
\$CC -c -o "\$\$.d" -M main.c
\$CC -c -o "\$\$.d" -MM main.c
# preprocessor flags shall be filtered
\$CC -c -o one.o -fpic -MD -MT target -MF one.d -Dver=one lib.c
\$CC -c -o two.o -fpic -MMD -MQ target -MF two.d -Dver=two lib.c
# linking shall not in the result
\$CC ${LD_FLAGS} one.o two.o
# linker flags shall be filtered
\$CC -o "${PREFIX}_one" "-l${PREFIX}" -L. -Dver=three main.c
\$CC -o "${PREFIX}_two" -l "${PREFIX}" -L . -Dver=four main.c
true;
EOF
chmod +x ${build_file}
cat > "${root_dir}/expected.json" << EOF
[
{
"command": "cc -c -fpic -Dver=one -o one.o lib.c",
"directory": "${root_dir}/src",
"file": "lib.c"
},
{
"command": "cc -c -fpic -Dver=two -o two.o lib.c",
"directory": "${root_dir}/src",
"file": "lib.c"
},
{
"command": "cc -c -Dver=three -o fooflag_one main.c",
"directory": "${root_dir}/src",
"file": "main.c"
},
{
"command": "cc -c -Dver=four -o fooflag_two main.c",
"directory": "${root_dir}/src",
"file": "main.c"
}
]
EOF
Bear-2.4.3/test/functional/cases/result/multiple_source_build.fts 0000664 0000000 0000000 00000002217 13613276011 0025240 0 ustar 00root root 0000000 0000000 #!/usr/bin/env bash
# REQUIRES: preload
# RUN: bash %s %T/multiple_source_build
# RUN: cd %T/multiple_source_build; %{intercept-build} --cdb result.json ./run.sh
# RUN: cd %T/multiple_source_build; %{cdb_diff} result.json expected.json
set -o errexit
set -o nounset
set -o xtrace
# the test creates a subdirectory inside output dir.
#
# ${root_dir}
# ├── run.sh
# ├── expected.json
# └── src
# ├── main.c
# ├── one.c
# └── two.c
root_dir=$1
mkdir -p "${root_dir}/src"
touch "${root_dir}/src/one.c"
touch "${root_dir}/src/two.c"
cp "${test_input_dir}/main.c" "${root_dir}/src/main.c"
build_file="${root_dir}/run.sh"
cat > ${build_file} << EOF
#!/usr/bin/env bash
set -o nounset
set -o xtrace
\$CC -Dver=1 src/one.c src/two.c src/main.c;
true;
EOF
chmod +x ${build_file}
cat > "${root_dir}/expected.json" << EOF
[
{
"command": "cc -c -Dver=1 src/one.c",
"directory": "${root_dir}",
"file": "src/one.c"
}
,
{
"command": "cc -c -Dver=1 src/two.c",
"directory": "${root_dir}",
"file": "src/two.c"
}
,
{
"command": "cc -c -Dver=1 src/main.c",
"directory": "${root_dir}",
"file": "src/main.c"
}
]
EOF
Bear-2.4.3/test/functional/cases/result/output_kept.fts 0000664 0000000 0000000 00000001667 13613276011 0023241 0 ustar 00root root 0000000 0000000 #!/usr/bin/env bash
# REQUIRES: preload
# RUN: bash %s %T/output_kept
# RUN: cd %T/output_kept; %{intercept-build} --cdb result.json ./run.sh
# RUN: cd %T/output_kept; %{cdb_diff} result.json expected.json
# the test creates a subdirectory inside output dir.
#
# ${root_dir}
# ├── run.sh
# ├── expected.json
# └── src
# └── empty.c
root_dir=$1
mkdir -p "${root_dir}/src"
touch "${root_dir}/src/empty.c"
build_file="${root_dir}/run.sh"
cat > ${build_file} << EOF
#!/usr/bin/env bash
set -o nounset
set -o xtrace
\$CC -c -o src/empty.o src/empty.c;
\$CC -c src/empty.c;
cd src
\$CC -c -o empty.obj empty.c;
\$CC -c empty.c;
true;
EOF
chmod +x ${build_file}
cat > "${root_dir}/expected.json" << EOF
[
{
"command": "cc -c -o src/empty.o src/empty.c",
"directory": "${root_dir}",
"file": "src/empty.c"
}
,
{
"command": "cc -c -o empty.obj empty.c",
"directory": "${root_dir}/src",
"file": "empty.c"
}
]
EOF
Bear-2.4.3/test/functional/cases/run_pep8.ft 0000664 0000000 0000000 00000000136 13613276011 0020703 0 ustar 00root root 0000000 0000000 # REQUIRES: pycodestyle
# RUN: pycodestyle --show-source --show-pep8 %S/../../../bear/bear.py
Bear-2.4.3/test/functional/lit.local.cfg 0000664 0000000 0000000 00000002176 13613276011 0020062 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
import os
import os.path
import lit.util
# test_source_root: The root path where tests are located.
this_dir = os.path.dirname(__file__)
tool_dir = os.path.join(this_dir, 'tools')
config.environment['test_input_dir'] = os.path.join(this_dir, 'Input')
config.environment['CC'] = 'cc'
config.environment['CXX'] = 'c++'
config.environment['LC_CTYPE'] = 'en_US.UTF-8'
config.substitutions.append(
('%{python}', sys.executable))
if 'EAR_EXE' in lit_config.params and 'EAR_LIB' in lit_config.params:
bear_call = '{python} {bear} -l {libear} -vvvv'.format(
python=sys.executable,
bear=lit_config.params['EAR_EXE'],
libear=lit_config.params['EAR_LIB'])
else:
bear_call = 'bear -vvvv'
config.substitutions.append(
('%{intercept-build}', bear_call))
config.substitutions.append(
('%{cdb_diff}',
'{python} {cdb_diff}'.format(python=sys.executable,
cdb_diff=os.path.join(tool_dir, 'cdb_diff.py'))))
config.substitutions.append(
('%{cmake}',
'cmake' if lit_config.params.get('MULTILIB') is None else 'cmake -DCMAKE_C_COMPILER_ARG1="-m32"'))
Bear-2.4.3/test/functional/tools/ 0000775 0000000 0000000 00000000000 13613276011 0016652 5 ustar 00root root 0000000 0000000 Bear-2.4.3/test/functional/tools/cdb_diff.py 0000775 0000000 0000000 00000004652 13613276011 0020756 0 ustar 00root root 0000000 0000000 #!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2012-2019 by László Nagy
# This file is part of Bear.
#
# Bear is a tool to generate compilation database for clang tooling.
#
# Bear is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Bear is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
import argparse
import json
import sys
import os.path
def diff(lhs, rhs, ignore_compiler):
left = {smooth(entry, ignore_compiler): entry for entry in lhs}
right = {smooth(entry, ignore_compiler): entry for entry in rhs}
for key in left.keys():
if key not in right:
yield '> {}'.format(left[key])
for key in right.keys():
if key not in left:
yield '< {}'.format(right[key])
def smooth(entry, ignore_compiler):
directory = os.path.normpath(entry['directory'])
source = entry['file'] if os.path.isabs(entry['file']) else \
os.path.normpath(os.path.join(directory, entry['file']))
arguments = entry['command'].split() if 'command' in entry else \
entry['arguments']
output = entry['output'] if 'output' in entry else ''
if ignore_compiler:
arguments = arguments[1:]
return '-'.join([source[::-1]] + arguments + [output])
def main():
""" Semantically diff two compilation databases. """
parser = argparse.ArgumentParser()
parser.add_argument(
'--ignore-compiler',
action='store_true',
help="Ignore the first element in the arguments field.")
parser.add_argument('left', type=argparse.FileType('r'))
parser.add_argument('right', type=argparse.FileType('r'))
args = parser.parse_args()
# files are open, parse the json content
lhs = json.load(args.left)
rhs = json.load(args.right)
# run the diff and print the result
count = 0
for result in diff(lhs, rhs, args.ignore_compiler):
print(result)
count += 1
return count
if __name__ == '__main__':
sys.exit(main())
Bear-2.4.3/test/lit.cfg 0000664 0000000 0000000 00000006052 13613276011 0014624 0 ustar 00root root 0000000 0000000 # -*- coding: utf-8 -*-
import sys
import re
import os.path
import subprocess
import lit.util
this_dir = os.path.dirname(__file__)
project_dir = os.path.dirname(this_dir)
config.name = 'bear'
config.test_format = lit.formats.ShTest()
config.test_exec_root = this_dir
config.test_source_root = this_dir
config.suffixes = ['.ft', '.fts', '.ftp']
config.excludes = []
config.substitutions.append(
('%{python}', sys.executable))
def is_available(program):
try:
subprocess.call([program, '--version'], stdout=subprocess.PIPE)
except:
return False
else:
return True
if is_available('pycodestyle'):
config.available_features.add('pycodestyle')
if is_available('coverage'):
config.available_features.add('coverage')
if is_available('scons') and sys.version_info < (3, 0):
config.available_features.add('scons')
if is_available('qmake-qt4'):
config.available_features.add('qmake')
config.substitutions.append(('%{qmake}', 'qmake-qt4'))
elif is_available('qmake-qt5'):
config.available_features.add('qmake')
config.substitutions.append(('%{qmake}', 'qmake-qt5'))
elif is_available('qmake'):
config.available_features.add('qmake')
config.substitutions.append(('%{qmake}', 'qmake'))
if is_available('make'):
config.available_features.add('make')
config.substitutions.append(('%{make}', 'make'))
elif is_available('mingw32-make'):
config.available_features.add('make')
config.substitutions.append(('%{make}', 'mingw32-make'))
if is_available('gfortran'):
config.available_features.add('fortran')
if is_available('nvcc'):
config.available_features.add('cuda')
# classify os script language
is_windows = sys.platform in {'win32', 'cygwin'}
if is_windows:
config.available_features.add('batch')
config.suffixes.append('.bat')
config.environment['windows'] = 'True'
else:
config.available_features.add('shell')
config.suffixes.append('.fts')
# check for library preload is available
def is_preload_disabled():
# type: (str) -> bool
""" Library-based interposition will fail silently if SIP is enabled,
so this should be detected. You can detect whether SIP is enabled on
Darwin by checking whether (1) there is a binary called 'csrutil' in
the path and, if so, (2) whether the output of executing 'csrutil status'
contains 'System Integrity Protection status: enabled'.
:param platform: name of the platform (returned by sys.platform),
:return: True if library preload will fail by the dynamic linker. """
if is_windows:
return True
elif sys.platform == 'darwin':
command = ['csrutil', 'status']
pattern = re.compile(r'System Integrity Protection status:\s+enabled')
try:
output = subprocess.check_output(command, stderr=subprocess.STDOUT)
return any(pattern.match(line) for line in output.splitlines())
except (OSError, subprocess.CalledProcessError):
return False
else:
return False
if not is_preload_disabled():
config.available_features.add('preload')