Skip to content

Commit ad87aa2

Browse files
authored
Merge pull request #4121 from jjhursey/explore/dlopen-local
mca: Dynamic components link against project lib
2 parents cc41c48 + 49c40f0 commit ad87aa2

File tree

192 files changed

+674
-137
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

192 files changed

+674
-137
lines changed

contrib/libadd_mca_comp_update.py

Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright (c) 2017 IBM Corporation. All rights reserved.
4+
# $COPYRIGHT$
5+
#
6+
7+
import glob, os, re, shutil
8+
9+
projects= {'opal' : ["$(top_builddir)/opal/lib@[email protected]"],
10+
'orte' : ["$(top_builddir)/orte/lib@[email protected]"],
11+
'ompi' : ["$(top_builddir)/ompi/lib@[email protected]"],
12+
'oshmem' : ["$(top_builddir)/oshmem/liboshmem.la"],
13+
}
14+
15+
no_anchor_file = []
16+
missing_files = []
17+
skipped_files = []
18+
partly_files = []
19+
updated_files = []
20+
21+
#
22+
# Check of all of the libadd fields are accounted for in the LIBADD
23+
# Return a list indicating which are missing (positional)
24+
#
25+
def check_libadd(content, libadd_field, project):
26+
global projects
27+
28+
libadd_list = projects[project]
29+
libadd_missing = [True] * len(libadd_list)
30+
31+
on_libadd = False
32+
for line in content:
33+
# First libadd line
34+
if re.search( r"^\s*"+libadd_field, line):
35+
# If line continuation, then keep searching after this point
36+
if line[-2] == '\\':
37+
on_libadd = True
38+
39+
for idx, lib in enumerate(libadd_list):
40+
if True == libadd_missing[idx]:
41+
if 0 <= line.find(lib):
42+
libadd_missing[idx] = False
43+
44+
# Line continuation
45+
elif True == on_libadd:
46+
for idx, lib in enumerate(libadd_list):
47+
if True == libadd_missing[idx]:
48+
if 0 <= line.find(lib):
49+
libadd_missing[idx] = False
50+
51+
# No more line continuations, so stop processing
52+
if line[-2] != '\\':
53+
on_libadd = False
54+
break
55+
56+
return libadd_missing
57+
58+
#
59+
# Update all of the Makefile.am's with the proper LIBADD additions
60+
#
61+
def update_makefile_ams():
62+
global projects
63+
global no_anchor_file
64+
global missing_files
65+
global skipped_files
66+
global partly_files
67+
global updated_files
68+
69+
for project, libadd_list in projects.items():
70+
libadd_str = " \\\n\t".join(libadd_list)
71+
72+
print("="*40)
73+
print("Project: "+project)
74+
print("LIBADD:\n"+libadd_str)
75+
print("="*40)
76+
77+
#
78+
# Walk the directory structure
79+
#
80+
for root, dirs, files in os.walk(project+"/mca"):
81+
parts = root.split("/")
82+
if len(parts) != 4:
83+
continue
84+
if parts[-1] == ".libs" or parts[-1] == ".deps" or parts[-1] == "base":
85+
continue
86+
if parts[2] == "common":
87+
continue
88+
89+
print("Processing: "+root)
90+
91+
#
92+
# Find Makefile.am
93+
#
94+
make_filename = os.path.join(root, "Makefile.am")
95+
if False == os.path.isfile( make_filename ):
96+
missing_files.append("Missing: "+make_filename)
97+
print(" ---> Error: "+make_filename+" is not present in this directory")
98+
continue
99+
100+
#
101+
# Stearching for: mca_FRAMEWORK_COMPONENT_la_{LIBADD|LDFLAGS}
102+
# First scan file to see if it has an LIBADD / LDFLAGS
103+
#
104+
libadd_field = "mca_"+parts[2]+"_"+parts[3]+"_la_LIBADD"
105+
ldflags_field = "mca_"+parts[2]+"_"+parts[3]+"_la_LDFLAGS"
106+
has_ldflags = False
107+
has_libadd = False
108+
109+
r_fd = open(make_filename, 'r')
110+
orig_content = r_fd.readlines()
111+
r_fd.close()
112+
libadd_missing = []
113+
114+
for line in orig_content:
115+
if re.search( r"^\s*"+ldflags_field, line):
116+
has_ldflags = True
117+
elif re.search( r"^\s*"+libadd_field, line):
118+
has_libadd = True
119+
120+
if True == has_libadd:
121+
libadd_missing = check_libadd(orig_content, libadd_field, project)
122+
123+
#
124+
# Sanity Check: Was there an anchor field.
125+
# If not skip, we might need to manually update or it might be a
126+
# static component.
127+
#
128+
if False == has_ldflags and False == has_libadd:
129+
no_anchor_file.append("No anchor ("+ldflags_field+"): "+make_filename)
130+
print(" ---> Error: Makefile.am does not contain necessary anchor")
131+
continue
132+
133+
#
134+
# Sanity Check: This file does not need to be updated.
135+
#
136+
if True == has_libadd and all(False == v for v in libadd_missing):
137+
skipped_files.append("Skip: "+make_filename)
138+
print(" Skip: Already updated Makefile.am")
139+
continue
140+
141+
#
142+
# Now go though and create a new version of the Makefile.am
143+
#
144+
r_fd = open(make_filename, 'r')
145+
w_fd = open(make_filename+".mod", 'w')
146+
147+
num_libadds=0
148+
for line in r_fd:
149+
# LDFLAGS anchor
150+
if re.search( r"^\s*"+ldflags_field, line):
151+
w_fd.write(line)
152+
# If there is no LIBADD, then put it after the LDFLAGS
153+
if False == has_libadd:
154+
w_fd.write(libadd_field+" = "+libadd_str+"\n")
155+
# Existing LIBADD field to extend
156+
elif 0 == num_libadds and re.search( r"^\s*"+libadd_field, line):
157+
parts = line.partition("=")
158+
num_libadds += 1
159+
160+
if parts[0][-1] == '+':
161+
w_fd.write(libadd_field+" += ")
162+
else:
163+
w_fd.write(libadd_field+" = ")
164+
165+
# If all libs are missing, then add the full string
166+
# Otherwise only add the missing items
167+
if all(True == v for v in libadd_missing):
168+
w_fd.write(libadd_str)
169+
# Only add a continuation if there is something to continue
170+
if 0 != len(parts[2].strip()):
171+
w_fd.write(" \\")
172+
w_fd.write("\n")
173+
else:
174+
partly_files.append("Partly updated: "+make_filename)
175+
for idx, lib in enumerate(libadd_list):
176+
if True == libadd_missing[idx]:
177+
w_fd.write(lib+" \\\n")
178+
179+
# Original content (unless it's just a line continuation)
180+
if 0 != len(parts[2].strip()) and parts[2].strip() != "\\":
181+
w_fd.write("\t"+parts[2].lstrip())
182+
183+
# Non matching line, just echo
184+
else:
185+
w_fd.write(line)
186+
187+
r_fd.close()
188+
w_fd.close()
189+
190+
#
191+
# Replace the original with the updated version
192+
#
193+
shutil.move(make_filename+".mod", make_filename)
194+
updated_files.append(make_filename)
195+
196+
197+
if __name__ == "__main__":
198+
199+
update_makefile_ams()
200+
201+
print("")
202+
203+
print("="*40);
204+
print("{:>3} : Files skipped".format(len(skipped_files)))
205+
print("="*40);
206+
207+
print("="*40);
208+
print("{:>3} : Files updated, but had some libs already in place.".format(len(partly_files)))
209+
print("="*40);
210+
for fn in partly_files:
211+
print(fn)
212+
213+
print("="*40);
214+
print("{:>3} : Files fully updated".format(len(updated_files)))
215+
print("="*40);
216+
for fn in updated_files:
217+
print(fn)
218+
219+
print("="*40);
220+
print("{:>3} : Missing Makefile.am".format(len(missing_files)))
221+
print("="*40);
222+
for err in missing_files:
223+
print(err)
224+
225+
print("="*40);
226+
print("{:>3} : Missing Anchor for parsing (might be static-only components)".format(len(no_anchor_file)))
227+
print("="*40);
228+
for err in no_anchor_file:
229+
print(err)
230+

