Skip to content

Commit

Permalink
- much cleanup and started adding hooks and/or events
Browse files Browse the repository at this point in the history
  • Loading branch information
jglanz committed May 27, 2019
1 parent f77007d commit 144845c
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 27 deletions.
36 changes: 24 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@
"@babel/preset-env": "^7.4.3",
"@types/handlebars": "^4.0.38",
"@types/jest": "^23.1.4",
"@types/shelljs": "^0.8.0",
"@types/lockfile": "^1.0.1",
"@types/lodash": "^4.14.132",
"@types/node": "^12.0.2",
"@types/shelljs": "^0.8.5",
"@types/yargs": "^11.0.0",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^23.4.2",
Expand Down
9 changes: 6 additions & 3 deletions src/project/BuiltType.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Triplet from "./Triplet"
import File, {fixPath} from "../util/File"
import GetLogger from "../Log"
import {Environment} from "../Config"
import * as Path from 'path'

const log = GetLogger(__filename)

Expand Down Expand Up @@ -118,6 +119,7 @@ export default class BuildType {
}

constructor(project, toolchain, isTool = false) {
this.arch = toolchain.triplet.arch
this.isTool = isTool
this.toolchain = toolchain

Expand Down Expand Up @@ -154,9 +156,9 @@ export default class BuildType {
this.toolchain.toScriptEnvironment(rootProject, project),
{
CXXPODS_BUILD_ROOT: this.rootDir,
CXXPODS_BUILD_LIB: `${this.rootDir}/lib`,
CXXPODS_BUILD_INCLUDE: `${this.rootDir}/include`,
CXXPODS_BUILD_CMAKE: `${this.rootDir}/lib/cmake`,
CXXPODS_BUILD_LIB: Path.join(this.rootDir,"lib"),
CXXPODS_BUILD_INCLUDE: Path.join(this.rootDir,"include"),
CXXPODS_BUILD_CMAKE: Path.join(this.rootDir, "lib","cmake"),
})
}

