-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the output of
ninja -t inputs
deterministic
This sorts the output of `ninja -t inputs` to make it deterministic and remove duplicates, and adds a regression test in output_test.py Note that the default is to print explicit and implicit inputs, but this can be changed using the --type=TYPE option or the tool as in: ninja -t inputs --type=explicit <targets> To print only explicit inputs. See --type=list for a list of all possible values.
- Loading branch information
1 parent
f404f00
commit 56ba9a2
Showing
11 changed files
with
350 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2022 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "inputs_type.h" | ||
|
||
#include <cstring> | ||
|
||
// static | ||
const InputsType::TypeInfo* InputsType::GetTypeInfos(int* count) { | ||
static const TypeInfo kInfo[] = { | ||
{ "default", InputsType::Default, "explicit and implicit inputs" }, | ||
{ "explicit", InputsType::Explicit, "explicit inputs only" }, | ||
{ "all", InputsType::All, "explicit, implicit and order-only inputs" }, | ||
}; | ||
*count = 3; | ||
return kInfo; | ||
} | ||
|
||
bool InputsType::ParseArg(const char* arg) { | ||
int count; | ||
const TypeInfo* infos = GetTypeInfos(&count); | ||
for (int n = 0; n < count; ++n) { | ||
if (!strcmp(infos[n].name, arg)) { | ||
value = infos[n].value; | ||
return true; | ||
} | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2022 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef NINJA_INPUTS_TYPE_H_ | ||
#define NINJA_INPUTS_TYPE_H_ | ||
|
||
// A small struct representing a value for the --inputs-type option, | ||
// used to select which inputs are printed by `-t inputs`. | ||
// | ||
// The Default value prints explicit and implicit inputs. | ||
// The Explicit value prints explicit inputs only. | ||
// The All value prints explicit, implicit as well as order-only inputs. | ||
struct InputsType { | ||
enum Type { | ||
Default, | ||
Explicit, | ||
All, | ||
}; | ||
|
||
InputsType() : value(Default) {} | ||
|
||
Type value; | ||
|
||
// Parse |arg| for a vlid --inputs-type argument. On | ||
// success return true and set |value|. On failure return false. | ||
bool ParseArg(const char* arg); | ||
|
||
// Small struct describing the name and purpose of each supported | ||
// argument. Does not include 'list'. | ||
struct TypeInfo { | ||
const char* name; | ||
Type value; | ||
const char* help; | ||
}; | ||
|
||
// Return the address of an array of TypeInfo items whichi describe | ||
// all supported argument strings, and their corresponding value, | ||
// plus some help text. Set |*count| to the size of the array. | ||
static const TypeInfo* GetTypeInfos(int* count); | ||
}; | ||
|
||
#endif // NINJA_INPUTS_TYPE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2022 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "inputs_type.h" | ||
|
||
#include "test.h" | ||
|
||
TEST(InputsType, Test) { | ||
InputsType type; | ||
EXPECT_EQ(InputsType::Default, type.value); | ||
|
||
EXPECT_TRUE(type.ParseArg("explicit")); | ||
EXPECT_EQ(InputsType::Explicit, type.value); | ||
|
||
EXPECT_TRUE(type.ParseArg("all")); | ||
EXPECT_EQ(InputsType::All, type.value); | ||
|
||
EXPECT_TRUE(type.ParseArg("default")); | ||
EXPECT_EQ(InputsType::Default, type.value); | ||
|
||
EXPECT_FALSE(type.ParseArg("unknown-type")); | ||
EXPECT_EQ(InputsType::Default, type.value); | ||
} | ||
|
||
TEST(InputsType, GetTypeInfos) { | ||
int count = 0; | ||
const InputsType::TypeInfo* infos = InputsType::GetTypeInfos(&count); | ||
EXPECT_GT(count, 0); | ||
} |
Oops, something went wrong.