~hjd/ubuntu/wily/gyp/debian-merged

« back to all changes in this revision

Viewing changes to .pc/2001_kfreebsd_flock.patch/pylib/gyp/generator/make.py

  • Committer: Hans Joachim Desserud
  • Date: 2015-10-31 12:46:59 UTC
  • mfrom: (6.2.6 sid)
  • Revision ID: hans_joachim_desserud-20151031124659-lzxekr6woskh4k0b
Merge latest Debian version

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
import gyp.common
30
30
import gyp.xcode_emulation
31
31
from gyp.common import GetEnvironFallback
 
32
from gyp.common import GypError
32
33
 
33
34
generator_default_variables = {
34
35
  'EXECUTABLE_PREFIX': '',
57
58
generator_additional_non_configuration_keys = []
58
59
generator_additional_path_sections = []
59
60
generator_extra_sources_for_rules = []
 
61
generator_filelist_paths = None
60
62
 
61
63
 
62
64
def CalculateVariables(default_variables, params):
103
105
    global generator_wants_sorted_dependencies
104
106
    generator_wants_sorted_dependencies = True
105
107
 
 
108
  output_dir = params['options'].generator_output or \
 
109
               params['options'].toplevel_dir
 
110
  builddir_name = generator_flags.get('output_dir', 'out')
 
111
  qualified_out_dir = os.path.normpath(os.path.join(
 
112
    output_dir, builddir_name, 'gypfiles'))
106
113
 
107
 
def ensure_directory_exists(path):
108
 
  dir = os.path.dirname(path)
109
 
  if dir and not os.path.exists(dir):
110
 
    os.makedirs(dir)
 
114
  global generator_filelist_paths
 
115
  generator_filelist_paths = {
 
116
    'toplevel': params['options'].toplevel_dir,
 
117
    'qualified_out_dir': qualified_out_dir,
 
118
  }
111
119
 
112
120
 
113
121
# The .d checking code below uses these functions:
201
209
"""
202
210
 
203
211
 
 
212
LINK_COMMANDS_AIX = """\
 
213
quiet_cmd_alink = AR($(TOOLSET)) $@
 
214
cmd_alink = rm -f $@ && $(AR.$(TOOLSET)) crs $@ $(filter %.o,$^)
 
215
 
 
216
quiet_cmd_alink_thin = AR($(TOOLSET)) $@
 
217
cmd_alink_thin = rm -f $@ && $(AR.$(TOOLSET)) crs $@ $(filter %.o,$^)
 
218
 
 
219
quiet_cmd_link = LINK($(TOOLSET)) $@
 
220
cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(LD_INPUTS) $(LIBS)
 
221
 
 
222
quiet_cmd_solink = SOLINK($(TOOLSET)) $@
 
223
cmd_solink = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(LD_INPUTS) $(LIBS)
 
224
 
 
225
quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
 
226
cmd_solink_module = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(filter-out FORCE_DO_CMD, $^) $(LIBS)
 
227
"""
 
228
 
 
229
 
204
230
# Header of toplevel Makefile.
205
231
# This should go into the build tree, but it's easier to keep it here for now.
206
232
SHARED_HEADER = ("""\
255
281
AR.target ?= $(AR)
256
282
 
257
283
# C++ apps need to be linked with g++.
258
 
#
259
 
# Note: flock is used to seralize linking. Linking is a memory-intensive
260
 
# process so running parallel links can often lead to thrashing.  To disable
261
 
# the serialization, override LINK via an envrionment variable as follows:
262
 
#
263
 
#   export LINK=g++
264
 
#
265
 
# This will allow make to invoke N linker processes as specified in -jN.
266
 
LINK ?= %(flock)s $(builddir)/linker.lock $(CXX.target)
 
284
LINK ?= $(CXX.target)
267
285
 
268
286
# TODO(evan): move all cross-compilation logic to gyp-time so we don't need
269
287
# to replicate this environment fallback in make as well.
479
497
cmd_infoplist = $(CC.$(TOOLSET)) -E -P -Wno-trigraphs -x c $(INFOPLIST_DEFINES) "$<" -o "$@"
480
498
"""
481
499
 
482
 
SHARED_HEADER_SUN_COMMANDS = """
483
 
# gyp-sun-tool is written next to the root Makefile by gyp.
484
 
# Use $(4) for the command, since $(2) and $(3) are used as flag by do_cmd
485
 
# already.
486
 
quiet_cmd_sun_tool = SUNTOOL $(4) $<
487
 
cmd_sun_tool = ./gyp-sun-tool $(4) $< "$@"
488
 
"""
489
 
 
490
500
 
491
501
def WriteRootHeaderSuffixRules(writer):
492
502
  extensions = sorted(COMPILABLE_EXTENSIONS.keys(), key=str.lower)
614
624
  return s.replace(' ', quote)
615
625
 
616
626
 
 
627
# TODO: Avoid code duplication with _ValidateSourcesForMSVSProject in msvs.py.
 
628
def _ValidateSourcesForOSX(spec, all_sources):
 
629
  """Makes sure if duplicate basenames are not specified in the source list.
 
630
 
 
631
  Arguments:
 
632
    spec: The target dictionary containing the properties of the target.
 
633
  """
 
634
  if spec.get('type', None) != 'static_library':
 
635
    return
 
636
 
 
637
  basenames = {}
 
638
  for source in all_sources:
 
639
    name, ext = os.path.splitext(source)
 
640
    is_compiled_file = ext in [
 
641
        '.c', '.cc', '.cpp', '.cxx', '.m', '.mm', '.s', '.S']
 
642
    if not is_compiled_file:
 
643
      continue
 
644
    basename = os.path.basename(name)  # Don't include extension.
 
645
    basenames.setdefault(basename, []).append(source)
 
646
 
 
647
  error = ''
 
648
  for basename, files in basenames.iteritems():
 
649
    if len(files) > 1:
 
650
      error += '  %s: %s\n' % (basename, ' '.join(files))
 
651
 
 
652
  if error:
 
653
    print('static library %s has several files with the same basename:\n' %
 
654
          spec['target_name'] + error + 'libtool on OS X will generate' +
 
655
          ' warnings for them.')
 
656
    raise GypError('Duplicate basenames in sources section, see list above')
 
657
 
 
658
 
617
659
# Map from qualified target to path to output.
618
660
target_outputs = {}
619
661
# Map from qualified target to any linkable output.  A subset
623
665
target_link_deps = {}
624
666
 
625
667
 
626
 
class MakefileWriter:
 
668
class MakefileWriter(object):
627
669
  """MakefileWriter packages up the writing of one target-specific foobar.mk.
628
670
 
629
671
  Its only real entry point is Write(), and is mostly used for namespacing.
668
710
      spec, configs: gyp info
669
711
      part_of_all: flag indicating this target is part of 'all'
670
712
    """
671
 
    ensure_directory_exists(output_filename)
 
713
    gyp.common.EnsureDirExists(output_filename)
672
714
 
673
715
    self.fp = open(output_filename, 'w')
674
716
 
741
783
    # Sources.
742
784
    all_sources = spec.get('sources', []) + extra_sources
743
785
    if all_sources:
 
786
      if self.flavor == 'mac':
 
787
        # libtool on OS X generates warnings for duplicate basenames in the same
 
788
        # target.
 
789
        _ValidateSourcesForOSX(spec, all_sources)
744
790
      self.WriteSources(
745
791
          configs, deps, all_sources, extra_outputs,
746
792
          extra_link_deps, part_of_all,
797
843
      targets: list of "all" targets for this sub-project
798
844
      build_dir: build output directory, relative to the sub-project
799
845
    """
800
 
    ensure_directory_exists(output_filename)
 
846
    gyp.common.EnsureDirExists(output_filename)
801
847
    self.fp = open(output_filename, 'w')
802
848
    self.fp.write(header)
803
849
    # For consistency with other builders, put sub-project build output in the
973
1019
        # accidentally writing duplicate dummy rules for those outputs.
974
1020
        self.WriteLn('%s: obj := $(abs_obj)' % outputs[0])
975
1021
        self.WriteLn('%s: builddir := $(abs_builddir)' % outputs[0])
976
 
        self.WriteMakeRule(outputs, inputs + ['FORCE_DO_CMD'], actions)
 
1022
        self.WriteMakeRule(outputs, inputs, actions,
 
1023
                           command="%s_%d" % (name, count))
977
1024
        # Spaces in rule filenames are not supported, but rule variables have
978
1025
        # spaces in them (e.g. RULE_INPUT_PATH expands to '$(abspath $<)').
979
1026
        # The spaces within the variables are valid, so remove the variables
1084
1131
    for output, res in gyp.xcode_emulation.GetMacBundleResources(
1085
1132
        generator_default_variables['PRODUCT_DIR'], self.xcode_settings,
1086
1133
        map(Sourceify, map(self.Absolutify, resources))):
1087
 
      self.WriteDoCmd([output], [res], 'mac_tool,,,copy-bundle-resource',
1088
 
                      part_of_all=True)
1089
 
      bundle_deps.append(output)
 
1134
      _, ext = os.path.splitext(output)
 
1135
      if ext != '.xcassets':
 
1136
        # Make does not supports '.xcassets' emulation.
 
1137
        self.WriteDoCmd([output], [res], 'mac_tool,,,copy-bundle-resource',
 
1138
                        part_of_all=True)
 
1139
        bundle_deps.append(output)
1090
1140
 
1091
1141
 
1092
1142
  def WriteMacInfoPlist(self, bundle_deps):
1404
1454
 
1405
1455
          # TARGET_POSTBUILDS_$(BUILDTYPE) is added to postbuilds later on.
1406
1456
          gyp_to_build = gyp.common.InvertRelativePath(self.path)
1407
 
          target_postbuild = self.xcode_settings.GetTargetPostbuilds(
 
1457
          target_postbuild = self.xcode_settings.AddImplicitPostbuilds(
1408
1458
              configname,
1409
1459
              QuoteSpaces(os.path.normpath(os.path.join(gyp_to_build,
1410
1460
                                                        self.output))),
1639
1689
    self.WriteMakeRule(outputs, inputs,
1640
1690
                       actions = ['$(call do_cmd,%s%s)' % (command, suffix)],
1641
1691
                       comment = comment,
 
1692
                       command = command,
1642
1693
                       force = True)
1643
1694
    # Add our outputs to the list of targets we read depfiles from.
1644
1695
    # all_deps is only used for deps file reading, and for deps files we replace
1649
1700
 
1650
1701
 
1651
1702
  def WriteMakeRule(self, outputs, inputs, actions=None, comment=None,
1652
 
                    order_only=False, force=False, phony=False):
 
1703
                    order_only=False, force=False, phony=False, command=None):
1653
1704
    """Write a Makefile rule, with some extra tricks.
1654
1705
 
1655
1706
    outputs: a list of outputs for the rule (note: this is not directly
1662
1713
    force: if true, include FORCE_DO_CMD as an order-only dep
1663
1714
    phony: if true, the rule does not actually generate the named output, the
1664
1715
           output is just a name to run the rule
 
1716
    command: (optional) command name to generate unambiguous labels
1665
1717
    """
1666
1718
    outputs = map(QuoteSpaces, outputs)
1667
1719
    inputs = map(QuoteSpaces, inputs)
1670
1722
      self.WriteLn('# ' + comment)
1671
1723
    if phony:
1672
1724
      self.WriteLn('.PHONY: ' + ' '.join(outputs))
1673
 
    # TODO(evanm): just make order_only a list of deps instead of these hacks.
 
1725
    if actions:
 
1726
      self.WriteLn("%s: TOOLSET := $(TOOLSET)" % outputs[0])
 
1727
    force_append = ' FORCE_DO_CMD' if force else ''
 
1728
 
1674
1729
    if order_only:
1675
 
      order_insert = '| '
1676
 
      pick_output = ' '.join(outputs)
1677
 
    else:
1678
 
      order_insert = ''
1679
 
      pick_output = outputs[0]
1680
 
    if force:
1681
 
      force_append = ' FORCE_DO_CMD'
1682
 
    else:
1683
 
      force_append = ''
1684
 
    if actions:
1685
 
      self.WriteLn("%s: TOOLSET := $(TOOLSET)" % outputs[0])
1686
 
    self.WriteLn('%s: %s%s%s' % (pick_output, order_insert, ' '.join(inputs),
1687
 
                                 force_append))
 
1730
      # Order only rule: Just write a simple rule.
 
1731
      # TODO(evanm): just make order_only a list of deps instead of this hack.
 
1732
      self.WriteLn('%s: | %s%s' %
 
1733
                   (' '.join(outputs), ' '.join(inputs), force_append))
 
1734
    elif len(outputs) == 1:
 
1735
      # Regular rule, one output: Just write a simple rule.
 
1736
      self.WriteLn('%s: %s%s' % (outputs[0], ' '.join(inputs), force_append))
 
1737
    else:
 
1738
      # Regular rule, more than one output: Multiple outputs are tricky in
 
1739
      # make. We will write three rules:
 
1740
      # - All outputs depend on an intermediate file.
 
1741
      # - Make .INTERMEDIATE depend on the intermediate.
 
1742
      # - The intermediate file depends on the inputs and executes the
 
1743
      #   actual command.
 
1744
      # - The intermediate recipe will 'touch' the intermediate file.
 
1745
      # - The multi-output rule will have an do-nothing recipe.
 
1746
      intermediate = "%s.intermediate" % (command if command else self.target)
 
1747
      self.WriteLn('%s: %s' % (' '.join(outputs), intermediate))
 
1748
      self.WriteLn('\t%s' % '@:');
 
1749
      self.WriteLn('%s: %s' % ('.INTERMEDIATE', intermediate))
 
1750
      self.WriteLn('%s: %s%s' %
 
1751
                   (intermediate, ' '.join(inputs), force_append))
 
1752
      actions.insert(0, '$(call do_cmd,touch)')
 
1753
 
1688
1754
    if actions:
1689
1755
      for action in actions:
1690
1756
        self.WriteLn('\t%s' % action)
1691
 
    if not order_only and len(outputs) > 1:
1692
 
      # If we have more than one output, a rule like
1693
 
      #   foo bar: baz
1694
 
      # that for *each* output we must run the action, potentially
1695
 
      # in parallel.  That is not what we're trying to write -- what
1696
 
      # we want is that we run the action once and it generates all
1697
 
      # the files.
1698
 
      # http://www.gnu.org/software/hello/manual/automake/Multiple-Outputs.html
1699
 
      # discusses this problem and has this solution:
1700
 
      # 1) Write the naive rule that would produce parallel runs of
1701
 
      # the action.
1702
 
      # 2) Make the outputs seralized on each other, so we won't start
1703
 
      # a parallel run until the first run finishes, at which point
1704
 
      # we'll have generated all the outputs and we're done.
1705
 
      self.WriteLn('%s: %s' % (' '.join(outputs[1:]), outputs[0]))
1706
 
      # Add a dummy command to the "extra outputs" rule, otherwise make seems to
1707
 
      # think these outputs haven't (couldn't have?) changed, and thus doesn't
1708
 
      # flag them as changed (i.e. include in '$?') when evaluating dependent
1709
 
      # rules, which in turn causes do_cmd() to skip running dependent commands.
1710
 
      self.WriteLn('%s: ;' % (' '.join(outputs[1:])))
1711
1757
    self.WriteLn()
1712
1758
 
1713
1759
 
1934
1980
    # We write the file in the base_path directory.
1935
1981
    output_file = os.path.join(options.depth, base_path, base_name)
1936
1982
    if options.generator_output:
1937
 
      output_file = os.path.join(options.generator_output, output_file)
 
1983
      output_file = os.path.join(
 
1984
          options.depth, options.generator_output, base_path, base_name)
1938
1985
    base_path = gyp.common.RelativePath(os.path.dirname(build_file),
1939
1986
                                        options.toplevel_dir)
1940
1987
    return base_path, output_file
1957
2004
  makefile_path = os.path.join(options.toplevel_dir, makefile_name)
1958
2005
  if options.generator_output:
1959
2006
    global srcdir_prefix
1960
 
    makefile_path = os.path.join(options.generator_output, makefile_path)
 
2007
    makefile_path = os.path.join(
 
2008
        options.toplevel_dir, options.generator_output, makefile_name)
1961
2009
    srcdir = gyp.common.RelativePath(srcdir, options.generator_output)
1962
2010
    srcdir_prefix = '$(srcdir)/'
1963
2011
 
1986
2034
    })
