1: %% 2: %% %CopyrightBegin% 3: %% 4: %% Copyright Ericsson AB 2010-2012. All Rights Reserved. 5: %% 6: %% The contents of this file are subject to the Erlang Public License, 7: %% Version 1.1, (the "License"); you may not use this file except in 8: %% compliance with the License. You should have received a copy of the 9: %% Erlang Public License along with this software. If not, it can be 10: %% retrieved online at http://www.erlang.org/. 11: %% 12: %% Software distributed under the License is distributed on an "AS IS" 13: %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 14: %% the License for the specific language governing rights and limitations 15: %% under the License. 16: %% 17: %% %CopyrightEnd% 18: %% 19: 20: 21: %%%------------------------------------------------------------------- 22: %%% File : install_SUITE.erl 23: %%% Author : Rickard Green 24: %%% Description : 25: %%% 26: %%% Created : 12 Jan 2010 by Rickard Green 27: %%%------------------------------------------------------------------- 28: -module(install_SUITE). 29: 30: %-define(line_trace, 1). 31: 32: -export([all/0, suite/0,groups/0,init_per_group/2,end_per_group/2, 33: init_per_suite/1, end_per_suite/1, 34: init_per_testcase/2, end_per_testcase/2]). 35: 36: -export([bin_default/1, 37: bin_default_dirty/1, 38: bin_outside_eprfx/1, 39: bin_outside_eprfx_dirty/1, 40: bin_unreasonable_path/1, 41: bin_not_abs/1, 42: 'bin white space'/1, 43: bin_no_srcfile/1, 44: bin_unreachable_absolute/1, 45: bin_unreachable_relative/1, 46: bin_same_dir/1, 47: bin_ok_symlink/1, 48: bin_dirname_fail/1, 49: bin_no_use_dirname_fail/1]). 50: 51: -define(DEFAULT_TIMEOUT, ?t:minutes(1)). 52: -define(JOIN(A,B,C), filename:join(A, B, C)). 53: 54: -include_lib("test_server/include/test_server.hrl"). 55: 56: -record(inst, {mkdirs = true, 57: symlinks = true, 58: cmd_prefix = "", 59: ln_s = "ln -s", 60: test_prefix = "", 61: destdir = "", 62: extra_prefix = "", 63: exec_prefix = "", 64: bindir = "", 65: erlang_bindir = "", 66: bindir_symlinks = ""}). 67: 68: need_symlink_cases() -> 69: [bin_unreachable_absolute, bin_unreachable_relative, 70: bin_same_dir, bin_ok_symlink, bin_dirname_fail, 71: bin_no_use_dirname_fail]. 72: 73: dont_need_symlink_cases() -> 74: [bin_default, bin_default_dirty, bin_outside_eprfx, 75: bin_outside_eprfx_dirty, bin_not_abs, 76: bin_unreasonable_path, 'bin white space', 77: bin_no_srcfile]. 78: 79: suite() -> [{ct_hooks,[ts_install_cth]}]. 80: 81: all() -> 82: dont_need_symlink_cases() ++ need_symlink_cases(). 83: 84: groups() -> 85: []. 86: 87: init_per_group(_GroupName, Config) -> 88: Config. 89: 90: end_per_group(_GroupName, Config) -> 91: Config. 92: 93: 94: %% 95: %% The test cases 96: %% 97: 98: bin_default(Config) when is_list(Config) -> 99: ?line E = "/usr/local", 100: ?line Bs = "/usr/local/bin", 101: ?line Be = Bs, 102: ?line EBs = "/usr/local/lib/erlang/bin", 103: ?line EBe = EBs, 104: ?line RP = "../lib/erlang/bin", 105: ChkRes = fun (Res, #inst{test_prefix = TP, 106: destdir = D, 107: extra_prefix = EP, 108: bindir_symlinks = BSL, 109: symlinks = SL}) -> 110: ?line B = join([TP, D, EP, Be]), 111: Expct = case {SL, BSL} of 112: {false, _} when BSL == "relative"; 113: BSL == "absolute" -> 114: ?line {error, no_ln_s}; 115: {false, _} -> 116: ?line {ok,{absolute, 117: B,join([TP,D,EP,EBe])}}; 118: {true, "absolute"} -> 119: ?line {ok,{absolute,B,join([TP,EP,EBe])}}; 120: {true, _} -> 121: ?line {ok,{relative,B,RP}} 122: end, 123: expect(Expct, Res) 124: end, 125: install_bin(Config, #inst{exec_prefix = E, 126: bindir = Bs, 127: erlang_bindir = EBs}, ChkRes). 128: 129: bin_default_dirty(Config) when is_list(Config) -> 130: ?line E = "/usr/./local/lib/..", 131: ?line Bs = "/usr/local//lib/../lib/erlang/../../bin", 132: ?line Be = "/usr/local/lib/../lib/erlang/../../bin", 133: ?line EBs = "/usr/local/lib/../lib/erlang/../erlang/bin/x/y/../..//", 134: ?line EBe = "/usr/local/lib/../lib/erlang/../erlang/bin/x/y/../..", 135: ?line RP = "../lib/erlang/bin", 136: ChkRes = fun (Res, #inst{test_prefix = TP, 137: destdir = D, 138: extra_prefix = EP, 139: bindir_symlinks = BSL, 140: symlinks = SL}) -> 141: ?line B = join([TP, D, EP, Be]), 142: Expct = case {SL, BSL} of 143: {false, _} when BSL == "relative"; 144: BSL == "absolute" -> 145: ?line {error, no_ln_s}; 146: {false, _} -> 147: ?line {ok,{absolute, 148: B,join([TP,D,EP,EBe])}}; 149: {true, "absolute"} -> 150: ?line {ok,{absolute, 151: B,join([TP,EP,EBe])}}; 152: {true, _} -> 153: ?line {ok,{relative,B,RP}} 154: end, 155: expect(Expct, Res) 156: end, 157: install_bin(Config, #inst{exec_prefix = E, 158: bindir = Bs, 159: erlang_bindir = EBs}, ChkRes). 160: 161: 162: bin_outside_eprfx(Config) when is_list(Config) -> 163: ?line E = "/usr/local", 164: ?line Bs = "/usr/bin", 165: ?line Be = Bs, 166: ?line EBs = "/usr/local/lib/erlang/bin", 167: ?line EBe = EBs, 168: ?line RP = "../local/lib/erlang/bin", 169: ChkRes = fun (Res, #inst{test_prefix = TP, 170: destdir = D, 171: extra_prefix = EP, 172: bindir_symlinks = BSL, 173: symlinks = SL}) -> 174: ?line B = join([TP, D, EP, Be]), 175: Expct = case {SL, BSL} of 176: {false, _} when BSL == "relative"; 177: BSL == "absolute" -> 178: ?line {error, no_ln_s}; 179: {false, _} -> 180: ?line {ok,{absolute, 181: B,join([TP,D,EP,EBe])}}; 182: {true, "relative"} -> 183: ?line {ok,{relative,B,RP}}; 184: {true, _} -> 185: ?line {ok,{absolute,B,join([TP,EP,EBe])}} 186: end, 187: expect(Expct, Res) 188: end, 189: install_bin(Config, #inst{exec_prefix = E, 190: bindir = Bs, 191: erlang_bindir = EBs}, ChkRes). 192: 193: 194: bin_outside_eprfx_dirty(Config) when is_list(Config) -> 195: ?line E = "/usr/local/lib/..", 196: ?line Bs = "/usr/local/lib/../../bin", 197: ?line Be = Bs, 198: ?line EBs = "/usr/local/lib/erlang/bin", 199: ?line EBe = EBs, 200: ?line RP = "../local/lib/erlang/bin", 201: ChkRes = fun (Res, #inst{test_prefix = TP, 202: destdir = D, 203: extra_prefix = EP, 204: bindir_symlinks = BSL, 205: symlinks = SL}) -> 206: ?line B = join([TP, D, EP, Be]), 207: Expct = case {SL, BSL} of 208: {false, _} when BSL == "relative"; 209: BSL == "absolute" -> 210: ?line {error, no_ln_s}; 211: {false, _} -> 212: ?line {ok,{absolute, 213: B,join([TP,D,EP,EBe])}}; 214: {true, "relative"} -> 215: ?line {ok,{relative,B,RP}}; 216: {true, _} -> 217: ?line {ok,{absolute,B,join([TP,EP,EBe])}} 218: end, 219: expect(Expct, Res) 220: end, 221: install_bin(Config, #inst{exec_prefix = E, 222: bindir = Bs, 223: erlang_bindir = EBs}, ChkRes). 224: 225: bin_unreasonable_path(Config) when is_list(Config) -> 226: ?line E = "/usr/local/../../..", 227: ?line Bs = "/usr/local/../../../bin", 228: ?line Be = Bs, 229: ?line EBs = "/usr/local/../../../bin_unreasonable_path/usr/local/lib/erlang/bin", 230: ?line EBe = EBs, 231: ?line RP = "../bin_unreasonable_path/usr/local/lib/erlang/bin", 232: ChkRes = fun (Res, #inst{test_prefix = TP, 233: destdir = D, 234: extra_prefix = EP, 235: bindir_symlinks = BSL, 236: symlinks = SL}) -> 237: ?line B = join([TP, D, EP, Be]), 238: Expct = case {TP, SL, BSL} of 239: {_, false, _} when BSL == "relative"; 240: BSL == "absolute" -> 241: ?line {error, no_ln_s}; 242: {_, false, _} -> 243: ?line {ok,{absolute, 244: B,join([TP,D,EP,EBe])}}; 245: {"", true, "relative"} -> 246: {error, unreasonable_path}; 247: {"", true, _} -> 248: ?line {ok,{absolute,B,join([TP,EP,EBe])}}; 249: {_, true, "absolute"} -> 250: ?line {ok,{absolute,B,join([TP,EP,EBe])}}; 251: _ -> 252: ?line {ok,{relative,B,RP}} 253: end, 254: expect(Expct, Res) 255: end, 256: install_bin(Config, #inst{exec_prefix = E, 257: bindir = Bs, 258: erlang_bindir = EBs}, ChkRes). 259: 260: bin_unreachable_absolute(Config) when is_list(Config) -> 261: TDir = ?config(test_dir, Config), 262: make_dirs(TDir, "/opt/local/lib/erlang/usr/bin"), 263: make_dirs(TDir, "/opt/local/lib/erlang/bin"), 264: Erl = join([TDir, "/opt/local/lib/erlang/bin/erl"]), 265: Erlc = join([TDir, "/opt/local/lib/erlang/bin/erlc"]), 266: make_dirs(TDir, "/usr/local/lib"), 267: make_dirs(TDir, "/usr/local/bin"), 268: ok = file:write_file(Erl, "erl"), 269: ok = file:write_file(Erlc, "erlc"), 270: ok = file:make_symlink("../../../opt/local/lib/erlang/usr", 271: join([TDir, "/usr/local/lib/erlang"])), 272: ?line E = "/usr/local", 273: ?line Bs = "/usr/local/bin", 274: ?line Be = Bs, 275: ?line EBs = "/usr/local/lib/erlang/../bin", 276: ?line EBe = EBs, 277: ChkRes = fun (Res, #inst{test_prefix = TP, 278: destdir = D, 279: extra_prefix = EP, 280: bindir_symlinks = BSL, 281: symlinks = SL}) -> 282: ?line B = join([TP, D, EP, Be]), 283: Expct = case {SL, BSL} of 284: {false, _} when BSL == "relative"; 285: BSL == "absolute" -> 286: ?line {error, no_ln_s}; 287: {false, _} -> 288: ?line {ok,{absolute, 289: B,join([TP,D,EP,EBe])}}; 290: {true, "relative"} -> 291: {error, unreachable_absolute}; 292: {true, _} -> 293: ?line {ok,{absolute,B,join([TP,EP,EBe])}} 294: end, 295: expect(Expct, Res) 296: end, 297: install_bin(Config, #inst{exec_prefix = E, 298: bindir = Bs, 299: erlang_bindir = EBs}, ChkRes). 300: 301: bin_unreachable_relative(Config) when is_list(Config) -> 302: TDir = ?config(test_dir, Config), 303: make_dirs(TDir, "/opt/local/lib/erlang/bin"), 304: make_dirs(TDir, "/opt/local/bin"), 305: make_dirs(TDir, "/usr/local/lib/erlang/bin"), 306: Erl = join([TDir, "/usr/local/lib/erlang/bin/erl"]), 307: Erlc = join([TDir, "/usr/local/lib/erlang/bin/erlc"]), 308: ok = file:write_file(Erl, "erl"), 309: ok = file:write_file(Erlc, "erlc"), 310: ok = file:make_symlink("../../opt/local/bin", 311: join([TDir, "/usr/local/bin"])), 312: 313: ?line E = "/usr/local", 314: ?line Bs = "/usr/local/bin", 315: ?line Be = Bs, 316: ?line EBs = "/usr/local/lib/erlang/bin", 317: ?line EBe = EBs, 318: ChkRes = fun (Res, #inst{test_prefix = TP, 319: destdir = D, 320: extra_prefix = EP, 321: bindir_symlinks = BSL, 322: symlinks = SL}) -> 323: ?line B = join([TP, D, EP, Be]), 324: Expct = case {SL, BSL} of 325: {false, _} when BSL == "relative"; 326: BSL == "absolute" -> 327: ?line {error, no_ln_s}; 328: {false, _} -> 329: ?line {ok,{absolute, 330: B,join([TP,D,EP,EBe])}}; 331: {true, "relative"} -> 332: {error, unreachable_relative}; 333: {true, _} -> 334: ?line {ok,{absolute,B,join([TP,EP,EBe])}} 335: end, 336: expect(Expct, Res) 337: end, 338: install_bin(Config, #inst{exec_prefix = E, 339: bindir = Bs, 340: erlang_bindir = EBs}, ChkRes). 341: 342: bin_ok_symlink(Config) when is_list(Config) -> 343: TDir = ?config(test_dir, Config), 344: make_dirs(TDir, "/usr/local/bin"), 345: make_dirs(TDir, "/opt/local/lib/erlang/bin"), 346: Erl = join([TDir, "/opt/local/lib/erlang/bin/erl"]), 347: Erlc = join([TDir, "/opt/local/lib/erlang/bin/erlc"]), 348: ok = file:write_file(Erl, "erl"), 349: ok = file:write_file(Erlc, "erlc"), 350: ok = file:make_symlink("../../opt/local/lib", 351: join([TDir, "/usr/local/lib"])), 352: ?line E = "/usr/local", 353: ?line Bs = "/usr/local/bin", 354: ?line Be = Bs, 355: ?line EBs = "/usr/local/lib/erlang/bin", 356: ?line EBe = EBs, 357: ?line RP = "../lib/erlang/bin", 358: ChkRes = fun (Res, #inst{test_prefix = TP, 359: destdir = D, 360: extra_prefix = EP, 361: bindir_symlinks = BSL, 362: symlinks = SL}) -> 363: ?line B = join([TP, D, EP, Be]), 364: Expct = case {SL, BSL} of 365: {false, _} when BSL == "relative"; 366: BSL == "absolute" -> 367: ?line {error, no_ln_s}; 368: {false, _} -> 369: ?line {ok,{absolute, 370: B,join([TP,D,EP,EBe])}}; 371: {true, "absolute"} -> 372: ?line {ok,{absolute,B,join([TP,EP,EBe])}}; 373: {true, _} -> 374: ?line {ok,{relative,B,RP}} 375: end, 376: expect(Expct, Res) 377: end, 378: install_bin(Config, #inst{exec_prefix = E, 379: bindir = Bs, 380: erlang_bindir = EBs}, ChkRes). 381: 382: bin_same_dir(Config) when is_list(Config) -> 383: TDir = ?config(test_dir, Config), 384: make_dirs(TDir, "/usr/local/bin"), 385: make_dirs(TDir, "/usr/local/lib"), 386: ok = file:make_symlink("..", join([TDir, "/usr/local/lib/erlang"])), 387: Erl = join([TDir, "/usr/local/lib/erlang/bin/erl"]), 388: Erlc = join([TDir, "/usr/local/lib/erlang/bin/erlc"]), 389: ok = file:write_file(Erl, "erl"), 390: ok = file:write_file(Erlc, "erlc"), 391: ChkRes = fun (Res, _) -> 392: expect({error, target_and_source_same_dir}, Res) 393: end, 394: install_bin(Config, 395: #inst{mkdirs = false, 396: exec_prefix = "/usr/local", 397: bindir = "/usr/local/bin", 398: erlang_bindir = "/usr/local/lib/erlang/bin"}, 399: ChkRes). 400: 401: bin_not_abs(Config) when is_list(Config) -> 402: ChkRes = fun (Res, #inst{test_prefix = TP}) -> 403: case TP of 404: "" -> 405: expect({error, {not_abs, 'bindir'}}, Res); 406: _ -> 407: B = join([TP, "/usr/local/bin"]), 408: {ok, {relative, B, "../lib/erlang/bin"}} 409: end 410: end, 411: install_bin(Config, 412: #inst{exec_prefix = "/usr/local", 413: bindir = "usr/local/bin", 414: erlang_bindir = "/usr/local/lib/erlang/bin"}, 415: ChkRes). 416: 417: 418: 'bin white space'(Config) when is_list(Config) -> 419: ?line E = "/u s r/local", 420: ?line Bs = "/u s r/local/b i n", 421: ?line Be = Bs, 422: ?line EBs = "/u s r/local/lib/erl ang/bin", 423: ?line EBe = EBs, 424: ?line RP = "../lib/erl ang/bin", 425: ChkRes = fun (Res, #inst{test_prefix = TP, 426: destdir = D, 427: extra_prefix = EP, 428: bindir_symlinks = BSL, 429: symlinks = SL}) -> 430: ?line B = join([TP, D, EP, Be]), 431: Expct = case {SL, BSL} of 432: {false, _} when BSL == "relative"; 433: BSL == "absolute" -> 434: ?line {error, no_ln_s}; 435: {false, _} -> 436: ?line {ok,{absolute, 437: B,join([TP,D,EP,EBe])}}; 438: {true, "absolute"} -> 439: ?line {ok,{absolute,B,join([TP,EP,EBe])}}; 440: {true, _} -> 441: ?line {ok,{relative,B,RP}} 442: end, 443: expect(Expct, Res) 444: end, 445: install_bin(Config, #inst{exec_prefix = E, 446: bindir = Bs, 447: erlang_bindir = EBs}, ChkRes). 448: 449: bin_dirname_fail(Config) when is_list(Config) -> 450: ?line E = "/opt", 451: ?line Bs = "/opt/lib/../bin", 452: ?line Be = Bs, 453: ?line EBs = "/opt/lib/erlang/otp/bin", 454: ?line EBe = EBs, 455: ?line CMDPRFX = "PATH=\""++?config(data_dir,Config)++":"++os:getenv("PATH")++"\"", 456: ChkRes = fun (Res, #inst{test_prefix = TP, 457: destdir = D, 458: extra_prefix = EP, 459: bindir_symlinks = BSL, 460: symlinks = SL}) -> 461: ?line B = join([TP, D, EP, Be]), 462: Expct = case {SL, BSL} of 463: {false, _} when BSL == "relative"; 464: BSL == "absolute" -> 465: ?line {error, no_ln_s}; 466: {false, _} -> 467: ?line {ok,{absolute, 468: B,join([TP,D,EP,EBe])}}; 469: {true, "relative"} -> 470: ?line {error, dirname_failed}; 471: {true, _} -> 472: ?line {ok,{absolute,B,join([TP,EP,EBe])}} 473: end, 474: expect(Expct, Res) 475: end, 476: install_bin(Config, #inst{cmd_prefix = CMDPRFX, 477: exec_prefix = E, 478: bindir = Bs, 479: erlang_bindir = EBs}, ChkRes). 480: 481: bin_no_use_dirname_fail(Config) when is_list(Config) -> 482: ?line E = "/opt", 483: ?line Bs = "/opt/bin", 484: ?line Be = Bs, 485: ?line EBs = "/opt/lib/erlang/otp/bin", 486: ?line EBe = EBs, 487: ?line RP = "../lib/erlang/otp/bin", 488: ?line CMDPRFX = "PATH=\""++?config(data_dir,Config)++":"++os:getenv("PATH")++"\"", 489: ChkRes = fun (Res, #inst{test_prefix = TP, 490: destdir = D, 491: extra_prefix = EP, 492: bindir_symlinks = BSL, 493: symlinks = SL}) -> 494: ?line B = join([TP, D, EP, Be]), 495: Expct = case {SL, BSL} of 496: {false, _} when BSL == "relative"; 497: BSL == "absolute" -> 498: ?line {error, no_ln_s}; 499: {false, _} -> 500: ?line {ok,{absolute, 501: B,join([TP,D,EP,EBe])}}; 502: {true, "absolute"} -> 503: ?line {ok,{absolute,B,join([TP,EP,EBe])}}; 504: {true, _} -> 505: ?line {ok,{relative,B,RP}} 506: end, 507: expect(Expct, Res) 508: end, 509: install_bin(Config, #inst{cmd_prefix = CMDPRFX, 510: exec_prefix = E, 511: bindir = Bs, 512: erlang_bindir = EBs}, ChkRes). 513: 514: bin_no_srcfile(Config) when is_list(Config) -> 515: TDir = ?config(test_dir, Config), 516: make_dirs(TDir, "/opt/local/bin"), 517: make_dirs(TDir, "/opt/local/lib/erlang/bin"), 518: Erl = join([TDir, "/opt/local/lib/erlang/bin/erl"]), 519: ok = file:write_file(Erl, "erl"), 520: Erlc = join([TDir, "/opt/local/lib/erlang/bin/erlc"]), 521: RP_Erlc = "../lib/erlang/bin/erlc", 522: ChkRes = fun (Res, #inst{bindir_symlinks = BSL, 523: symlinks = SL}) -> 524: Expct = case {SL, BSL} of 525: {false, _} when BSL == "relative"; 526: BSL == "absolute" -> 527: ?line {error, no_ln_s}; 528: {false,_} -> 529: ?line {error,{no_srcfile, Erlc}}; 530: {true, "absolute"} -> 531: ?line {error,{no_srcfile, Erlc}}; 532: {true, _} -> 533: ?line {error,{no_srcfile, RP_Erlc}} 534: end, 535: expect(Expct, Res) 536: end, 537: install_bin(Config, 538: #inst{mkdirs = false, 539: exec_prefix = "/opt/local", 540: bindir = "/opt/local/bin", 541: erlang_bindir = "/opt/local/lib/erlang/bin"}, 542: ChkRes). 543: 544: %% 545: %% 546: %% Auxiliary functions 547: %% 548: %% 549: 550: expect(X, X) -> 551: ?t:format("result: ~p~n", [X]), 552: ?t:format("-----------------------------------------------~n", []), 553: ok; 554: expect(X, Y) -> 555: ?t:format("expected: ~p~n", [X]), 556: ?t:format("got : ~p~n", [Y]), 557: ?t:format("-----------------------------------------------~n", []), 558: ?t:fail({X,Y}). 559: 560: init_per_suite(Config) -> 561: PD = ?config(priv_dir, Config), 562: SymLinks = case ?t:os_type() of 563: {win32, _} -> false; 564: _ -> 565: case file:make_symlink("nothing", 566: filename:join(PD, 567: "symlink_test")) of 568: ok -> true; 569: _ -> false 570: end 571: end, 572: [{symlinks, SymLinks} | Config]. 573: 574: end_per_suite(_Config) -> 575: ok. 576: 577: init_per_testcase(Case, Config) -> 578: init_per_testcase_aux(?config(symlinks,Config),?t:os_type(),Case,Config). 579: 580: init_per_testcase_aux(_, {win32, _}, _Case, _Config) -> 581: {skip, "Not on windows"}; 582: init_per_testcase_aux(false, OsType, Case, Config) -> 583: case lists:member(Case, need_symlink_cases()) of 584: false -> init_per_testcase_aux(true, OsType, Case, Config); 585: true -> {skip, "Cannot create symbolic links"} 586: end; 587: init_per_testcase_aux(true, _OsType, Case, Config) -> 588: Dog = ?t:timetrap(?DEFAULT_TIMEOUT), 589: [{watchdog, Dog}, 590: {testcase, Case}, 591: {test_dir, make_dirs(?config(priv_dir, Config), atom_to_list(Case))} 592: | Config]. 593: 594: end_per_testcase(_Case, Config) -> 595: Dog = ?config(watchdog, Config), 596: ?t:timetrap_cancel(Dog), 597: ok. 598: 599: 600: make_dirs(Root, Suffix) -> 601: do_make_dirs(Root, string:tokens(Suffix, [$/])). 602: 603: do_make_dirs(_Root, []) -> 604: ""; 605: do_make_dirs(Root, [D|Ds]) -> 606: Dir = filename:join(Root, D), 607: case file:make_dir(Dir) of 608: {error, eexist} -> ok; 609: ok -> ok; 610: Err -> exit({make_dir, Err}) 611: end, 612: filename:join(Dir, do_make_dirs(Dir, Ds)). 613: 614: install_bin(Config, #inst{mkdirs = MkDirs, 615: exec_prefix = EXEC_PREFIX, 616: bindir = BINDIR, 617: erlang_bindir = ERLANG_BINDIR} = Inst, ChkRes) -> 618: PDir = ?config(priv_dir, Config), 619: TDir = ?config(test_dir, Config), 620: TD = atom_to_list(?config(testcase, Config)), 621: case MkDirs of 622: false -> ok; 623: true -> 624: make_dirs(TDir, EXEC_PREFIX), 625: make_dirs(TDir, BINDIR), 626: make_dirs(TDir, ERLANG_BINDIR), 627: Erl = join([TDir, ERLANG_BINDIR, "/erl"]), 628: Erlc = join([TDir, ERLANG_BINDIR, "/erlc"]), 629: ok = file:write_file(Erl, "erl"), 630: ok = file:write_file(Erlc, "erlc") 631: end, 632: 633: install_bin2(Config, Inst#inst{destdir = TDir}, ChkRes), 634: install_bin2(Config, Inst#inst{extra_prefix = TDir}, ChkRes), 635: install_bin2(Config, Inst#inst{destdir = PDir, 636: extra_prefix = "/"++TD}, ChkRes), 637: install_bin2(Config, 638: Inst#inst{test_prefix = TDir, 639: exec_prefix = join([TDir, EXEC_PREFIX]), 640: bindir = join([TDir, BINDIR]), 641: erlang_bindir = join([TDir, ERLANG_BINDIR])}, 642: ChkRes), 643: case ?config(symlinks, Config) of 644: true -> ok; 645: false -> {comment, "No symlink tests run, since symlinks not working"} 646: end. 647: 648: 649: install_bin2(Config, Inst, ChkRes) -> 650: install_bin3(Config, Inst#inst{symlinks = false, 651: ln_s = "ln"}, ChkRes), 652: install_bin3(Config, Inst#inst{symlinks = false, 653: ln_s = "ln", 654: bindir_symlinks = "relative"}, ChkRes), 655: install_bin3(Config, Inst#inst{symlinks = false, 656: ln_s = "ln", 657: bindir_symlinks = "absolute"}, ChkRes), 658: install_bin3(Config, Inst#inst{symlinks = false, 659: ln_s = "cp -p"}, ChkRes), 660: install_bin3(Config, Inst#inst{symlinks = false, 661: ln_s = "cp -p", 662: bindir_symlinks = "relative"}, ChkRes), 663: install_bin3(Config, Inst#inst{symlinks = false, 664: ln_s = "cp -p", 665: bindir_symlinks = "absolute"}, ChkRes), 666: case ?config(symlinks, Config) of 667: true -> 668: install_bin3(Config, Inst#inst{symlinks = true, 669: ln_s = "ln -s"}, ChkRes), 670: install_bin3(Config, Inst#inst{symlinks = true, 671: ln_s = "ln -s", 672: bindir_symlinks = "relative"}, ChkRes), 673: install_bin3(Config, Inst#inst{symlinks = true, 674: ln_s = "ln -s", 675: bindir_symlinks = "absolute"}, ChkRes); 676: false -> 677: ok 678: end. 679: 680: 681: 682: install_bin3(Config, 683: #inst{cmd_prefix = CMD_PRFX, 684: ln_s = LN_S, 685: destdir = DESTDIR, 686: extra_prefix = EXTRA_PREFIX, 687: exec_prefix = EXEC_PREFIX, 688: bindir = BINDIR, 689: erlang_bindir = ERLANG_BINDIR, 690: bindir_symlinks = BINDIR_SYMLINKS} = Inst, 691: ChkRes) -> 692: Test = ?config(testcase, Config), 693: DDir = ?config(data_dir, Config), 694: TDir = ?config(test_dir, Config), 695: InstallBin = filename:join(DDir, "install_bin"), 696: ResFile = filename:join(TDir, atom_to_list(Test) ++ "-result.txt"), 697: Cmd = CMD_PRFX ++ " " 698: ++ InstallBin ++ " --ln_s \"" ++ LN_S 699: ++ "\" --destdir \"" ++ DESTDIR 700: ++ "\" --extra-prefix \"" ++ EXTRA_PREFIX 701: ++ "\" --bindir-symlinks \"" ++ BINDIR_SYMLINKS 702: ++ "\" --bindir \"" ++ BINDIR 703: ++ "\" --erlang-bindir \"" ++ ERLANG_BINDIR 704: ++ "\" --exec-prefix \"" ++ EXEC_PREFIX 705: ++ "\" --test-file \"" ++ ResFile ++ "\" erl erlc", 706: 707: ?t:format("CMD_PRFX = \"~s\"~n" 708: "LN_S = \"~s\"~n" 709: "BINDIR_SYMLINKS = \"~s\"~n" 710: "exec_prefix = \"~s\"~n" 711: "bindir = \"~s\"~n" 712: "erlang_bindir = \"~s\"~n" 713: "EXTRA_PREFIX = \"~s\"~n" 714: "DESTDIR = \"~s\"~n", 715: [CMD_PRFX, LN_S, BINDIR_SYMLINKS, EXEC_PREFIX, BINDIR, 716: ERLANG_BINDIR, EXTRA_PREFIX, DESTDIR]), 717: 718: ?t:format("$ ~s~n", [Cmd]), 719: CmdOutput = os:cmd(Cmd), 720: ?t:format("~s~n", [CmdOutput]), 721: ChkRes(case file:consult(ResFile) of 722: {ok, [Res]} -> Res; 723: Err -> exit({result, Err}) 724: end, 725: Inst). 726: 727: join("") -> 728: ""; 729: join([""|Ds]) -> 730: join(Ds); 731: join([D|Ds]) -> 732: "/" ++ string:strip(D, both, $/) ++ join(Ds). 733: