File: .lake/packages/lean4/src/lean/lake/Lake/Build/Common.lean

full_name: Lake.platformTrace
code: /--
Build trace for the host platform.
If an artifact includes this in its trace, it is platform-dependent
and will be rebuilt on different host platforms.
-/
def platformTrace 
goal: Lake.Hash

full_name: Lake.BuildMetadata.depHash
code: /--
The build trace file format,
which stores information about a (successful) build.
-/
structure BuildMetadata where
  depHash : Hash
  log : Log
  deriving ToJson
goal: Lake.Hash

full_name: Lake.BuildMetadata
code: /--
The build trace file format,
which stores information about a (successful) build.
-/
structure BuildMetadata where
  depHash : Hash
  log : Log
  deriving ToJson
goal: Type

full_name: Lake.BuildMetadata.log
code: /--
The build trace file format,
which stores information about a (successful) build.
-/
structure BuildMetadata where
  depHash : Hash
  log : Log
  deriving ToJson
goal: Lake.Log

full_name: Lake.instToJsonBuildMetadata
code: ToJson
goal: Lean.ToJson Lake.BuildMetadata

full_name: Lake.BuildMetadata.ofHash
code: def BuildMetadata.ofHash (h : Hash) : BuildMetadata 
goal: Lake.BuildMetadata

full_name: Lake.BuildMetadata.fromJson?
code: def BuildMetadata.fromJson? (json : Json) : Except String BuildMetadata 
goal: Except String Lake.BuildMetadata

full_name: Lake.instFromJsonBuildMetadata
code: instance : FromJson BuildMetadata 
goal: Lean.FromJson Lake.BuildMetadata

full_name: Lake.readTraceFile?
code: /-- Read persistent trace data from a file. -/
def readTraceFile? (path : FilePath) : LogIO (Option BuildMetadata) 
goal: Lake.LogIO (Option Lake.BuildMetadata)

full_name: Lake.writeTraceFile
code: /-- Write persistent trace data to a file. -/
def writeTraceFile (path : FilePath) (depTrace : BuildTrace) (log : Log) 
goal: IO Unit

full_name: Lake.checkHashUpToDate
code: /--
Checks if the `info` is up-to-date by comparing `depTrace` with `depHash`.
If old mode is enabled (e.g., `--old`), uses the `oldTrace` modification time
as the point of comparison instead.
-/
@[specialize] def checkHashUpToDate
  [CheckExists ι] [GetMTime ι]
  (info : ι) (depTrace : BuildTrace) (depHash : Option Hash)
  (oldTrace := depTrace.mtime)
: JobM Bool 
goal: Lake.JobM Bool

full_name: Lake.buildUnlessUpToDate?.go
code: /--
Checks whether `info` is up-to-date, and runs `build` to recreate it if not.
If rebuilt, saves the new `depTrace` and build log to `traceFile`.
Returns whether `info` was already up-to-date.

**Up-to-date Checking**

If `traceFile` exists, checks that the hash in `depTrace` matches that
of the `traceFile`. If not, and old mode is enabled (e.g., `--old`), falls back
to the `oldTrace` modification time as the point of comparison.
If up-to-date, replay the build log stored in `traceFile`.

If `traceFile` does not exist, checks that `info` has a newer modification time
then `depTrace` / `oldTrace`. No log will be replayed.
-/
@[specialize] def buildUnlessUpToDate?
  [CheckExists ι] [GetMTime ι] (info : ι)
  (depTrace : BuildTrace) (traceFile : FilePath) (build : JobM PUnit)
  (action : JobAction := .build) (oldTrace := depTrace.mtime)
: JobM Bool 
goal: Lake.JobM Bool

full_name: Lake.buildUnlessUpToDate?
code: /--
Checks whether `info` is up-to-date, and runs `build` to recreate it if not.
If rebuilt, saves the new `depTrace` and build log to `traceFile`.
Returns whether `info` was already up-to-date.

**Up-to-date Checking**

If `traceFile` exists, checks that the hash in `depTrace` matches that
of the `traceFile`. If not, and old mode is enabled (e.g., `--old`), falls back
to the `oldTrace` modification time as the point of comparison.
If up-to-date, replay the build log stored in `traceFile`.

