Ninja
|
00001 // Copyright 2013 Google Inc. All Rights Reserved. 00002 // 00003 // Licensed under the Apache License, Version 2.0 (the "License"); 00004 // you may not use this file except in compliance with the License. 00005 // You may obtain a copy of the License at 00006 // 00007 // http://www.apache.org/licenses/LICENSE-2.0 00008 // 00009 // Unless required by applicable law or agreed to in writing, software 00010 // distributed under the License is distributed on an "AS IS" BASIS, 00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00012 // See the License for the specific language governing permissions and 00013 // limitations under the License. 00014 00015 #include "version.h" 00016 00017 #include <stdlib.h> 00018 00019 #include "util.h" 00020 00021 const char* kNinjaVersion = "1.3.4"; 00022 00023 void ParseVersion(const string& version, int* major, int* minor) { 00024 size_t end = version.find('.'); 00025 *major = atoi(version.substr(0, end).c_str()); 00026 *minor = 0; 00027 if (end != string::npos) { 00028 size_t start = end + 1; 00029 end = version.find('.', start); 00030 *minor = atoi(version.substr(start, end).c_str()); 00031 } 00032 } 00033 00034 void CheckNinjaVersion(const string& version) { 00035 int bin_major, bin_minor; 00036 ParseVersion(kNinjaVersion, &bin_major, &bin_minor); 00037 int file_major, file_minor; 00038 ParseVersion(version, &file_major, &file_minor); 00039 00040 if (bin_major > file_major) { 00041 Warning("ninja executable version (%s) greater than build file " 00042 "ninja_required_version (%s); versions may be incompatible.", 00043 kNinjaVersion, version.c_str()); 00044 return; 00045 } 00046 00047 if ((bin_major == file_major && bin_minor < file_minor) || 00048 bin_major < file_major) { 00049 Fatal("ninja version (%s) incompatible with build file " 00050 "ninja_required_version version (%s).", 00051 kNinjaVersion, version.c_str()); 00052 } 00053 }