2020-04-22 17:38:25 +02:00
|
|
|
# Copyright 2020 MongoDB Inc.
|
2015-07-24 21:37:27 +02:00
|
|
|
#
|
2020-04-22 17:38:25 +02:00
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
# a copy of this software and associated documentation files (the
|
|
|
|
# "Software"), to deal in the Software without restriction, including
|
|
|
|
# without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
# permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
# the following conditions:
|
2015-07-24 21:37:27 +02:00
|
|
|
#
|
2020-04-22 17:38:25 +02:00
|
|
|
# The above copyright notice and this permission notice shall be included
|
|
|
|
# in all copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
|
|
|
|
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
|
|
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2015-07-24 21:37:27 +02:00
|
|
|
#
|
|
|
|
|
|
|
|
import SCons
|
|
|
|
import subprocess
|
|
|
|
|
2017-05-25 15:37:12 +02:00
|
|
|
# TODO: Make a SUFF variable for the suffix to write to
|
|
|
|
# TODO: Prevent using abilink when -gsplit-dwarf is in play, since it doesn't work
|
|
|
|
# TODO: Make a variable for the md5sum utility (allow any hasher)
|
|
|
|
# TODO: Add an ABILINKCOM variable to the Action, so it can be silenced.
|
|
|
|
|
2019-02-19 16:50:57 +01:00
|
|
|
|
2015-07-24 21:37:27 +02:00
|
|
|
def _detect(env):
|
|
|
|
try:
|
2020-01-07 19:48:42 +01:00
|
|
|
abidw = env["ABIDW"]
|
2015-07-24 21:37:27 +02:00
|
|
|
if not abidw:
|
|
|
|
return None
|
2015-07-29 15:50:12 +02:00
|
|
|
return abidw
|
2015-07-24 21:37:27 +02:00
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
|
2020-01-07 19:48:42 +01:00
|
|
|
return env.WhereIs("abidw")
|
2015-07-24 21:37:27 +02:00
|
|
|
|
2019-02-19 16:50:57 +01:00
|
|
|
|
2017-05-25 15:37:12 +02:00
|
|
|
def _add_emitter(builder):
|
|
|
|
base_emitter = builder.emitter
|
2015-07-24 21:37:27 +02:00
|
|
|
|
2017-05-25 15:37:12 +02:00
|
|
|
def new_emitter(target, source, env):
|
|
|
|
new_targets = []
|
|
|
|
for t in target:
|
|
|
|
abidw = str(t) + ".abidw"
|
|
|
|
abidw = (t.builder.target_factory or env.File)(abidw)
|
|
|
|
new_targets.append(abidw)
|
|
|
|
setattr(t.attributes, "abidw", abidw)
|
|
|
|
targets = target + new_targets
|
|
|
|
return (targets, source)
|
2015-07-24 21:37:27 +02:00
|
|
|
|
2017-05-25 15:37:12 +02:00
|
|
|
new_emitter = SCons.Builder.ListEmitter([base_emitter, new_emitter])
|
|
|
|
builder.emitter = new_emitter
|
2015-07-24 21:37:27 +02:00
|
|
|
|
2019-02-19 16:50:57 +01:00
|
|
|
|
2017-05-25 15:37:12 +02:00
|
|
|
def _add_scanner(builder):
|
|
|
|
old_scanner = builder.target_scanner
|
|
|
|
path_function = old_scanner.path_function
|
SERVER-27380 Re-enable the thin archive tool
This refactors the thin_archive tool to use emitters and scanners
to note that when linking to a thin archive, you must also depend on
the children of that thin archive. Failing to do so is an error,
because a changed .o does not necessarily lead to a different .a,
which would subvert the SCons dependency mechanism.
This also includes a refactoring of the ABILINK tool to use a similar
mechanism, to achieve the opposite effect. For ABILINK, we want to
depend not on the actual .so, but on the hash of its abidw result. We
use emitters, actions, and scanners to produce an associated .abidw
file for each .so we build, and then update the scanner to depend on
the .abidw of our libraries, not the library itself. This allows us to
elide needless relinks.
2017-05-20 15:02:32 +02:00
|
|
|
|
2017-05-25 15:37:12 +02:00
|
|
|
def new_scanner(node, env, path):
|
|
|
|
old_results = old_scanner(node, env, path)
|
|
|
|
new_results = []
|
|
|
|
for base in old_results:
|
|
|
|
abidw = getattr(env.Entry(base).attributes, "abidw", None)
|
|
|
|
new_results.append(abidw if abidw else base)
|
|
|
|
return new_results
|
SERVER-27380 Re-enable the thin archive tool
This refactors the thin_archive tool to use emitters and scanners
to note that when linking to a thin archive, you must also depend on
the children of that thin archive. Failing to do so is an error,
because a changed .o does not necessarily lead to a different .a,
which would subvert the SCons dependency mechanism.
This also includes a refactoring of the ABILINK tool to use a similar
mechanism, to achieve the opposite effect. For ABILINK, we want to
depend not on the actual .so, but on the hash of its abidw result. We
use emitters, actions, and scanners to produce an associated .abidw
file for each .so we build, and then update the scanner to depend on
the .abidw of our libraries, not the library itself. This allows us to
elide needless relinks.
2017-05-20 15:02:32 +02:00
|
|
|
|
2020-01-07 19:48:42 +01:00
|
|
|
builder.target_scanner = SCons.Scanner.Scanner(
|
|
|
|
function=new_scanner, path_function=path_function
|
|
|
|
)
|
2019-02-19 16:50:57 +01:00
|
|
|
|
SERVER-27380 Re-enable the thin archive tool
This refactors the thin_archive tool to use emitters and scanners
to note that when linking to a thin archive, you must also depend on
the children of that thin archive. Failing to do so is an error,
because a changed .o does not necessarily lead to a different .a,
which would subvert the SCons dependency mechanism.
This also includes a refactoring of the ABILINK tool to use a similar
mechanism, to achieve the opposite effect. For ABILINK, we want to
depend not on the actual .so, but on the hash of its abidw result. We
use emitters, actions, and scanners to produce an associated .abidw
file for each .so we build, and then update the scanner to depend on
the .abidw of our libraries, not the library itself. This allows us to
elide needless relinks.
2017-05-20 15:02:32 +02:00
|
|
|
|
2017-05-25 15:37:12 +02:00
|
|
|
def _add_action(builder):
|
|
|
|
actions = builder.action
|
2019-02-19 16:50:57 +01:00
|
|
|
builder.action = actions + SCons.Action.Action(
|
2020-01-07 19:48:42 +01:00
|
|
|
"$ABIDW --no-show-locs $TARGET | md5sum > ${TARGET}.abidw"
|
|
|
|
)
|
2019-02-19 16:50:57 +01:00
|
|
|
|
2017-05-25 14:22:58 +02:00
|
|
|
|
|
|
|
def exists(env):
|
|
|
|
result = _detect(env) != None
|
|
|
|
return result
|
2017-05-25 15:37:12 +02:00
|
|
|
|
2019-02-19 16:50:57 +01:00
|
|
|
|
2017-05-25 15:37:12 +02:00
|
|
|
def generate(env):
|
|
|
|
|
|
|
|
if not exists(env):
|
|
|
|
return
|
|
|
|
|
2020-01-07 19:48:42 +01:00
|
|
|
builder = env["BUILDERS"]["SharedLibrary"]
|
2017-05-25 15:37:12 +02:00
|
|
|
_add_emitter(builder)
|
|
|
|
_add_action(builder)
|
|
|
|
_add_scanner(builder)
|
2020-01-07 19:48:42 +01:00
|
|
|
_add_scanner(env["BUILDERS"]["Program"])
|
|
|
|
_add_scanner(env["BUILDERS"]["LoadableModule"])
|