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

fix(core): generated files were sometimes deleted between build and run #640

Merged
merged 1 commit into from
Mar 18, 2019
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
1 change: 0 additions & 1 deletion garden-service/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ export class ActionHelper implements TypeGuard {
}

async build<T extends Module>(params: ModuleActionHelperParams<BuildModuleParams<T>>): Promise<BuildResult> {
await this.garden.buildDir.syncDependencyProducts(params.module)
return this.callModuleHandler({ params, actionType: "build" })
}

Expand Down
22 changes: 17 additions & 5 deletions garden-service/src/build-dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
parse,
resolve,
sep,
relative,
} from "path"
import {
emptyDir,
Expand All @@ -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.

Expand All @@ -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 || []
Expand Down Expand Up @@ -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)
})
})
}
Expand Down Expand Up @@ -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<void> {
private async sync(sourcePath: string, destinationPath: string, withDelete: boolean, log: LogEntry): Promise<void> {
const destinationDir = parse(destinationPath).dir
await ensureDir(destinationDir)

Expand All @@ -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])
}
}
Expand Down
6 changes: 3 additions & 3 deletions garden-service/src/tasks/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand Down
2 changes: 1 addition & 1 deletion garden-service/test/unit/src/build-dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
1 change: 1 addition & 0 deletions garden-service/test/unit/src/plugins/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down