Skip to content

Commit

Permalink
deploy: 89a8d55
Browse files Browse the repository at this point in the history
  • Loading branch information
Gohla committed Sep 20, 2023
1 parent 0e75a03 commit 44b1281
Show file tree
Hide file tree
Showing 48 changed files with 359 additions and 764 deletions.
2 changes: 1 addition & 1 deletion 1_programmability/0_setup/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ <h1 id="setup"><a class="header" href="#setup">Setup</a></h1>
<p>Run <code>cargo build</code> to test if the project was set up correctly.
The output should look something like:</p>
<pre><code class="language-shell "> Compiling pie v0.1.0 (/pie)
Finished dev [unoptimized + debuginfo] target(s) in 0.12s
Finished dev [unoptimized + debuginfo] target(s) in 0.08s
</code></pre>
<details id="admonition-download-source-code" class="admonition example">
<summary class="admonition-title">
Expand Down
2 changes: 1 addition & 1 deletion 1_programmability/1_api/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ <h2 id="api-implementation"><a class="header" href="#api-implementation">API Imp
<p>Build the project by running <code>cargo build</code>.
The output should look something like:</p>
<pre><code class="language-shell "> Compiling pie v0.1.0 (/pie)
Finished dev [unoptimized + debuginfo] target(s) in 0.06s
Finished dev [unoptimized + debuginfo] target(s) in 0.04s
</code></pre>
<details id="admonition-rust-help" class="admonition info">
<summary class="admonition-title">
Expand Down
20 changes: 20 additions & 0 deletions 1_programmability/2_non_incremental/g_remove_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#[cfg(test)]
mod test {
use super::*;

#[test]
fn test_require_task_direct() {
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
struct ReturnHelloWorld;

impl Task for ReturnHelloWorld {
type Output = String;
fn execute<C: Context<Self>>(&self, _context: &mut C) -> Self::Output {
"Hello World!".to_string()
}
}

let mut context = NonIncrementalContext;
assert_eq!("Hello World!", context.require_task(&ReturnHelloWorld));
}
}
43 changes: 43 additions & 0 deletions 1_programmability/2_non_incremental/h_test_correct.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#[cfg(test)]
mod test {
use super::*;

#[test]
fn test_require_task_direct() {
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
struct ReturnHelloWorld;

impl Task for ReturnHelloWorld {
type Output = String;
fn execute<C: Context<Self>>(&self, _context: &mut C) -> Self::Output {
"Hello World!".to_string()
}
}

let mut context = NonIncrementalContext;
assert_eq!("Hello World!", context.require_task(&ReturnHelloWorld));
}

#[test]
fn test_require_task() {
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
enum Test {
ReturnHelloWorld,
ToLowerCase,
}

impl Task for Test {
type Output = String;
fn execute<C: Context<Self>>(&self, context: &mut C) -> Self::Output {
match self {
Self::ReturnHelloWorld => "Hello World!".to_string(),
Self::ToLowerCase => context.require_task(&Self::ReturnHelloWorld).to_lowercase(),
}
}
}

let mut context = NonIncrementalContext;
assert_eq!("Hello World!", context.require_task(&Test::ReturnHelloWorld));
assert_eq!("hello world!", context.require_task(&Test::ToLowerCase));
}
}
48 changes: 37 additions & 11 deletions 1_programmability/2_non_incremental/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,14 @@ <h2 id="context-module"><a class="header" href="#context-module">Context module<
fileListToggle: false,
fileContentToggle: false,

outputFormat: 'side-by-side',
outputFormat: 'line-by-line',
matching: 'lines',
};
let diff2htmlUi = new Diff2HtmlUI(target, diff, configuration, hljs);
diff2htmlUi.draw();
});
</script>
<p>This is a diff over <code>pie/src/lib.rs</code> where lines with a green background are additions, lines with a red background are removals, and lines with a grey background are context on where to add/remove lines, similar to diffs on source code hubs like GitHub.</p>
<p>This is a diff over <code>pie/src/lib.rs</code> where lines with a green background are additions, lines with a red background are removals, lines without a special background are context on where to add/remove lines, and lines starting with <code>@@</code> denote changed lines (in unified diff style). This is similar to diffs on source code hubs like GitHub.</p>
<p>Create the <code>pie/src/context</code> directory, and in it, create the <code>pie/src/context/mod.rs</code> file with the following contents:</p>
<pre><code class="language-rust ">pub mod non_incremental;</code></pre>
<p>Both modules are public so that users of our library can access context implementations.</p>
Expand Down Expand Up @@ -300,7 +300,7 @@ <h2 id="simple-test"><a class="header" href="#simple-test">Simple Test</a></h2>
<p>Run the test by running <code>cargo test</code>.
The output should look something like:</p>
<pre><code class="language-shell "> Compiling pie v0.1.0 (/pie)
Finished test [unoptimized + debuginfo] target(s) in 0.47s
Finished test [unoptimized + debuginfo] target(s) in 0.31s
Running unittests src/lib.rs (/pie/target/debug/deps/pie-6c9d55a7ef727e00)

