2
0
mirror of https://github.com/boostorg/build.git synced 2026-02-15 00:52:16 +00:00

Port asm.set_asm_type()

This commit is contained in:
Aaron Boman
2014-09-04 12:57:52 -05:00
parent bbd5539a26
commit abbc562e4b
2 changed files with 46 additions and 9 deletions

View File

@@ -4,10 +4,30 @@
# Distributed under the Boost
# Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
from b2.build import type as type_
from b2.manager import get_manager
from b2.tools.cast import cast
from b2.util import bjam_signature
from b2.build import type
def register():
type.register_type('ASM', ['s', 'S', 'asm'])
MANAGER = get_manager()
PROJECT_REGISTRY = MANAGER.projects()
register()
# maps project.name() + type to type
_project_types = {}
type_.register_type('ASM', ['s', 'S', 'asm'])
@bjam_signature((['type_'], ['sources', '*'], ['name', '?']))
def set_asm_type(type_, sources, name=''):
project = PROJECT_REGISTRY.current()
_project_types[project.name() + type_] = _project_types.get(
project.name() + type_, type_) + '_'
name = name if name else _project_types[project.name() + type_]
type_ += '.asm'
cast(name, type_.upper(), sources, [], [], [])
PROJECT_REGISTRY.add_rule("set-asm-type", set_asm_type)

View File

@@ -9,8 +9,8 @@ from b2.util import bjam_signature
def transform (list, pattern, indices = [1]):
""" Matches all elements of 'list' agains the 'pattern'
and returns a list of the elements indicated by indices of
""" Matches all elements of 'list' agains the 'pattern'
and returns a list of the elements indicated by indices of
all successfull matches. If 'indices' is omitted returns
a list of first paranthethised groups of all successfull
matches.
@@ -27,11 +27,28 @@ def transform (list, pattern, indices = [1]):
return result
@bjam_signature((['s', 'match', 'replacement']))
def replace(s, match, replacement):
return s.replace(match, replacement)
@bjam_signature([['s', 'pattern', 'replacement']])
def replace(s, pattern, replacement):
"""Replaces occurrences of a match string in a given
string and returns the new string. The match string
can be a regex expression.
Args:
s (str): the string to modify
pattern (str): the search expression
replacement (str): the string to replace each match with
"""
return re.sub(pattern, replacement, s)
@bjam_signature((['items', '*'], ['match'], ['replacement']))
def replace_list(items, match, replacement):
"""Replaces occurrences of a match string in a given list of strings and returns
a list of new strings. The match string can be a regex expression.
Args:
items (list): the list of strings to modify.
match (str): the search expression.
replacement (str): the string to replace with.
"""
return [replace(item, match, replacement) for item in items]