If `traceFile` does not exist, checks that `info` has a newer modification time
then `depTrace` / `oldTrace`. No log will be replayed.
-/
@[specialize] def buildUnlessUpToDate?
  [CheckExists ι] [GetMTime ι] (info : ι)
  (depTrace : BuildTrace) (traceFile : FilePath) (build : JobM PUnit)
  (action : JobAction := .build) (oldTrace := depTrace.mtime)
: JobM Bool 
goal: Lake.JobM Bool

full_name: Lake.buildUnlessUpToDate
code: /--
Checks whether `info` is up-to-date, and runs `build` to recreate it if not.
If rebuilt, saves the new `depTrace` and build log to `traceFile`.

See `buildUnlessUpToDate?` for more details on how Lake determines whether
`info` is up-to-date.
-/
@[inline] def buildUnlessUpToDate
  [CheckExists ι] [GetMTime ι] (info : ι)
  (depTrace : BuildTrace) (traceFile : FilePath) (build : JobM PUnit)
  (action : JobAction := .build) (oldTrace := depTrace.mtime)
: JobM PUnit 
goal: Lake.JobM PUnit

full_name: Lake.cacheFileHash
code: /-- Computes the hash of a file and saves it to a `.hash` file. -/
def cacheFileHash (file : FilePath) : IO Unit 
goal: IO Unit

full_name: Lake.clearFileHash
code: /-- Remove the cached hash of a file (its `.hash` file). -/
def clearFileHash (file : FilePath) : IO Unit 
goal: IO Unit

full_name: Lake.fetchFileHash
code: /--
Fetches the hash of a file that may already be cached in a `.hash` file.
If the `.hash` file does not exist or hash files are not trusted
(e.g., with `--rehash`), creates it with a newly computed hash.
-/
def fetchFileHash (file : FilePath) : JobM Hash 
goal: Lake.JobM Lake.Hash

full_name: Lake.fetchFileTrace
code: /--
Fetches the trace of a file that may have already have its hash cached
in a `.hash` file. If no such `.hash` file exists, recomputes and creates it.
-/
def fetchFileTrace (file : FilePath) : JobM BuildTrace 
goal: Lake.JobM Lake.BuildTrace

full_name: Lake.buildFileUnlessUpToDate
code: /--
Builds `file` using `build` unless it already exists and `depTrace` matches
the trace stored in the `.trace` file. If built, save the new `depTrace` and
cache `file`'s hash in a `.hash` file. Otherwise, try to fetch the hash from
the `.hash` file using `fetchFileTrace`. Build logs (if any) are saved to
a `.log.json` file and replayed from there if the build is skipped.

For example, given `file := "foo.c"`, compares `depTrace` with that in
`foo.c.trace` with the hash cached in `foo.c.hash` and the log cached in
`foo.c.trace`.
-/
def buildFileUnlessUpToDate
  (file : FilePath) (depTrace : BuildTrace) (build : JobM PUnit)
: JobM BuildTrace 
goal: Lake.JobM Lake.BuildTrace

full_name: Lake.buildFileAfterDep
code: /--
Build `file` using `build` after `dep` completes if the dependency's
trace (and/or `extraDepTrace`) has changed.
-/
@[inline] def buildFileAfterDep
  (file : FilePath) (dep : BuildJob α) (build : α → JobM PUnit)
  (extraDepTrace : JobM _ := pure BuildTrace.nil)
: SpawnM (BuildJob FilePath) 
goal: Lake.SpawnM (Lake.BuildJob Lake.FilePath)

full_name: Lake.buildFileAfterDepList
code: /-- Build `file` using `build` after `deps` have built if any of their traces change. -/
@[inline] def buildFileAfterDepList
  (file : FilePath) (deps : List (BuildJob α)) (build : List α → JobM PUnit)
  (extraDepTrace : JobM _ := pure BuildTrace.nil)
: SpawnM (BuildJob FilePath) 
goal: Lake.SpawnM (Lake.BuildJob Lake.FilePath)

full_name: Lake.buildFileAfterDepArray
code: /-- Build `file` using `build` after `deps` have built if any of their traces change. -/
@[inline] def buildFileAfterDepArray
  (file : FilePath) (deps : Array (BuildJob α)) (build : Array α → JobM PUnit)
  (extraDepTrace : JobM _ := pure BuildTrace.nil)
: SpawnM (BuildJob FilePath) 
goal: Lake.SpawnM (Lake.BuildJob Lake.FilePath)