running 1 test
Expand Down Expand Up @@ -382,7 +382,7 @@ <h2 id="test-with-multiple-tasks"><a class="header" href="#test-with-multiple-ta
fileListToggle: false,
fileContentToggle: false,

outputFormat: 'side-by-side',
outputFormat: 'line-by-line',
matching: 'lines',
};
let diff2htmlUi = new Diff2HtmlUI(target, diff, configuration, hljs);
Expand Down Expand Up @@ -486,17 +486,17 @@ <h2 id="test-with-multiple-tasks"><a class="header" href="#test-with-multiple-ta
</div>
</details>
<p>For now, we will solve this by just using a single task type which is an enumeration of the different possible tasks.
Replace the test with the following:</p>
First remove the problematic test:</p>
<div class="diff2html" id="diff2html_3"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- original
+++ modified
@@ -0,28 +0,27 @@
let diff = String.raw`--- pie/src/context/non_incremental.rs
+++ pie/src/context/non_incremental.rs
@@ -17,28 +17,4 @@
let mut context = NonIncrementalContext;
assert_eq!("Hello World!", context.require_task(&ReturnHelloWorld));
}
-
- #[test]
- fn test_require_task_problematic() {
- #[derive(Clone, PartialEq, Eq, Hash, Debug)]
Expand All @@ -520,6 +520,32 @@ <h2 id="test-with-multiple-tasks"><a class="header" href="#test-with-multiple-ta
- let mut context = NonIncrementalContext;
- assert_eq!("hello world!", context.require_task(&ToLowerCase));
- }
}
`;
let target = document.getElementById('diff2html_3');
let configuration = {
drawFileList: false,
fileListToggle: false,
fileContentToggle: false,

outputFormat: 'line-by-line',
matching: 'lines',
};
let diff2htmlUi = new Diff2HtmlUI(target, diff, configuration, hljs);
diff2htmlUi.draw();
});
</script>
<p>Then add the following test:</p>
<div class="diff2html" id="diff2html_4"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- pie/src/context/non_incremental.rs
+++ pie/src/context/non_incremental.rs
@@ -17,4 +17,27 @@
let mut context = NonIncrementalContext;
assert_eq!("Hello World!", context.require_task(&ReturnHelloWorld));
}
+
+ #[test]
+ fn test_require_task() {
+ #[derive(Clone, PartialEq, Eq, Hash, Debug)]
Expand All @@ -544,13 +570,13 @@ <h2 id="test-with-multiple-tasks"><a class="header" href="#test-with-multiple-ta
+ }
}
`;
let target = document.getElementById('diff2html_3');
let target = document.getElementById('diff2html_4');
let configuration = {
drawFileList: false,
fileListToggle: false,
fileContentToggle: false,

outputFormat: 'side-by-side',
outputFormat: 'line-by-line',
matching: 'lines',
};
let diff2htmlUi = new Diff2HtmlUI(target, diff, configuration, hljs);
Expand Down
15 changes: 4 additions & 11 deletions 2_incrementality/1_require_file/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ <h1 id="requiring-files"><a class="header" href="#requiring-files">Requiring Fil
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- pie/src/lib.rs
+++ pie/src/lib.rs
@@ -1,19 +1,29 @@
@@ -1,5 +1,8 @@
use std::fmt::Debug;
+use std::fs::File;
use std::hash::Hash;
Expand All @@ -193,14 +193,7 @@ <h1 id="requiring-files"><a class="header" href="#requiring-files">Requiring Fil
pub mod context;
/// A unit of computation in a programmatic incremental build system.
pub trait Task: Clone + Eq + Hash + Debug {
/// Type of output this task returns when executed.
type Output: Clone + Eq + Debug;
/// Execute the task, using ${"`"}context${"`"} to specify dynamic dependencies, returning ${"`"}Self::Output${"`"}.
fn execute<C: Context<Self>>(&self, context: &mut C) -> Self::Output;
}
@@ -14,6 +17,13 @@
/// Programmatic incremental build context, enabling tasks to create dynamic dependencies that context implementations
/// use for incremental execution.
pub trait Context<T: Task> {
Expand Down Expand Up @@ -277,7 +270,7 @@ <h1 id="requiring-files"><a class="header" href="#requiring-files">Requiring Fil
fileListToggle: false,
fileContentToggle: false,

outputFormat: 'side-by-side',
outputFormat: 'line-by-line',
matching: 'lines',
};
let diff2htmlUi = new Diff2HtmlUI(target, diff, configuration, hljs);
Expand Down Expand Up @@ -404,7 +397,7 @@ <h1 id="requiring-files"><a class="header" href="#requiring-files">Requiring Fil
fileListToggle: false,
fileContentToggle: false,

outputFormat: 'side-by-side',
outputFormat: 'line-by-line',
matching: 'lines',
};
let diff2htmlUi = new Diff2HtmlUI(target, diff, configuration, hljs);
Expand Down
74 changes: 18 additions & 56 deletions 2_incrementality/2_stamp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ <h1 id="stamps"><a class="header" href="#stamps">Stamps</a></h1>
fileListToggle: false,
fileContentToggle: false,

outputFormat: 'side-by-side',
outputFormat: 'line-by-line',
matching: 'lines',
};
let diff2htmlUi = new Diff2HtmlUI(target, diff, configuration, hljs);
Expand Down Expand Up @@ -376,8 +376,16 @@ <h2 id="tests"><a class="header" href="#tests">Tests</a></h2>
}</code></pre>
<p>We test file stamps by creating a stamp, changing the file, creating a new stamp, and then compare the stamps.
We test task output stamps by just passing a different output value to the <code>stamp</code> function, and then compare the stamps.</p>
<p>Run <code>cargo test</code> to confirm the stamp implementation.
If test <code>test_modified_file_stamper</code> fails, do continue to the next section, because we're going to fix it!</p>
<p>Run <code>cargo test</code> to confirm the stamp implementation.</p>
<div id="admonition-warning" class="admonition warning">
<div class="admonition-title">
<p>Warning</p>
<p><a class="admonition-anchor-link" href="#admonition-warning"></a></p>
</div>
<div>
<p>Test <code>test_modified_file_stamper</code> will likely fail. Do continue to the next section, because we're going to fix it!</p>
</div>
</div>
<h2 id="testing-with-file-modified-time-correctly"><a class="header" href="#testing-with-file-modified-time-correctly">Testing with file modified time, correctly</a></h2>
<p>Unfortunately, these tests may fail on some operating systems (Linux and Windows in my testing), due to an imprecise file last modified timer.
What can happen is that we write to a file, making the OS update its modified time to <code>1000</code> (as an example, not a real timestamp), then very quickly write to the file again, making the OS update its modified time to <code>1000</code> again.
Expand All @@ -391,16 +399,15 @@ <h2 id="testing-with-file-modified-time-correctly"><a class="header" href="#test
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- dev_shared/src/lib.rs
+++ dev_shared/src/lib.rs
@@ -1,9 +1,38 @@
@@ -1,4 +1,7 @@
+use std::fs::{metadata, write};
use std::io;
+use std::path::Path;
+use std::time::SystemTime;
use tempfile::{NamedTempFile, TempDir};
/// Creates a new temporary file that gets cleaned up when dropped.
pub fn create_temp_file() -> Result<NamedTempFile, io::Error> { NamedTempFile::new() }
@@ -7,3 +10,29 @@
/// Creates a new temporary directory that gets cleaned up when dropped.
pub fn create_temp_dir() -> Result<TempDir, io::Error> { TempDir::new() }
Expand Down Expand Up @@ -437,7 +444,7 @@ <h2 id="testing-with-file-modified-time-correctly"><a class="header" href="#test
fileListToggle: false,
fileContentToggle: false,

outputFormat: 'side-by-side',
outputFormat: 'line-by-line',
matching: 'lines',
};
let diff2htmlUi = new Diff2HtmlUI(target, diff, configuration, hljs);
Expand All @@ -451,7 +458,7 @@ <h2 id="testing-with-file-modified-time-correctly"><a class="header" href="#test
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- pie/src/stamp.rs
+++ pie/src/stamp.rs
@@ -1,50 +1,52 @@
@@ -1,9 +1,9 @@
#[cfg(test)]
mod test {
- use std::fs::{remove_file, write};
Expand All @@ -463,23 +470,7 @@ <h2 id="testing-with-file-modified-time-correctly"><a class="header" href="#test
use super::*;
#[test]
fn test_exists_file_stamper() -> Result<(), io::Error> {
let stamper = FileStamper::Exists;
let temp_file = create_temp_file()?;
let stamp = stamper.stamp(&temp_file)?;
assert_eq!(stamp, stamper.stamp(&temp_file)?);
remove_file(&temp_file)?;
assert_ne!(stamp, stamper.stamp(&temp_file)?);
Ok(())
}
#[test]
fn test_modified_file_stamper() -> Result<(), io::Error> {
let stamper = FileStamper::Modified;
let temp_file = create_temp_file()?;
@@ -27,7 +27,9 @@
let stamp = stamper.stamp(&temp_file)?;
assert_eq!(stamp, stamper.stamp(&temp_file)?);
Expand All @@ -490,23 +481,6 @@ <h2 id="testing-with-file-modified-time-correctly"><a class="header" href="#test
let new_stamp = stamper.stamp(&temp_file)?;
assert_ne!(stamp, new_stamp);
let stamp = new_stamp;
remove_file(&temp_file)?;
assert_ne!(stamp, stamper.stamp(&temp_file)?);
Ok(())
}
#[test]
fn test_inconsequential_output_stamper() {
let stamper = OutputStamper::Inconsequential;
let stamp = stamper.stamp(&1);
assert_eq!(stamp, stamper.stamp(&1));
assert_eq!(stamp, stamper.stamp(&2));
}
#[test]
fn test_equals_output_stamper() {
`;
let target = document.getElementById('diff2html_2');
let configuration = {
Expand All @@ -533,10 +507,7 @@ <h2 id="stamps-in-context"><a class="header" href="#stamps-in-context">Stamps in
document.addEventListener('DOMContentLoaded', function () {
let diff = String.raw`--- pie/src/lib.rs
+++ pie/src/lib.rs
@@ -1,31 +1,46 @@
use std::fmt::Debug;
use std::fs::File;
use std::hash::Hash;
@@ -4,6 +4,8 @@
use std::io;
use std::path::Path;
Expand All @@ -545,15 +516,7 @@ <h2 id="stamps-in-context"><a class="header" href="#stamps-in-context">Stamps in
pub mod stamp;
pub mod context;
mod fs;
/// A unit of computation in a programmatic incremental build system.
pub trait Task: Clone + Eq + Hash + Debug {
/// Type of output this task returns when executed.
type Output: Clone + Eq + Debug;
/// Execute the task, using ${"`"}context${"`"} to specify dynamic dependencies, returning ${"`"}Self::Output${"`"}.
fn execute<C: Context<Self>>(&self, context: &mut C) -> Self::Output;
}
@@ -19,12 +21,25 @@
/// Programmatic incremental build context, enabling tasks to create dynamic dependencies that context implementations
/// use for incremental execution.
pub trait Context<T: Task> {
Expand Down Expand Up @@ -583,7 +546,6 @@ <h2 id="stamps-in-context"><a class="header" href="#stamps-in-context">Stamps in
/// Requires given ${"`"}task${"`"}, recording a dependency and selectively executing it. Returns its up-to-date output.
fn require_task(&mut self, task: &T) -> T::Output;
}
`;
let target = document.getElementById('diff2html_3');
let configuration = {
Expand Down
2 changes: 1 addition & 1 deletion 2_incrementality/3_dependency/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ <h1 id="dynamic-dependencies"><a class="header" href="#dynamic-dependencies">Dyn
fileListToggle: false,
fileContentToggle: false,

outputFormat: 'side-by-side',
outputFormat: 'line-by-line',
matching: 'lines',
};
let diff2htmlUi = new Diff2HtmlUI(target, diff, configuration, hljs);
Expand Down
Loading

0 comments on commit 44b1281

Please sign in to comment.