Skip to content

Commit fe7e00d

Browse files
committed
gyp: add sunos support
1 parent 0d80040 commit fe7e00d

2 files changed

Lines changed: 90 additions & 18 deletions

File tree

tools/gyp/pylib/gyp/generator/make.py

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@
6161

6262
def GetFlavor(params):
6363
"""Returns |params.flavor| if it's set, the system's default flavor else."""
64-
return params.get('flavor', 'mac' if sys.platform == 'darwin' else 'linux')
64+
flavors = {
65+
'darwin': 'mac',
66+
'sunos5': 'solaris',
67+
}
68+
flavor = flavors.get(sys.platform, 'linux')
69+
return params.get('flavor', flavor)
6570

6671

6772
def CalculateVariables(default_variables, params):
@@ -70,7 +75,8 @@ def CalculateVariables(default_variables, params):
7075
default_variables['LINKER_SUPPORTS_ICF'] = \
7176
gyp.system_test.TestLinkerSupportsICF(cc_command=cc_target)
7277

73-
if GetFlavor(params) == 'mac':
78+
flavor = GetFlavor(params)
79+
if flavor == 'mac':
7480
default_variables.setdefault('OS', 'mac')
7581
default_variables.setdefault('SHARED_LIB_SUFFIX', '.dylib')
7682
default_variables.setdefault('SHARED_LIB_DIR',
@@ -93,7 +99,7 @@ def CalculateVariables(default_variables, params):
9399
global COMPILABLE_EXTENSIONS
94100
COMPILABLE_EXTENSIONS.update({'.m': 'objc', '.mm' : 'objcxx'})
95101
else:
96-
default_variables.setdefault('OS', 'linux')
102+
default_variables.setdefault('OS', flavor)
97103
default_variables.setdefault('SHARED_LIB_SUFFIX', '.so')
98104
default_variables.setdefault('SHARED_LIB_DIR','$(builddir)/lib.$(TOOLSET)')
99105
default_variables.setdefault('LIB_DIR', '$(obj).$(TOOLSET)')
@@ -324,7 +330,7 @@ def ensure_directory_exists(path):
324330
325331
quiet_cmd_cxx = CXX($(TOOLSET)) $@
326332
cmd_cxx = $(CXX.$(TOOLSET)) $(GYP_CXXFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) -c -o $@ $<
327-
%(mac_commands)s
333+
%(extra_commands)s
328334
quiet_cmd_touch = TOUCH $@
329335
cmd_touch = touch $@
330336
@@ -438,6 +444,14 @@ def ensure_directory_exists(path):
438444
cmd_mac_package_framework = ./gyp-mac-tool package-framework "$@" $(4)
439445
"""
440446

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

442456
def WriteRootHeaderSuffixRules(writer):
443457
extensions = sorted(COMPILABLE_EXTENSIONS.keys(), key=str.lower)
@@ -2382,17 +2396,31 @@ def RunSystemTests(flavor):
23822396
'LINK_flags': link_flags }
23832397

23842398

2385-
def CopyMacTool(out_path):
2386-
"""Finds mac_tool.gyp in the gyp directory and copies it to |out_path|."""
2399+
def CopyTool(flavor, out_path):
2400+
"""Finds (mac|sun)_tool.gyp in the gyp directory and copies it to |out_path|."""
2401+
prefix = { 'solaris': 'sun', 'mac': 'mac' }.get(flavor, None)
2402+
if not prefix:
2403+
return
2404+
2405+
tool_path = os.path.join(out_path, 'gyp-%s-tool' % prefix)
2406+
if os.path.exists(tool_path):
2407+
os.remove(tool_path)
2408+
2409+
# Slurp input file.
23872410
source_path = os.path.join(
2388-
os.path.dirname(os.path.abspath(__file__)), '..', 'mac_tool.py')
2411+
os.path.dirname(os.path.abspath(__file__)), '..', '%s_tool.py' % prefix)
23892412
source_file = open(source_path)
23902413
source = source_file.readlines()
23912414
source_file.close()
2392-
mactool_file = open(out_path, 'w')
2393-
mactool_file.write(
2415+
2416+
# Add header and write it out.
2417+
tool_file = open(tool_path, 'w')
2418+
tool_file.write(
23942419
''.join([source[0], '# Generated by gyp. Do not edit.\n'] + source[1:]))
2395-
mactool_file.close()
2420+
tool_file.close()
2421+
2422+
# Make file executable.
2423+
os.chmod(tool_path, 0o755)
23962424

23972425

23982426
def GenerateOutput(target_list, target_dicts, data, params):
@@ -2446,16 +2474,23 @@ def CalculateMakefilePath(build_file, base_name):
24462474
'flock': 'flock',
24472475
'flock_index': 1,
24482476
'link_commands': LINK_COMMANDS_LINUX,
2449-
'mac_commands': '',
2477+
'extra_commands': '',
24502478
'srcdir': srcdir,
24512479
}
24522480
if flavor == 'mac':
24532481
header_params.update({
24542482
'flock': './gyp-mac-tool flock',
24552483
'flock_index': 2,
24562484
'link_commands': LINK_COMMANDS_MAC,
2457-
'mac_commands': SHARED_HEADER_MAC_COMMANDS,
2485+
'extra_commands': SHARED_HEADER_MAC_COMMANDS,
24582486
})
2487+
elif flavor == 'solaris':
2488+
header_params.update({
2489+
'flock': './gyp-sun-tool flock',
2490+
'flock_index': 2,
2491+
'extra_commands': SHARED_HEADER_SUN_COMMANDS,
2492+
})
2493+
24592494
header_params.update(RunSystemTests(flavor))
24602495

24612496
build_file, _, _ = gyp.common.ParseQualifiedTarget(target_list[0])
@@ -2493,12 +2528,8 @@ def CalculateMakefilePath(build_file, base_name):
24932528
WriteRootHeaderSuffixRules(root_makefile)
24942529

24952530
# Put mac_tool next to the root Makefile.
2496-
if flavor == 'mac':
2497-
mactool_path = os.path.join(os.path.dirname(makefile_path), 'gyp-mac-tool')
2498-
if os.path.exists(mactool_path):
2499-
os.remove(mactool_path)
2500-
CopyMacTool(mactool_path)
2501-
os.chmod(mactool_path, 0o755) # Make file executable.
2531+
dest_path = os.path.dirname(makefile_path)
2532+
CopyTool(flavor, dest_path)
25022533

25032534
# Find the list of targets that derive from the gyp file(s) being built.
25042535
needed_targets = set()

tools/gyp/pylib/gyp/sun_tool.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python
2+
# Copyright (c) 2011 Google Inc. All rights reserved.
3+
# Use of this source code is governed by a BSD-style license that can be
4+
# found in the LICENSE file.
5+
6+
"""These functions are executed via gyp-sun-tool when using the Makefile generator."""
7+
8+
import os
9+
import fcntl
10+
import plistlib
11+
import shutil
12+
import string
13+
import subprocess
14+
import sys
15+
16+
def main(args):
17+
executor = SunTool()
18+
executor.Dispatch(args)
19+
20+
class SunTool(object):
21+
"""This class performs all the SunOS tooling steps. The methods can either be
22+
executed directly, or dispatched from an argument list."""
23+
24+
def Dispatch(self, args):
25+
"""Dispatches a string command to a method."""
26+
if len(args) < 1:
27+
raise Exception("Not enough arguments")
28+
29+
method = "Exec%s" % self._CommandifyName(args[0])
30+
getattr(self, method)(*args[1:])
31+
32+
def _CommandifyName(self, name_string):
33+
"""Transforms a tool name like copy-info-plist to CopyInfoPlist"""
34+
return name_string.title().replace('-', '')
35+
36+
def ExecFlock(self, lockfile, *cmd_list):
37+
"""Emulates the most basic behavior of Linux's flock(1)."""
38+
# Rely on exception handling to report errors.
39+
fd = os.open(lockfile, os.O_RDONLY|os.O_NOCTTY|os.O_CREAT, 0o666)
40+
fcntl.flock(fd, fcntl.LOCK_EX)
41+
return subprocess.call(cmd_list)

0 commit comments

Comments
 (0)