Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
clang-hash
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Christian Dietrich
clang-hash
Commits
f2ec5eef
Commit
f2ec5eef
authored
8 years ago
by
Christian Dietrich
Browse files
Options
Downloads
Patches
Plain Diff
clang-hash-plugin: make backup of object file
parent
df544943
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/clang-hash.cc
+27
-0
27 additions, 0 deletions
src/clang-hash.cc
with
27 additions
and
0 deletions
src/clang-hash.cc
+
27
−
0
View file @
f2ec5eef
...
@@ -8,12 +8,23 @@
...
@@ -8,12 +8,23 @@
#include
<fstream>
#include
<fstream>
#include
<unistd.h>
#include
<unistd.h>
#include
<utime.h>
#include
<utime.h>
#include
<sys/stat.h>
#include
<sys/types.h>
using
namespace
clang
;
using
namespace
clang
;
using
namespace
llvm
;
using
namespace
llvm
;
static
std
::
chrono
::
high_resolution_clock
::
time_point
StartCompilation
;
static
std
::
chrono
::
high_resolution_clock
::
time_point
StartCompilation
;
static
char
*
objectfile
=
NULL
;
static
char
*
objectfile_copy
=
NULL
;
static
void
link_object_file
()
{
if
(
objectfile
&&
objectfile_copy
)
{
link
(
objectfile
,
objectfile_copy
);
}
}
class
HashTranslationUnitConsumer
:
public
ASTConsumer
{
class
HashTranslationUnitConsumer
:
public
ASTConsumer
{
public:
public:
HashTranslationUnitConsumer
(
raw_ostream
*
HS
,
raw_ostream
*
OS
,
HashTranslationUnitConsumer
(
raw_ostream
*
HS
,
raw_ostream
*
OS
,
...
@@ -48,6 +59,13 @@ public:
...
@@ -48,6 +59,13 @@ public:
delete
TopLevelHashStream
;
delete
TopLevelHashStream
;
}
}
// After this binary finishes, we have to call link_object_file to
// copy away our object file.
std
::
string
OutputFileCopy
=
OutputFile
+
".hash_copy"
;
objectfile_copy
=
strdup
(
OutputFileCopy
.
c_str
());
objectfile
=
strdup
(
OutputFile
.
c_str
());
atexit
(
link_object_file
);
// Sometimes we do terminal output
// Sometimes we do terminal output
if
(
Terminal
)
{
if
(
Terminal
)
{
*
Terminal
<<
"hash-start-time-ns "
*
Terminal
<<
"hash-start-time-ns "
...
@@ -86,10 +104,17 @@ public:
...
@@ -86,10 +104,17 @@ public:
*
Terminal
<<
"]
\n
"
;
*
Terminal
<<
"]
\n
"
;
*
Terminal
<<
"skipped: "
<<
(
StopCompiling
?
"true"
:
"false"
)
<<
"
\n
"
;
*
Terminal
<<
"skipped: "
<<
(
StopCompiling
?
"true"
:
"false"
)
<<
"
\n
"
;
}
}
if
(
StopCompiling
)
{
if
(
StopCompiling
)
{
struct
stat
dummy
;
// Object file not existing. Copy it from the backup
if
(
stat
(
OutputFile
.
c_str
(),
&
dummy
)
==
-
1
)
{
link
(
OutputFileCopy
.
c_str
(),
OutputFile
.
c_str
());
}
utime
(
OutputFile
.
c_str
(),
nullptr
);
// touch object file
utime
(
OutputFile
.
c_str
(),
nullptr
);
// touch object file
exit
(
0
);
exit
(
0
);
}
}
}
}
private
:
private
:
...
@@ -213,7 +238,9 @@ private:
...
@@ -213,7 +238,9 @@ private:
}
}
return
HashString
;
return
HashString
;
}
}
};
};
static
FrontendPluginRegistry
::
Add
<
HashTranslationUnitAction
>
static
FrontendPluginRegistry
::
Add
<
HashTranslationUnitAction
>
X
(
"clang-hash"
,
"hash translation unit"
);
X
(
"clang-hash"
,
"hash translation unit"
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment