1/* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7    http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14==============================================================================*/
15
16#include <stdio.h>
17
18#include "tensorflow/core/framework/op_def_util.h"
19#include "tensorflow/core/lib/core/status.h"
20#include "tensorflow/core/ops/compat/op_compatibility_lib.h"
21#include "tensorflow/core/platform/env.h"
22#include "tensorflow/core/platform/init_main.h"
23#include "tensorflow/core/platform/protobuf.h"
24#include "tensorflow/core/public/version.h"
25
26namespace tensorflow {
27namespace {
28
29void WriteUpdateTo(const string& directory) {
30  OpCompatibilityLib compatibility(
31      directory, strings::StrCat("v", TF_MAJOR_VERSION), nullptr);
32
33  // Write full copy of all ops to ops.pbtxt.
34  Env* env = Env::Default();
35  {
36    const string& ops_file = compatibility.ops_file();
37    printf("Writing ops to %s...\n", ops_file.c_str());
38    TF_QCHECK_OK(WriteStringToFile(env, ops_file, compatibility.OpsString()));
39  }
40
41  // Make sure the current version of ops are compatible with the
42  // historical versions, and generate a new history adding all
43  // changed ops.
44  OpList out_op_history;
45  int changed_ops = 0;
46  int added_ops = 0;
47  TF_QCHECK_OK(compatibility.ValidateCompatible(env, &changed_ops, &added_ops,
48                                                &out_op_history));
49  printf("%d changed ops\n%d added ops\n", changed_ops, added_ops);
50
51  if (changed_ops + added_ops > 0) {
52    // Write out new op history.
53    const string& history_file = compatibility.op_history_file();
54    printf("Writing updated op history to %s...\n", history_file.c_str());
55    TF_QCHECK_OK(
56        WriteStringToFile(env, history_file, out_op_history.DebugString()));
57  }
58}
59
60}  // namespace
61}  // namespace tensorflow
62
63int main(int argc, char* argv[]) {
64  tensorflow::port::InitMain(argv[0], &argc, &argv);
65  if (argc != 2) {
66    printf("Usage: %s <core/ops directory>\n", argv[0]);
67    return 1;
68  }
69  printf("TensorFlow version: %s\n", TF_VERSION_STRING);
70  tensorflow::WriteUpdateTo(argv[1]);
71  return 0;
72}
73