full_name: Lake.inputBinFile
code: /--
A build job for binary file that is expected to already exist (e.g., a data blob).
Any byte difference in the file will trigger a rebuild of dependents.
-/
def inputBinFile (path : FilePath) : SpawnM (BuildJob FilePath) 
goal: Lake.SpawnM (Lake.BuildJob Lake.FilePath)

full_name: Lake.inputTextFile
code: /--
A build job for text file that is expected to already exist (e.g., a source file).
Normalizes line endings (converts CRLF to LF) to produce platform-independent traces.
-/
def inputTextFile (path : FilePath) : SpawnM (BuildJob FilePath) 
goal: Lake.SpawnM (Lake.BuildJob Lake.FilePath)

full_name: Lake.inputFile
code: /--
A build job for file that is expected to already exist.

**Deprecated:** Use either `inputTextFile` or `inputBinFile`.
`inputTextFile` normalizes line endings to produce platform-independent traces.
-/
@[deprecated] abbrev inputFile 
goal: Lake.SpawnM (Lake.BuildJob Lake.FilePath)

full_name: Lake.buildO
code: /--
Build an object file from a source file job using `compiler`. The invocation is:

```
compiler -c -o oFile srcFile weakArgs... traceArgs...
```

The `traceArgs` are included as part of the dependency trace hash, whereas
the `weakArgs` are not. Thus, system-dependent options like `-I` or `-L` should
be `weakArgs` to avoid build artifact incompatibility between systems
(i.e., a change in the file path should not cause a rebuild).

You can add more components to the trace via `extraDepTrace`,
which will be computed in the resulting `BuildJob` before building.
-/
@[inline] def buildO
  (oFile : FilePath) (srcJob : BuildJob FilePath)
  (weakArgs traceArgs : Array String := #[]) (compiler : FilePath := "cc")
  (extraDepTrace : JobM _ := pure BuildTrace.nil)
: SpawnM (BuildJob FilePath) 
goal: Lake.SpawnM (Lake.BuildJob Lake.FilePath)

full_name: Lake.buildLeanO
code: /-- Build an object file from a source fie job (i.e, a `lean -c` output) using `leanc`. -/
@[inline] def buildLeanO
  (oFile : FilePath) (srcJob : BuildJob FilePath)
  (weakArgs traceArgs : Array String := #[])
: SpawnM (BuildJob FilePath) 
goal: Lake.SpawnM (Lake.BuildJob Lake.FilePath)

full_name: Lake.buildStaticLib
code: /-- Build a static library from object file jobs using the `ar` packaged with Lean. -/
def buildStaticLib
  (libFile : FilePath) (oFileJobs : Array (BuildJob FilePath))
: SpawnM (BuildJob FilePath) 
goal: Lake.SpawnM (Lake.BuildJob Lake.FilePath)

full_name: Lake.buildLeanSharedLib
code: /-- Build a shared library by linking the results of `linkJobs` using `leanc`. -/
def buildLeanSharedLib
  (libFile : FilePath) (linkJobs : Array (BuildJob FilePath))
  (weakArgs traceArgs : Array String := #[])
: SpawnM (BuildJob FilePath) 
goal: Lake.SpawnM (Lake.BuildJob Lake.FilePath)

full_name: Lake.buildLeanExe
code: /-- Build an executable by linking the results of `linkJobs` using `leanc`. -/
def buildLeanExe
  (exeFile : FilePath) (linkJobs : Array (BuildJob FilePath))
  (weakArgs traceArgs : Array String := #[])
: SpawnM (BuildJob FilePath) 
goal: Lake.SpawnM (Lake.BuildJob Lake.FilePath)

full_name: Lake.buildLeanSharedLibOfStatic
code: /-- Build a shared library from a static library using `leanc`. -/
def buildLeanSharedLibOfStatic
  (staticLibJob : BuildJob FilePath)
  (weakArgs traceArgs : Array String := #[])
: SpawnM (BuildJob FilePath) 
goal: Lake.SpawnM (Lake.BuildJob Lake.FilePath)

full_name: Lake.computeDynlibOfShared
code: /-- Construct a `Dynlib` object for a shared library target. -/
def computeDynlibOfShared (sharedLibTarget : BuildJob FilePath) : SpawnM (BuildJob Dynlib) 
goal: Lake.SpawnM (Lake.BuildJob Lake.Dynlib)