@@ -133,33 +133,45 @@ def _symlink_genrule_for_dir(
133
133
dest_dir ,
134
134
genrule_name ,
135
135
src_files = [],
136
- dest_files = []):
137
- """Returns a genrule to symlink(or copy if on Windows) a set of files.
136
+ dest_files = [],
137
+ tf_pip_dir_rename_pair = []):
138
138
139
+ """Returns a genrule to symlink(or copy if on Windows) a set of files.
139
140
If src_dir is passed, files will be read from the given directory; otherwise
140
141
we assume files are in src_files and dest_files.
141
-
142
142
Args:
143
143
repository_ctx: the repository_ctx object.
144
144
src_dir: source directory.
145
145
dest_dir: directory to create symlink in.
146
146
genrule_name: genrule name.
147
147
src_files: list of source files instead of src_dir.
148
148
dest_files: list of corresonding destination files.
149
-
149
+ tf_pip_dir_rename_pair: list of the pair of tf pip parent directory to
150
+ replace. For example, in TF pip package, the source code is under
151
+ "tensorflow_core", and we might want to replace it with
152
+ "tensorflow" to match the header includes.
150
153
Returns:
151
154
genrule target that creates the symlinks.
152
155
"""
156
+ # Check that tf_pip_dir_rename_pair has the right length
157
+ tf_pip_dir_rename_pair_len = len (tf_pip_dir_rename_pair )
158
+ if tf_pip_dir_rename_pair_len != 0 and tf_pip_dir_rename_pair_len != 2 :
159
+ _fail ("The size of argument tf_pip_dir_rename_pair should be either 0 or 2, but %d is given." % tf_pip_dir_rename_pair_len )
160
+
153
161
if src_dir != None :
154
162
src_dir = _norm_path (src_dir )
155
163
dest_dir = _norm_path (dest_dir )
156
164
files = "\n " .join (sorted (_read_dir (repository_ctx , src_dir ).splitlines ()))
157
165
158
166
# Create a list with the src_dir stripped to use for outputs.
159
- dest_files = files .replace (src_dir , "" ).splitlines ()
167
+ if tf_pip_dir_rename_pair_len :
168
+ dest_files = files .replace (src_dir , "" ).replace (tf_pip_dir_rename_pair [0 ], tf_pip_dir_rename_pair [1 ]).splitlines ()
169
+ else :
170
+ dest_files = files .replace (src_dir , "" ).splitlines ()
160
171
src_files = files .splitlines ()
161
172
command = []
162
173
outs = []
174
+
163
175
for i in range (len (dest_files )):
164
176
if dest_files [i ] != "" :
165
177
# If we have only one file to link we do not want to use the dest_dir, as
@@ -168,8 +180,9 @@ def _symlink_genrule_for_dir(
168
180
169
181
# Copy the headers to create a sandboxable setup.
170
182
cmd = "cp -f"
171
- command .append (cmd + ' "%s" "%s" | true ' % (src_files [i ], dest ))
183
+ command .append (cmd + ' "%s" "%s"' % (src_files [i ], dest ))
172
184
outs .append (' "' + dest_dir + dest_files [i ] + '",' )
185
+
173
186
genrule = _genrule (
174
187
genrule_name ,
175
188
" && " .join (command ),
@@ -184,13 +197,15 @@ def _tf_pip_impl(repository_ctx):
184
197
tf_header_dir ,
185
198
"include" ,
186
199
"tf_header_include" ,
200
+ tf_pip_dir_rename_pair = ["tensorflow_core" , "tensorflow" ]
187
201
)
188
202
189
203
tf_shared_library_dir = repository_ctx .os .environ [_TF_SHARED_LIBRARY_DIR ]
190
204
tf_shared_library_name = repository_ctx .os .environ [_TF_SHARED_LIBRARY_NAME ]
191
205
tf_shared_library_path = "%s/%s" % (tf_shared_library_dir , tf_shared_library_name )
192
206
tf_cx11_abi = "-D_GLIBCXX_USE_CXX11_ABI=%s" % (repository_ctx .os .environ [_TF_CXX11_ABI_FLAG ])
193
207
208
+
194
209
tf_shared_library_rule = _symlink_genrule_for_dir (
195
210
repository_ctx ,
196
211
None ,
0 commit comments