1// Copyright 2013 Google Inc. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#include "version.h"
16
17#include <stdlib.h>
18
19#include "util.h"
20
21using namespace std;
22
23const char* kNinjaVersion = "1.12.0.git";
24
25void ParseVersion(const string& version, int* major, int* minor) {
26 size_t end = version.find('.');
27 *major = atoi(version.substr(0, end).c_str());
28 *minor = 0;
29 if (end != string::npos) {
30 size_t start = end + 1;
31 end = version.find('.', start);
32 *minor = atoi(version.substr(start, end).c_str());
33 }
34}
35
36void CheckNinjaVersion(const string& version) {
37 int bin_major, bin_minor;
38 ParseVersion(kNinjaVersion, &bin_major, &bin_minor);
39 int file_major, file_minor;
40 ParseVersion(version, &file_major, &file_minor);
41
42 if (bin_major > file_major) {
43 Warning("ninja executable version (%s) greater than build file "
44 "ninja_required_version (%s); versions may be incompatible.",
45 kNinjaVersion, version.c_str());
46 return;
47 }
48
49 if ((bin_major == file_major && bin_minor < file_minor) ||
50 bin_major < file_major) {
51 Fatal("ninja version (%s) incompatible with build file "
52 "ninja_required_version version (%s).",
53 kNinjaVersion, version.c_str());
54 }
55}
56