1987
2035
  elif flavor == 'solaris':
1988
2036
    header_params.update({
1989
 
        'flock': './gyp-sun-tool flock',
 
2037
        'flock': './gyp-flock-tool flock',
1990
2038
        'flock_index': 2,
1991
 
        'extra_commands': SHARED_HEADER_SUN_COMMANDS,
1992
2039
    })
1993
2040
  elif flavor == 'freebsd':
1994
2041
    # Note: OpenBSD has sysutils/flock. lockf seems to be FreeBSD specific.
1995
2042
    header_params.update({
1996
2043
        'flock': 'lockf',
1997
2044
    })
 
2045
  elif flavor == 'aix':
 
2046
    header_params.update({
 
2047
        'link_commands': LINK_COMMANDS_AIX,
 
2048
        'flock': './gyp-flock-tool flock',
 
2049
        'flock_index': 2,
 
2050
    })
1998
2051
 
1999
2052
  header_params.update({
2000
2053
    'CC.target':   GetEnvironFallback(('CC_target', 'CC'), '$(CC)'),
2010
2063
  build_file, _, _ = gyp.common.ParseQualifiedTarget(target_list[0])
2011
2064
  make_global_settings_array = data[build_file].get('make_global_settings', [])
2012
2065
  wrappers = {}
2013
 
  wrappers['LINK'] = '%s $(builddir)/linker.lock' % flock_command
2014
2066
  for key, value in make_global_settings_array:
2015
2067
    if key.endswith('_wrapper'):
2016
2068
      wrappers[key[:-len('_wrapper')]] = '$(abspath %s)' % value
2028
2080
      make_global_settings += (
2029
2081
          'ifneq (,$(filter $(origin %s), undefined default))\n' % key)
2030
2082
      # Let gyp-time envvars win over global settings.
2031
 
      if key in os.environ:
2032
 
        value = os.environ[key]
 
2083
      env_key = key.replace('.', '_')  # CC.host -> CC_host
 
2084
      if env_key in os.environ:
 
2085
        value = os.environ[env_key]
2033
2086
      make_global_settings += '  %s = %s\n' % (key, value)
2034
2087
      make_global_settings += 'endif\n'
2035
2088
    else:
2039
2092
 
2040
2093
  header_params['make_global_settings'] = make_global_settings
2041
2094
 
2042
 
  ensure_directory_exists(makefile_path)
 
2095
  gyp.common.EnsureDirExists(makefile_path)
2043
2096
  root_makefile = open(makefile_path, 'w')
2044
2097
  root_makefile.write(SHARED_HEADER % header_params)
2045
2098
  # Currently any versions have the same effect, but in future the behavior
2071
2124
 
2072
2125
    this_make_global_settings = data[build_file].get('make_global_settings', [])
2073
2126
    assert make_global_settings_array == this_make_global_settings, (
2074
 
        "make_global_settings needs to be the same for all targets.")
 
2127
        "make_global_settings needs to be the same for all targets. %s vs. %s" %
 
2128
        (this_make_global_settings, make_global_settings))
2075
2129
 
2076
2130
    build_files.add(gyp.common.RelativePath(build_file, options.toplevel_dir))
2077
2131
    included_files = data[build_file]['included_files']