View | Details | Raw Unified | Return to bug 1403
Collapse All | Expand All

(-)a/build.py (+50 lines)
 Lines 13-18    Link Here 
13
    run_command([sys.executable, 'scons.py'])
13
    run_command([sys.executable, 'scons.py'])
14
    
14
    
15
15
16
def build_netanim(qmakepath):
17
    qmake = 'qmake'
18
    if qmakepath:
19
        qmake = qmakepath
20
    try:    
21
    	if sys.platform in ['darwin']:
22
    		run_command([qmake, '-spec', 'macx-g++', 'NetAnim.pro'])
23
    	else:
24
    		run_command([qmake, 'NetAnim.pro'])
25
    	run_command(['make'])
26
    except OSError:
27
        print "Error building NetAnim. Ensure the path to qmake is correct"
28
        print "Note: Some systems use qmake-qt4 instead of qmake"
29
        print "Skipping NetAnim ...."
30
	pass
31
    except:
32
        print "Error building NetAnim."
33
        print "Skipping NetAnim ...."
34
	pass
35
16
def build_ns3(config, build_examples, build_tests, args, build_options):
36
def build_ns3(config, build_examples, build_tests, args, build_options):
17
    cmd = [sys.executable, "waf", "configure"] + args
37
    cmd = [sys.executable, "waf", "configure"] + args
18
38
 Lines 66-71    Link Here 
66
    parser.add_option('--disable-nsc',
86
    parser.add_option('--disable-nsc',
67
                      help=("Don't try to build NSC (built by default)"), action="store_true", default=False,
87
                      help=("Don't try to build NSC (built by default)"), action="store_true", default=False,
68
                      dest='disable_nsc')
88
                      dest='disable_nsc')
89
    parser.add_option('--disable-netanim',
90
                      help=("Don't try to build NetAnim (built by default)"), action="store_true", default=False,
91
                      dest='disable_netanim')
92
    parser.add_option('--qmake-path',
93
                      help=("Provide absolute path to qmake executable for NetAnim"), action="store", default='qmake',
94
                      dest='qmake_path')
69
    parser.add_option('--enable-examples',
95
    parser.add_option('--enable-examples',
70
                      help=("Do try to build examples (not built by default)"), action="store_true", default=False,
96
                      help=("Do try to build examples (not built by default)"), action="store_true", default=False,
71
                      dest='enable_examples')
97
                      dest='enable_examples')
 Lines 112-117    Link Here 
112
                os.chdir(cwd)
138
                os.chdir(cwd)
113
            print "Leaving directory `%s'" % nsc_dir
139
            print "Leaving directory `%s'" % nsc_dir
114
140
141
    if options.disable_netanim:
142
        print "# Skip NetAnimC (by user request)"
143
        for node in config.getElementsByTagName("netanim"):
144
            config.documentElement.removeChild(node)
145
    elif sys.platform in ['cygwin', 'win32']:
146
        print "# Skip NetAnim (platform not supported)"
147
    else:
148
        netanim_config_elems = config.getElementsByTagName("netanim")
149
        if netanim_config_elems:
150
            netanim_config, = netanim_config_elems
151
            netanim_dir = netanim_config.getAttribute("dir")
152
            print "# Build NetAnim"
153
            os.chdir(netanim_dir)
154
            print "Entering directory `%s'" % netanim_dir
155
            try:
156
                try:
157
                    build_netanim(options.qmake_path)
158
                except CommandError:
159
                    print "# Build NetAnim: failure (ignoring NetAnim)"
160
                    config.documentElement.removeChild(netanim_config)
161
            finally:
162
                os.chdir(cwd)
163
            print "Leaving directory `%s'" % netanim_dir
164
115
    if options.enable_examples:
165
    if options.enable_examples:
116
        print "# Building examples (by user request)"
166
        print "# Building examples (by user request)"
117
        build_examples = True
167
        build_examples = True
(-)a/constants.py (+6 lines)
 Lines 40-42    Link Here 
40
NSC_RELEASE_URL = "http://research.wand.net.nz/software/nsc"
40
NSC_RELEASE_URL = "http://research.wand.net.nz/software/nsc"
41
41
42
LOCAL_NSC_PATH = "nsc"
42
LOCAL_NSC_PATH = "nsc"
43
44
# NetAnim
45
NETANIM_REPO = "http://code.nsnam.org/jabraham3/netanim"
46
NETANIM_RELEASE_URL = "http://www.nsnam.org/tools/netanim"
47
48
LOCAL_NETANIM_PATH = "netanim"
(-)a/dist.py (-3 / +17 lines)
 Lines 98-104    Link Here 
98
    print "Adding %s as %s" % (ns3_dir, os.path.join(dist_dir, new_ns3_dir))
98
    print "Adding %s as %s" % (ns3_dir, os.path.join(dist_dir, new_ns3_dir))
99
    tar_add_tree(tar, ns3_dir, os.path.join(dist_dir, new_ns3_dir), dir_excl, file_excl)
99
    tar_add_tree(tar, ns3_dir, os.path.join(dist_dir, new_ns3_dir), dir_excl, file_excl)
100
100
101
102
    # add pybindgen
101
    # add pybindgen
103
    pybindgen_dir = config.getElementsByTagName("pybindgen")[0].getAttribute("dir")
102
    pybindgen_dir = config.getElementsByTagName("pybindgen")[0].getAttribute("dir")
104
    new_pybindgen_dir = "pybindgen-%s" % config.getElementsByTagName("pybindgen")[0].getAttribute("version")
103
    new_pybindgen_dir = "pybindgen-%s" % config.getElementsByTagName("pybindgen")[0].getAttribute("version")
 Lines 120-127    Link Here 
120
    print "Adding %s as %s" % (pybindgen_dir, os.path.join(dist_dir, new_pybindgen_dir))
119
    print "Adding %s as %s" % (pybindgen_dir, os.path.join(dist_dir, new_pybindgen_dir))
121
    tar_add_tree(tar, pybindgen_dir, os.path.join(dist_dir, new_pybindgen_dir), dir_excl, file_excl)
120
    tar_add_tree(tar, pybindgen_dir, os.path.join(dist_dir, new_pybindgen_dir), dir_excl, file_excl)
122
121
123
124
125
    # add network simulation cradle
122
    # add network simulation cradle
126
    nsc_dir = config.getElementsByTagName("nsc")[0].getAttribute("dir")
123
    nsc_dir = config.getElementsByTagName("nsc")[0].getAttribute("dir")
127
    new_nsc_dir = config.getElementsByTagName("nsc")[0].getAttribute("version")
124
    new_nsc_dir = config.getElementsByTagName("nsc")[0].getAttribute("version")
 Lines 141-146    Link Here 
141
    print "Adding %s as %s" % (nsc_dir, os.path.join(dist_dir, new_nsc_dir))
138
    print "Adding %s as %s" % (nsc_dir, os.path.join(dist_dir, new_nsc_dir))
142
    tar_add_tree(tar, nsc_dir, os.path.join(dist_dir, new_nsc_dir), dir_excl, file_excl)
139
    tar_add_tree(tar, nsc_dir, os.path.join(dist_dir, new_nsc_dir), dir_excl, file_excl)
143
140
141
    # add NetAnim
142
    netanim_dir = config.getElementsByTagName("netanim")[0].getAttribute("dir");
143
    new_netanim_dir = config.getElementsByTagName("netanim")[0].getAttribute("version")
144
    assert new_netanim_dir.startswith("netanim")
145
    new_config.getElementsByTagName("netanim")[0].setAttribute("dir", new_netanim_dir)
146
    def dir_excl(reldirpath, dirname):
147
        if dirname[0] == '.':
148
            return True
149
        return False
150
    def file_excl(reldirpath, filename):
151
        if filename.startswith('.'):
152
            return True
153
        if filename.endswith('~'):
154
            return True
155
        return False
156
    print "Adding %s as %s" % (netanim_dir, os.path.join(dist_dir, new_netanim_dir))
157
    tar_add_tree(tar, netanim_dir, os.path.join(dist_dir, new_netanim_dir), dir_excl, file_excl)
144
158
145
    # add the build script files
159
    # add the build script files
146
    print "Adding the build script files"
160
    print "Adding the build script files"
