anaisbetts / grunt-build-atom-shell

Grunt task to build Electron and rebuild node modules
MIT License
122 stars 11 forks source link

breaking change in atom-shell 0.20.3 build #7

Open ttilley opened 9 years ago

ttilley commented 9 years ago

The 'atom.gyp' rigging needs to be fixed for atom-shell 0.20.3 and beyond. The upstream build process has changed in order to make this customization simpler. Now the suggested method of renaming is:

export GYP_DEFINES="product_name=MyApp project_name=myapp"
./script/update.py
./script/build.py -C Release -t myapp

In grunt-build-atom-shell 1.1.4, attempting to compile atom-shell 0.20.3 will throw the following error:

>> Running: python script/bootstrap.py
>> Running: python script/build.py -c Release -t triple-triad-atom
>> ninja: error: unknown target 'triple-triad-atom'

The 'atom.gyp' file ends up containing:

    'project_name%': 'atom',
    'product_name%': 'Atom',

Dealing with quoting and interpolation for multiple options in a single string feels weird for me, so it might just be simpler to add another two replace statements for the new form. I haven't looked at the changes in depth to see what else might have changed (or if those defines are used in other places).

If I get un-lazy I'll patch and submit a pull quest, but considering i'm both lazy and hung over you'll probably get to it first. :laughing:

ttilley commented 9 years ago

It appears that there's a typo in atom-shell upstream that mixes up product_name and project_name in one place, breaking the build anyways.

This is what i'm doing to work around it locally:

diff --git i/tasks/build-atom-shell-task.coffee w/tasks/build-atom-shell-task.coffee
index 66f8812..a5d42a1 100644
--- i/tasks/build-atom-shell-task.coffee
+++ w/tasks/build-atom-shell-task.coffee
@@ -62,16 +62,27 @@ module.exports = (grunt) ->
       .concatMap (x) -> spawnObservable(x)
       .takeLast(1)

+  envWithGypDefines = (projectName, productName) ->
+    ewg = _.extend {}, process.env
+    ewg.GYP_DEFINES = "project_name=#{projectName} product_name=#{productName}"
+    if process.env.GYP_DEFINES?
+      ewg.GYP_DEFINES = "#{process.env.GYP_DEFINES} #{ewg.GYP_DEFINES}"
+    ewg
+
   buildAtomShell = (atomShellDir, config, projectName, productName, forceRebuild) ->
+    cmdOptions =
+      cwd: atomShellDir
+      env: envWithGypDefines(projectName, productName)
+
     bootstrapCmd =
       cmd: 'python'
       args: ['script/bootstrap.py']
-      opts: {cwd: atomShellDir}
+      opts: cmdOptions

     buildCmd =
       cmd: 'python'
       args: ['script/build.py', '-c', config, '-t', projectName]
-      opts: {cwd: atomShellDir}
+      opts: cmdOptions

     rx.Observable.create (subj) ->
       grunt.verbose.ok "Rigging atom.gyp to have correct name"
@@ -81,6 +92,7 @@ module.exports = (grunt) ->
         .replace("'project_name': 'atom'", "'project_name': '#{projectName}'")
         .replace("'product_name': 'Atom'", "'product_name': '#{productName}'")
         .replace("'framework_name': 'Atom Framework'", "'framework_name': '#{productName} Framework'")
+        .replace("'<(project_name) Framework'", "'<(product_name) Framework'") # fix upstream typo in 0.20.3

       grunt.file.write gypFile, atomGyp
anaisbetts commented 9 years ago

@ttilley Good catch - I knew about the breaking changes but not about the typo. Can you submit a PR to fix the typo to Atom Shell, and I'll work on updating grunt-build-atom-shell to be compatible with both < 0.20.3 and >= 0.20.3

ttilley commented 9 years ago

i left a line comment with a github ping to the committer... dunno if i should follow that up with an actual issue or if that's sufficient. I don't want to be that guy that pokes someone repeatedly over the holidays. ;)