From dcfb7e10054466bf89c86a27f7ca82a249c73265 Mon Sep 17 00:00:00 2001 From: Jon Edvald Date: Mon, 18 Mar 2019 15:15:23 +0100 Subject: [PATCH] fix(core): generated files were sometimes deleted between build and run --- garden-service/src/actions.ts | 1 - garden-service/src/build-dir.ts | 22 +++++++++++++++----- garden-service/src/tasks/build.ts | 6 +++--- garden-service/test/unit/src/build-dir.ts | 2 +- garden-service/test/unit/src/plugins/exec.ts | 1 + 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/garden-service/src/actions.ts b/garden-service/src/actions.ts index 63e54e0a90..6733f2ab64 100644 --- a/garden-service/src/actions.ts +++ b/garden-service/src/actions.ts @@ -244,7 +244,6 @@ export class ActionHelper implements TypeGuard { } async build(params: ModuleActionHelperParams>): Promise { - await this.garden.buildDir.syncDependencyProducts(params.module) return this.callModuleHandler({ params, actionType: "build" }) } diff --git a/garden-service/src/build-dir.ts b/garden-service/src/build-dir.ts index adde7dfa27..b18dcc9149 100644 --- a/garden-service/src/build-dir.ts +++ b/garden-service/src/build-dir.ts @@ -13,6 +13,7 @@ import { parse, resolve, sep, + relative, } from "path" import { emptyDir, @@ -30,6 +31,7 @@ import * as execa from "execa" import { platform } from "os" import { toCygwinPath } from "./util/util" import { ModuleConfig } from "./config/module" +import { LogEntry } from "./logger/log-entry" // Lazily construct a directory of modules inside which all build steps are performed. @@ -47,16 +49,16 @@ export class BuildDir { return new BuildDir(projectRoot, buildDirPath, buildMetadataDirPath) } - async syncFromSrc(module: ModuleConfig) { + async syncFromSrc(module: ModuleConfig, log: LogEntry) { await this.sync( resolve(this.projectRoot, module.path) + sep, await this.buildPath(module.name), true, + log, ) } - async syncDependencyProducts(module: Module) { - await this.syncFromSrc(module) + async syncDependencyProducts(module: Module, log: LogEntry) { const buildPath = await this.buildPath(module.name) const buildDependencies = await module.build.dependencies const dependencyConfigs = module.build.dependencies || [] @@ -84,7 +86,7 @@ export class BuildDir { const sourcePath = join(sourceBuildPath, copy.source) const destinationPath = join(buildPath, copy.target) - return this.sync(sourcePath, destinationPath, false) + return this.sync(sourcePath, destinationPath, false, log) }) }) } @@ -114,7 +116,7 @@ export class BuildDir { * * If withDelete = true, files/folders in destinationPath that are not in sourcePath will also be deleted. */ - private async sync(sourcePath: string, destinationPath: string, withDelete: boolean): Promise { + private async sync(sourcePath: string, destinationPath: string, withDelete: boolean, log: LogEntry): Promise { const destinationDir = parse(destinationPath).dir await ensureDir(destinationDir) @@ -133,6 +135,16 @@ export class BuildDir { if (withDelete) { syncOpts.push("--delete") } + + let logMsg = + `Syncing from ${relative(this.projectRoot, sourcePath)} to ${relative(this.projectRoot, destinationPath)}` + + if (withDelete) { + logMsg += " (with delete)" + } + + log.debug(logMsg) + await execa("rsync", [...syncOpts, sourcePath, destinationPath]) } } diff --git a/garden-service/src/tasks/build.ts b/garden-service/src/tasks/build.ts index b6453444c5..8a1bb19728 100644 --- a/garden-service/src/tasks/build.ts +++ b/garden-service/src/tasks/build.ts @@ -76,14 +76,14 @@ export class BuildTask extends BaseTask { log.setSuccess({ msg: chalk.green(`Done (took ${log.getDuration(1)} sec)`), append: true }) } - await this.garden.buildDir.syncFromSrc(this.module) + await this.garden.buildDir.syncFromSrc(this.module, log) + await this.garden.buildDir.syncDependencyProducts(this.module, log) if (!this.force) { + log.setState({ msg: `Getting build status...` }) const status = await this.garden.actions.getBuildStatus({ log: this.log, module }) if (status.ready) { - // this is necessary in case other modules depend on files from this one - await this.garden.buildDir.syncDependencyProducts(this.module) logSuccess() return { fresh: false } } diff --git a/garden-service/test/unit/src/build-dir.ts b/garden-service/test/unit/src/build-dir.ts index dc8dfa8212..27884d0f9a 100644 --- a/garden-service/test/unit/src/build-dir.ts +++ b/garden-service/test/unit/src/build-dir.ts @@ -48,7 +48,7 @@ describe("BuildDir", () => { it("should sync sources to the build dir", async () => { const garden = await makeGarden() const moduleA = await garden.resolveModuleConfig("module-a") - await garden.buildDir.syncFromSrc(moduleA) + await garden.buildDir.syncFromSrc(moduleA, garden.log) const buildDirA = await garden.buildDir.buildPath(moduleA.name) const copiedPaths = [ diff --git a/garden-service/test/unit/src/plugins/exec.ts b/garden-service/test/unit/src/plugins/exec.ts index c9b36120f3..297d8d4cdd 100644 --- a/garden-service/test/unit/src/plugins/exec.ts +++ b/garden-service/test/unit/src/plugins/exec.ts @@ -158,6 +158,7 @@ describe("exec plugin", () => { const buildMetadataPath = module.buildMetadataPath const versionFilePath = join(buildMetadataPath, GARDEN_BUILD_VERSION_FILENAME) + await garden.buildDir.syncFromSrc(module, log) await garden.actions.build({ log, module }) const versionFileContents = await readModuleVersionFile(versionFilePath)