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
21 const char* kNinjaVersion = "1.10.1";
22
ParseVersion(const string & version,int * major,int * minor)23 void ParseVersion(const string& version, int* major, int* minor) {
24 size_t end = version.find('.');
25 *major = atoi(version.substr(0, end).c_str());
26 *minor = 0;
27 if (end != string::npos) {
28 size_t start = end + 1;
29 end = version.find('.', start);
30 *minor = atoi(version.substr(start, end).c_str());
31 }
32 }
33
CheckNinjaVersion(const string & version)34 void CheckNinjaVersion(const string& version) {
35 int bin_major, bin_minor;
36 ParseVersion(kNinjaVersion, &bin_major, &bin_minor);
37 int file_major, file_minor;
38 ParseVersion(version, &file_major, &file_minor);
39
40 if (bin_major > file_major) {
41 Warning("ninja executable version (%s) greater than build file "
42 "ninja_required_version (%s); versions may be incompatible.",
43 kNinjaVersion, version.c_str());
44 return;
45 }
46
47 if ((bin_major == file_major && bin_minor < file_minor) ||
48 bin_major < file_major) {
49 Fatal("ninja version (%s) incompatible with build file "
50 "ninja_required_version version (%s).",
51 kNinjaVersion, version.c_str());
52 }
53 }
54