fips icon indicating copy to clipboard operation
fips copied to clipboard

Suggestion: custom post-generator scripts

Open code-disaster opened this issue 8 years ago • 1 comments

Use case: I'm doing a little side-project which uses Crinkler to shrink the executable. For this build variant, I'm using VS2013 because Crinkler doesn't work well with more recent versions of the Windows SDK.

My current work flow:

  • Run ./fips gen win32-vs2013-minsizerel which is a release config which adds the /CRINKLER link parameter, among other things.
  • Run ./fips open win32-vs2013-minsizerel to load the VS 2013 project.
  • In the VS2013 project properties, add ${projectRoot}\ to the ExecutablePath settings.
  • In my project root, there is the Crinkler executable named link.exe which is then picked as the linker by Visual Studio.
  • Redo the changes inside VS each time the project changes, and project files are overwritten.

Now, in theory there is a CMake option to customize the linker executable, but my StackOverflow skills have failed me to find a working solution, if there even is one supposed to work with the VS generators.

Here's the idea: Allow a post-generator script, very much like code generation, which runs after ./fips gen. The script can just sit in fips-generators, and can be added as an option to fips-configs/${my-custom-config}.yml.

The script may need to pass a few information, e.g. the project root, the generator output path in fips-build/, and/or the (a list of) project path(s). In my example, a custom script would then try to open fips-build/${path-to-project}/${project-name}.vcxproj, and inject an <ExecutablePath> property.

code-disaster avatar Apr 27 '17 09:04 code-disaster

Sounds doable :)

In the meantime a workaround could be to write your own 'fips verb' scripts, which runs the 'fips gen' functionality, and after that injects crinkle, it would look roughly like this (copied from https://github.com/floooh/oryol/blob/master/fips-verbs/testrunner.py), and you would run "./fips crinkle" instead of "./fips gen"

from mod import log, project, settings, util, config

#-------------------------------------------------------------------------------
def run(fips_dir, proj_dir, args) :
    cfg_name = settings.get(proj_dir, 'config')
    project.gen(fips_dir, proj_dir, cfg_name)

    # for each application target, inject crinkle in vcxproj file
    cfg = config.load(fips_dir, proj_dir, cfg_name)[0]
    proj_name = util.get_project_name_from_dir(proj_dir)
    build_dir = util.get_build_dir(fips_dir, proj_name, cfg)
    success, targets = project.get_target_list(fips_dir, proj_dir, cfg_name)
    if success :
        app_targets = [tgt for tgt in targets if targets[tgt] == 'app']
        for app in app_targets :
            # hmmmmm... ok now it gets tricky... the vcxproj file for this
            # target which has been generated by cmake is somewhere under 
            # build_dir but we don't have the information WHERE... so some
            # hackery and hard-wiring would be involved here...
            log.info(">>> patching vcxproj for target '{}'".format(app))

#-------------------------------------------------------------------------------
def help() :
    log.info(log.YELLOW +
             'fips crinkle\n' +
             log.DEF +
             '    gen and inject crinkle')

floooh avatar Apr 27 '17 16:04 floooh