@@ -723,6 +723,31 @@ struct BuildWithLogTest : public BuildTest {
723
723
BuildLog build_log_;
724
724
};
725
725
726
+ TEST_F (BuildWithLogTest, NotInLogButOnDisk) {
727
+ ASSERT_NO_FATAL_FAILURE (AssertParse (&state_,
728
+ " rule cc\n "
729
+ " command = cc\n "
730
+ " build out1: cc in\n " ));
731
+
732
+ // Create input/output that would be considered up to date when
733
+ // not considering the command line hash.
734
+ fs_.Create (" in" , now_, " " );
735
+ fs_.Create (" out1" , now_, " " );
736
+ string err;
737
+
738
+ // Because it's not in the log, it should not be up-to-date until
739
+ // we build again.
740
+ EXPECT_TRUE (builder_.AddTarget (" out1" , &err));
741
+ EXPECT_FALSE (builder_.AlreadyUpToDate ());
742
+
743
+ commands_ran_.clear ();
744
+ state_.Reset ();
745
+
746
+ EXPECT_TRUE (builder_.AddTarget (" out1" , &err));
747
+ EXPECT_TRUE (builder_.Build (&err));
748
+ EXPECT_TRUE (builder_.AlreadyUpToDate ());
749
+ }
750
+
726
751
TEST_F (BuildWithLogTest, RestatTest) {
727
752
ASSERT_NO_FATAL_FAILURE (AssertParse (&state_,
728
753
" rule true\n "
@@ -743,9 +768,22 @@ TEST_F(BuildWithLogTest, RestatTest) {
743
768
744
769
fs_.Create (" in" , now_, " " );
745
770
771
+ // Do a pre-build so that there's commands in the log for the outputs,
772
+ // otherwise, the lack of an entry in the build log will cause out3 to rebuild
773
+ // regardless of restat.
774
+ string err;
775
+ EXPECT_TRUE (builder_.AddTarget (" out3" , &err));
776
+ ASSERT_EQ (" " , err);
777
+ EXPECT_TRUE (builder_.Build (&err));
778
+ ASSERT_EQ (" " , err);
779
+ commands_ran_.clear ();
780
+ state_.Reset ();
781
+
782
+ now_++;
783
+
784
+ fs_.Create (" in" , now_, " " );
746
785
// "cc" touches out1, so we should build out2. But because "true" does not
747
786
// touch out2, we should cancel the build of out3.
748
- string err;
749
787
EXPECT_TRUE (builder_.AddTarget (" out3" , &err));
750
788
ASSERT_EQ (" " , err);
751
789
EXPECT_TRUE (builder_.Build (&err));
@@ -790,10 +828,24 @@ TEST_F(BuildWithLogTest, RestatMissingFile) {
790
828
fs_.Create (" in" , now_, " " );
791
829
fs_.Create (" out2" , now_, " " );
792
830
831
+ // Do a pre-build so that there's commands in the log for the outputs,
832
+ // otherwise, the lack of an entry in the build log will cause out2 to rebuild
833
+ // regardless of restat.
834
+ string err;
835
+ EXPECT_TRUE (builder_.AddTarget (" out2" , &err));
836
+ ASSERT_EQ (" " , err);
837
+ EXPECT_TRUE (builder_.Build (&err));
838
+ ASSERT_EQ (" " , err);
839
+ commands_ran_.clear ();
840
+ state_.Reset ();
841
+
842
+ now_++;
843
+ fs_.Create (" in" , now_, " " );
844
+ fs_.Create (" out2" , now_, " " );
845
+
793
846
// Run a build, expect only the first command to run.
794
847
// It doesn't touch its output (due to being the "true" command), so
795
848
// we shouldn't run the dependent build.
796
- string err;
797
849
EXPECT_TRUE (builder_.AddTarget (" out2" , &err));
798
850
ASSERT_EQ (" " , err);
799
851
EXPECT_TRUE (builder_.Build (&err));
0 commit comments