(-)a/download.py (+67 lines)
 Lines 126-131    Link Here 
126
126
127
    return (constants.LOCAL_PYBINDGEN_PATH, '.'.join([str(x) for x in required_pybindgen_version]))
127
    return (constants.LOCAL_PYBINDGEN_PATH, '.'.join([str(x) for x in required_pybindgen_version]))
128
128
129
def get_netanim(ns3_dir):
130
    print """
131
    #
132
    # Get NetAnim
133
    #
134
    """
135
136
    if sys.platform in ['cygwin']:
137
	print "Architecture (%s) does not support NetAnim... skipping" % (sys.platform)
138
        raise RuntimeError
139
140
    # (peek into the ns-3 wscript and extract the required netanim version)
141
    try:
142
        # For the recent versions
143
        netanim_wscript = open(os.path.join(ns3_dir, "src", "netanim", "wscript"), "rt")
144
    except:
145
        print "Unable to detect NetAnim required version.Skipping download"
146
        pass
147
        return
148
149
    required_netanim_version = None
150
    for line in netanim_wscript:
151
        if 'NETANIM_RELEASE_NAME' in line:
152
            required_netanim_version = eval(line.split('=')[1].strip())
153
            break
154
    netanim_wscript.close()
155
    if required_netanim_version is None:
156
        fatal("Unable to detect NetAnim required version")
157
    print "Required NetAnim version: ", required_netanim_version
158
159
160
    def netanim_clone():
161
        print "Retrieving NetAnim from " + constants.NETANIM_REPO
162
        run_command(['hg', 'clone', constants.NETANIM_REPO, constants.LOCAL_NETANIM_PATH])
163
164
    def netanim_update():
165
        print "Pulling NetAnim updates from " + constants.NETANIM_REPO
166
        run_command(['hg', '--cwd', constants.LOCAL_NETANIM_PATH, 'pull', '-u', constants.NETANIM_REPO])
167
168
    def netanim_download():
169
        local_file = required_netanim_version + ".tar.bz2"
170
        remote_file = constants.NETANIM_RELEASE_URL + "/" + local_file
171
        print "Retrieving NetAnim from " + remote_file
172
        urllib.urlretrieve(remote_file, local_file)
173
        print "Uncompressing " + local_file
174
        run_command(["tar", "-xjf", local_file])
175
        print "Rename %s as %s" % (required_netanim_version, constants.LOCAL_NETANIM_PATH)
176
        os.rename(required_netanim_version, constants.LOCAL_NETANIM_PATH)
177
178
    if not os.path.exists(os.path.join(ns3_dir, '.hg')):
179
        netanim_download()
180
    elif not os.path.exists(constants.LOCAL_NETANIM_PATH):
181
        netanim_clone()
182
    else:
183
        netanim_update()
184
185
    return (constants.LOCAL_NETANIM_PATH, required_netanim_version)
129
186
130
def get_nsc(ns3_dir):
187
def get_nsc(ns3_dir):
131
    print """
188
    print """
 Lines 228-233    Link Here 
228
        pybindgen_config.setAttribute("dir", pybindgen_dir)
285
        pybindgen_config.setAttribute("dir", pybindgen_dir)
229
        pybindgen_config.setAttribute("version", pybindgen_version)
286
        pybindgen_config.setAttribute("version", pybindgen_version)
230
287
288
    # -- download NetAnim --
289
    try:
290
	netanim_dir, netanim_version = get_netanim(ns3_dir)
291
    except (CommandError, IOError, RuntimeError):
292
	print " *** Did not fetch NetAnim offline animator. Please visit http://www.nsnam.org/wiki/index.php/NetAnim ."
293
    else:
294
	netanim_config = config.documentElement.appendChild(config.createElement("netanim"))
295
	netanim_config.setAttribute("dir", netanim_dir)
296
        netanim_config.setAttribute("version", netanim_version)
297
231
    # -- download network simulation cradle --
298
    # -- download network simulation cradle --
232
    try:
299
    try:
233
        nsc_dir, nsc_version = get_nsc(ns3_dir)
300
        nsc_dir, nsc_version = get_nsc(ns3_dir)

Return to bug 1403