ompi/mca/bml/r2/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# Copyright (c) 2004-2005 The Regents of the University of California.
99
# All rights reserved.
1010
# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
11+
# Copyright (c) 2017 IBM Corporation. All rights reserved.
1112
# $COPYRIGHT$
1213
#
1314
# Additional copyrights may follow
@@ -37,6 +38,7 @@ mcacomponentdir = $(ompilibdir)
3738
mcacomponent_LTLIBRARIES = $(component_install)
3839
mca_bml_r2_la_SOURCES = $(r2_sources)
3940
mca_bml_r2_la_LDFLAGS = -module -avoid-version
41+
mca_bml_r2_la_LIBADD = $(top_builddir)/ompi/lib@[email protected]
4042

4143
noinst_LTLIBRARIES = $(component_noinst)
4244
libmca_bml_r2_la_SOURCES = $(r2_sources)

ompi/mca/coll/basic/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# Copyright (c) 2012 Sandia National Laboratories. All rights reserved.
1414
# Copyright (c) 2013 Los Alamos National Security, LLC. All rights
1515
# reserved.
16+
# Copyright (c) 2017 IBM Corporation. All rights reserved.
1617
# $COPYRIGHT$
1718
#
1819
# Additional copyrights may follow
@@ -63,6 +64,7 @@ mcacomponentdir = $(ompilibdir)
6364
mcacomponent_LTLIBRARIES = $(component_install)
6465
mca_coll_basic_la_SOURCES = $(sources)
6566
mca_coll_basic_la_LDFLAGS = -module -avoid-version
67+
mca_coll_basic_la_LIBADD = $(top_builddir)/ompi/lib@[email protected]
6668

