revise processing of vendor
@@ -8,7 +8,6 @@ import tempfile
arcadia_project_prefix = 'a.yandex-team.ru/'
contrib_go_std_src_prefix = 'contrib/go/_std/src/'
-contrib_go_prefix = 'vendor/'
vendor_prefix = 'vendor/'
@@ -16,15 +15,26 @@ def copy_args(args):
return copy.copy(args)
+def get_vendor_index(import_path):
+ index = import_path.rfind('/' + vendor_prefix)
+ if index < 0:
+ index = 0 if import_path.startswith(vendor_prefix) else index
+ else:
+ index = index + 1
+ return index
+
+
def get_import_path(module_path):
assert len(module_path) > 0
import_path = module_path.replace('\\', '/')
is_std_module = import_path.startswith(contrib_go_std_src_prefix)
if is_std_module:
import_path = import_path[len(contrib_go_std_src_prefix):]
- elif import_path.startswith(contrib_go_prefix):
- import_path = import_path[len(contrib_go_prefix):]
- else:
+ index = get_vendor_index(import_path)
+ if index >= 0:
+ index += len(vendor_prefix)
+ import_path = import_path[index:]
+ elif not is_std_module:
import_path = arcadia_project_prefix + import_path
assert len(import_path) > 0
return import_path, is_std_module
@@ -44,14 +54,14 @@ def classify_srcs(srcs, args):
args.packages = list(filter(lambda x: x.endswith('.a'), srcs))
-def create_import_config(peers, remap_vendor, import_map={}, module_map={}):
+def create_import_config(peers, import_map={}, module_map={}):
content = ''
for key, value in import_map.items():
content += 'importmap {}={}\n'.format(key, value)
for peer in peers:
peer_import_path, _ = get_import_path(os.path.dirname(peer))
- index = peer_import_path.find(vendor_prefix) if remap_vendor else -1
- if index == 0 or index > 0 and peer_import_path[index-1] == '/':
+ index = get_vendor_index(peer_import_path)
+ if index >= 0:
index += len(vendor_prefix)
content += 'importmap {}={}\n'.format(peer_import_path[index:], peer_import_path)
content += 'packagefile {}={}\n'.format(peer_import_path, os.path.join(args.build_root, peer))
@@ -72,7 +82,7 @@ def do_compile_go(args):
cmd.append('-std')
if import_path == 'runtime':
cmd.append('-+')
- import_config_name = create_import_config(args.peers, True, args.import_map, args.module_map)
+ import_config_name = create_import_config(args.peers, args.import_map, args.module_map)
if import_config_name:
cmd += ['-importcfg', import_config_name]
else:
@@ -117,7 +127,7 @@ def do_link_exe(args):
compile_args.output = os.path.join(args.output_root, 'main.a')
do_link_lib(compile_args)
cmd = [args.go_link, '-o', args.output]
- import_config_name = create_import_config(args.peers, False, args.import_map, args.module_map)
+ import_config_name = create_import_config(args.peers, args.import_map, args.module_map)
if import_config_name:
cmd += ['-importcfg', import_config_name]
cmd += ['-buildmode=exe', '-extld=gcc', compile_args.output]
