Skip to content

Commit 1ac423c

Browse files
authored
Fixing the native build so it can find the tsl headers. (#534)
1 parent 5c93ae1 commit 1ac423c

File tree

5 files changed

+28
-12
lines changed

5 files changed

+28
-12
lines changed

Diff for: tensorflow-core/tensorflow-core-generator/src/main/java/org/tensorflow/generator/op/OpGenerator.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.util.Map;
3838
import java.util.Scanner;
3939
import java.util.stream.Collectors;
40+
import java.util.stream.Stream;
4041
import org.bytedeco.javacpp.BytePointer;
4142
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
4243
import org.tensorflow.internal.c_api.TF_ApiDefMap;
@@ -72,7 +73,7 @@ public final class OpGenerator {
7273

7374
private static final String DEFAULT_OP_DEF_FILE = "org/tensorflow/ops.pbtxt";
7475

75-
private static final Scanner USER_PROMPT = new Scanner(System.in);
76+
private static final Scanner USER_PROMPT = new Scanner(System.in, StandardCharsets.UTF_8);
7677

7778
/**
7879
* Args should be {@code <outputDir> <opDefFile> [base_package]}.
@@ -195,7 +196,8 @@ private static String arg(String[] args, int idx) {
195196
private static OpList readOpList(String filename, InputStream protoInput) {
196197
try {
197198
if (filename.endsWith(".pbtxt")) {
198-
return TextFormat.parse(new String(protoInput.readAllBytes()), OpList.class);
199+
return TextFormat.parse(
200+
new String(protoInput.readAllBytes(), StandardCharsets.UTF_8), OpList.class);
199201
}
200202
return OpList.parseFrom(protoInput);
201203

@@ -286,9 +288,8 @@ private void mergeBaseApiDefs(TF_ApiDefMap apiDefMap, TF_Status status) {
286288
}
287289

288290
private void mergeApiDefs(TF_ApiDefMap apiDefMap, TF_Status status) {
289-
try {
290-
Files.walk(apiDefsPath)
291-
.filter(p -> p.toString().endsWith(".pbtxt"))
291+
try (Stream<Path> s = Files.walk(apiDefsPath)) {
292+
s.filter(p -> p.toString().endsWith(".pbtxt"))
292293
.forEach(
293294
p -> {
294295
try {
@@ -366,7 +367,7 @@ private void createApiDef(OpDef opDef, File apiDefFile) throws IOException {
366367
if (!apiDefFile.exists() && !apiDefFile.createNewFile()) {
367368
System.err.println("Cannot create API definition file \"" + apiDefFile.getPath() + "\"");
368369
}
369-
try (var apiDefWriter = new FileWriter(apiDefFile)) {
370+
try (var apiDefWriter = new FileWriter(apiDefFile, StandardCharsets.UTF_8)) {
370371
var apiDefs = ApiDefs.newBuilder();
371372
apiDefs.addOp(apiDef.build());
372373
apiDefWriter.write(TextFormat.printer().printToString(apiDefs.build()));

Diff for: tensorflow-core/tensorflow-core-generator/src/main/java/org/tensorflow/generator/op/javadoc/JavaDocNodeRendererContext.java

+12
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
public interface JavaDocNodeRendererContext {
1010

1111
/**
12+
* Encode a URL into a String.
13+
*
1214
* @param url to be encoded
1315
* @return an encoded URL (depending on the configuration)
1416
*/
@@ -26,11 +28,15 @@ public interface JavaDocNodeRendererContext {
2628
Map<String, String> extendAttributes(Node node, String tagName, Map<String, String> attributes);
2729

2830
/**
31+
* Gets the HTML writer.
32+
*
2933
* @return the HTML writer to use
3034
*/
3135
JavaDocWriter getWriter();
3236

3337
/**
38+
* The HTML for a line break.
39+
*
3440
* @return HTML that should be rendered for a soft line break
3541
*/
3642
String getSoftbreak();
@@ -45,17 +51,23 @@ public interface JavaDocNodeRendererContext {
4551
void render(Node node);
4652

4753
/**
54+
* Should HTML be escaped?
55+
*
4856
* @return whether HTML blocks and tags should be escaped or not
4957
*/
5058
boolean shouldEscapeHtml();
5159

5260
/**
61+
* Should URLs be sanitized?
62+
*
5363
* @return true if the {@link UrlSanitizer} should be used.
5464
* @since 0.14.0
5565
*/
5666
boolean shouldSanitizeUrls();
5767

5868
/**
69+
* Gets the URL sanitizer.
70+
*
5971
* @return Sanitizer to use for securing {@link Link} href and {@link Image} src if {@link
6072
* #shouldSanitizeUrls()} is true.
6173
* @since 0.14.0

Diff for: tensorflow-core/tensorflow-core-native/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@
318318
<includePath>${native.source.directory}/org/tensorflow/internal/c_api/</includePath>
319319
<!-- additional include paths in case of a full native build -->
320320
<includePath>${project.basedir}/bazel-${project.artifactId}/external/org_tensorflow/</includePath>
321+
<includePath>${project.basedir}/bazel-${project.artifactId}/external/local_tsl/</includePath>
321322
<includePath>${project.basedir}/bazel-bin/external/org_tensorflow/</includePath>
322323
<includePath>${project.basedir}/bazel-${project.artifactId}/external/com_google_absl/</includePath>
323324
<includePath>${project.basedir}/bazel-${project.artifactId}/external/eigen_archive/</includePath>

Diff for: tensorflow-core/tensorflow-core-native/src/gen/java/org/tensorflow/internal/c_api/global/tensorflow.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
public class tensorflow extends org.tensorflow.internal.c_api.presets.tensorflow {
1212
static { Loader.load(); }
1313

14-
// Parsed from tensorflow/tsl/platform/ctstring_internal.h
14+
// Parsed from tsl/platform/ctstring_internal.h
1515

1616
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
1717
@@ -165,7 +165,7 @@ public static native void TF_TString_Copy(TF_TString dst, String src,
165165
// #endif // TENSORFLOW_TSL_PLATFORM_CTSTRING_INTERNAL_H_
166166

167167

168-
// Parsed from tensorflow/tsl/platform/ctstring.h
168+
// Parsed from tsl/platform/ctstring.h
169169

170170
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
171171
@@ -274,7 +274,7 @@ public static native void TF_TString_Copy(TF_TString dst, String src,
274274
// #endif // TENSORFLOW_TSL_PLATFORM_CTSTRING_H_
275275

276276

277-
// Parsed from tensorflow/tsl/c/tsl_status.h
277+
// Parsed from tsl/c/tsl_status.h
278278

279279
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
280280

Diff for: tensorflow-core/tensorflow-core-native/src/main/java/org/tensorflow/internal/c_api/presets/tensorflow.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@
3636
value = {"linux", "macosx", "windows"},
3737
compiler = "cpp17",
3838
include = {
39-
"tensorflow/tsl/platform/ctstring_internal.h",
40-
"tensorflow/tsl/platform/ctstring.h",
41-
"tensorflow/tsl/c/tsl_status.h",
39+
// TSL headers are in different places in a bazel build and the downloaded whl
40+
// The lower part is still the same, so multiple roots are set in the pom file.
41+
"tsl/platform/ctstring_internal.h",
42+
"tsl/platform/ctstring.h",
43+
"tsl/c/tsl_status.h",
4244
"tensorflow/c/c_api_macros.h",
4345
"tensorflow/c/tf_datatype.h",
4446
"tensorflow/c/tf_status.h",

0 commit comments

Comments
 (0)