6769
noinst_LTLIBRARIES = $(component_noinst)
6870
libmca_coll_basic_la_SOURCES =$(sources)

ompi/mca/coll/cuda/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# of Tennessee Research Foundation. All rights
44
# reserved.
55
# Copyright (c) 2014 NVIDIA Corporation. All rights reserved.
6+
# Copyright (c) 2017 IBM Corporation. All rights reserved.
67
# $COPYRIGHT$
78
#
89
# Additional copyrights may follow
@@ -31,6 +32,7 @@ mcacomponentdir = $(ompilibdir)
3132
mcacomponent_LTLIBRARIES = $(component_install)
3233
mca_coll_cuda_la_SOURCES = $(sources)
3334
mca_coll_cuda_la_LDFLAGS = -module -avoid-version
35+
mca_coll_cuda_la_LIBADD = $(top_builddir)/ompi/lib@[email protected]
3436

3537
noinst_LTLIBRARIES = $(component_noinst)
3638
libmca_coll_cuda_la_SOURCES =$(sources)

ompi/mca/coll/demo/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# Copyright (c) 2004-2005 The Regents of the University of California.
1111
# All rights reserved.
1212
# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
13+
# Copyright (c) 2017 IBM Corporation. All rights reserved.
1314
# $COPYRIGHT$
1415
#
1516
# Additional copyrights may follow
@@ -56,6 +57,7 @@ mcacomponentdir = $(ompilibdir)
5657
mcacomponent_LTLIBRARIES = $(component_install)
5758
mca_coll_demo_la_SOURCES = $(sources)
5859
mca_coll_demo_la_LDFLAGS = -module -avoid-version
60+
mca_coll_demo_la_LIBADD = $(top_builddir)/ompi/lib@[email protected]
5961

6062
noinst_LTLIBRARIES = $(component_noinst)
6163
libmca_coll_demo_la_SOURCES = $(sources)

ompi/mca/coll/fca/Makefile.am

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#
33
#
44
# Copyright (c) 2011 Mellanox Technologies. All rights reserved.
5+
# Copyright (c) 2017 IBM Corporation. All rights reserved.
56
# $COPYRIGHT$
67
#
78
# Additional copyrights may follow
@@ -37,7 +38,8 @@ endif
3738
mcacomponentdir = $(ompilibdir)
3839
mcacomponent_LTLIBRARIES = $(component_install)
3940
mca_coll_fca_la_SOURCES = $(coll_fca_sources)
40-
mca_coll_fca_la_LIBADD = $(coll_fca_LIBS)
41+
mca_coll_fca_la_LIBADD = $(top_builddir)/ompi/lib@[email protected] \
42+
$(coll_fca_LIBS)
4143
mca_coll_fca_la_LDFLAGS = -module -avoid-version $(coll_fca_LDFLAGS)
4244

4345
noinst_LTLIBRARIES = $(component_noinst)

ompi/mca/coll/hcoll/Makefile.am

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Copyright (c) 2011 Mellanox Technologies. All rights reserved.
55
# Copyright (c) 2015 Research Organization for Information Science
66
# and Technology (RIST). All rights reserved.
7+
# Copyright (c) 2017 IBM Corporation. All rights reserved.
78
# $COPYRIGHT$
89
#
910
# Additional copyrights may follow
@@ -38,7 +39,8 @@ endif
3839
mcacomponentdir = $(ompilibdir)
3940
mcacomponent_LTLIBRARIES = $(component_install)
4041
mca_coll_hcoll_la_SOURCES = $(coll_hcoll_sources)
41-
mca_coll_hcoll_la_LIBADD = $(coll_hcoll_LIBS)
42+
mca_coll_hcoll_la_LIBADD = $(top_builddir)/ompi/lib@[email protected] \
43+
$(coll_hcoll_LIBS)
4244
mca_coll_hcoll_la_LDFLAGS = -module -avoid-version $(coll_hcoll_LDFLAGS)
4345

4446
noinst_LTLIBRARIES = $(component_noinst)

ompi/mca/coll/inter/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# Copyright (c) 2004-2005 The Regents of the University of California.
1111
# All rights reserved.
1212
# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
13+
# Copyright (c) 2017 IBM Corporation. All rights reserved.
1314
# $COPYRIGHT$
1415
#
1516
# Additional copyrights may follow
@@ -32,6 +33,7 @@ mcacomponentdir = $(ompilibdir)
3233
mcacomponent_LTLIBRARIES = $(component_install)
3334
mca_coll_inter_la_SOURCES = $(sources)
3435
mca_coll_inter_la_LDFLAGS = -module -avoid-version
36+
mca_coll_inter_la_LIBADD = $(top_builddir)/ompi/lib@[email protected]
3537

3638
noinst_LTLIBRARIES = $(component_noinst)
3739
libmca_coll_inter_la_SOURCES = $(sources)

ompi/mca/coll/libnbc/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# reserved.
1515
# Copyright (c) 2017 Research Organization for Information Science
1616
# and Technology (RIST). All rights reserved.
17+
# Copyright (c) 2017 IBM Corporation. All rights reserved.
1718
# $COPYRIGHT$
1819
#
1920
# Additional copyrights may follow
@@ -71,6 +72,7 @@ mcacomponentdir = $(ompilibdir)
7172
mcacomponent_LTLIBRARIES = $(component_install)
7273
mca_coll_libnbc_la_SOURCES = $(sources)
7374
mca_coll_libnbc_la_LDFLAGS = -module -avoid-version
75+
mca_coll_libnbc_la_LIBADD = $(top_builddir)/ompi/lib@[email protected]
7476

7577
noinst_LTLIBRARIES = $(component_noinst)
7678
libmca_coll_libnbc_la_SOURCES =$(sources)

ompi/mca/coll/monitoring/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#
22
# Copyright (c) 2016 Inria. All rights reserved.
3+
# Copyright (c) 2017 IBM Corporation. All rights reserved.
34
# $COPYRIGHT$
45
#
56
# Additional copyrights may follow
@@ -45,7 +46,7 @@ mcacomponentdir = $(ompilibdir)
4546
mcacomponent_LTLIBRARIES = $(component_install)
4647
mca_coll_monitoring_la_SOURCES = $(monitoring_sources)
4748
mca_coll_monitoring_la_LDFLAGS = -module -avoid-version
48-
mca_coll_monitoring_la_LIBADD = \
49+
mca_coll_monitoring_la_LIBADD = $(top_builddir)/ompi/lib@[email protected] \
4950
$(OMPI_TOP_BUILDDIR)/ompi/mca/common/monitoring/libmca_common_monitoring.la
5051

5152
noinst_LTLIBRARIES = $(component_noinst)

0 commit comments

Comments
 (0)