Skip to content

Commit

Permalink
fix: building windows 32 bit and 64 bit simultaneously
Browse files Browse the repository at this point in the history
Close #470
  • Loading branch information
develar committed Jun 5, 2016
1 parent 12ba8b7 commit cec4b3d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
17 changes: 11 additions & 6 deletions src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ export function normalizeOptions(args: CliOptions): BuildOptions {
}

function commonArch(): Array<Arch> {
if (args.ia32) {
if (args.ia32 && args.x64) {
return [Arch.x64, Arch.ia32]
}
else if (args.ia32) {
return [Arch.ia32]
}
else if (args.x64) {
return [Arch.x64]
}
else if (args.ia32 && args.x64) {
return [Arch.x64, Arch.ia32]
}
else {
return [archFromString(process.arch)]
}
Expand Down Expand Up @@ -128,7 +128,12 @@ export function normalizeOptions(args: CliOptions): BuildOptions {
}

if (targets.size === 0) {
targets = createTargets(normalizePlatforms(args.platform), null, args.arch)
if (args.platform == null) {
processTargets(Platform.current(), [])
}
else {
targets = createTargets(normalizePlatforms(args.platform), null, args.arch)
}
}

const result = Object.assign({}, args)
Expand Down Expand Up @@ -158,7 +163,7 @@ export function createTargets(platforms: Array<Platform>, type?: string | null,
const targets = new Map<Platform, Map<Arch, Array<string>>>()
for (let platform of platforms) {
const archs = platform === Platform.OSX ? [Arch.x64] : (arch === "all" ? [Arch.x64, Arch.ia32] : [archFromString(arch == null ? process.arch : arch)])
let archToType = new Map<Arch, Array<string>>()
const archToType = new Map<Arch, Array<string>>()
targets.set(platform, archToType)

for (let arch of archs) {
Expand Down
12 changes: 10 additions & 2 deletions src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,16 @@ export class Platform {
return this.name
}

public createTarget(type?: string | null, arch: Arch = archFromString(process.arch)): Map<Platform, Map<Arch, Array<string>>> {
return new Map([[this, new Map([[arch, type == null ? [] : [type]]])]])
public createTarget(type?: string | null, ...archs: Array<Arch>): Map<Platform, Map<Arch, Array<string>>> {
const archToType = new Map()
for (let arch of (archs == null || archs.length === 0 ? [archFromString(process.arch)] : archs)) {
archToType.set(arch, type == null ? [] : [type])
}
return new Map([[this, archToType]])
}

public static current(): Platform {
return Platform.fromString(process.platform)
}

public static fromString(name: string): Platform {
Expand Down
1 change: 1 addition & 0 deletions test/src/BuildTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ test("cli", () => {
}

assertThat(parse("--osx")).isEqualTo(expected({targets: Platform.OSX.createTarget()}))
assertThat(parse("--ia32 --x64")).isEqualTo(expected({targets: Platform.current().createTarget(null, Arch.x64, Arch.ia32)}))
assertThat(parse("--linux")).isEqualTo(expected({targets: Platform.LINUX.createTarget()}))
assertThat(parse("--win")).isEqualTo(expected({targets: Platform.WINDOWS.createTarget()}))
assertThat(parse("-owl")).isEqualTo(expected({targets: createTargets([Platform.OSX, Platform.WINDOWS, Platform.LINUX])}))
Expand Down
6 changes: 5 additions & 1 deletion test/src/helpers/fileAssert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ class Assertions {

isEqualTo(expected: any) {
if (!json8.equal(this.actual, expected)) {
const actualJson = JSON.stringify(this.actual, jsonReplacer, 2)
const expectedJson = JSON.stringify(expected, jsonReplacer, 2)
throw new AssertionError({
message: prettyDiff(JSON.parse(JSON.stringify(this.actual, jsonReplacer)), JSON.parse(JSON.stringify(expected, jsonReplacer)))
message: `Expected \n${expectedJson}\n\nis not equal to\n\n${actualJson}\n\n${prettyDiff(JSON.parse(actualJson), JSON.parse(expectedJson))}`,
actual: this.actual,
expected: expected,
})
}
}
Expand Down

0 comments on commit cec4b3d

Please sign in to comment.