Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate both real and smoke manifests before pruning #31

Merged
merged 1 commit into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/build_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@ impl<'a> BuildManifest<'a> {
})
}

pub(crate) fn run(&self, upload_base: &str) -> Result<Execution, Error> {
pub(crate) fn run(&self, upload_base: &str, dest: &Path) -> Result<Execution, Error> {
let config = &self.builder.config;

// Ensure the manifest dir exists but is empty.
let manifest_dir = self.builder.manifest_dir();
if manifest_dir.is_dir() {
std::fs::remove_dir_all(&manifest_dir)?;
if dest.is_dir() {
std::fs::remove_dir_all(&dest)?;
}
std::fs::create_dir_all(&manifest_dir)?;
std::fs::create_dir_all(&dest)?;

// Ensure the shipped files path does not exists
if self.shipped_files_path.is_file() {
Expand All @@ -57,7 +56,7 @@ impl<'a> BuildManifest<'a> {
let num_threads = self.builder.config.num_threads.to_string();
let status = Command::new(self.executable.path())
.arg(self.builder.dl_dir())
.arg(self.builder.manifest_dir())
.arg(dest)
.arg(&self.builder.date)
.arg(upload_base)
.arg(config.channel.to_string())
Expand Down
50 changes: 29 additions & 21 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,38 +189,42 @@ impl Context {
if BuildManifest::exists(self) {
let mut signer = Signer::new(&self.config)?;
let build_manifest = BuildManifest::new(self)?;
let smoke_test = SmokeTester::new(&[self.manifest_dir(), self.dl_dir()])?;

// First of all, a manifest is generated pointing to the smoke test server. This will
// produce the correct checksums and shipped files list, as the only difference from
// between the "real" execution and this one is the URLs included in the manifest.
let execution =
build_manifest.run(&format!("http://{}/dist", smoke_test.server_addr()))?;
signer.override_checksum_cache(execution.checksum_cache);
let smoke_test = SmokeTester::new(&[self.smoke_manifest_dir(), self.dl_dir()])?;

// First of all, the real manifests are generated, pointing to the public download
// endpoint. This will also collect the list of files shipped in the release (used
// later to prune the files we're not shipping) and a cache of all the checksums
// generated by build-manifest.
let execution = build_manifest.run(
&format!("{}/{}", self.config.upload_addr, self.config.upload_dir),
&self.real_manifest_dir(),
)?;

// Then another set of manifests is generated pointing to the smoke test server. These
// manifests will be discarded later.
build_manifest.run(
&format!("http://{}/dist", smoke_test.server_addr()),
&self.smoke_manifest_dir(),
)?;

// Removes files that we are not shipping from the files we're about to upload.
if let Some(shipped_files) = &execution.shipped_files {
self.prune_unused_files(&shipped_files)?;
}

// Sign both the downloaded artifacts and the generated manifests. The signatures of
// the downloaded files are permanent, while the signatures for the generated manifests
// will be discarded later (as the manifests point to the smoke test server).
// Sign both the downloaded artifacts and all the generated manifests. The signatures
// of the downloaded files and the real manifests are permanent, while the signatures
// for the smoke test manifests will be discarded later.
signer.override_checksum_cache(execution.checksum_cache);
signer.sign_directory(&self.dl_dir())?;
signer.sign_directory(&self.manifest_dir())?;
signer.sign_directory(&self.real_manifest_dir())?;
signer.sign_directory(&self.smoke_manifest_dir())?;

// Ensure the release is downloadable from rustup and can execute a basic binary.
smoke_test.test(&self.config.channel)?;

// Generate the real manifests and sign them.
build_manifest.run(&format!(
"{}/{}",
self.config.upload_addr, self.config.upload_dir
))?;
signer.sign_directory(&self.manifest_dir())?;

// Merge the generated manifests with the downloaded artifacts.
for entry in std::fs::read_dir(&self.manifest_dir())? {
for entry in std::fs::read_dir(&self.real_manifest_dir())? {
let entry = entry?;
if entry.file_type()?.is_file() {
std::fs::rename(entry.path(), self.dl_dir().join(entry.file_name()))?;
Expand Down Expand Up @@ -702,10 +706,14 @@ upload-addr = \"{}/{}\"
self.work.join("dl")
}

fn manifest_dir(&self) -> PathBuf {
fn real_manifest_dir(&self) -> PathBuf {
self.work.join("manifests")
}

fn smoke_manifest_dir(&self) -> PathBuf {
self.work.join("manifests-smoke")
}

fn build_dir(&self) -> PathBuf {
self.work.join("build")
}
Expand Down