Running OL3 dev environment under win32 #427

Closed
kalbermattenm opened this Issue Mar 24, 2013 · 10 comments

Projects

None yet

3 participants

@kalbermattenm
Contributor

I just tried to run the OL3 environment under Windows 32 and followed the instructions of https://github.com/openlayers/ol3/wiki/Developer-Guide

All my requirements are installed at non-standard places (not in C:\Program Files), but all the necessary PATH variables are set correctly.

In the build.py file, you define everything with absolute paths if the system is win32, but I don't get why...

If win32 users follow the wiki instructions, everything is working like a charm without having to define all these absolute paths. For the test, I just did get rid of two if conditions in build.py. (see lines https://github.com/openlayers/ol3/blob/master/build.py#L15 and https://github.com/openlayers/ol3/blob/master/build.py#L514)

I am now able to run build.py serve and build.py check without any errors.

I am not an expert, so maybe did I miss something, but is there a reason for having all these absolute paths defined in build.py if sys.platform == 'win32'?

Contributor
twpayne commented Mar 24, 2013

The reasons for defining absolute paths on Windows are:

  • the required binaries (python.exe, git.exe, etc.) are not always in the user's PATH; it sounds like you've configured your PATH correctly, but not everybody does
  • the paths vary a lot according to the Windows version and native language

That said, although I wrote this part of build.py, I've haven't really used Windows for over a decade. It might well be possible to trim down the logic. However, I think it's important that build continues to work even if PATH is not configured correctly.

Contributor

I know that I might be the only weirdo trying that on Windows ;-)

I agree with you regarding your last sentence, but on Windows, you can install stuff in about all folders / devices (like installing stuff in My Documents, which is really bad, but...)

What's more, the version of Phantomjs you defined in build.py can not be downloaded anymore (see http://code.google.com/p/phantomjs/downloads/list)....

I don't know if it's of any interest, but I added these lines at the top of my build.py file and, in the same file I suppressed lines https://github.com/openlayers/ol3/blob/master/build.py#L514 to https://github.com/openlayers/ol3/blob/master/build.py#L531. The which() function can be found here: http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python/377028

It looks like this is working (not intensively tested...).

Sorry to annoy you with my Ballmer issues ;-)

def which(program):
    import os
    def is_exe(fpath):
        return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

    fpath, fname = os.path.split(program)
    if fpath:
        if is_exe(program):
            return program
    else:
        for path in os.environ["PATH"].split(os.pathsep):
            path = path.strip('"')
            exe_file = os.path.join(path, program)
            if is_exe(exe_file):
                return exe_file
    return None

if sys.platform == 'win32':

    windows_defaults = {
    'ProgramFiles': os.environ['PROGRAMFILES'],
    'Python27': os.environ.get('SystemDrive', 'C:') + '\\Python27',
    'jsdoc': os.environ.get('SystemDrive', 'C:') + '\\jsdoc3',
    'phantomjs': os.environ.get('SystemDrive', 'C:') + '\\phantomjs-1.9.0-windows'
    }

    if which('git.exe'):
        variables.GIT = 'git'
    else:
        variables.GIT = os.path.join(windows_defaults['ProgramFiles'],
                                     'Git', 'bin', 'git.exe')

    if which('gjslint.exe'):
        variables.GJSLINT = 'gjslint'
    else:
        variables.GJSLINT = os.path.join(windows_defaults['Python27'],
                                         'Scripts', 'gjslint.exe')

    if which('java.exe'):
        variables.JAVA = 'java'
    else:
        variables.JAVA = os.path.join(windows_defaults['ProgramFiles'],
                                      'Java', 'jre7', 'bin', 'java.exe')

    if which('jsdoc.cmd'):
        variables.JSDOC = 'jsdoc.cmd'
    else:
        variables.JSDOC = os.path.join(windows_defaults['jsdoc'],
                                        'jsdoc.cmd')

    if which('python.exe'):
        variables.PYTHON = 'python'
    else:
        variables.PYTHON = os.path.join(windows_defaults['Python27'],
                                        'python.exe')

    if which('phantomjs.exe'):
        variables.PHANTOMJS = 'phantomjs'
    else:
        variables.PHANTOMJS =  os.path.join(windows_defaults['phantomjs'],
                                            'phantomjs.exe')
Contributor
twpayne commented Mar 24, 2013

Many thanks for this @kalbermattenm ! This is a much better solution than the existing code.

Windows support is important - for example, all the Cesium developers use Windows, so Windows support is critical for good Cesium/ol3 integration.

Would you like to turn this into a pull request? The which function should go in pake.py, the rest of the code should modify build.py of course.

Contributor

Maybe it would be good to improve Windows support. I'll be happy to help and submit a PR.

Two last questions:

  • Seems have to fill in the CLA form, right?
  • I currently tested build.py serve and build.py check. Are there other commands I should / could test?

I would also like to test the whole thing on Windows 7 64-bits (currently I tested this stuff on Windows XP 32-bits), so it might take a few days before I submit anything...

Contributor
twpayne commented Mar 24, 2013

Great!

Yes, please submit a CLA. You can do it online, and it takes less than a minute.

As an extra check, you can try running build.py integration-test, but go grab a coffee while it runs!

Member

Just out of curiosity, would 858574b (included in #335) detect that your setup is fine? That particular commit also includes the which from SO.

Contributor

Thanks @marcjansen for spotting that! I did not see that one. I'll check if 858574b is helping in any way before spending too much time in a brand new solution...

Contributor

@marcjansen, this actually detects the setup really quite well.

As some of these are defined using absolute paths in the current build.py file, your checker tells me that there are some problems (see result hereunder). On purpose, I didn't install Phantomjs and gjslint (jsdoc is installed elsewhere, but that is the absolute path issue)...

But I find your checker really good, nice job!

Would it be coherent to put the which() function into pake.py as @twpayne suggested, to improve the if sys.platform == win32 section and to integrate our checker ?

I think that with such tools, anyone should be able to run build.py correctly...

C:\travail\git_openlayers3>python build.py checkdeps
Program "C:\Program Files (x86)\Git\bin\git.exe" seems to be present.
Program "C:\Python27\Scripts\gjslint.exe" seems to be MISSING.
Program "C:\Program Files (x86)\Java\jre7\bin\java.exe" seems to be present.
Program "jsdoc" seems to be present.
Program "C:\Python27\python.exe" seems to be present.
Program "build/phantomjs-1.8.1-windows/phantomjs.exe" seems to be MISSING.
For certain targets all above programs need to be present.
Member

Yes, please go ahead and do as @twpayne suggested:

  • which into pake.py
  • using it in the win32 section

Thanks for this. If eventually #335 becomes obsolete, I wouldn't mind.

Contributor
twpayne commented Apr 4, 2013

This is being addressed in #448.

@twpayne twpayne closed this Apr 4, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment