Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
gyp: upgrade to r1081
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Oct 21, 2011
1 parent 9b2335a commit 3c3ec7b
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 22 deletions.
81 changes: 61 additions & 20 deletions tools/gyp/pylib/gyp/generator/make.py
Expand Up @@ -62,7 +62,14 @@

def GetFlavor(params):
"""Returns |params.flavor| if it's set, the system's default flavor else."""
return params.get('flavor', 'mac' if sys.platform == 'darwin' else 'linux')
flavors = {
'darwin': 'mac',
'sunos5': 'solaris',
'freebsd7': 'freebsd',
'freebsd8': 'freebsd',
}
flavor = flavors.get(sys.platform, 'linux')
return params.get('flavor', flavor)


def CalculateVariables(default_variables, params):
Expand All @@ -71,7 +78,8 @@ def CalculateVariables(default_variables, params):
default_variables['LINKER_SUPPORTS_ICF'] = \
gyp.system_test.TestLinkerSupportsICF(cc_command=cc_target)

if GetFlavor(params) == 'mac':
flavor = GetFlavor(params)
if flavor == 'mac':
default_variables.setdefault('OS', 'mac')
default_variables.setdefault('SHARED_LIB_SUFFIX', '.dylib')
default_variables.setdefault('SHARED_LIB_DIR',
Expand All @@ -94,7 +102,10 @@ def CalculateVariables(default_variables, params):
global COMPILABLE_EXTENSIONS
COMPILABLE_EXTENSIONS.update({'.m': 'objc', '.mm' : 'objcxx'})
else:
default_variables.setdefault('OS', 'linux')
operating_system = flavor
if flavor == 'android':
operating_system = 'linux' # Keep this legacy behavior for now.
default_variables.setdefault('OS', operating_system)
default_variables.setdefault('SHARED_LIB_SUFFIX', '.so')
default_variables.setdefault('SHARED_LIB_DIR','$(builddir)/lib.$(TOOLSET)')
default_variables.setdefault('LIB_DIR', '$(obj).$(TOOLSET)')
Expand Down Expand Up @@ -349,7 +360,7 @@ def ensure_directory_exists(path):
quiet_cmd_cxx = CXX($(TOOLSET)) $@
cmd_cxx = $(CXX.$(TOOLSET)) $(GYP_CXXFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) -c -o $@ $<
%(mac_commands)s
%(extra_commands)s
quiet_cmd_touch = TOUCH $@
cmd_touch = touch $@
Expand Down Expand Up @@ -480,6 +491,14 @@ def ensure_directory_exists(path):
cmd_mac_package_framework = ./gyp-mac-tool package-framework "$@" $(4)
"""

SHARED_HEADER_SUN_COMMANDS = """
# gyp-sun-tool is written next to the root Makefile by gyp.
# Use $(4) for the command, since $(2) and $(3) are used as flag by do_cmd
# already.
quiet_cmd_sun_tool = SUNTOOL $(4) $<
cmd_sun_tool = ./gyp-sun-tool $(4) $< "$@"
"""


def WriteRootHeaderSuffixRules(writer):
extensions = sorted(COMPILABLE_EXTENSIONS.keys(), key=str.lower)
Expand Down Expand Up @@ -2407,11 +2426,13 @@ def StripProductDir(s):
env['UNLOCALIZED_RESOURCES_FOLDER_PATH'] = \
self.xcode_settings.GetBundleResourceFolder()
env['INFOPLIST_PATH'] = self.xcode_settings.GetBundlePlistPath()
env['WRAPPER_NAME'] = self.xcode_settings.GetWrapperName()

# TODO(thakis): Remove this.
env['EXECUTABLE_PATH'] = QuoteSpaces(env['EXECUTABLE_PATH'])
env['CONTENTS_FOLDER_PATH'] = QuoteSpaces(env['CONTENTS_FOLDER_PATH'])
env['INFOPLIST_PATH'] = QuoteSpaces(env['INFOPLIST_PATH'])
env['WRAPPER_NAME'] = QuoteSpaces(env['WRAPPER_NAME'])

return env

Expand Down Expand Up @@ -2576,17 +2597,32 @@ def RunSystemTests(flavor):
'LINK_flags': link_flags }


def CopyMacTool(out_path):
"""Finds mac_tool.gyp in the gyp directory and copies it to |out_path|."""
def CopyTool(flavor, out_path):
"""Finds (mac|sun)_tool.gyp in the gyp directory and copies it
to |out_path|."""
prefix = { 'solaris': 'sun', 'mac': 'mac' }.get(flavor, None)
if not prefix:
return

tool_path = os.path.join(out_path, 'gyp-%s-tool' % prefix)
if os.path.exists(tool_path):
os.remove(tool_path)

# Slurp input file.
source_path = os.path.join(
os.path.dirname(os.path.abspath(__file__)), '..', 'mac_tool.py')
os.path.dirname(os.path.abspath(__file__)), '..', '%s_tool.py' % prefix)
source_file = open(source_path)
source = source_file.readlines()
source_file.close()
mactool_file = open(out_path, 'w')
mactool_file.write(

# Add header and write it out.
tool_file = open(tool_path, 'w')
tool_file.write(
''.join([source[0], '# Generated by gyp. Do not edit.\n'] + source[1:]))
mactool_file.close()
tool_file.close()

# Make file executable.
os.chmod(tool_path, 0755)


def GenerateOutput(target_list, target_dicts, data, params):
Expand Down Expand Up @@ -2641,7 +2677,7 @@ def CalculateMakefilePath(build_file, base_name):
'flock': flock_command,
'flock_index': 1,
'link_commands': LINK_COMMANDS_LINUX,
'mac_commands': '',
'extra_commands': '',
'srcdir': srcdir,
}
if flavor == 'mac':
Expand All @@ -2650,12 +2686,22 @@ def CalculateMakefilePath(build_file, base_name):
'flock': flock_command,
'flock_index': 2,
'link_commands': LINK_COMMANDS_MAC,
'mac_commands': SHARED_HEADER_MAC_COMMANDS,
'extra_commands': SHARED_HEADER_MAC_COMMANDS,
})
if flavor == 'android':
elif flavor == 'android':
header_params.update({
'link_commands': LINK_COMMANDS_ANDROID,
})
elif flavor == 'solaris':
header_params.update({
'flock': './gyp-sun-tool flock',
'flock_index': 2,
'extra_commands': SHARED_HEADER_SUN_COMMANDS,
})
elif flavor == 'freebsd':
header_params.update({
'flock': 'lockf',
})
header_params.update(RunSystemTests(flavor))

build_file, _, _ = gyp.common.ParseQualifiedTarget(target_list[0])
Expand Down Expand Up @@ -2693,13 +2739,8 @@ def CalculateMakefilePath(build_file, base_name):
WriteRootHeaderSuffixRules(root_makefile)

# Put mac_tool next to the root Makefile.
if flavor == 'mac':
mactool_path = os.path.join(os.path.dirname(makefile_path), 'gyp-mac-tool')
if os.path.exists(mactool_path):
os.remove(mactool_path)
CopyMacTool(mactool_path)
# Make file executable.
os.chmod(mactool_path, 0755)
dest_path = os.path.dirname(makefile_path)
CopyTool(flavor, dest_path)

# Find the list of targets that derive from the gyp file(s) being built.
needed_targets = set()
Expand Down
53 changes: 51 additions & 2 deletions tools/gyp/pylib/gyp/sun_tool.py
Expand Up @@ -3,7 +3,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""These functions are executed via gyp-sun-tool when using the Makefile generator."""
"""These functions are executed via gyp-sun-tool when using the Makefile
generator."""

import fcntl
import os
Expand Down Expand Up @@ -38,7 +39,55 @@ def ExecFlock(self, lockfile, *cmd_list):
# where fcntl.flock(fd, LOCK_EX) always fails
# with EBADF, that's why we use this F_SETLK
# hack instead.
fd = os.open(lockfile, os.O_WRONLY|os.O_NOCTTY|os.O_CREAT, 0o666)
fd = os.open(lockfile, os.O_WRONLY|os.O_NOCTTY|os.O_CREAT, 0666)
op = struct.pack('hhllhhl', fcntl.F_WRLCK, 0, 0, 0, 0, 0, 0)
fcntl.fcntl(fd, fcntl.F_SETLK, op)
return subprocess.call(cmd_list)

if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
#!/usr/bin/env python
# Copyright (c) 2011 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""These functions are executed via gyp-sun-tool when using the Makefile
generator."""

import fcntl
import os
import struct
import subprocess
import sys

def main(args):
executor = SunTool()
executor.Dispatch(args)

class SunTool(object):
"""This class performs all the SunOS tooling steps. The methods can either be
executed directly, or dispatched from an argument list."""

def Dispatch(self, args):
"""Dispatches a string command to a method."""
if len(args) < 1:
raise Exception("Not enough arguments")

method = "Exec%s" % self._CommandifyName(args[0])
getattr(self, method)(*args[1:])

def _CommandifyName(self, name_string):
"""Transforms a tool name like copy-info-plist to CopyInfoPlist"""
return name_string.title().replace('-', '')

def ExecFlock(self, lockfile, *cmd_list):
"""Emulates the most basic behavior of Linux's flock(1)."""
# Rely on exception handling to report errors.
# Note that the stock python on SunOS has a bug
# where fcntl.flock(fd, LOCK_EX) always fails
# with EBADF, that's why we use this F_SETLK
# hack instead.
fd = os.open(lockfile, os.O_WRONLY|os.O_NOCTTY|os.O_CREAT, 0666)
op = struct.pack('hhllhhl', fcntl.F_WRLCK, 0, 0, 0, 0, 0, 0)
fcntl.fcntl(fd, fcntl.F_SETLK, op)
return subprocess.call(cmd_list)
Expand Down

0 comments on commit 3c3ec7b

Please sign in to comment.