Expand All @@ -172,6 +174,7 @@ export default class BuildType {
{
CMAKE_INSTALL_PREFIX: this.rootDir,
CMAKE_MODULE_PATH: `${this.rootDir}/lib/cmake`,
CMAKE_FIND_ROOT_PATH: `${this.rootDir}/lib/cmake`,
CMAKE_LIBRARY_PATH: `${this.rootDir}/lib`,
CMAKE_INCLUDE_PATH: `${this.rootDir}/include`,
CMAKE_C_FLAGS: `-I${this.rootDir}/include`,
Expand Down
2 changes: 2 additions & 0 deletions src/project/Configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ async function buildDependency(project, dep, buildConfig) {

// CHECKOUT+UPDATE DEPENDENCY SOURCE
await builder.checkout()
await builder.triggerHook("preconfigure")
await builder.applyOverrides()
await builder.build()
builder.finish()

Expand Down
7 changes: 6 additions & 1 deletion src/project/Dependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import File from "../util/File"
import * as _ from 'lodash'
import * as SemVer from 'semver'
import {realRootProject} from "../util/ProjectUtils"
import {getValue} from "typeguard"

const
log = GetLogger(__filename)

Expand Down Expand Up @@ -54,7 +56,10 @@ const DependencyManager = {
// FIND MAX UNIQUE VERSION FIRST
_.groupBy(this.allDependencies,"name"), versionGroup =>
versionGroup.reduce((maxVersion, version) =>
!maxVersion || SemVer.gt(SemVer.coerce(version.version),SemVer.coerce(maxVersion.version)) ?
!maxVersion || getValue(() =>
SemVer.gt(SemVer.coerce(version.version),SemVer.coerce(maxVersion.version)),
version.version <= maxVersion.version
) ?
version :
maxVersion
, null))
Expand Down
50 changes: 48 additions & 2 deletions src/project/DependencyBuilder.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import File, {fixPath} from "../util/File"
import File, {exists, fixPath, isDirectory} from "../util/File"
import {getValue} from "typeguard"
import OS from 'os'
import * as Sh from 'shelljs'
import Git from "simple-git/promise"
import {processTemplate} from "../util/Template"
import _ from "lodash"
import GetLogger from "../Log"
import Path from 'path'
import * as Path from 'path'
import * as Fs from "fs"

const
log = GetLogger(__filename)
Expand Down Expand Up @@ -68,6 +70,46 @@ export default class DependencyBuilder {
return this.buildConfig.type
}

async applyOverrides() {
const
{dir} = this.dep,
overrideDir = Path.join(dir, "override")

log.debug(`Checking overrides: ${overrideDir}`)
if (isDirectory(overrideDir)) {
const {src} = this.buildConfig
log.info("Applying overrides",overrideDir, "to", src)
Sh.cp("-R", Path.join(overrideDir,"*"), src)
}
}

async triggerHook(hook) {
const
{dir} = this.dep,
{src} = this.buildConfig,
hooksDir = Path.join(dir,"hooks"),
hookDir = Path.join(hooksDir,hook)

if (!isDirectory(hookDir)) {
log.info("No hooks for", hook, "in", this.dep.name, dir, hooksDir, hookDir)
return
}

const scripts = Fs.readdirSync(hookDir)
.filter(file => !file.startsWith("."))
.map(script => Path.join(hookDir, script))

log.info("Scripts to run", scripts)

scripts
.forEach(script => {
Sh.exec(script,{
cwd: src
})
})


}

/**
* Checkout the latest code
Expand All @@ -94,6 +136,10 @@ export default class DependencyBuilder {
// noinspection JSUnresolvedFunction
const git = Git(src)

try {
await git.raw(['reset', '--hard'])
} catch (err) {}

// noinspection JSCheckFunctionSignatures
await git.raw(['fetch', '--all', '--tags', '--prune'])
await git.raw(['fetch'])
Expand Down
11 changes: 9 additions & 2 deletions src/project/DependencyBuilderCMake.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ export default class DependencyBuilderCMake extends DependencyBuilder {
cmakeOptionsObj = _.merge(
{},
cmakeFlags,
type.toCMakeOptions(this.project,this.dep.project))
type.toCMakeOptions(this.project,this.dep.project)),
cmakeEnv =type.toScriptEnvironment(this.project,this.dep.project)


const
Expand Down Expand Up @@ -126,7 +127,13 @@ export default class DependencyBuilderCMake extends DependencyBuilder {
sh.pushd(build)
log.info(`Configuring with cmake root: ${cmakeRoot}`)
log.info(`Using command: ${cmakeCmd}`)
if (sh.exec(cmakeCmd).code !== 0) {
if (sh.exec(cmakeCmd, {
cwd: build,
env: {
...process.env,
...cmakeEnv
}
}).code !== 0) {
throw `CMake config failed`
}
sh.popd()
Expand Down
11 changes: 6 additions & 5 deletions src/project/Toolchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {processTemplate} from "../util/Template"
import {getValue} from "typeguard"
import {isDefined} from "../util/Checker"
import Triplet from "./Triplet"

import * as _ from 'lodash'
const log = GetLogger(__filename)

/**
Expand Down Expand Up @@ -174,7 +174,8 @@ export default class Toolchain {
LD: makeCrossTool('ld'),
LDD: makeCrossTool('ldd', true),
STRINGS: makeCrossTool('strings', true),
SYSROOT: props.SYSROOT || props.CMAKE_SYSROOT
SYSROOT: props.SYSROOT || props.CMAKE_SYSROOT,
ARCH: this.triplet.arch
})
return props
}
Expand All @@ -192,9 +193,9 @@ export default class Toolchain {
}

// SYSROOT IF POSSIBLE
const androidNdk = opts.ANDROID_NDK
let sysroot = opts.CMAKE_SYSROOT || opts.SYSROOT
if (!sysroot && androidNdk) {
const androidNdk = opts.ANDROID_NDK || process.env.ANDROID_NDK
let sysroot = !_.isEmpty(opts.CMAKE_SYSROOT) ? opts.CMAKE_SYSROOT : !_.isEmpty(opts.SYSROOT) ? opts.SYSROOT : null
if (this.android && !sysroot && androidNdk) {
sysroot = `${androidNdk}/sysroot`
}

Expand Down
3 changes: 2 additions & 1 deletion src/util/CMakeOptions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import CommandOptions from "./CommandOptions"
import {isFunction, isString} from "typeguard"

export default class CMakeOptions extends CommandOptions {
constructor(values = {}) {
Expand All @@ -16,7 +17,7 @@ export default class CMakeOptions extends CommandOptions {
* @param {string} value - process a given value
*/
processValue(value) {
return value.replace(/\\/g,'/')
return isString(value) && isFunction(value.replace) ? value.replace(/\\/g,'/') : value
}
}

0 comments on commit 144845c

Please sign in to comment.